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/counters.h"
8 #include "src/isolate.h"
9 #include "src/platform.h"
14 StatsTable::StatsTable()
15 : lookup_function_(NULL),
16 create_histogram_function_(NULL),
17 add_histogram_sample_function_(NULL) {}
20 int* StatsCounter::FindLocationInStatsTable() const {
21 return isolate_->stats_table()->FindLocation(name_);
25 void Histogram::AddSample(int sample) {
27 isolate()->stats_table()->AddHistogramSample(histogram_, sample);
31 void* Histogram::CreateHistogram() const {
32 return isolate()->stats_table()->
33 CreateHistogram(name_, min_, max_, num_buckets_);
38 void HistogramTimer::Start() {
42 isolate()->event_logger()(name(), Logger::START);
46 // Stop the timer and record the results.
47 void HistogramTimer::Stop() {
49 // Compute the delta between start and stop, in milliseconds.
50 AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
53 isolate()->event_logger()(name(), Logger::END);
57 Counters::Counters(Isolate* isolate) {
58 #define HT(name, caption) \
59 name##_ = HistogramTimer(#caption, 0, 10000, 50, isolate);
60 HISTOGRAM_TIMER_LIST(HT)
63 #define HP(name, caption) \
64 name##_ = Histogram(#caption, 0, 101, 100, isolate);
65 HISTOGRAM_PERCENTAGE_LIST(HP)
68 #define HM(name, caption) \
69 name##_ = Histogram(#caption, 1000, 500000, 50, isolate);
70 HISTOGRAM_MEMORY_LIST(HM)
73 #define SC(name, caption) \
74 name##_ = StatsCounter(isolate, "c:" #caption);
76 STATS_COUNTER_LIST_1(SC)
77 STATS_COUNTER_LIST_2(SC)
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)
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);
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)
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)
112 void Counters::ResetHistograms() {
113 #define HT(name, caption) name##_.Reset();
114 HISTOGRAM_TIMER_LIST(HT)
117 #define HP(name, caption) name##_.Reset();
118 HISTOGRAM_PERCENTAGE_LIST(HP)
121 #define HM(name, caption) name##_.Reset();
122 HISTOGRAM_MEMORY_LIST(HM)
126 } } // namespace v8::internal