Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/tracing/trace-event.cc

Issue 2187693002: [Tracing] Embed V8 runtime call stats into tracing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8
9 #include "src/isolate.h"
7 #include "src/v8.h" 10 #include "src/v8.h"
8 11
9 namespace v8 { 12 namespace v8 {
10 namespace internal { 13 namespace internal {
11 namespace tracing { 14 namespace tracing {
12 15
16 // A global flag used as a shortcut to check for the
17 // v8.runtime category due to its high frequency use.
18 int kRuntimeCallsTracingEnabled = 0;
Camillo Bruni 2016/07/27 08:29:07 Please make this a bool to make your intentions a
lpy 2016/07/27 19:58:37 Done.
19
13 v8::Platform* TraceEventHelper::GetCurrentPlatform() { 20 v8::Platform* TraceEventHelper::GetCurrentPlatform() {
14 return v8::internal::V8::GetCurrentPlatform(); 21 return v8::internal::V8::GetCurrentPlatform();
15 } 22 }
16 23
24 CallStatsScopedTracer::~CallStatsScopedTracer() {
25 if (p_data_ && *data_.category_group_enabled) {
Camillo Bruni 2016/07/27 08:29:07 can you put the test in the header and delegate th
lpy 2016/07/27 19:58:37 Done.
26 if (!has_parent_scope_) {
27 v8::internal::tracing::AddTraceEvent(
28 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
29 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
30 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId,
31 "runtime-call-stat",
32 p_data_->isolate
33 ? TRACE_STR_COPY(
34 p_data_->isolate->trace_event_stats_table()->Dump())
35 : "");
36 } else {
37 v8::internal::tracing::AddTraceEvent(
38 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
39 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
40 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId);
41 }
42 }
43 }
44
45 void CallStatsScopedTracer::Initialize(Isolate* isolate,
46 const uint8_t* category_group_enabled,
47 const char* name) {
48 data_.isolate = isolate;
49 data_.category_group_enabled = category_group_enabled;
50 data_.name = name;
51 p_data_ = &data_;
52 TraceEventStatsTable* table = isolate->trace_event_stats_table();
53 has_parent_scope_ = table->InUse();
54 if (!has_parent_scope_) table->Reset();
55 v8::internal::tracing::AddTraceEvent(
56 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name,
57 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
58 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId);
59 }
60
61 void TraceEventStatsTable::Enter(Isolate* isolate,
62 TraceEventCallStatsTimer* timer,
63 CounterId counter_id) {
64 TraceEventStatsTable* table = isolate->trace_event_stats_table();
65 RuntimeCallCounter* counter = &(table->*counter_id);
66 timer->Start(counter, table->current_timer_);
67 table->current_timer_ = timer;
68 }
69
70 void TraceEventStatsTable::Leave(Isolate* isolate,
71 TraceEventCallStatsTimer* timer) {
72 TraceEventStatsTable* table = isolate->trace_event_stats_table();
73 if (table->current_timer_ == timer) {
74 table->current_timer_ = timer->Stop();
75 }
76 }
77
78 void TraceEventStatsTable::Reset() {
79 in_use_ = true;
80 current_timer_ = nullptr;
81 #define RESET_COUNTER(name) this->name.Reset();
82 FOR_EACH_MANUAL_COUNTER(RESET_COUNTER)
83 #undef RESET_COUNTER
84
85 #define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset();
86 FOR_EACH_INTRINSIC(RESET_COUNTER)
87 #undef RESET_COUNTER
88
89 #define RESET_COUNTER(name) this->Builtin_##name.Reset();
90 BUILTIN_LIST_C(RESET_COUNTER)
91 #undef RESET_COUNTER
92
93 #define RESET_COUNTER(name) this->API_##name.Reset();
94 FOR_EACH_API_COUNTER(RESET_COUNTER)
95 #undef RESET_COUNTER
96
97 #define RESET_COUNTER(name) this->Handler_##name.Reset();
98 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER)
99 #undef RESET_COUNTER
100 }
101
102 const char* TraceEventStatsTable::Dump() {
103 buffer_.str("");
104 buffer_.clear();
105 buffer_ << "{";
106 #define DUMP_COUNTER(name) \
107 if (this->name.count > 0) this->name.Dump(buffer_);
108 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER)
109 #undef DUMP_COUNTER
110
111 #define DUMP_COUNTER(name, nargs, result_size) \
112 if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(buffer_);
113 FOR_EACH_INTRINSIC(DUMP_COUNTER)
114 #undef DUMP_COUNTER
115
116 #define DUMP_COUNTER(name) \
117 if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(buffer_);
118 BUILTIN_LIST_C(DUMP_COUNTER)
119 #undef DUMP_COUNTER
120
121 #define DUMP_COUNTER(name) \
122 if (this->API_##name.count > 0) this->API_##name.Dump(buffer_);
123 FOR_EACH_API_COUNTER(DUMP_COUNTER)
124 #undef DUMP_COUNTER
125
126 #define DUMP_COUNTER(name) \
127 if (this->Handler_##name.count > 0) this->Handler_##name.Dump(buffer_);
128 FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER)
129 #undef DUMP_COUNTER
130 buffer_ << "\"END\":[]}";
131 std::string buffer_str = buffer_.str();
132 size_t length = buffer_str.size();
133 char* buffer_c_str = new char[length + 1];
134 memcpy(buffer_c_str, buffer_str.c_str(), length + 1);
135 in_use_ = false;
136 return buffer_c_str;
137 }
138
139 CounterScope::CounterScope(Isolate* isolate,
140 TraceEventStatsTable::CounterId counter_id)
141 : isolate_(nullptr) {
142 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) {
143 isolate_ = isolate;
144 TraceEventStatsTable::Enter(isolate_, &timer_, counter_id);
145 }
146 }
147
148 CounterScope::~CounterScope() {
149 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED()) &&
150 isolate_) {
151 TraceEventStatsTable::Leave(isolate_, &timer_);
152 }
153 }
154
17 } // namespace tracing 155 } // namespace tracing
18 } // namespace internal 156 } // namespace internal
19 } // namespace v8 157 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698