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

Side by Side Diff: base/metrics/histogram.cc

Issue 6976044: Fix http://codereview.chromium.org/6869009 to ignore an existing object exactly once and land the... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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
« no previous file with comments | « base/debug/leak_annotations.h ('k') | net/disk_cache/stats.cc » ('j') | 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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 // See header file for details and examples. 8 // See header file for details and examples.
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 11
12 #include <math.h> 12 #include <math.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <string> 15 #include <string>
16 16
17 #include "base/debug/leak_annotations.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/pickle.h" 19 #include "base/pickle.h"
19 #include "base/stringprintf.h" 20 #include "base/stringprintf.h"
20 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
21 22
22 namespace base { 23 namespace base {
23 24
24 // Static table of checksums for all possible 8 bit bytes. 25 // Static table of checksums for all possible 8 bit bytes.
25 const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL, 26 const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL,
26 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L, 27 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Extra variable is not needed... but this keeps this section basically 91 // Extra variable is not needed... but this keeps this section basically
91 // identical to other derived classes in this file (and compiler will 92 // identical to other derived classes in this file (and compiler will
92 // optimize away the extra variable. 93 // optimize away the extra variable.
93 // To avoid racy destruction at shutdown, the following will be leaked. 94 // To avoid racy destruction at shutdown, the following will be leaked.
94 Histogram* tentative_histogram = 95 Histogram* tentative_histogram =
95 new Histogram(name, minimum, maximum, bucket_count); 96 new Histogram(name, minimum, maximum, bucket_count);
96 tentative_histogram->InitializeBucketRange(); 97 tentative_histogram->InitializeBucketRange();
97 tentative_histogram->SetFlags(flags); 98 tentative_histogram->SetFlags(flags);
98 histogram = 99 histogram =
99 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 100 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
101 if (histogram == tentative_histogram)
102 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
100 } 103 }
101 104
102 DCHECK_EQ(HISTOGRAM, histogram->histogram_type()); 105 DCHECK_EQ(HISTOGRAM, histogram->histogram_type());
103 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); 106 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
104 return histogram; 107 return histogram;
105 } 108 }
106 109
107 Histogram* Histogram::FactoryTimeGet(const std::string& name, 110 Histogram* Histogram::FactoryTimeGet(const std::string& name,
108 TimeDelta minimum, 111 TimeDelta minimum,
109 TimeDelta maximum, 112 TimeDelta maximum,
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 maximum = kSampleType_MAX - 1; 787 maximum = kSampleType_MAX - 1;
785 788
786 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { 789 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
787 // To avoid racy destruction at shutdown, the following will be leaked. 790 // To avoid racy destruction at shutdown, the following will be leaked.
788 LinearHistogram* tentative_histogram = 791 LinearHistogram* tentative_histogram =
789 new LinearHistogram(name, minimum, maximum, bucket_count); 792 new LinearHistogram(name, minimum, maximum, bucket_count);
790 tentative_histogram->InitializeBucketRange(); 793 tentative_histogram->InitializeBucketRange();
791 tentative_histogram->SetFlags(flags); 794 tentative_histogram->SetFlags(flags);
792 histogram = 795 histogram =
793 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 796 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
797 if (histogram == tentative_histogram)
798 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
794 } 799 }
795 800
796 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); 801 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type());
797 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); 802 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
798 return histogram; 803 return histogram;
799 } 804 }
800 805
801 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name, 806 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name,
802 TimeDelta minimum, 807 TimeDelta minimum,
803 TimeDelta maximum, 808 TimeDelta maximum,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) { 880 Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) {
876 Histogram* histogram(NULL); 881 Histogram* histogram(NULL);
877 882
878 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { 883 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
879 // To avoid racy destruction at shutdown, the following will be leaked. 884 // To avoid racy destruction at shutdown, the following will be leaked.
880 BooleanHistogram* tentative_histogram = new BooleanHistogram(name); 885 BooleanHistogram* tentative_histogram = new BooleanHistogram(name);
881 tentative_histogram->InitializeBucketRange(); 886 tentative_histogram->InitializeBucketRange();
882 tentative_histogram->SetFlags(flags); 887 tentative_histogram->SetFlags(flags);
883 histogram = 888 histogram =
884 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 889 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
890 if (histogram == tentative_histogram)
891 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
885 } 892 }
886 893
887 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); 894 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type());
888 return histogram; 895 return histogram;
889 } 896 }
890 897
891 Histogram::ClassType BooleanHistogram::histogram_type() const { 898 Histogram::ClassType BooleanHistogram::histogram_type() const {
892 return BOOLEAN_HISTOGRAM; 899 return BOOLEAN_HISTOGRAM;
893 } 900 }
894 901
(...skipping 27 matching lines...) Expand all
922 929
923 DCHECK_LT(ranges.back(), kSampleType_MAX); 930 DCHECK_LT(ranges.back(), kSampleType_MAX);
924 931
925 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { 932 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
926 // To avoid racy destruction at shutdown, the following will be leaked. 933 // To avoid racy destruction at shutdown, the following will be leaked.
927 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); 934 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges);
928 tentative_histogram->InitializedCustomBucketRange(ranges); 935 tentative_histogram->InitializedCustomBucketRange(ranges);
929 tentative_histogram->SetFlags(flags); 936 tentative_histogram->SetFlags(flags);
930 histogram = 937 histogram =
931 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 938 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
939 if (histogram == tentative_histogram)
940 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
932 } 941 }
933 942
934 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); 943 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM);
935 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(), 944 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(),
936 ranges.size())); 945 ranges.size()));
937 return histogram; 946 return histogram;
938 } 947 }
939 948
940 Histogram::ClassType CustomHistogram::histogram_type() const { 949 Histogram::ClassType CustomHistogram::histogram_type() const {
941 return CUSTOM_HISTOGRAM; 950 return CUSTOM_HISTOGRAM;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 } 1147 }
1139 1148
1140 // static 1149 // static
1141 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 1150 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
1142 // static 1151 // static
1143 base::Lock* StatisticsRecorder::lock_ = NULL; 1152 base::Lock* StatisticsRecorder::lock_ = NULL;
1144 // static 1153 // static
1145 bool StatisticsRecorder::dump_on_exit_ = false; 1154 bool StatisticsRecorder::dump_on_exit_ = false;
1146 1155
1147 } // namespace base 1156 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/leak_annotations.h ('k') | net/disk_cache/stats.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698