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* StatsCounterBase::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 : StatsCounterBase(isolate, name) { |
| 35 GetPtr(); |
| 36 } |
| 37 |
| 38 void StatsCounterThreadSafe::Set(int Value) { |
| 39 if (ptr_) { |
| 40 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 41 SetLoc(ptr_, Value); |
| 42 } |
| 43 } |
| 44 |
| 45 void StatsCounterThreadSafe::Increment() { |
| 46 if (ptr_) { |
| 47 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 48 IncrementLoc(ptr_); |
| 49 } |
| 50 } |
| 51 |
| 52 void StatsCounterThreadSafe::Increment(int value) { |
| 53 if (ptr_) { |
| 54 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 55 IncrementLoc(ptr_, value); |
| 56 } |
| 57 } |
| 58 |
| 59 void StatsCounterThreadSafe::Decrement() { |
| 60 if (ptr_) { |
| 61 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 62 DecrementLoc(ptr_); |
| 63 } |
| 64 } |
| 65 |
| 66 void StatsCounterThreadSafe::Decrement(int value) { |
| 67 if (ptr_) { |
| 68 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 69 DecrementLoc(ptr_, value); |
| 70 } |
| 71 } |
| 72 |
| 73 int* StatsCounterThreadSafe::GetPtr() { |
| 74 base::LockGuard<base::Mutex> Guard(&mutex_); |
| 75 ptr_ = FindLocationInStatsTable(); |
| 76 return ptr_; |
| 77 } |
28 | 78 |
29 void Histogram::AddSample(int sample) { | 79 void Histogram::AddSample(int sample) { |
30 if (Enabled()) { | 80 if (Enabled()) { |
31 isolate()->stats_table()->AddHistogramSample(histogram_, sample); | 81 isolate()->stats_table()->AddHistogramSample(histogram_, sample); |
32 } | 82 } |
33 } | 83 } |
34 | 84 |
35 void* Histogram::CreateHistogram() const { | 85 void* Histogram::CreateHistogram() const { |
36 return isolate()->stats_table()-> | 86 return isolate()->stats_table()-> |
37 CreateHistogram(name_, min_, max_, num_buckets_); | 87 CreateHistogram(name_, min_, max_, num_buckets_); |
(...skipping 15 matching lines...) Expand all Loading... |
53 int64_t sample = resolution_ == MICROSECOND | 103 int64_t sample = resolution_ == MICROSECOND |
54 ? timer_.Elapsed().InMicroseconds() | 104 ? timer_.Elapsed().InMicroseconds() |
55 : timer_.Elapsed().InMilliseconds(); | 105 : timer_.Elapsed().InMilliseconds(); |
56 // Compute the delta between start and stop, in microseconds. | 106 // Compute the delta between start and stop, in microseconds. |
57 AddSample(static_cast<int>(sample)); | 107 AddSample(static_cast<int>(sample)); |
58 timer_.Stop(); | 108 timer_.Stop(); |
59 } | 109 } |
60 Logger::CallEventLogger(isolate(), name(), Logger::END, true); | 110 Logger::CallEventLogger(isolate(), name(), Logger::END, true); |
61 } | 111 } |
62 | 112 |
63 | 113 Counters::Counters(Isolate* isolate) |
64 Counters::Counters(Isolate* isolate) { | 114 : |
| 115 // clang format off |
| 116 #define SC(name, caption) name##_(isolate, "c:" #caption), |
| 117 STATS_COUNTER_TS_LIST(SC) |
| 118 #undef SC |
| 119 // clang format on |
| 120 runtime_call_stats_() { |
65 static const struct { | 121 static const struct { |
66 Histogram Counters::*member; | 122 Histogram Counters::*member; |
67 const char* caption; | 123 const char* caption; |
68 int min; | 124 int min; |
69 int max; | 125 int max; |
70 int num_buckets; | 126 int num_buckets; |
71 } kHistograms[] = { | 127 } kHistograms[] = { |
72 #define HR(name, caption, min, max, num_buckets) \ | 128 #define HR(name, caption, min, max, num_buckets) \ |
73 {&Counters::name##_, #caption, min, max, num_buckets}, | 129 {&Counters::name##_, #caption, min, max, num_buckets}, |
74 HISTOGRAM_RANGE_LIST(HR) | 130 HISTOGRAM_RANGE_LIST(HR) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 "c:" "V8.SizeOf_CODE_AGE-" #name}, | 249 "c:" "V8.SizeOf_CODE_AGE-" #name}, |
194 CODE_AGE_LIST_COMPLETE(SC) | 250 CODE_AGE_LIST_COMPLETE(SC) |
195 #undef SC | 251 #undef SC |
196 }; | 252 }; |
197 // clang-format on | 253 // clang-format on |
198 for (const auto& counter : kStatsCounters) { | 254 for (const auto& counter : kStatsCounters) { |
199 this->*counter.member = StatsCounter(isolate, counter.caption); | 255 this->*counter.member = StatsCounter(isolate, counter.caption); |
200 } | 256 } |
201 } | 257 } |
202 | 258 |
203 | |
204 void Counters::ResetCounters() { | 259 void Counters::ResetCounters() { |
205 #define SC(name, caption) name##_.Reset(); | 260 #define SC(name, caption) name##_.Reset(); |
206 STATS_COUNTER_LIST_1(SC) | 261 STATS_COUNTER_LIST_1(SC) |
207 STATS_COUNTER_LIST_2(SC) | 262 STATS_COUNTER_LIST_2(SC) |
208 #undef SC | 263 #undef SC |
209 | 264 |
| 265 #define SC(name, caption) name##_.Reset(); |
| 266 STATS_COUNTER_TS_LIST(SC) |
| 267 #undef SC |
| 268 |
210 #define SC(name) \ | 269 #define SC(name) \ |
211 count_of_##name##_.Reset(); \ | 270 count_of_##name##_.Reset(); \ |
212 size_of_##name##_.Reset(); | 271 size_of_##name##_.Reset(); |
213 INSTANCE_TYPE_LIST(SC) | 272 INSTANCE_TYPE_LIST(SC) |
214 #undef SC | 273 #undef SC |
215 | 274 |
216 #define SC(name) \ | 275 #define SC(name) \ |
217 count_of_CODE_TYPE_##name##_.Reset(); \ | 276 count_of_CODE_TYPE_##name##_.Reset(); \ |
218 size_of_CODE_TYPE_##name##_.Reset(); | 277 size_of_CODE_TYPE_##name##_.Reset(); |
219 CODE_KIND_LIST(SC) | 278 CODE_KIND_LIST(SC) |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 RuntimeCallStats::counters) { | 584 RuntimeCallStats::counters) { |
526 RuntimeCallCounter* counter = &(this->*counter_id); | 585 RuntimeCallCounter* counter = &(this->*counter_id); |
527 if (counter->count() > 0) counter->Dump(value); | 586 if (counter->count() > 0) counter->Dump(value); |
528 } | 587 } |
529 | 588 |
530 in_use_ = false; | 589 in_use_ = false; |
531 } | 590 } |
532 | 591 |
533 } // namespace internal | 592 } // namespace internal |
534 } // namespace v8 | 593 } // namespace v8 |
OLD | NEW |