Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 5 | #include "src/counters.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #include "src/base/platform/platform.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/isolate.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9 | #include "src/log-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 14 | StatsTable::StatsTable() |
| 15 | : lookup_function_(NULL), |
| 16 | create_histogram_function_(NULL), |
| 17 | add_histogram_sample_function_(NULL) {} |
| 18 | |
| 19 | |
| 20 | int* StatsCounter::FindLocationInStatsTable() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 21 | return isolate_->stats_table()->FindLocation(name_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 22 | } |
| 23 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 24 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 | void Histogram::AddSample(int sample) { |
| 26 | if (Enabled()) { |
| 27 | isolate()->stats_table()->AddHistogramSample(histogram_, sample); |
| 28 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | void* Histogram::CreateHistogram() const { |
| 32 | return isolate()->stats_table()-> |
| 33 | CreateHistogram(name_, min_, max_, num_buckets_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | // Start the timer. |
| 38 | void HistogramTimer::Start() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 39 | if (Enabled()) { |
| 40 | timer_.Start(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 42 | Logger::CallEventLogger(isolate(), name(), Logger::START, true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | // Stop the timer and record the results. |
| 47 | void HistogramTimer::Stop() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 48 | if (Enabled()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 49 | int64_t sample = resolution_ == MICROSECOND |
| 50 | ? timer_.Elapsed().InMicroseconds() |
| 51 | : timer_.Elapsed().InMilliseconds(); |
| 52 | // Compute the delta between start and stop, in microseconds. |
| 53 | AddSample(static_cast<int>(sample)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 54 | timer_.Stop(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 55 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 56 | Logger::CallEventLogger(isolate(), name(), Logger::END, true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 59 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | Counters::Counters(Isolate* isolate) { |
| 61 | #define HR(name, caption, min, max, num_buckets) \ |
| 62 | name##_ = Histogram(#caption, min, max, num_buckets, isolate); |
| 63 | HISTOGRAM_RANGE_LIST(HR) |
| 64 | #undef HR |
| 65 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 66 | #define HT(name, caption, max, res) \ |
| 67 | name##_ = HistogramTimer(#caption, 0, max, HistogramTimer::res, 50, isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | HISTOGRAM_TIMER_LIST(HT) |
| 69 | #undef HT |
| 70 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 71 | #define AHT(name, caption) \ |
| 72 | name##_ = AggregatableHistogramTimer(#caption, 0, 10000000, 50, isolate); |
| 73 | AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
| 74 | #undef AHT |
| 75 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 76 | #define HP(name, caption) \ |
| 77 | name##_ = Histogram(#caption, 0, 101, 100, isolate); |
| 78 | HISTOGRAM_PERCENTAGE_LIST(HP) |
| 79 | #undef HP |
| 80 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 81 | |
| 82 | // Exponential histogram assigns bucket limits to points |
| 83 | // p[1], p[2], ... p[n] such that p[i+1] / p[i] = constant. |
| 84 | // The constant factor is equal to the n-th root of (high / low), |
| 85 | // where the n is the number of buckets, the low is the lower limit, |
| 86 | // the high is the upper limit. |
| 87 | // For n = 50, low = 1000, high = 500000: the factor = 1.13. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 88 | #define HM(name, caption) \ |
| 89 | name##_ = Histogram(#caption, 1000, 500000, 50, isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 90 | HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
| 91 | #undef HM |
| 92 | // For n = 100, low = 4000, high = 2000000: the factor = 1.06. |
| 93 | #define HM(name, caption) \ |
| 94 | name##_ = Histogram(#caption, 4000, 2000000, 100, isolate); |
| 95 | HISTOGRAM_MEMORY_LIST(HM) |
| 96 | #undef HM |
| 97 | |
| 98 | #define HM(name, caption) \ |
| 99 | aggregated_##name##_ = AggregatedMemoryHistogram<Histogram>(&name##_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 100 | HISTOGRAM_MEMORY_LIST(HM) |
| 101 | #undef HM |
| 102 | |
| 103 | #define SC(name, caption) \ |
| 104 | name##_ = StatsCounter(isolate, "c:" #caption); |
| 105 | |
| 106 | STATS_COUNTER_LIST_1(SC) |
| 107 | STATS_COUNTER_LIST_2(SC) |
| 108 | #undef SC |
| 109 | |
| 110 | #define SC(name) \ |
| 111 | count_of_##name##_ = StatsCounter(isolate, "c:" "V8.CountOf_" #name); \ |
| 112 | size_of_##name##_ = StatsCounter(isolate, "c:" "V8.SizeOf_" #name); |
| 113 | INSTANCE_TYPE_LIST(SC) |
| 114 | #undef SC |
| 115 | |
| 116 | #define SC(name) \ |
| 117 | count_of_CODE_TYPE_##name##_ = \ |
| 118 | StatsCounter(isolate, "c:" "V8.CountOf_CODE_TYPE-" #name); \ |
| 119 | size_of_CODE_TYPE_##name##_ = \ |
| 120 | StatsCounter(isolate, "c:" "V8.SizeOf_CODE_TYPE-" #name); |
| 121 | CODE_KIND_LIST(SC) |
| 122 | #undef SC |
| 123 | |
| 124 | #define SC(name) \ |
| 125 | count_of_FIXED_ARRAY_##name##_ = \ |
| 126 | StatsCounter(isolate, "c:" "V8.CountOf_FIXED_ARRAY-" #name); \ |
| 127 | size_of_FIXED_ARRAY_##name##_ = \ |
| 128 | StatsCounter(isolate, "c:" "V8.SizeOf_FIXED_ARRAY-" #name); |
| 129 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
| 130 | #undef SC |
| 131 | |
| 132 | #define SC(name) \ |
| 133 | count_of_CODE_AGE_##name##_ = \ |
| 134 | StatsCounter(isolate, "c:" "V8.CountOf_CODE_AGE-" #name); \ |
| 135 | size_of_CODE_AGE_##name##_ = \ |
| 136 | StatsCounter(isolate, "c:" "V8.SizeOf_CODE_AGE-" #name); |
| 137 | CODE_AGE_LIST_COMPLETE(SC) |
| 138 | #undef SC |
| 139 | } |
| 140 | |
| 141 | |
| 142 | void Counters::ResetCounters() { |
| 143 | #define SC(name, caption) name##_.Reset(); |
| 144 | STATS_COUNTER_LIST_1(SC) |
| 145 | STATS_COUNTER_LIST_2(SC) |
| 146 | #undef SC |
| 147 | |
| 148 | #define SC(name) \ |
| 149 | count_of_##name##_.Reset(); \ |
| 150 | size_of_##name##_.Reset(); |
| 151 | INSTANCE_TYPE_LIST(SC) |
| 152 | #undef SC |
| 153 | |
| 154 | #define SC(name) \ |
| 155 | count_of_CODE_TYPE_##name##_.Reset(); \ |
| 156 | size_of_CODE_TYPE_##name##_.Reset(); |
| 157 | CODE_KIND_LIST(SC) |
| 158 | #undef SC |
| 159 | |
| 160 | #define SC(name) \ |
| 161 | count_of_FIXED_ARRAY_##name##_.Reset(); \ |
| 162 | size_of_FIXED_ARRAY_##name##_.Reset(); |
| 163 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
| 164 | #undef SC |
| 165 | |
| 166 | #define SC(name) \ |
| 167 | count_of_CODE_AGE_##name##_.Reset(); \ |
| 168 | size_of_CODE_AGE_##name##_.Reset(); |
| 169 | CODE_AGE_LIST_COMPLETE(SC) |
| 170 | #undef SC |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void Counters::ResetHistograms() { |
| 175 | #define HR(name, caption, min, max, num_buckets) name##_.Reset(); |
| 176 | HISTOGRAM_RANGE_LIST(HR) |
| 177 | #undef HR |
| 178 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 179 | #define HT(name, caption, max, res) name##_.Reset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 180 | HISTOGRAM_TIMER_LIST(HT) |
| 181 | #undef HT |
| 182 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 183 | #define AHT(name, caption) name##_.Reset(); |
| 184 | AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
| 185 | #undef AHT |
| 186 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | #define HP(name, caption) name##_.Reset(); |
| 188 | HISTOGRAM_PERCENTAGE_LIST(HP) |
| 189 | #undef HP |
| 190 | |
| 191 | #define HM(name, caption) name##_.Reset(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 192 | HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 193 | #undef HM |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 194 | } |
| 195 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 196 | } // namespace internal |
| 197 | } // namespace v8 |