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