| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/metrics_log_base.h" | 5 #include "chrome/common/metrics/metrics_log_base.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 DCHECK(!locked_); | 445 DCHECK(!locked_); |
| 446 | 446 |
| 447 int result = xmlTextWriterEndElement(xml_wrapper_->writer()); | 447 int result = xmlTextWriterEndElement(xml_wrapper_->writer()); |
| 448 DCHECK_GE(result, 0); | 448 DCHECK_GE(result, 0); |
| 449 } | 449 } |
| 450 | 450 |
| 451 // TODO(JAR): A The following should really be part of the histogram class. | 451 // TODO(JAR): A The following should really be part of the histogram class. |
| 452 // Internal state is being needlessly exposed, and it would be hard to reuse | 452 // Internal state is being needlessly exposed, and it would be hard to reuse |
| 453 // this code. If we moved this into the Histogram class, then we could use | 453 // this code. If we moved this into the Histogram class, then we could use |
| 454 // the same infrastructure for logging StatsCounters, RatesCounters, etc. | 454 // the same infrastructure for logging StatsCounters, RatesCounters, etc. |
| 455 void MetricsLogBase::RecordHistogramDelta( | 455 void MetricsLogBase::RecordHistogramDelta(const std::string& histogram_name, |
| 456 const Histogram& histogram, | 456 const HistogramSamples& snapshot) { |
| 457 const HistogramSamples& snapshot) { | |
| 458 DCHECK(!locked_); | 457 DCHECK(!locked_); |
| 459 DCHECK_NE(0, snapshot.TotalCount()); | 458 DCHECK_NE(0, snapshot.TotalCount()); |
| 460 | 459 |
| 461 // We will ignore the MAX_INT/infinite value in the last element of range[]. | 460 // We will ignore the MAX_INT/infinite value in the last element of range[]. |
| 462 | 461 |
| 463 OPEN_ELEMENT_FOR_SCOPE("histogram"); | 462 OPEN_ELEMENT_FOR_SCOPE("histogram"); |
| 464 | 463 |
| 465 std::string base64_name_hash; | 464 std::string base64_name_hash; |
| 466 uint64 numeric_name_hash; | 465 uint64 numeric_name_hash; |
| 467 CreateHashes(histogram.histogram_name(), | 466 CreateHashes(histogram_name, &base64_name_hash, &numeric_name_hash); |
| 468 &base64_name_hash, | |
| 469 &numeric_name_hash); | |
| 470 | 467 |
| 471 // Write the XML version. | 468 // Write the XML version. |
| 472 WriteAttribute("name", base64_name_hash); | 469 WriteAttribute("name", base64_name_hash); |
| 473 | 470 |
| 474 WriteInt64Attribute("sum", snapshot.sum()); | 471 WriteInt64Attribute("sum", snapshot.sum()); |
| 475 // TODO(jar): Remove sumsquares when protobuffer accepts this as optional. | 472 // TODO(jar): Remove sumsquares when protobuffer accepts this as optional. |
| 476 WriteInt64Attribute("sumsquares", 0); | 473 WriteInt64Attribute("sumsquares", 0); |
| 477 | 474 |
| 478 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); | 475 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); |
| 479 !it->Done(); | 476 !it->Done(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 503 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); | 500 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); |
| 504 bucket->set_min(min); | 501 bucket->set_min(min); |
| 505 bucket->set_max(max); | 502 bucket->set_max(max); |
| 506 bucket->set_count(count); | 503 bucket->set_count(count); |
| 507 | 504 |
| 508 size_t index; | 505 size_t index; |
| 509 if (it->GetBucketIndex(&index)) | 506 if (it->GetBucketIndex(&index)) |
| 510 bucket->set_bucket_index(index); | 507 bucket->set_bucket_index(index); |
| 511 } | 508 } |
| 512 } | 509 } |
| OLD | NEW |