Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / src / counters.cc
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/base/platform/platform.h"
8 #include "src/counters.h"
9 #include "src/isolate.h"
10 #include "src/log-inl.h"
11
12 namespace v8 {
13 namespace internal {
14
15 StatsTable::StatsTable()
16     : lookup_function_(NULL),
17       create_histogram_function_(NULL),
18       add_histogram_sample_function_(NULL) {}
19
20
21 int* StatsCounter::FindLocationInStatsTable() const {
22   return isolate_->stats_table()->FindLocation(name_);
23 }
24
25
26 void Histogram::AddSample(int sample) {
27   if (Enabled()) {
28     isolate()->stats_table()->AddHistogramSample(histogram_, sample);
29   }
30 }
31
32 void* Histogram::CreateHistogram() const {
33   return isolate()->stats_table()->
34       CreateHistogram(name_, min_, max_, num_buckets_);
35 }
36
37
38 // Start the timer.
39 void HistogramTimer::Start() {
40   if (Enabled()) {
41     timer_.Start();
42   }
43   Logger::CallEventLogger(isolate(), name(), Logger::START, true);
44 }
45
46
47 // Stop the timer and record the results.
48 void HistogramTimer::Stop() {
49   if (Enabled()) {
50     // Compute the delta between start and stop, in milliseconds.
51     AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
52     timer_.Stop();
53   }
54   Logger::CallEventLogger(isolate(), name(), Logger::END, true);
55 }
56
57
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)
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
118 void 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
150 void 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
166 }
167
168 } }  // namespace v8::internal