blob: 972bd6862c0f5a5524dfd9f57021e9eb4b61c1a8 [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 Murdochb8a8cc12014-11-26 15:28:44 +00005#include "src/v8.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/base/platform/platform.h"
8#include "src/counters.h"
9#include "src/isolate.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010#include "src/log-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000011
12namespace v8 {
13namespace internal {
14
Steve Block44f0eee2011-05-26 01:26:41 +010015StatsTable::StatsTable()
16 : lookup_function_(NULL),
17 create_histogram_function_(NULL),
18 add_histogram_sample_function_(NULL) {}
19
20
21int* StatsCounter::FindLocationInStatsTable() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022 return isolate_->stats_table()->FindLocation(name_);
Steve Block44f0eee2011-05-26 01:26:41 +010023}
24
Steve Blocka7e24c12009-10-30 11:49:00 +000025
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026void Histogram::AddSample(int sample) {
27 if (Enabled()) {
28 isolate()->stats_table()->AddHistogramSample(histogram_, sample);
29 }
Steve Blocka7e24c12009-10-30 11:49:00 +000030}
31
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032void* Histogram::CreateHistogram() const {
33 return isolate()->stats_table()->
34 CreateHistogram(name_, min_, max_, num_buckets_);
Steve Blocka7e24c12009-10-30 11:49:00 +000035}
36
Ben Murdochb8a8cc12014-11-26 15:28:44 +000037
Steve Blocka7e24c12009-10-30 11:49:00 +000038// Start the timer.
39void HistogramTimer::Start() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040 if (Enabled()) {
41 timer_.Start();
Steve Blocka7e24c12009-10-30 11:49:00 +000042 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040043 Logger::CallEventLogger(isolate(), name(), Logger::START, true);
Steve Blocka7e24c12009-10-30 11:49:00 +000044}
45
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046
Steve Blocka7e24c12009-10-30 11:49:00 +000047// Stop the timer and record the results.
48void HistogramTimer::Stop() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049 if (Enabled()) {
Steve Blocka7e24c12009-10-30 11:49:00 +000050 // Compute the delta between start and stop, in milliseconds.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
52 timer_.Stop();
Steve Blocka7e24c12009-10-30 11:49:00 +000053 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040054 Logger::CallEventLogger(isolate(), name(), Logger::END, true);
Steve Blocka7e24c12009-10-30 11:49:00 +000055}
56
Steve Block44f0eee2011-05-26 01:26:41 +010057
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058Counters::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
118void 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
150void 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 Block44f0eee2011-05-26 01:26:41 +0100166}
167
Steve Blocka7e24c12009-10-30 11:49:00 +0000168} } // namespace v8::internal