Chromium Code Reviews| Index: chrome/browser/metrics/metrics_log_serializer.cc |
| diff --git a/chrome/browser/metrics/metrics_log_serializer.cc b/chrome/browser/metrics/metrics_log_serializer.cc |
| index 3369f85a7a630d2fb4048732e554a3b5d0a8c320..b7d01c959bf2f792bab979adac599f740bbd0a39 100644 |
| --- a/chrome/browser/metrics/metrics_log_serializer.cc |
| +++ b/chrome/browser/metrics/metrics_log_serializer.cc |
| @@ -30,6 +30,12 @@ const size_t kMaxInitialLogsPersisted = 20; |
| // ongoing_log_ at startup). |
| const size_t kMaxOngoingLogsPersisted = 8; |
| +// The number of bytes each of initial and ongoing logs that must be reached |
| +// before the count-based limits above will be enforced. This ensures that a |
| +// reasonable amount of history will be stored even if there is a long series |
| +// of very small logs. |
| +const size_t kMinStorageBytesPerLogType = 300000; |
| + |
| // We append (2) more elements to persisted lists: the size of the list and a |
| // checksum of the elements. |
| const size_t kChecksumEntryCount = 2; |
| @@ -94,11 +100,13 @@ void MetricsLogSerializer::SerializeLogs( |
| // Write the XML version. |
| ListPrefUpdate update_xml(local_state, pref_xml); |
| - WriteLogsToPrefList(logs, true, max_store_count, update_xml.Get()); |
| + WriteLogsToPrefList(logs, true, max_store_count, kMinStorageBytesPerLogType, |
| + update_xml.Get()); |
| // Write the protobuf version. |
| ListPrefUpdate update_proto(local_state, pref_proto); |
| - WriteLogsToPrefList(logs, false, max_store_count, update_proto.Get()); |
| + WriteLogsToPrefList(logs, false, max_store_count, kMinStorageBytesPerLogType, |
| + update_proto.Get()); |
| } |
| void MetricsLogSerializer::DeserializeLogs( |
| @@ -131,14 +139,32 @@ void MetricsLogSerializer::DeserializeLogs( |
| void MetricsLogSerializer::WriteLogsToPrefList( |
| const std::vector<MetricsLogManager::SerializedLog>& local_list, |
| bool is_xml, |
| - size_t max_list_size, |
| + size_t max_list_length, |
| + size_t min_bytes, |
|
jar (doing other things)
2012/05/10 16:49:40
This should be max_bytes.
stuartmorgan
2012/05/11 09:16:40
Why? In the new model it behaves as a minimum, not
jar (doing other things)
2012/05/11 21:36:50
Both lines 142 and 143 represent limits. When tho
stuartmorgan
2012/05/15 15:57:05
Good point; I'll change them both to limit (see be
jar (doing other things)
2012/05/15 18:27:39
I'm fine with the word "limit."
I think the diffe
|
| base::ListValue* list) { |
| + // One of the limit arguments must be non-zero. |
| + DCHECK(max_list_length > 0 || min_bytes > 0); |
|
jar (doing other things)
2012/05/10 16:49:40
nit: I think you're using a 0 to mean "don't check
stuartmorgan
2012/05/11 09:16:40
It doesn't mean don't check. Passing both argument
jar (doing other things)
2012/05/11 21:36:50
If you don't want to persist unsent logs, I'd expe
stuartmorgan
2012/05/15 15:57:05
I would expect someone who doesn't want to persist
|
| + |
| list->Clear(); |
| - size_t start = 0; |
| - if (local_list.size() > max_list_size) |
| - start = local_list.size() - max_list_size; |
|
jar (doing other things)
2012/05/10 16:49:40
IMO, it would be much easier to read (not to menti
stuartmorgan
2012/05/11 09:16:40
Done.
|
| - DCHECK_LE(start, local_list.size()); |
| - if (local_list.size() <= start) |
| + if (local_list.size() == 0) |
| + return; |
| + |
| + // Keep the most recent logs, up to the size limit. |
| + size_t start = local_list.size(); |
| + size_t bytes_used = 0; |
| + for (std::vector<MetricsLogManager::SerializedLog>::const_reverse_iterator |
| + it = local_list.rbegin(); it != local_list.rend(); ++it) { |
| + // TODO(isherman): Always uses XML length so both formats of a given log |
| + // will be saved; switch to proto once that's the primary format. |
| + size_t log_size = it->xml.length(); |
| + bytes_used += log_size; |
| + --start; |
|
jar (doing other things)
2012/05/11 21:36:50
IT surprised me a bit that you decremented start h
stuartmorgan
2012/05/15 15:57:05
Since the method is currently designed such that i
|
| + if ((min_bytes == 0 || bytes_used > min_bytes) && |
|
jar (doing other things)
2012/05/10 16:49:40
The test for ==0 seemed superfluous, and made this
stuartmorgan
2012/05/11 09:16:40
Done.
|
| + (local_list.size() - start) >= max_list_length) |
| + break; |
| + } |
| + DCHECK_LT(start, local_list.size()); |
| + if (start == local_list.size()) |
|
jar (doing other things)
2012/05/10 16:49:40
The DCHECK makes it clear that we should never hav
stuartmorgan
2012/05/11 09:16:40
Actually, the whole if check goes against Chromium
jar (doing other things)
2012/05/11 21:36:50
I don't know where you heard such, as it is not in
stuartmorgan
2012/05/11 22:04:37
Not only is it in our style guide, it's one of the
jar (doing other things)
2012/05/15 18:27:39
I went around on this with Darin. The style guide
stuartmorgan
2012/05/15 19:02:58
I can re-add the error-handling. (I'm not clear ho
|
| return; |
| // Store size at the beginning of the list. |