From d3386720cc5be20f0b656c7b8e24db872d8bbf01 Mon Sep 17 00:00:00 2001 From: mathp Date: Tue, 20 Oct 2015 19:38:08 -0700 Subject: Revert of Port over the mojo tracing service from the mojo repo. (patchset #3 id:40001 of https://codereview.chromium.org/1415843003/ ) Reason for revert: Seems to have broken at least the Win x64 gn build http://build.chromium.org/p/chromium.win/builders/Win%20x64%20GN/builds/7438 Original issue's description: > Port over the mojo tracing service from the mojo repo. > > When we unforked from the mojo repo, we got the tracing service in a > state where it didn't reliably collect reports from different > processes. This ports all the startup time tracking changes we added to > the tracing application onto the mojo repo's tracing service. > > With this change, mandoline traces go from totally useless to merely > missing most of the data. > > BUG=534895 > R=msw@chromium.org > TBR=ben@chromium.org > > Committed: https://crrev.com/83e47b933a49ee7ba011a862eb706a0d25ec1624 > Cr-Commit-Position: refs/heads/master@{#355197} TBR=msw@chromium.org,ben@chromium.org,erg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=534895 Review URL: https://codereview.chromium.org/1408323005 Cr-Commit-Position: refs/heads/master@{#355222} --- mandoline/app/desktop/launcher_process.cc | 88 ++++++++++++++++++++++++++----- mandoline/services/core_services/BUILD.gn | 2 +- 2 files changed, 76 insertions(+), 14 deletions(-) (limited to 'mandoline') diff --git a/mandoline/app/desktop/launcher_process.cc b/mandoline/app/desktop/launcher_process.cc index 0b28d7a..2424045 100644 --- a/mandoline/app/desktop/launcher_process.cc +++ b/mandoline/app/desktop/launcher_process.cc @@ -21,34 +21,97 @@ #include "mandoline/app/desktop/launcher_process.h" #include "mojo/runner/context.h" #include "mojo/runner/switches.h" -#include "mojo/runner/tracer.h" namespace mandoline { +namespace { + +// Whether we're currently tracing. +bool g_tracing = false; + +// Number of tracing blocks written. +uint32_t g_blocks = 0; + +// Trace file, if open. +FILE* g_trace_file = nullptr; + +void WriteTraceDataCollected( + base::WaitableEvent* event, + const scoped_refptr& events_str, + bool has_more_events) { + if (g_blocks) { + fwrite(",", 1, 1, g_trace_file); + } + + ++g_blocks; + fwrite(events_str->data().c_str(), 1, events_str->data().length(), + g_trace_file); + if (!has_more_events) { + static const char kEnd[] = "]}"; + fwrite(kEnd, 1, strlen(kEnd), g_trace_file); + PCHECK(fclose(g_trace_file) == 0); + g_trace_file = nullptr; + event->Signal(); + } +} + +void EndTraceAndFlush(base::WaitableEvent* event) { + g_trace_file = fopen("mojo_shell.trace", "w+"); + PCHECK(g_trace_file); + static const char kStart[] = "{\"traceEvents\":["; + fwrite(kStart, 1, strlen(kStart), g_trace_file); + base::trace_event::TraceLog::GetInstance()->SetDisabled(); + base::trace_event::TraceLog::GetInstance()->Flush( + base::Bind(&WriteTraceDataCollected, base::Unretained(event))); +} + +void StopTracingAndFlushToDisk() { + g_tracing = false; + base::trace_event::TraceLog::GetInstance()->SetDisabled(); + base::WaitableEvent flush_complete_event(false, false); + // TraceLog::Flush requires a message loop but we've already shut ours down. + // Spin up a new thread to flush things out. + base::Thread flush_thread("mojo_shell_trace_event_flush"); + flush_thread.Start(); + flush_thread.message_loop()->PostTask( + FROM_HERE, + base::Bind(EndTraceAndFlush, base::Unretained(&flush_complete_event))); + flush_complete_event.Wait(); +} + +} // namespace int LauncherProcessMain(int argc, char** argv) { - mojo::runner::Tracer tracer; const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); - - bool trace_startup = command_line.HasSwitch(switches::kTraceStartup); - if (trace_startup) { - tracer.Start( + if (command_line.HasSwitch(switches::kTraceStartup)) { + g_tracing = true; + base::trace_event::TraceConfig trace_config( command_line.GetSwitchValueASCII(switches::kTraceStartup), - command_line.GetSwitchValueASCII(switches::kTraceStartupDuration), - "mandoline.trace"); + base::trace_event::RECORD_UNTIL_FULL); + base::trace_event::TraceLog::GetInstance()->SetEnabled( + trace_config, base::trace_event::TraceLog::RECORDING_MODE); + } else if (tracing::TraceConfigFile::GetInstance()->IsEnabled()) { + g_tracing = true; + base::trace_event::TraceLog::GetInstance()->SetEnabled( + tracing::TraceConfigFile::GetInstance()->GetTraceConfig(), + base::trace_event::TraceLog::RECORDING_MODE); } // We want the runner::Context to outlive the MessageLoop so that pipes are // all gracefully closed / error-out before we try to shut the Context down. base::FilePath shell_dir; PathService::Get(base::DIR_MODULE, &shell_dir); - mojo::runner::Context shell_context(shell_dir, &tracer); + mojo::runner::Context shell_context(shell_dir); { base::MessageLoop message_loop; - tracer.DidCreateMessageLoop(); if (!shell_context.Init()) { return 0; } + if (g_tracing) { + message_loop.PostDelayedTask(FROM_HERE, + base::Bind(StopTracingAndFlushToDisk), + base::TimeDelta::FromSeconds(5)); + } message_loop.PostTask(FROM_HERE, base::Bind(&mojo::runner::Context::Run, @@ -60,9 +123,8 @@ int LauncherProcessMain(int argc, char** argv) { shell_context.Shutdown(); } - if (trace_startup) - tracer.StopAndFlushToFile(); - + if (g_tracing) + StopTracingAndFlushToDisk(); return 0; } diff --git a/mandoline/services/core_services/BUILD.gn b/mandoline/services/core_services/BUILD.gn index f3b6ed7..9edb1f1 100644 --- a/mandoline/services/core_services/BUILD.gn +++ b/mandoline/services/core_services/BUILD.gn @@ -48,10 +48,10 @@ source_set("sources") { "//components/filesystem:lib", "//components/web_view:lib", "//mojo/application/public/cpp", + "//mojo/common:tracing_impl", "//mojo/logging", "//mojo/message_pump", "//mojo/services/tracing:lib", - "//mojo/services/tracing/public/cpp", "//third_party/icu", "//third_party/mojo/src/mojo/public/cpp/bindings", "//url", -- cgit v1.1