Commit 7d7abeaa authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

[tracing] Replace semaphores with {Start,Stop}Blocking

Use Perfetto's Start/StopBlocking() helpers instead of bespoke
synchronization with semaphores.

Cq-Include-Trybots: luci.v8.try:v8_linux64_perfetto_dbg_ng
Bug: v8:8339
Change-Id: If8266d5fa5e3ff6403b9b2e539ec985bc67fcc90
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1728623
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63102}
parent 6a143fd0
......@@ -26,14 +26,10 @@
class V8DataSource : public perfetto::DataSource<V8DataSource> {
public:
void OnSetup(const SetupArgs&) override {}
void OnStart(const StartArgs&) override { started_.Signal(); }
void OnStart(const StartArgs&) override {}
void OnStop(const StopArgs&) override {}
static v8::base::Semaphore started_;
};
v8::base::Semaphore V8DataSource::started_{0};
PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(V8DataSource);
#endif // V8_USE_PERFETTO
......@@ -300,9 +296,7 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
tracing_session_ =
perfetto::Tracing::NewTrace(perfetto::BackendType::kUnspecifiedBackend);
tracing_session_->Setup(perfetto_trace_config);
// TODO(petermarshall): Switch to StartBlocking when available.
tracing_session_->Start();
V8DataSource::started_.Wait();
tracing_session_->StartBlocking();
#endif // V8_USE_PERFETTO
......@@ -345,10 +339,7 @@ void TracingController::StopTracing() {
V8DataSource::Trace([&](V8DataSource::TraceContext ctx) {
auto packet = ctx.NewTracePacket();
});
base::Semaphore stopped_{0};
tracing_session_->SetOnStopCallback([&stopped_]() { stopped_.Signal(); });
tracing_session_->Stop();
stopped_.Wait();
tracing_session_->StopBlocking();
std::vector<char> trace = tracing_session_->ReadTraceBlocking();
json_listener_->ParseFromArray(trace);
......
......@@ -23,14 +23,10 @@
class TestDataSource : public perfetto::DataSource<TestDataSource> {
public:
void OnSetup(const SetupArgs&) override {}
void OnStart(const StartArgs&) override { started_.Signal(); }
void OnStart(const StartArgs&) override {}
void OnStop(const StopArgs&) override {}
static v8::base::Semaphore started_;
};
v8::base::Semaphore TestDataSource::started_{0};
PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(TestDataSource);
#endif // V8_USE_PERFETTO
......@@ -914,8 +910,7 @@ TEST(TracingPerfetto) {
auto tracing_session_ =
perfetto::Tracing::NewTrace(perfetto::BackendType::kInProcessBackend);
tracing_session_->Setup(perfetto_trace_config);
tracing_session_->Start();
TestDataSource::started_.Wait();
tracing_session_->StartBlocking();
for (int i = 0; i < 15; i++) {
TestDataSource::Trace([&](TestDataSource::TraceContext ctx) {
......@@ -930,10 +925,7 @@ TEST(TracingPerfetto) {
trace_event->set_thread_timestamp(123);
});
}
v8::base::Semaphore stopped_{0};
tracing_session_->SetOnStopCallback([&stopped_]() { stopped_.Signal(); });
tracing_session_->Stop();
stopped_.Wait();
tracing_session_->StopBlocking();
std::ostringstream perfetto_json_stream_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment