11cb0ef41Sopenharmony_ci// Copyright 2015 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/tracing/trace-event.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include <string.h> 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci#include "src/execution/isolate.h" 101cb0ef41Sopenharmony_ci#include "src/init/v8.h" 111cb0ef41Sopenharmony_ci#include "src/logging/counters.h" 121cb0ef41Sopenharmony_ci#include "src/tracing/traced-value.h" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace v8 { 151cb0ef41Sopenharmony_cinamespace internal { 161cb0ef41Sopenharmony_cinamespace tracing { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci#if !defined(V8_USE_PERFETTO) 191cb0ef41Sopenharmony_civ8::TracingController* TraceEventHelper::GetTracingController() { 201cb0ef41Sopenharmony_ci return v8::internal::V8::GetCurrentPlatform()->GetTracingController(); 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci#ifdef V8_RUNTIME_CALL_STATS 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_civoid CallStatsScopedTracer::AddEndTraceEvent() { 261cb0ef41Sopenharmony_ci if (!has_parent_scope_ && p_data_->isolate) { 271cb0ef41Sopenharmony_ci auto value = v8::tracing::TracedValue::Create(); 281cb0ef41Sopenharmony_ci p_data_->isolate->counters()->runtime_call_stats()->Dump(value.get()); 291cb0ef41Sopenharmony_ci v8::internal::tracing::AddTraceEvent( 301cb0ef41Sopenharmony_ci TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, 311cb0ef41Sopenharmony_ci v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, 321cb0ef41Sopenharmony_ci v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, 331cb0ef41Sopenharmony_ci "runtime-call-stats", std::move(value)); 341cb0ef41Sopenharmony_ci } else { 351cb0ef41Sopenharmony_ci v8::internal::tracing::AddTraceEvent( 361cb0ef41Sopenharmony_ci TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, 371cb0ef41Sopenharmony_ci v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, 381cb0ef41Sopenharmony_ci v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE); 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_civoid CallStatsScopedTracer::Initialize(v8::internal::Isolate* isolate, 431cb0ef41Sopenharmony_ci const uint8_t* category_group_enabled, 441cb0ef41Sopenharmony_ci const char* name) { 451cb0ef41Sopenharmony_ci data_.isolate = isolate; 461cb0ef41Sopenharmony_ci data_.category_group_enabled = category_group_enabled; 471cb0ef41Sopenharmony_ci data_.name = name; 481cb0ef41Sopenharmony_ci p_data_ = &data_; 491cb0ef41Sopenharmony_ci RuntimeCallStats* table = isolate->counters()->runtime_call_stats(); 501cb0ef41Sopenharmony_ci has_parent_scope_ = table->InUse(); 511cb0ef41Sopenharmony_ci if (!has_parent_scope_) table->Reset(); 521cb0ef41Sopenharmony_ci v8::internal::tracing::AddTraceEvent( 531cb0ef41Sopenharmony_ci TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name, 541cb0ef41Sopenharmony_ci v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, 551cb0ef41Sopenharmony_ci TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); 561cb0ef41Sopenharmony_ci} 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci#endif // defined(V8_RUNTIME_CALL_STATS) 591cb0ef41Sopenharmony_ci#endif // !defined(V8_USE_PERFETTO) 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci} // namespace tracing 621cb0ef41Sopenharmony_ci} // namespace internal 631cb0ef41Sopenharmony_ci} // namespace v8 64