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
3 // found in the LICENSE file.
4
5 #include "src/tracing/trace-event.h"
6
7 #include <string.h>
8
9 #include "src/execution/isolate.h"
10 #include "src/init/v8.h"
11 #include "src/logging/counters.h"
12 #include "src/tracing/traced-value.h"
13
14 namespace v8 {
15 namespace internal {
16 namespace tracing {
17
18 #if !defined(V8_USE_PERFETTO)
GetTracingController()19 v8::TracingController* TraceEventHelper::GetTracingController() {
20 return v8::internal::V8::GetCurrentPlatform()->GetTracingController();
21 }
22
23 #ifdef V8_RUNTIME_CALL_STATS
24
AddEndTraceEvent()25 void CallStatsScopedTracer::AddEndTraceEvent() {
26 if (!has_parent_scope_ && p_data_->isolate) {
27 auto value = v8::tracing::TracedValue::Create();
28 p_data_->isolate->counters()->runtime_call_stats()->Dump(value.get());
29 v8::internal::tracing::AddTraceEvent(
30 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
31 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
32 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE,
33 "runtime-call-stats", std::move(value));
34 } else {
35 v8::internal::tracing::AddTraceEvent(
36 TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name,
37 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
38 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE);
39 }
40 }
41
Initialize(v8::internal::Isolate * isolate,const uint8_t * category_group_enabled,const char * name)42 void CallStatsScopedTracer::Initialize(v8::internal::Isolate* isolate,
43 const uint8_t* category_group_enabled,
44 const char* name) {
45 data_.isolate = isolate;
46 data_.category_group_enabled = category_group_enabled;
47 data_.name = name;
48 p_data_ = &data_;
49 RuntimeCallStats* table = isolate->counters()->runtime_call_stats();
50 has_parent_scope_ = table->InUse();
51 if (!has_parent_scope_) table->Reset();
52 v8::internal::tracing::AddTraceEvent(
53 TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name,
54 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,
55 TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId);
56 }
57
58 #endif // defined(V8_RUNTIME_CALL_STATS)
59 #endif // !defined(V8_USE_PERFETTO)
60
61 } // namespace tracing
62 } // namespace internal
63 } // namespace v8
64