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/counters.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| 11 #include "src/tracing/traced-value.h" |
11 #include "src/v8.h" | 12 #include "src/v8.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 namespace tracing { | 16 namespace tracing { |
16 | 17 |
17 // A global flag used as a shortcut to check for the | 18 // A global flag used as a shortcut to check for the |
18 // v8.runtime-call-stats category due to its high frequency use. | 19 // v8.runtime-call-stats category due to its high frequency use. |
19 base::Atomic32 kRuntimeCallStatsTracingEnabled = false; | 20 base::Atomic32 kRuntimeCallStatsTracingEnabled = false; |
20 | 21 |
21 v8::Platform* TraceEventHelper::GetCurrentPlatform() { | 22 v8::Platform* TraceEventHelper::GetCurrentPlatform() { |
22 return v8::internal::V8::GetCurrentPlatform(); | 23 return v8::internal::V8::GetCurrentPlatform(); |
23 } | 24 } |
24 | 25 |
25 void CallStatsScopedTracer::AddEndTraceEvent() { | 26 void CallStatsScopedTracer::AddEndTraceEvent() { |
26 if (!has_parent_scope_ && p_data_->isolate) { | 27 if (!has_parent_scope_ && p_data_->isolate) { |
| 28 auto value = v8::tracing::TracedValue::Create(); |
| 29 p_data_->isolate->counters()->runtime_call_stats()->Dump(value.get()); |
27 v8::internal::tracing::AddTraceEvent( | 30 v8::internal::tracing::AddTraceEvent( |
28 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, | 31 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, |
29 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, | 32 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
30 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, | 33 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, |
31 "runtime-call-stats", TRACE_STR_COPY(p_data_->isolate->counters() | 34 "runtime-call-stats", std::move(value)); |
32 ->runtime_call_stats() | |
33 ->Dump() | |
34 .c_str())); | |
35 } else { | 35 } else { |
36 v8::internal::tracing::AddTraceEvent( | 36 v8::internal::tracing::AddTraceEvent( |
37 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, | 37 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, |
38 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, | 38 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
39 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE); | 39 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 void CallStatsScopedTracer::Initialize(v8::internal::Isolate* isolate, | 43 void CallStatsScopedTracer::Initialize(v8::internal::Isolate* isolate, |
44 const uint8_t* category_group_enabled, | 44 const uint8_t* category_group_enabled, |
45 const char* name) { | 45 const char* name) { |
46 data_.isolate = isolate; | 46 data_.isolate = isolate; |
47 data_.category_group_enabled = category_group_enabled; | 47 data_.category_group_enabled = category_group_enabled; |
48 data_.name = name; | 48 data_.name = name; |
49 p_data_ = &data_; | 49 p_data_ = &data_; |
50 RuntimeCallStats* table = isolate->counters()->runtime_call_stats(); | 50 RuntimeCallStats* table = isolate->counters()->runtime_call_stats(); |
51 has_parent_scope_ = table->InUse(); | 51 has_parent_scope_ = table->InUse(); |
52 if (!has_parent_scope_) table->Reset(); | 52 if (!has_parent_scope_) table->Reset(); |
53 v8::internal::tracing::AddTraceEvent( | 53 v8::internal::tracing::AddTraceEvent( |
54 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name, | 54 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name, |
55 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, | 55 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
56 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); | 56 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); |
57 } | 57 } |
58 | 58 |
59 } // namespace tracing | 59 } // namespace tracing |
60 } // namespace internal | 60 } // namespace internal |
61 } // namespace v8 | 61 } // namespace v8 |
OLD | NEW |