blob: e8dea2e0736d58ef5db3b608e1dc1cdca09c70e6 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 Blocka7e24c12009-10-30 11:49:00 +00004
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/counters.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/base/platform/platform.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/isolate.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009#include "src/log-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000010
11namespace v8 {
12namespace internal {
13
Steve Block44f0eee2011-05-26 01:26:41 +010014StatsTable::StatsTable()
15 : lookup_function_(NULL),
16 create_histogram_function_(NULL),
17 add_histogram_sample_function_(NULL) {}
18
19
20int* StatsCounter::FindLocationInStatsTable() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000021 return isolate_->stats_table()->FindLocation(name_);
Steve Block44f0eee2011-05-26 01:26:41 +010022}
23
Steve Blocka7e24c12009-10-30 11:49:00 +000024
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025void Histogram::AddSample(int sample) {
26 if (Enabled()) {
27 isolate()->stats_table()->AddHistogramSample(histogram_, sample);
28 }
Steve Blocka7e24c12009-10-30 11:49:00 +000029}
30
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031void* Histogram::CreateHistogram() const {
32 return isolate()->stats_table()->
33 CreateHistogram(name_, min_, max_, num_buckets_);
Steve Blocka7e24c12009-10-30 11:49:00 +000034}
35
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036
Steve Blocka7e24c12009-10-30 11:49:00 +000037// Start the timer.
38void HistogramTimer::Start() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039 if (Enabled()) {
40 timer_.Start();
Steve Blocka7e24c12009-10-30 11:49:00 +000041 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040042 Logger::CallEventLogger(isolate(), name(), Logger::START, true);
Steve Blocka7e24c12009-10-30 11:49:00 +000043}
44
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045
Steve Blocka7e24c12009-10-30 11:49:00 +000046// Stop the timer and record the results.
47void HistogramTimer::Stop() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048 if (Enabled()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 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 Murdochb8a8cc12014-11-26 15:28:44 +000054 timer_.Stop();
Steve Blocka7e24c12009-10-30 11:49:00 +000055 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040056 Logger::CallEventLogger(isolate(), name(), Logger::END, true);
Steve Blocka7e24c12009-10-30 11:49:00 +000057}
58
Steve Block44f0eee2011-05-26 01:26:41 +010059
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060Counters::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 Murdoch4a90d5f2016-03-22 12:00:34 +000066#define HT(name, caption, max, res) \
67 name##_ = HistogramTimer(#caption, 0, max, HistogramTimer::res, 50, isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068 HISTOGRAM_TIMER_LIST(HT)
69#undef HT
70
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071#define AHT(name, caption) \
72 name##_ = AggregatableHistogramTimer(#caption, 0, 10000000, 50, isolate);
73 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
74#undef AHT
75
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076#define HP(name, caption) \
77 name##_ = Histogram(#caption, 0, 101, 100, isolate);
78 HISTOGRAM_PERCENTAGE_LIST(HP)
79#undef HP
80
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081
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 Murdochb8a8cc12014-11-26 15:28:44 +000088#define HM(name, caption) \
89 name##_ = Histogram(#caption, 1000, 500000, 50, isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090 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 Murdochb8a8cc12014-11-26 15:28:44 +0000100 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
142void 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
174void Counters::ResetHistograms() {
175#define HR(name, caption, min, max, num_buckets) name##_.Reset();
176 HISTOGRAM_RANGE_LIST(HR)
177#undef HR
178
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000179#define HT(name, caption, max, res) name##_.Reset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000180 HISTOGRAM_TIMER_LIST(HT)
181#undef HT
182
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000183#define AHT(name, caption) name##_.Reset();
184 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
185#undef AHT
186
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187#define HP(name, caption) name##_.Reset();
188 HISTOGRAM_PERCENTAGE_LIST(HP)
189#undef HP
190
191#define HM(name, caption) name##_.Reset();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000192 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000193#undef HM
Steve Block44f0eee2011-05-26 01:26:41 +0100194}
195
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000196} // namespace internal
197} // namespace v8