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 | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.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" |
| 8 | #include "src/counters.h" |
| 9 | #include "src/isolate.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 10 | #include "src/log-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 15 | StatsTable::StatsTable() |
| 16 | : lookup_function_(NULL), |
| 17 | create_histogram_function_(NULL), |
| 18 | add_histogram_sample_function_(NULL) {} |
| 19 | |
| 20 | |
| 21 | int* StatsCounter::FindLocationInStatsTable() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | return isolate_->stats_table()->FindLocation(name_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 25 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 26 | void Histogram::AddSample(int sample) { |
| 27 | if (Enabled()) { |
| 28 | isolate()->stats_table()->AddHistogramSample(histogram_, sample); |
| 29 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | void* Histogram::CreateHistogram() const { |
| 33 | return isolate()->stats_table()-> |
| 34 | CreateHistogram(name_, min_, max_, num_buckets_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | // Start the timer. |
| 39 | void HistogramTimer::Start() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | if (Enabled()) { |
| 41 | timer_.Start(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 42 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 43 | Logger::CallEventLogger(isolate(), name(), Logger::START, true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 47 | // Stop the timer and record the results. |
| 48 | void HistogramTimer::Stop() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 49 | if (Enabled()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | // Compute the delta between start and stop, in milliseconds. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds())); |
| 52 | timer_.Stop(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 53 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 54 | Logger::CallEventLogger(isolate(), name(), Logger::END, true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 57 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | Counters::Counters(Isolate* isolate) { |
| 59 | #define HR(name, caption, min, max, num_buckets) \ |
| 60 | name##_ = Histogram(#caption, min, max, num_buckets, isolate); |
| 61 | HISTOGRAM_RANGE_LIST(HR) |
| 62 | #undef HR |
| 63 | |
| 64 | #define HT(name, caption) \ |
| 65 | name##_ = HistogramTimer(#caption, 0, 10000, 50, isolate); |
| 66 | HISTOGRAM_TIMER_LIST(HT) |
| 67 | #undef HT |
| 68 | |
| 69 | #define HP(name, caption) \ |
| 70 | name##_ = Histogram(#caption, 0, 101, 100, isolate); |
| 71 | HISTOGRAM_PERCENTAGE_LIST(HP) |
| 72 | #undef HP |
| 73 | |
| 74 | #define HM(name, caption) \ |
| 75 | name##_ = Histogram(#caption, 1000, 500000, 50, isolate); |
| 76 | HISTOGRAM_MEMORY_LIST(HM) |
| 77 | #undef HM |
| 78 | |
| 79 | #define SC(name, caption) \ |
| 80 | name##_ = StatsCounter(isolate, "c:" #caption); |
| 81 | |
| 82 | STATS_COUNTER_LIST_1(SC) |
| 83 | STATS_COUNTER_LIST_2(SC) |
| 84 | #undef SC |
| 85 | |
| 86 | #define SC(name) \ |
| 87 | count_of_##name##_ = StatsCounter(isolate, "c:" "V8.CountOf_" #name); \ |
| 88 | size_of_##name##_ = StatsCounter(isolate, "c:" "V8.SizeOf_" #name); |
| 89 | INSTANCE_TYPE_LIST(SC) |
| 90 | #undef SC |
| 91 | |
| 92 | #define SC(name) \ |
| 93 | count_of_CODE_TYPE_##name##_ = \ |
| 94 | StatsCounter(isolate, "c:" "V8.CountOf_CODE_TYPE-" #name); \ |
| 95 | size_of_CODE_TYPE_##name##_ = \ |
| 96 | StatsCounter(isolate, "c:" "V8.SizeOf_CODE_TYPE-" #name); |
| 97 | CODE_KIND_LIST(SC) |
| 98 | #undef SC |
| 99 | |
| 100 | #define SC(name) \ |
| 101 | count_of_FIXED_ARRAY_##name##_ = \ |
| 102 | StatsCounter(isolate, "c:" "V8.CountOf_FIXED_ARRAY-" #name); \ |
| 103 | size_of_FIXED_ARRAY_##name##_ = \ |
| 104 | StatsCounter(isolate, "c:" "V8.SizeOf_FIXED_ARRAY-" #name); |
| 105 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
| 106 | #undef SC |
| 107 | |
| 108 | #define SC(name) \ |
| 109 | count_of_CODE_AGE_##name##_ = \ |
| 110 | StatsCounter(isolate, "c:" "V8.CountOf_CODE_AGE-" #name); \ |
| 111 | size_of_CODE_AGE_##name##_ = \ |
| 112 | StatsCounter(isolate, "c:" "V8.SizeOf_CODE_AGE-" #name); |
| 113 | CODE_AGE_LIST_COMPLETE(SC) |
| 114 | #undef SC |
| 115 | } |
| 116 | |
| 117 | |
| 118 | void Counters::ResetCounters() { |
| 119 | #define SC(name, caption) name##_.Reset(); |
| 120 | STATS_COUNTER_LIST_1(SC) |
| 121 | STATS_COUNTER_LIST_2(SC) |
| 122 | #undef SC |
| 123 | |
| 124 | #define SC(name) \ |
| 125 | count_of_##name##_.Reset(); \ |
| 126 | size_of_##name##_.Reset(); |
| 127 | INSTANCE_TYPE_LIST(SC) |
| 128 | #undef SC |
| 129 | |
| 130 | #define SC(name) \ |
| 131 | count_of_CODE_TYPE_##name##_.Reset(); \ |
| 132 | size_of_CODE_TYPE_##name##_.Reset(); |
| 133 | CODE_KIND_LIST(SC) |
| 134 | #undef SC |
| 135 | |
| 136 | #define SC(name) \ |
| 137 | count_of_FIXED_ARRAY_##name##_.Reset(); \ |
| 138 | size_of_FIXED_ARRAY_##name##_.Reset(); |
| 139 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
| 140 | #undef SC |
| 141 | |
| 142 | #define SC(name) \ |
| 143 | count_of_CODE_AGE_##name##_.Reset(); \ |
| 144 | size_of_CODE_AGE_##name##_.Reset(); |
| 145 | CODE_AGE_LIST_COMPLETE(SC) |
| 146 | #undef SC |
| 147 | } |
| 148 | |
| 149 | |
| 150 | void Counters::ResetHistograms() { |
| 151 | #define HR(name, caption, min, max, num_buckets) name##_.Reset(); |
| 152 | HISTOGRAM_RANGE_LIST(HR) |
| 153 | #undef HR |
| 154 | |
| 155 | #define HT(name, caption) name##_.Reset(); |
| 156 | HISTOGRAM_TIMER_LIST(HT) |
| 157 | #undef HT |
| 158 | |
| 159 | #define HP(name, caption) name##_.Reset(); |
| 160 | HISTOGRAM_PERCENTAGE_LIST(HP) |
| 161 | #undef HP |
| 162 | |
| 163 | #define HM(name, caption) name##_.Reset(); |
| 164 | HISTOGRAM_MEMORY_LIST(HM) |
| 165 | #undef HM |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | } } // namespace v8::internal |