OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/counters.h" | 5 #include "src/counters.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/builtins/builtins-definitions.h" | 10 #include "src/builtins/builtins-definitions.h" |
11 #include "src/isolate.h" | 11 #include "src/isolate.h" |
12 #include "src/log-inl.h" | 12 #include "src/log-inl.h" |
13 #include "src/log.h" | 13 #include "src/log.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 StatsTable::StatsTable() | 18 StatsTable::StatsTable() |
19 : lookup_function_(NULL), | 19 : lookup_function_(NULL), |
20 create_histogram_function_(NULL), | 20 create_histogram_function_(NULL), |
21 add_histogram_sample_function_(NULL) {} | 21 add_histogram_sample_function_(NULL) {} |
22 | 22 |
| 23 void StatsTable::SetCounterFunction(CounterLookupCallback f, Isolate* isolate) { |
| 24 lookup_function_ = f; |
| 25 if (!isolate->InitializeCounters()) isolate->counters()->ResetCounters(); |
| 26 } |
23 | 27 |
24 int* StatsCounter::FindLocationInStatsTable() const { | 28 int* StatsCounter::FindLocationInStatsTable() const { |
25 return isolate_->stats_table()->FindLocation(name_); | 29 return isolate_->stats_table()->FindLocation(name_); |
26 } | 30 } |
27 | 31 |
| 32 StatsCounterThreadSafe::StatsCounterThreadSafe(Isolate* isolate, |
| 33 const char* name) |
| 34 : StatsCounter(isolate, name) { |
| 35 lookup_done_ = true; |
| 36 GetPtr(); |
| 37 } |
| 38 |
| 39 void StatsCounterThreadSafe::Set(int Value) { |
| 40 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 41 StatsCounter::Set(ptr_, Value); |
| 42 } |
| 43 |
| 44 void StatsCounterThreadSafe::Increment() { |
| 45 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 46 StatsCounter::Increment(ptr_); |
| 47 } |
| 48 |
| 49 void StatsCounterThreadSafe::Increment(int value) { |
| 50 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 51 StatsCounter::Increment(ptr_, value); |
| 52 } |
| 53 |
| 54 void StatsCounterThreadSafe::Decrement() { |
| 55 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 56 StatsCounter::Decrement(ptr_); |
| 57 } |
| 58 |
| 59 void StatsCounterThreadSafe::Decrement(int value) { |
| 60 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 61 StatsCounter::Decrement(ptr_, value); |
| 62 } |
| 63 |
| 64 void StatsCounterThreadSafe::Reset() { GetPtr(); } |
| 65 |
| 66 int* StatsCounterThreadSafe::GetPtr() { |
| 67 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 68 ptr_ = FindLocationInStatsTable(); |
| 69 return ptr_; |
| 70 } |
28 | 71 |
29 void Histogram::AddSample(int sample) { | 72 void Histogram::AddSample(int sample) { |
30 if (Enabled()) { | 73 if (Enabled()) { |
31 isolate()->stats_table()->AddHistogramSample(histogram_, sample); | 74 isolate()->stats_table()->AddHistogramSample(histogram_, sample); |
32 } | 75 } |
33 } | 76 } |
34 | 77 |
35 void* Histogram::CreateHistogram() const { | 78 void* Histogram::CreateHistogram() const { |
36 return isolate()->stats_table()-> | 79 return isolate()->stats_table()-> |
37 CreateHistogram(name_, min_, max_, num_buckets_); | 80 CreateHistogram(name_, min_, max_, num_buckets_); |
(...skipping 15 matching lines...) Expand all Loading... |
53 int64_t sample = resolution_ == MICROSECOND | 96 int64_t sample = resolution_ == MICROSECOND |
54 ? timer_.Elapsed().InMicroseconds() | 97 ? timer_.Elapsed().InMicroseconds() |
55 : timer_.Elapsed().InMilliseconds(); | 98 : timer_.Elapsed().InMilliseconds(); |
56 // Compute the delta between start and stop, in microseconds. | 99 // Compute the delta between start and stop, in microseconds. |
57 AddSample(static_cast<int>(sample)); | 100 AddSample(static_cast<int>(sample)); |
58 timer_.Stop(); | 101 timer_.Stop(); |
59 } | 102 } |
60 Logger::CallEventLogger(isolate(), name(), Logger::END, true); | 103 Logger::CallEventLogger(isolate(), name(), Logger::END, true); |
61 } | 104 } |
62 | 105 |
63 | 106 Counters::Counters(Isolate* isolate) |
64 Counters::Counters(Isolate* isolate) { | 107 : |
| 108 // clang format off |
| 109 #define SC(name, caption) name##_(isolate, "c:" #caption), |
| 110 STATS_COUNTER_TS_LIST(SC) |
| 111 #undef SC |
| 112 // clang format on |
| 113 runtime_call_stats_() { |
65 static const struct { | 114 static const struct { |
66 Histogram Counters::*member; | 115 Histogram Counters::*member; |
67 const char* caption; | 116 const char* caption; |
68 int min; | 117 int min; |
69 int max; | 118 int max; |
70 int num_buckets; | 119 int num_buckets; |
71 } kHistograms[] = { | 120 } kHistograms[] = { |
72 #define HR(name, caption, min, max, num_buckets) \ | 121 #define HR(name, caption, min, max, num_buckets) \ |
73 {&Counters::name##_, #caption, min, max, num_buckets}, | 122 {&Counters::name##_, #caption, min, max, num_buckets}, |
74 HISTOGRAM_RANGE_LIST(HR) | 123 HISTOGRAM_RANGE_LIST(HR) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 "c:" "V8.SizeOf_CODE_AGE-" #name}, | 242 "c:" "V8.SizeOf_CODE_AGE-" #name}, |
194 CODE_AGE_LIST_COMPLETE(SC) | 243 CODE_AGE_LIST_COMPLETE(SC) |
195 #undef SC | 244 #undef SC |
196 }; | 245 }; |
197 // clang-format on | 246 // clang-format on |
198 for (const auto& counter : kStatsCounters) { | 247 for (const auto& counter : kStatsCounters) { |
199 this->*counter.member = StatsCounter(isolate, counter.caption); | 248 this->*counter.member = StatsCounter(isolate, counter.caption); |
200 } | 249 } |
201 } | 250 } |
202 | 251 |
203 | |
204 void Counters::ResetCounters() { | 252 void Counters::ResetCounters() { |
205 #define SC(name, caption) name##_.Reset(); | 253 #define SC(name, caption) name##_.Reset(); |
206 STATS_COUNTER_LIST_1(SC) | 254 STATS_COUNTER_LIST_1(SC) |
207 STATS_COUNTER_LIST_2(SC) | 255 STATS_COUNTER_LIST_2(SC) |
208 #undef SC | 256 #undef SC |
209 | 257 |
| 258 #define SC(name, caption) name##_.Reset(); |
| 259 STATS_COUNTER_TS_LIST(SC) |
| 260 #undef SC |
| 261 |
210 #define SC(name) \ | 262 #define SC(name) \ |
211 count_of_##name##_.Reset(); \ | 263 count_of_##name##_.Reset(); \ |
212 size_of_##name##_.Reset(); | 264 size_of_##name##_.Reset(); |
213 INSTANCE_TYPE_LIST(SC) | 265 INSTANCE_TYPE_LIST(SC) |
214 #undef SC | 266 #undef SC |
215 | 267 |
216 #define SC(name) \ | 268 #define SC(name) \ |
217 count_of_CODE_TYPE_##name##_.Reset(); \ | 269 count_of_CODE_TYPE_##name##_.Reset(); \ |
218 size_of_CODE_TYPE_##name##_.Reset(); | 270 size_of_CODE_TYPE_##name##_.Reset(); |
219 CODE_KIND_LIST(SC) | 271 CODE_KIND_LIST(SC) |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 RuntimeCallStats::counters) { | 577 RuntimeCallStats::counters) { |
526 RuntimeCallCounter* counter = &(this->*counter_id); | 578 RuntimeCallCounter* counter = &(this->*counter_id); |
527 if (counter->count() > 0) counter->Dump(value); | 579 if (counter->count() > 0) counter->Dump(value); |
528 } | 580 } |
529 | 581 |
530 in_use_ = false; | 582 in_use_ = false; |
531 } | 583 } |
532 | 584 |
533 } // namespace internal | 585 } // namespace internal |
534 } // namespace v8 | 586 } // namespace v8 |
OLD | NEW |