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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.cc

Issue 6765035: More PrefixSet diagnostics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/safe_browsing/safe_browsing_database.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 PREFIX_SET_EVENT_HIT, 214 PREFIX_SET_EVENT_HIT,
215 PREFIX_SET_EVENT_BLOOM_HIT, 215 PREFIX_SET_EVENT_BLOOM_HIT,
216 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT, 216 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT,
217 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT_INVALID, 217 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT_INVALID,
218 PREFIX_SET_GETPREFIXES_BROKEN, 218 PREFIX_SET_GETPREFIXES_BROKEN,
219 PREFIX_SET_GETPREFIXES_BROKEN_SIZE, 219 PREFIX_SET_GETPREFIXES_BROKEN_SIZE,
220 PREFIX_SET_GETPREFIXES_FIRST_BROKEN, 220 PREFIX_SET_GETPREFIXES_FIRST_BROKEN,
221 PREFIX_SET_SBPREFIX_WAS_BROKEN, 221 PREFIX_SET_SBPREFIX_WAS_BROKEN,
222 PREFIX_SET_GETPREFIXES_BROKEN_SORTING, 222 PREFIX_SET_GETPREFIXES_BROKEN_SORTING,
223 PREFIX_SET_GETPREFIXES_BROKEN_DUPLICATION, 223 PREFIX_SET_GETPREFIXES_BROKEN_DUPLICATION,
224 PREFIX_SET_GETPREFIX_UNSORTED_IS_DELTA,
225 PREFIX_SET_GETPREFIX_UNSORTED_IS_INDEX,
224 226
225 // Memory space for histograms is determined by the max. ALWAYS ADD 227 // Memory space for histograms is determined by the max. ALWAYS ADD
226 // NEW VALUES BEFORE THIS ONE. 228 // NEW VALUES BEFORE THIS ONE.
227 PREFIX_SET_EVENT_MAX 229 PREFIX_SET_EVENT_MAX
228 }; 230 };
229 231
230 void RecordPrefixSetInfo(PrefixSetEvent event_type) { 232 void RecordPrefixSetInfo(PrefixSetEvent event_type) {
231 UMA_HISTOGRAM_ENUMERATION("SB2.PrefixSetEvent", event_type, 233 UMA_HISTOGRAM_ENUMERATION("SB2.PrefixSetEvent", event_type,
232 PREFIX_SET_EVENT_MAX); 234 PREFIX_SET_EVENT_MAX);
233 } 235 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 logged_broken = true; 280 logged_broken = true;
279 } 281 }
280 282
281 // This seems so very very unlikely. But if it ever were true, then 283 // This seems so very very unlikely. But if it ever were true, then
282 // it could explain why GetPrefixes() seemed broken. 284 // it could explain why GetPrefixes() seemed broken.
283 if (sizeof(int) != sizeof(int32)) 285 if (sizeof(int) != sizeof(int32))
284 RecordPrefixSetInfo(PREFIX_SET_SBPREFIX_WAS_BROKEN); 286 RecordPrefixSetInfo(PREFIX_SET_SBPREFIX_WAS_BROKEN);
285 287
286 // Check whether |restored| is unsorted, or has duplication. 288 // Check whether |restored| is unsorted, or has duplication.
287 if (restored.size()) { 289 if (restored.size()) {
288 bool unsorted = false; 290 size_t unsorted_count = 0;
289 bool duplicates = false; 291 bool duplicates = false;
290 std::vector<SBPrefix>::const_iterator prev = restored.begin(); 292 SBPrefix prev = restored[0];
291 for (std::vector<SBPrefix>::const_iterator iter = prev + 1; 293 for (size_t i = 0; i < restored.size(); prev = restored[i], ++i) {
292 iter != restored.end(); prev = iter, ++iter) { 294 if (prev > restored[i]) {
293 if (*prev > *iter) 295 unsorted_count++;
294 unsorted = true; 296 UMA_HISTOGRAM_COUNTS("SB2.PrefixSetUnsortedDifference",
295 if (*prev == *iter) 297 prev - restored[i]);
298
299 // When unsorted, how big is the set, and how far are we into
300 // it. If the set is very small or large, that might inform
301 // pursuit of a degenerate case. If the percentage is close
302 // to 0%, 100%, or 50%, then there might be an interesting
303 // degenerate case to explore.
304 UMA_HISTOGRAM_COUNTS("SB2.PrefixSetUnsortedSize", restored.size());
305 UMA_HISTOGRAM_PERCENTAGE("SB2.PrefixSetUnsortedPercent",
306 i * 100 / restored.size());
307
308 if (prefix_set->IsDeltaAt(i)) {
309 RecordPrefixSetInfo(PREFIX_SET_GETPREFIX_UNSORTED_IS_DELTA);
310
311 // Histograms require memory on the order of the number of
312 // buckets, making high-precision logging expensive. For
313 // now aim for a sense of the range of the problem.
314 UMA_HISTOGRAM_CUSTOM_COUNTS("SB2.PrefixSetUnsortedDelta",
315 prefix_set->DeltaAt(i), 1, 0xFFFF, 50);
316 } else {
317 RecordPrefixSetInfo(PREFIX_SET_GETPREFIX_UNSORTED_IS_INDEX);
318 }
319 }
320 if (prev == restored[i])
296 duplicates = true; 321 duplicates = true;
297 } 322 }
298 323
299 // Record findings. 324 // Record findings.
300 if (unsorted) 325 if (unsorted_count) {
301 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_BROKEN_SORTING); 326 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_BROKEN_SORTING);
327 UMA_HISTOGRAM_COUNTS_100("SB2.PrefixSetUnsorted", unsorted_count);
328 }
302 if (duplicates) 329 if (duplicates)
303 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_BROKEN_DUPLICATION); 330 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_BROKEN_DUPLICATION);
304 331
305 // Fix the problems noted. If |restored| was unsorted, then 332 // Fix the problems noted. If |restored| was unsorted, then
306 // |duplicates| may give a false negative. 333 // |duplicates| may give a false negative.
307 if (unsorted) 334 if (unsorted_count)
308 std::sort(restored.begin(), restored.end()); 335 std::sort(restored.begin(), restored.end());
309 if (unsorted || duplicates) 336 if (unsorted_count || duplicates)
310 restored.erase(std::unique(restored.begin(), restored.end()), 337 restored.erase(std::unique(restored.begin(), restored.end()),
311 restored.end()); 338 restored.end());
312 } 339 }
313 340
314 // NOTE(shess): The following could be done using a single 341 // NOTE(shess): The following could be done using a single
315 // uber-loop, but it's complicated by needing multiple parallel 342 // uber-loop, but it's complicated by needing multiple parallel
316 // iterators. Didn't seem worthwhile for something that will only 343 // iterators. Didn't seem worthwhile for something that will only
317 // live for a short period and only fires for one in a million 344 // live for a short period and only fires for one in a million
318 // updates. 345 // updates.
319 346
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 if (std::binary_search(new_csd_whitelist.begin(), new_csd_whitelist.end(), 1279 if (std::binary_search(new_csd_whitelist.begin(), new_csd_whitelist.end(),
1253 kill_switch)) { 1280 kill_switch)) {
1254 // The kill switch is whitelisted hence we whitelist all URLs. 1281 // The kill switch is whitelisted hence we whitelist all URLs.
1255 CsdWhitelistAllUrls(); 1282 CsdWhitelistAllUrls();
1256 } else { 1283 } else {
1257 base::AutoLock locked(lookup_lock_); 1284 base::AutoLock locked(lookup_lock_);
1258 csd_whitelist_all_urls_ = false; 1285 csd_whitelist_all_urls_ = false;
1259 csd_whitelist_.swap(new_csd_whitelist); 1286 csd_whitelist_.swap(new_csd_whitelist);
1260 } 1287 }
1261 } 1288 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698