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.
7 #include "src/base/platform/platform.h"
8 #include "src/counters.h"
9 #include "src/isolate.h"
10 #include "src/log-inl.h"
15 StatsTable::StatsTable()
16 : lookup_function_(NULL),
17 create_histogram_function_(NULL),
18 add_histogram_sample_function_(NULL) {}
21 int* StatsCounter::FindLocationInStatsTable() const {
22 return isolate_->stats_table()->FindLocation(name_);
26 void Histogram::AddSample(int sample) {
28 isolate()->stats_table()->AddHistogramSample(histogram_, sample);
32 void* Histogram::CreateHistogram() const {
33 return isolate()->stats_table()->
34 CreateHistogram(name_, min_, max_, num_buckets_);
39 void HistogramTimer::Start() {
43 Logger::CallEventLogger(isolate(), name(), Logger::START, true);
47 // Stop the timer and record the results.
48 void HistogramTimer::Stop() {
50 // Compute the delta between start and stop, in milliseconds.
51 AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
54 Logger::CallEventLogger(isolate(), name(), Logger::END, true);
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)
64 #define HT(name, caption) \
65 name##_ = HistogramTimer(#caption, 0, 10000, 50, isolate);
66 HISTOGRAM_TIMER_LIST(HT)
69 #define HP(name, caption) \
70 name##_ = Histogram(#caption, 0, 101, 100, isolate);
71 HISTOGRAM_PERCENTAGE_LIST(HP)
74 #define HM(name, caption) \
75 name##_ = Histogram(#caption, 1000, 500000, 50, isolate);
76 HISTOGRAM_MEMORY_LIST(HM)
79 #define SC(name, caption) \
80 name##_ = StatsCounter(isolate, "c:" #caption);
82 STATS_COUNTER_LIST_1(SC)
83 STATS_COUNTER_LIST_2(SC)
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)
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);
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)
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)
118 void Counters::ResetCounters() {
119 #define SC(name, caption) name##_.Reset();
120 STATS_COUNTER_LIST_1(SC)
121 STATS_COUNTER_LIST_2(SC)
125 count_of_##name##_.Reset(); \
126 size_of_##name##_.Reset();
127 INSTANCE_TYPE_LIST(SC)
131 count_of_CODE_TYPE_##name##_.Reset(); \
132 size_of_CODE_TYPE_##name##_.Reset();
137 count_of_FIXED_ARRAY_##name##_.Reset(); \
138 size_of_FIXED_ARRAY_##name##_.Reset();
139 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC)
143 count_of_CODE_AGE_##name##_.Reset(); \
144 size_of_CODE_AGE_##name##_.Reset();
145 CODE_AGE_LIST_COMPLETE(SC)
150 void Counters::ResetHistograms() {
151 #define HR(name, caption, min, max, num_buckets) name##_.Reset();
152 HISTOGRAM_RANGE_LIST(HR)
155 #define HT(name, caption) name##_.Reset();
156 HISTOGRAM_TIMER_LIST(HT)
159 #define HP(name, caption) name##_.Reset();
160 HISTOGRAM_PERCENTAGE_LIST(HP)
163 #define HM(name, caption) name##_.Reset();
164 HISTOGRAM_MEMORY_LIST(HM)
168 } } // namespace v8::internal