Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/metrics/metrics_log_serializer.cc

Issue 9562007: Add a minimum byte count to metrics log serialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use the byte count as a minimum Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/metrics_log_serializer.h" 5 #include "chrome/browser/metrics/metrics_log_serializer.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/md5.h" 8 #include "base/md5.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 12 matching lines...) Expand all
23 // send during a this or future sessions. Note that each log may be pretty 23 // send during a this or future sessions. Note that each log may be pretty
24 // large, as presumably the related "initial" log wasn't sent (probably nothing 24 // large, as presumably the related "initial" log wasn't sent (probably nothing
25 // was, as the user was probably off-line). As a result, the log probably kept 25 // was, as the user was probably off-line). As a result, the log probably kept
26 // accumulating while the "initial" log was stalled, and couldn't be sent. As a 26 // accumulating while the "initial" log was stalled, and couldn't be sent. As a
27 // result, we don't want to save too many of these mega-logs. 27 // result, we don't want to save too many of these mega-logs.
28 // A "standard shutdown" will create a small log, including just the data that 28 // A "standard shutdown" will create a small log, including just the data that
29 // was not yet been transmitted, and that is normal (to have exactly one 29 // was not yet been transmitted, and that is normal (to have exactly one
30 // ongoing_log_ at startup). 30 // ongoing_log_ at startup).
31 const size_t kMaxOngoingLogsPersisted = 8; 31 const size_t kMaxOngoingLogsPersisted = 8;
32 32
33 // The number of bytes each of initial and ongoing logs that must be reached
34 // before the count-based limits above will be enforced. This ensures that a
35 // reasonable amount of history will be stored even if there is a long series
36 // of very small logs.
37 const size_t kMinStorageBytesPerLogType = 300000;
38
33 // We append (2) more elements to persisted lists: the size of the list and a 39 // We append (2) more elements to persisted lists: the size of the list and a
34 // checksum of the elements. 40 // checksum of the elements.
35 const size_t kChecksumEntryCount = 2; 41 const size_t kChecksumEntryCount = 2;
36 42
37 // TODO(isherman): Remove this histogram once it's confirmed that there are no 43 // TODO(isherman): Remove this histogram once it's confirmed that there are no
38 // encoding failures for protobuf logs. 44 // encoding failures for protobuf logs.
39 enum LogStoreStatus { 45 enum LogStoreStatus {
40 STORE_SUCCESS, // Successfully presisted log. 46 STORE_SUCCESS, // Successfully presisted log.
41 ENCODE_FAIL, // Failed to encode log. 47 ENCODE_FAIL, // Failed to encode log.
42 COMPRESS_FAIL, // Failed to compress log. 48 COMPRESS_FAIL, // Failed to compress log.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 pref_proto = prefs::kMetricsOngoingLogsProto; 93 pref_proto = prefs::kMetricsOngoingLogsProto;
88 max_store_count = kMaxOngoingLogsPersisted; 94 max_store_count = kMaxOngoingLogsPersisted;
89 break; 95 break;
90 default: 96 default:
91 NOTREACHED(); 97 NOTREACHED();
92 return; 98 return;
93 }; 99 };
94 100
95 // Write the XML version. 101 // Write the XML version.
96 ListPrefUpdate update_xml(local_state, pref_xml); 102 ListPrefUpdate update_xml(local_state, pref_xml);
97 WriteLogsToPrefList(logs, true, max_store_count, update_xml.Get()); 103 WriteLogsToPrefList(logs, true, max_store_count, kMinStorageBytesPerLogType,
104 update_xml.Get());
98 105
99 // Write the protobuf version. 106 // Write the protobuf version.
100 ListPrefUpdate update_proto(local_state, pref_proto); 107 ListPrefUpdate update_proto(local_state, pref_proto);
101 WriteLogsToPrefList(logs, false, max_store_count, update_proto.Get()); 108 WriteLogsToPrefList(logs, false, max_store_count, kMinStorageBytesPerLogType,
109 update_proto.Get());
102 } 110 }
103 111
104 void MetricsLogSerializer::DeserializeLogs( 112 void MetricsLogSerializer::DeserializeLogs(
105 MetricsLogManager::LogType log_type, 113 MetricsLogManager::LogType log_type,
106 std::vector<MetricsLogManager::SerializedLog>* logs) { 114 std::vector<MetricsLogManager::SerializedLog>* logs) {
107 DCHECK(logs); 115 DCHECK(logs);
108 PrefService* local_state = g_browser_process->local_state(); 116 PrefService* local_state = g_browser_process->local_state();
109 DCHECK(local_state); 117 DCHECK(local_state);
110 118
111 const char* pref_xml; 119 const char* pref_xml;
(...skipping 12 matching lines...) Expand all
124 // In order to try to keep the data sent to both servers roughly in sync, 132 // In order to try to keep the data sent to both servers roughly in sync,
125 // only read the protobuf data if we read the XML data successfully. 133 // only read the protobuf data if we read the XML data successfully.
126 ReadLogsFromPrefList(*unsent_logs_proto, false, logs); 134 ReadLogsFromPrefList(*unsent_logs_proto, false, logs);
127 } 135 }
128 } 136 }
129 137
130 // static 138 // static
131 void MetricsLogSerializer::WriteLogsToPrefList( 139 void MetricsLogSerializer::WriteLogsToPrefList(
132 const std::vector<MetricsLogManager::SerializedLog>& local_list, 140 const std::vector<MetricsLogManager::SerializedLog>& local_list,
133 bool is_xml, 141 bool is_xml,
134 size_t max_list_size, 142 size_t max_list_length,
143 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
135 base::ListValue* list) { 144 base::ListValue* list) {
145 // One of the limit arguments must be non-zero.
146 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
147
136 list->Clear(); 148 list->Clear();
137 size_t start = 0; 149 if (local_list.size() == 0)
138 if (local_list.size() > max_list_size) 150 return;
139 start = local_list.size() - max_list_size; 151
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.
140 DCHECK_LE(start, local_list.size()); 152 // Keep the most recent logs, up to the size limit.
141 if (local_list.size() <= start) 153 size_t start = local_list.size();
154 size_t bytes_used = 0;
155 for (std::vector<MetricsLogManager::SerializedLog>::const_reverse_iterator
156 it = local_list.rbegin(); it != local_list.rend(); ++it) {
157 // TODO(isherman): Always uses XML length so both formats of a given log
158 // will be saved; switch to proto once that's the primary format.
159 size_t log_size = it->xml.length();
160 bytes_used += log_size;
161 --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
162 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.
163 (local_list.size() - start) >= max_list_length)
164 break;
165 }
166 DCHECK_LT(start, local_list.size());
167 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
142 return; 168 return;
143 169
144 // Store size at the beginning of the list. 170 // Store size at the beginning of the list.
145 list->Append(Value::CreateIntegerValue(local_list.size() - start)); 171 list->Append(Value::CreateIntegerValue(local_list.size() - start));
146 172
147 base::MD5Context ctx; 173 base::MD5Context ctx;
148 base::MD5Init(&ctx); 174 base::MD5Init(&ctx);
149 std::string encoded_log; 175 std::string encoded_log;
150 for (std::vector<MetricsLogManager::SerializedLog>::const_iterator it = 176 for (std::vector<MetricsLogManager::SerializedLog>::const_iterator it =
151 local_list.begin() + start; 177 local_list.begin() + start;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (!valid) { 262 if (!valid) {
237 local_list->clear(); 263 local_list->clear();
238 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION, is_xml); 264 return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION, is_xml);
239 } 265 }
240 if (recovered_md5 != base::MD5DigestToBase16(digest)) { 266 if (recovered_md5 != base::MD5DigestToBase16(digest)) {
241 local_list->clear(); 267 local_list->clear();
242 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION, is_xml); 268 return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION, is_xml);
243 } 269 }
244 return MakeRecallStatusHistogram(RECALL_SUCCESS, is_xml); 270 return MakeRecallStatusHistogram(RECALL_SUCCESS, is_xml);
245 } 271 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log_serializer.h ('k') | chrome/browser/metrics/metrics_log_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698