OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/tracing/trace-event.h" | 5 #include "src/tracing/trace-event.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
| 9 #include "src/counters.h" |
9 #include "src/isolate.h" | 10 #include "src/isolate.h" |
10 #include "src/v8.h" | 11 #include "src/v8.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace tracing { | 15 namespace tracing { |
15 | 16 |
16 // A global flag used as a shortcut to check for the | 17 // A global flag used as a shortcut to check for the |
17 // v8.runtime-call-stats category due to its high frequency use. | 18 // v8.runtime-call-stats category due to its high frequency use. |
18 base::Atomic32 kRuntimeCallStatsTracingEnabled = false; | 19 base::Atomic32 kRuntimeCallStatsTracingEnabled = false; |
19 | 20 |
20 v8::Platform* TraceEventHelper::GetCurrentPlatform() { | 21 v8::Platform* TraceEventHelper::GetCurrentPlatform() { |
21 return v8::internal::V8::GetCurrentPlatform(); | 22 return v8::internal::V8::GetCurrentPlatform(); |
22 } | 23 } |
23 | 24 |
24 void CallStatsScopedTracer::AddEndTraceEvent() { | 25 void CallStatsScopedTracer::AddEndTraceEvent() { |
25 if (!has_parent_scope_ && p_data_->isolate) { | 26 if (!has_parent_scope_ && p_data_->isolate) { |
26 v8::internal::tracing::AddTraceEvent( | 27 v8::internal::tracing::AddTraceEvent( |
27 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, | 28 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, |
28 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, | 29 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
29 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, | 30 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, |
30 "runtime-call-stats", | 31 "runtime-call-stats", TRACE_STR_COPY(p_data_->isolate->counters() |
31 TRACE_STR_COPY(p_data_->isolate->trace_event_stats_table()->Dump())); | 32 ->tracing_runtime_call_stats() |
| 33 ->Dump())); |
32 } else { | 34 } else { |
33 v8::internal::tracing::AddTraceEvent( | 35 v8::internal::tracing::AddTraceEvent( |
34 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, | 36 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, |
35 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, | 37 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
36 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE); | 38 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE); |
37 } | 39 } |
38 } | 40 } |
39 | 41 |
40 void CallStatsScopedTracer::Initialize(Isolate* isolate, | 42 void CallStatsScopedTracer::Initialize(v8::internal::Isolate* isolate, |
41 const uint8_t* category_group_enabled, | 43 const uint8_t* category_group_enabled, |
42 const char* name) { | 44 const char* name) { |
43 data_.isolate = isolate; | 45 data_.isolate = isolate; |
44 data_.category_group_enabled = category_group_enabled; | 46 data_.category_group_enabled = category_group_enabled; |
45 data_.name = name; | 47 data_.name = name; |
46 p_data_ = &data_; | 48 p_data_ = &data_; |
47 TraceEventStatsTable* table = isolate->trace_event_stats_table(); | 49 RuntimeCallStats* table = isolate->counters()->tracing_runtime_call_stats(); |
48 has_parent_scope_ = table->InUse(); | 50 has_parent_scope_ = table->InUse(); |
49 if (!has_parent_scope_) table->Reset(); | 51 if (!has_parent_scope_) table->Reset(); |
50 v8::internal::tracing::AddTraceEvent( | 52 v8::internal::tracing::AddTraceEvent( |
51 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name, | 53 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name, |
52 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, | 54 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
53 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); | 55 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); |
54 } | 56 } |
55 | 57 |
56 void TraceEventStatsTable::Enter(Isolate* isolate, | |
57 TraceEventCallStatsTimer* timer, | |
58 CounterId counter_id) { | |
59 TraceEventStatsTable* table = isolate->trace_event_stats_table(); | |
60 RuntimeCallCounter* counter = &(table->*counter_id); | |
61 timer->Start(counter, table->current_timer_); | |
62 table->current_timer_ = timer; | |
63 } | |
64 | |
65 void TraceEventStatsTable::Leave(Isolate* isolate, | |
66 TraceEventCallStatsTimer* timer) { | |
67 TraceEventStatsTable* table = isolate->trace_event_stats_table(); | |
68 if (table->current_timer_ == timer) { | |
69 table->current_timer_ = timer->Stop(); | |
70 } | |
71 } | |
72 | |
73 void TraceEventStatsTable::Reset() { | |
74 in_use_ = true; | |
75 current_timer_ = nullptr; | |
76 | |
77 #define RESET_COUNTER(name) this->name.Reset(); | |
78 FOR_EACH_MANUAL_COUNTER(RESET_COUNTER) | |
79 #undef RESET_COUNTER | |
80 | |
81 #define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset(); | |
82 FOR_EACH_INTRINSIC(RESET_COUNTER) | |
83 #undef RESET_COUNTER | |
84 | |
85 #define RESET_COUNTER(name) this->Builtin_##name.Reset(); | |
86 BUILTIN_LIST_C(RESET_COUNTER) | |
87 #undef RESET_COUNTER | |
88 | |
89 #define RESET_COUNTER(name) this->API_##name.Reset(); | |
90 FOR_EACH_API_COUNTER(RESET_COUNTER) | |
91 #undef RESET_COUNTER | |
92 | |
93 #define RESET_COUNTER(name) this->Handler_##name.Reset(); | |
94 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) | |
95 #undef RESET_COUNTER | |
96 } | |
97 | |
98 const char* TraceEventStatsTable::Dump() { | |
99 buffer_.str(std::string()); | |
100 buffer_.clear(); | |
101 buffer_ << "{"; | |
102 #define DUMP_COUNTER(name) \ | |
103 if (this->name.count > 0) this->name.Dump(buffer_); | |
104 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) | |
105 #undef DUMP_COUNTER | |
106 | |
107 #define DUMP_COUNTER(name, nargs, result_size) \ | |
108 if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(buffer_); | |
109 FOR_EACH_INTRINSIC(DUMP_COUNTER) | |
110 #undef DUMP_COUNTER | |
111 | |
112 #define DUMP_COUNTER(name) \ | |
113 if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(buffer_); | |
114 BUILTIN_LIST_C(DUMP_COUNTER) | |
115 #undef DUMP_COUNTER | |
116 | |
117 #define DUMP_COUNTER(name) \ | |
118 if (this->API_##name.count > 0) this->API_##name.Dump(buffer_); | |
119 FOR_EACH_API_COUNTER(DUMP_COUNTER) | |
120 #undef DUMP_COUNTER | |
121 | |
122 #define DUMP_COUNTER(name) \ | |
123 if (this->Handler_##name.count > 0) this->Handler_##name.Dump(buffer_); | |
124 FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER) | |
125 #undef DUMP_COUNTER | |
126 buffer_ << "\"END\":[]}"; | |
127 const std::string& buffer_str = buffer_.str(); | |
128 size_t length = buffer_str.size(); | |
129 if (length > len_) { | |
130 buffer_c_str_.reset(new char[length + 1]); | |
131 len_ = length; | |
132 } | |
133 strncpy(buffer_c_str_.get(), buffer_str.c_str(), length + 1); | |
134 in_use_ = false; | |
135 return buffer_c_str_.get(); | |
136 } | |
137 | |
138 } // namespace tracing | 58 } // namespace tracing |
139 } // namespace internal | 59 } // namespace internal |
140 } // namespace v8 | 60 } // namespace v8 |
OLD | NEW |