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

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

Issue 7071036: Introduce the ANNOTATE_LEAKING_OBJECT_PTR annotation that can be used to mark (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
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
100 } 101 }
101 102
102 DCHECK_EQ(HISTOGRAM, histogram->histogram_type()); 103 DCHECK_EQ(HISTOGRAM, histogram->histogram_type());
103 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); 104 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
105 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
jar (doing other things) 2011/05/27 18:13:02 Perchance this line should appear only once, insid
Alexander Potapenko 2011/05/30 08:00:38 Indeed. I've forgotten to upload the actual diff f
104 return histogram; 106 return histogram;
105 } 107 }
106 108
107 Histogram* Histogram::FactoryTimeGet(const std::string& name, 109 Histogram* Histogram::FactoryTimeGet(const std::string& name,
108 TimeDelta minimum, 110 TimeDelta minimum,
109 TimeDelta maximum, 111 TimeDelta maximum,
110 size_t bucket_count, 112 size_t bucket_count,
111 Flags flags) { 113 Flags flags) {
112 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), 114 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
113 bucket_count, flags); 115 bucket_count, flags);
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 LinearHistogram* tentative_histogram = 790 LinearHistogram* tentative_histogram =
789 new LinearHistogram(name, minimum, maximum, bucket_count); 791 new LinearHistogram(name, minimum, maximum, bucket_count);
790 tentative_histogram->InitializeBucketRange(); 792 tentative_histogram->InitializeBucketRange();
791 tentative_histogram->SetFlags(flags); 793 tentative_histogram->SetFlags(flags);
792 histogram = 794 histogram =
793 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 795 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
794 } 796 }
795 797
796 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type()); 798 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->histogram_type());
797 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); 799 DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
800 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
798 return histogram; 801 return histogram;
799 } 802 }
800 803
801 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name, 804 Histogram* LinearHistogram::FactoryTimeGet(const std::string& name,
802 TimeDelta minimum, 805 TimeDelta minimum,
803 TimeDelta maximum, 806 TimeDelta maximum,
804 size_t bucket_count, 807 size_t bucket_count,
805 Flags flags) { 808 Flags flags) {
806 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(), 809 return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
807 bucket_count, flags); 810 bucket_count, flags);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 if (!StatisticsRecorder::FindHistogram(name, &histogram)) { 881 if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
879 // To avoid racy destruction at shutdown, the following will be leaked. 882 // To avoid racy destruction at shutdown, the following will be leaked.
880 BooleanHistogram* tentative_histogram = new BooleanHistogram(name); 883 BooleanHistogram* tentative_histogram = new BooleanHistogram(name);
881 tentative_histogram->InitializeBucketRange(); 884 tentative_histogram->InitializeBucketRange();
882 tentative_histogram->SetFlags(flags); 885 tentative_histogram->SetFlags(flags);
883 histogram = 886 histogram =
884 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 887 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
885 } 888 }
886 889
887 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type()); 890 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->histogram_type());
891 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
888 return histogram; 892 return histogram;
889 } 893 }
890 894
891 Histogram::ClassType BooleanHistogram::histogram_type() const { 895 Histogram::ClassType BooleanHistogram::histogram_type() const {
892 return BOOLEAN_HISTOGRAM; 896 return BOOLEAN_HISTOGRAM;
893 } 897 }
894 898
895 void BooleanHistogram::AddBoolean(bool value) { 899 void BooleanHistogram::AddBoolean(bool value) {
896 Add(value ? 1 : 0); 900 Add(value ? 1 : 0);
897 } 901 }
(...skipping 29 matching lines...) Expand all
927 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); 931 CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges);
928 tentative_histogram->InitializedCustomBucketRange(ranges); 932 tentative_histogram->InitializedCustomBucketRange(ranges);
929 tentative_histogram->SetFlags(flags); 933 tentative_histogram->SetFlags(flags);
930 histogram = 934 histogram =
931 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 935 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
932 } 936 }
933 937
934 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM); 938 DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM);
935 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(), 939 DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(),
936 ranges.size())); 940 ranges.size()));
941 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
937 return histogram; 942 return histogram;
938 } 943 }
939 944
940 Histogram::ClassType CustomHistogram::histogram_type() const { 945 Histogram::ClassType CustomHistogram::histogram_type() const {
941 return CUSTOM_HISTOGRAM; 946 return CUSTOM_HISTOGRAM;
942 } 947 }
943 948
944 // static 949 // static
945 std::vector<Histogram::Sample> CustomHistogram::ArrayToCustomRanges( 950 std::vector<Histogram::Sample> CustomHistogram::ArrayToCustomRanges(
946 const Sample* values, size_t num_values) { 951 const Sample* values, size_t num_values) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 } 1143 }
1139 1144
1140 // static 1145 // static
1141 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 1146 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
1142 // static 1147 // static
1143 base::Lock* StatisticsRecorder::lock_ = NULL; 1148 base::Lock* StatisticsRecorder::lock_ = NULL;
1144 // static 1149 // static
1145 bool StatisticsRecorder::dump_on_exit_ = false; 1150 bool StatisticsRecorder::dump_on_exit_ = false;
1146 1151
1147 } // namespace base 1152 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698