42b0574b373a71f8b3a0d86922b1b835e22ad794
[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/counters.h"
8 #include "src/isolate.h"
9 #include "src/platform.h"
10
11 namespace v8 {
12 namespace internal {
13
14 StatsTable::StatsTable()
15     : lookup_function_(NULL),
16       create_histogram_function_(NULL),
17       add_histogram_sample_function_(NULL) {}
18
19
20 int* StatsCounter::FindLocationInStatsTable() const {
21   return isolate_->stats_table()->FindLocation(name_);
22 }
23
24
25 void Histogram::AddSample(int sample) {
26   if (Enabled()) {
27     isolate()->stats_table()->AddHistogramSample(histogram_, sample);
28   }
29 }
30
31 void* Histogram::CreateHistogram() const {
32   return isolate()->stats_table()->
33       CreateHistogram(name_, min_, max_, num_buckets_);
34 }
35
36
37 // Start the timer.
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.
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
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
112 void Counters::ResetHistograms() {
113 #define HT(name, caption) name##_.Reset();
114     HISTOGRAM_TIMER_LIST(HT)
115 #undef HT
116
117 #define HP(name, caption) name##_.Reset();
118     HISTOGRAM_PERCENTAGE_LIST(HP)
119 #undef HP
120
121 #define HM(name, caption) name##_.Reset();
122     HISTOGRAM_MEMORY_LIST(HM)
123 #undef HM
124 }
125
126 } }  // namespace v8::internal