| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/common/metrics_helpers.h" | 5 #include "chrome/common/metrics_helpers.h" |
| 6 | 6 |
| 7 #if defined(USE_SYSTEM_LIBBZ2) | 7 #if defined(USE_SYSTEM_LIBBZ2) |
| 8 #include <bzlib.h> | 8 #include <bzlib.h> |
| 9 #else | 9 #else |
| 10 #include "third_party/bzip2/bzlib.h" | 10 #include "third_party/bzip2/bzlib.h" |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 ++it) { | 477 ++it) { |
| 478 if ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag) | 478 if ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag) |
| 479 RecordHistogram(**it); | 479 RecordHistogram(**it); |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 void MetricsServiceBase::RecordHistogram(const Histogram& histogram) { | 483 void MetricsServiceBase::RecordHistogram(const Histogram& histogram) { |
| 484 // Get up-to-date snapshot of sample stats. | 484 // Get up-to-date snapshot of sample stats. |
| 485 Histogram::SampleSet snapshot; | 485 Histogram::SampleSet snapshot; |
| 486 histogram.SnapshotSample(&snapshot); | 486 histogram.SnapshotSample(&snapshot); |
| 487 |
| 487 const std::string& histogram_name = histogram.histogram_name(); | 488 const std::string& histogram_name = histogram.histogram_name(); |
| 488 | 489 |
| 489 int corruption = histogram.FindCorruption(snapshot); | |
| 490 if (corruption) { | |
| 491 NOTREACHED(); | |
| 492 // Don't send corrupt data to metrics survices. | |
| 493 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser", | |
| 494 corruption, Histogram::NEVER_EXCEEDED_VALUE); | |
| 495 typedef std::map<std::string, int> ProblemMap; | |
| 496 static ProblemMap* inconsistencies = new ProblemMap; | |
| 497 int old_corruption = (*inconsistencies)[histogram_name]; | |
| 498 if (old_corruption == (corruption | old_corruption)) | |
| 499 return; // We've already seen this corruption for this histogram. | |
| 500 (*inconsistencies)[histogram_name] |= corruption; | |
| 501 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", | |
| 502 corruption, Histogram::NEVER_EXCEEDED_VALUE); | |
| 503 return; | |
| 504 } | |
| 505 | |
| 506 // Find the already sent stats, or create an empty set. | 490 // Find the already sent stats, or create an empty set. |
| 507 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); | 491 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); |
| 508 Histogram::SampleSet* already_logged; | 492 Histogram::SampleSet* already_logged; |
| 509 if (logged_samples_.end() == it) { | 493 if (logged_samples_.end() == it) { |
| 510 // Add new entry | 494 // Add new entry |
| 511 already_logged = &logged_samples_[histogram.histogram_name()]; | 495 already_logged = &logged_samples_[histogram.histogram_name()]; |
| 512 already_logged->Resize(histogram); // Complete initialization. | 496 already_logged->Resize(histogram); // Complete initialization. |
| 513 } else { | 497 } else { |
| 514 already_logged = &(it->second); | 498 already_logged = &(it->second); |
| 515 // Deduct any stats we've already logged from our snapshot. | 499 // Deduct any stats we've already logged from our snapshot. |
| 516 snapshot.Subtract(*already_logged); | 500 snapshot.Subtract(*already_logged); |
| 517 } | 501 } |
| 518 | 502 |
| 519 // Snapshot now contains only a delta to what we've already_logged. | 503 // Snapshot now contains only a delta to what we've already_logged. |
| 520 | 504 |
| 521 if (snapshot.TotalCount() > 0) { | 505 if (snapshot.TotalCount() > 0) { |
| 522 current_log_->RecordHistogramDelta(histogram, snapshot); | 506 current_log_->RecordHistogramDelta(histogram, snapshot); |
| 523 // Add new data into our running total. | 507 // Add new data into our running total. |
| 524 already_logged->Add(snapshot); | 508 already_logged->Add(snapshot); |
| 525 } | 509 } |
| 526 } | 510 } |
| 527 | 511 |
| 528 void MetricsServiceBase::DiscardPendingLog() { | 512 void MetricsServiceBase::DiscardPendingLog() { |
| 529 if (pending_log_) { // Shutdown might have deleted it! | 513 if (pending_log_) { // Shutdown might have deleted it! |
| 530 delete pending_log_; | 514 delete pending_log_; |
| 531 pending_log_ = NULL; | 515 pending_log_ = NULL; |
| 532 } | 516 } |
| 533 compressed_log_.clear(); | 517 compressed_log_.clear(); |
| 534 } | 518 } |
| OLD | NEW |