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

Unified Diff: src/profiler/tracing-cpu-profiler.cc

Issue 2396733002: [profiler] Tracing-based CPU profiler. (Closed)
Patch Set: Addressing comments + moving traced-value back to src/tracing Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/profiler/tracing-cpu-profiler.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/profiler/tracing-cpu-profiler.cc
diff --git a/src/profiler/tracing-cpu-profiler.cc b/src/profiler/tracing-cpu-profiler.cc
index b24ca2fd254ce655384195bf1847e4d00db87aa3..8b3122590500925c312d2a4377d4ede4617d8cb8 100644
--- a/src/profiler/tracing-cpu-profiler.cc
+++ b/src/profiler/tracing-cpu-profiler.cc
@@ -4,8 +4,13 @@
#include "src/profiler/tracing-cpu-profiler.h"
+#include "src/profiler/cpu-profiler.h"
+#include "src/tracing/trace-event.h"
#include "src/v8.h"
+#define PROFILER_TRACE_CATEGORY_ENABLED(cat) \
+ (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT(cat)))
+
namespace v8 {
std::unique_ptr<TracingCpuProfiler> TracingCpuProfiler::Create(
@@ -17,9 +22,57 @@ std::unique_ptr<TracingCpuProfiler> TracingCpuProfiler::Create(
namespace internal {
-TracingCpuProfilerImpl::TracingCpuProfilerImpl(Isolate* isolate) {}
+TracingCpuProfilerImpl::TracingCpuProfilerImpl(Isolate* isolate)
+ : isolate_(isolate), profiling_enabled_(false) {
+ // Make sure tracing system notices profiler categories.
+ PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler");
+ PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler.hires");
+ V8::GetCurrentPlatform()->AddTraceStateObserver(this);
+}
+
+TracingCpuProfilerImpl::~TracingCpuProfilerImpl() {
+ StopProfiling();
+ V8::GetCurrentPlatform()->RemoveTraceStateObserver(this);
+}
+
+void TracingCpuProfilerImpl::OnTraceEnabled() {
+ if (!PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler")) return;
+ profiling_enabled_ = true;
+ isolate_->RequestInterrupt(
+ [](v8::Isolate*, void* data) {
+ reinterpret_cast<TracingCpuProfilerImpl*>(data)->StartProfiling();
+ },
+ this);
+}
-TracingCpuProfilerImpl::~TracingCpuProfilerImpl() {}
+void TracingCpuProfilerImpl::OnTraceDisabled() {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ if (!profiling_enabled_) return;
+ profiling_enabled_ = false;
+ isolate_->RequestInterrupt(
+ [](v8::Isolate*, void* data) {
+ reinterpret_cast<TracingCpuProfilerImpl*>(data)->StopProfiling();
+ },
+ this);
+}
+
+void TracingCpuProfilerImpl::StartProfiling() {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ if (!profiling_enabled_ || profiler_) return;
+ int sampling_interval_us =
+ PROFILER_TRACE_CATEGORY_ENABLED("v8.cpu_profiler.hires") ? 100 : 1000;
+ profiler_.reset(new CpuProfiler(isolate_));
+ profiler_->set_sampling_interval(
+ base::TimeDelta::FromMicroseconds(sampling_interval_us));
+ profiler_->StartProfiling("", true);
+}
+
+void TracingCpuProfilerImpl::StopProfiling() {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ if (!profiler_) return;
+ profiler_->StopProfiling("");
+ profiler_.reset();
+}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/profiler/tracing-cpu-profiler.h ('k') | test/cctest/test-cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698