OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 8 |
9 // It supports calls to accumulate either time intervals (which are processed | 9 // It supports calls to accumulate either time intervals (which are processed |
10 // as integral number of milliseconds), or arbitrary integral units. | 10 // as integral number of milliseconds), or arbitrary integral units. |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 #include "base/lock.h" | 38 #include "base/lock.h" |
39 #include "base/scoped_ptr.h" | 39 #include "base/scoped_ptr.h" |
40 #include "base/stats_counters.h" | 40 #include "base/stats_counters.h" |
41 | 41 |
42 //------------------------------------------------------------------------------ | 42 //------------------------------------------------------------------------------ |
43 // Provide easy general purpose histogram in a macro, just like stats counters. | 43 // Provide easy general purpose histogram in a macro, just like stats counters. |
44 // These macros all use 50 buckets. | 44 // These macros all use 50 buckets. |
45 | 45 |
46 #define HISTOGRAM_TIMES(name, sample) do { \ | 46 #define HISTOGRAM_TIMES(name, sample) do { \ |
47 static Histogram counter((name), TimeDelta::FromMilliseconds(1), \ | 47 static Histogram counter((name), base::TimeDelta::FromMilliseconds(1), \ |
48 TimeDelta::FromSeconds(10), 50); \ | 48 base::TimeDelta::FromSeconds(10), 50); \ |
49 counter.AddTime(sample); \ | 49 counter.AddTime(sample); \ |
50 } while (0) | 50 } while (0) |
51 | 51 |
52 #define HISTOGRAM_COUNTS(name, sample) do { \ | 52 #define HISTOGRAM_COUNTS(name, sample) do { \ |
53 static Histogram counter((name), 1, 1000000, 50); \ | 53 static Histogram counter((name), 1, 1000000, 50); \ |
54 counter.Add(sample); \ | 54 counter.Add(sample); \ |
55 } while (0) | 55 } while (0) |
56 | 56 |
57 //------------------------------------------------------------------------------ | 57 //------------------------------------------------------------------------------ |
58 // This macro set is for a histogram that can support both addition and removal | 58 // This macro set is for a histogram that can support both addition and removal |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 //------------------------------------------------------------------------------ | 97 //------------------------------------------------------------------------------ |
98 // The following macros provide typical usage scenarios for callers that wish | 98 // The following macros provide typical usage scenarios for callers that wish |
99 // to record histogram data, and have the data submitted/uploaded via UMA. | 99 // to record histogram data, and have the data submitted/uploaded via UMA. |
100 // Not all systems support such UMA, but if they do, the following macros | 100 // Not all systems support such UMA, but if they do, the following macros |
101 // should work with the service. | 101 // should work with the service. |
102 | 102 |
103 static const int kUmaTargetedHistogramFlag = 0x1; | 103 static const int kUmaTargetedHistogramFlag = 0x1; |
104 | 104 |
105 #define UMA_HISTOGRAM_TIMES(name, sample) do { \ | 105 #define UMA_HISTOGRAM_TIMES(name, sample) do { \ |
106 static Histogram counter((name), TimeDelta::FromMilliseconds(1), \ | 106 static Histogram counter((name), base::TimeDelta::FromMilliseconds(1), \ |
107 TimeDelta::FromSeconds(10), 50); \ | 107 base::TimeDelta::FromSeconds(10), 50); \ |
108 counter.SetFlags(kUmaTargetedHistogramFlag); \ | 108 counter.SetFlags(kUmaTargetedHistogramFlag); \ |
109 counter.AddTime(sample); \ | 109 counter.AddTime(sample); \ |
110 } while (0) | 110 } while (0) |
111 | 111 |
112 // Use this macro when times can routinely be much longer than 10 seconds. | 112 // Use this macro when times can routinely be much longer than 10 seconds. |
113 #define UMA_HISTOGRAM_LONG_TIMES(name, sample) do { \ | 113 #define UMA_HISTOGRAM_LONG_TIMES(name, sample) do { \ |
114 static Histogram counter((name), TimeDelta::FromMilliseconds(1), \ | 114 static Histogram counter((name), base::TimeDelta::FromMilliseconds(1), \ |
115 TimeDelta::FromHours(1), 50); \ | 115 base::TimeDelta::FromHours(1), 50); \ |
116 counter.SetFlags(kUmaTargetedHistogramFlag); \ | 116 counter.SetFlags(kUmaTargetedHistogramFlag); \ |
117 counter.AddTime(sample); \ | 117 counter.AddTime(sample); \ |
118 } while (0) | 118 } while (0) |
119 | 119 |
120 #define UMA_HISTOGRAM_COUNTS(name, sample) do { \ | 120 #define UMA_HISTOGRAM_COUNTS(name, sample) do { \ |
121 static Histogram counter((name), 1, 1000000, 50); \ | 121 static Histogram counter((name), 1, 1000000, 50); \ |
122 counter.SetFlags(kUmaTargetedHistogramFlag); \ | 122 counter.SetFlags(kUmaTargetedHistogramFlag); \ |
123 counter.Add(sample); \ | 123 counter.Add(sample); \ |
124 } while (0) | 124 } while (0) |
125 | 125 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 // Save simple stats locally. Note that this MIGHT get done in base class | 185 // Save simple stats locally. Note that this MIGHT get done in base class |
186 // without shared memory at some point. | 186 // without shared memory at some point. |
187 int64 sum_; // sum of samples. | 187 int64 sum_; // sum of samples. |
188 int64 square_sum_; // sum of squares of samples. | 188 int64 square_sum_; // sum of squares of samples. |
189 }; | 189 }; |
190 //---------------------------------------------------------------------------- | 190 //---------------------------------------------------------------------------- |
191 | 191 |
192 Histogram(const wchar_t* name, Sample minimum, | 192 Histogram(const wchar_t* name, Sample minimum, |
193 Sample maximum, size_t bucket_count); | 193 Sample maximum, size_t bucket_count); |
194 Histogram(const wchar_t* name, TimeDelta minimum, | 194 Histogram(const wchar_t* name, base::TimeDelta minimum, |
195 TimeDelta maximum, size_t bucket_count); | 195 base::TimeDelta maximum, size_t bucket_count); |
196 virtual ~Histogram(); | 196 virtual ~Histogram(); |
197 | 197 |
198 // Hooks to override stats counter methods. This ensures that we gather all | 198 // Hooks to override stats counter methods. This ensures that we gather all |
199 // input the stats counter sees. | 199 // input the stats counter sees. |
200 virtual void Add(int value); | 200 virtual void Add(int value); |
201 | 201 |
202 // The following methods provide a graphical histogram displays. | 202 // The following methods provide a graphical histogram displays. |
203 void WriteHTMLGraph(std::string* output) const; | 203 void WriteHTMLGraph(std::string* output) const; |
204 void WriteAscii(bool graph_it, const std::string& newline, | 204 void WriteAscii(bool graph_it, const std::string& newline, |
205 std::string* output) const; | 205 std::string* output) const; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 // LinearHistogram is a more traditional histogram, with evenly spaced | 323 // LinearHistogram is a more traditional histogram, with evenly spaced |
324 // buckets. | 324 // buckets. |
325 class LinearHistogram : public Histogram { | 325 class LinearHistogram : public Histogram { |
326 public: | 326 public: |
327 struct DescriptionPair { | 327 struct DescriptionPair { |
328 Sample sample; | 328 Sample sample; |
329 const char* description; // Null means end of a list of pairs. | 329 const char* description; // Null means end of a list of pairs. |
330 }; | 330 }; |
331 LinearHistogram(const wchar_t* name, Sample minimum, | 331 LinearHistogram(const wchar_t* name, Sample minimum, |
332 Sample maximum, size_t bucket_count); | 332 Sample maximum, size_t bucket_count); |
333 LinearHistogram(const wchar_t* name, TimeDelta minimum, | 333 LinearHistogram(const wchar_t* name, base::TimeDelta minimum, |
334 TimeDelta maximum, size_t bucket_count); | 334 base::TimeDelta maximum, size_t bucket_count); |
335 ~LinearHistogram() {} | 335 ~LinearHistogram() {} |
336 | 336 |
337 // Store a list of number/text values for use in rendering the histogram. | 337 // Store a list of number/text values for use in rendering the histogram. |
338 // The last element in the array has a null in its "description" slot. | 338 // The last element in the array has a null in its "description" slot. |
339 void SetRangeDescriptions(const DescriptionPair descriptions[]); | 339 void SetRangeDescriptions(const DescriptionPair descriptions[]); |
340 | 340 |
341 protected: | 341 protected: |
342 // Initialize ranges_ mapping. | 342 // Initialize ranges_ mapping. |
343 virtual void InitializeBucketRange(); | 343 virtual void InitializeBucketRange(); |
344 // Find bucket to increment for sample value. | 344 // Find bucket to increment for sample value. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 static Lock* lock_; | 436 static Lock* lock_; |
437 | 437 |
438 // Dump all known histograms to log. | 438 // Dump all known histograms to log. |
439 static bool dump_on_exit_; | 439 static bool dump_on_exit_; |
440 | 440 |
441 DISALLOW_EVIL_CONSTRUCTORS(StatisticsRecorder); | 441 DISALLOW_EVIL_CONSTRUCTORS(StatisticsRecorder); |
442 }; | 442 }; |
443 | 443 |
444 #endif // BASE_HISTOGRAM_H__ | 444 #endif // BASE_HISTOGRAM_H__ |
445 | 445 |
OLD | NEW |