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

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: Fix memory leak 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
« no previous file with comments | « src/tracing/trace-event.h ('k') | src/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-call-stats category due to its high frequency use.
18 base::Atomic32 kRuntimeCallStatsTracingEnabled = false;
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 void CallStatsScopedTracer::AddEndTraceEvent() {
25 if (!has_parent_scope_ && p_data_->isolate) {
26 v8::internal::tracing::AddTraceEvent(
27 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::kNoId, TRACE_EVENT_FLAG_COPY,
30 "runtime-call-stat",
31 TRACE_STR_COPY(p_data_->isolate->trace_event_stats_table()->Dump()));
32 } else {
33 v8::internal::tracing::AddTraceEvent(
34 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
35 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
36 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE);
37 }
38 }
39
40 void CallStatsScopedTracer::Initialize(Isolate* isolate,
41 const uint8_t* category_group_enabled,
42 const char* name) {
43 data_.isolate = isolate;
44 data_.category_group_enabled = category_group_enabled;
45 data_.name = name;
46 p_data_ = &data_;
47 TraceEventStatsTable* table = isolate->trace_event_stats_table();
48 has_parent_scope_ = table->InUse();
49 if (!has_parent_scope_) table->Reset();
50 v8::internal::tracing::AddTraceEvent(
51 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name,
52 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
53 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId);
54 }
55
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
17 } // namespace tracing 138 } // namespace tracing
18 } // namespace internal 139 } // namespace internal
19 } // namespace v8 140 } // namespace v8
OLDNEW
« no previous file with comments | « src/tracing/trace-event.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698