| Index: chrome/browser/chromeos/trace/sys_trace_agent.cc
|
| diff --git a/chrome/browser/chromeos/trace/sys_trace_agent.cc b/chrome/browser/chromeos/trace/sys_trace_agent.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b14a9b3db5f78700da8de26a5c5ed1f033fe3bea
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/trace/sys_trace_agent.cc
|
| @@ -0,0 +1,85 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/trace/sys_trace_agent.h"
|
| +
|
| +#include <string>
|
| +#include <utility>
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/memory/singleton.h"
|
| +#include "base/trace_event/trace_event.h"
|
| +#include "chromeos/dbus/dbus_thread_manager.h"
|
| +#include "chromeos/dbus/debug_daemon_client.h"
|
| +#include "components/arc/trace/arc_trace_bridge.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +
|
| +constexpr char kCrosTracingAgentName[] = "cros";
|
| +constexpr char kCrosTraceLabel[] = "systemTraceEvents";
|
| +
|
| +} // namespace
|
| +
|
| +std::string SysTraceAgent::GetTracingAgentName() {
|
| + return kCrosTracingAgentName;
|
| +}
|
| +
|
| +std::string SysTraceAgent::GetTraceEventLabel() {
|
| + return kCrosTraceLabel;
|
| +}
|
| +
|
| +void SysTraceAgent::StartAgentTracing(
|
| + const base::trace_event::TraceConfig& trace_config,
|
| + const StartAgentTracingCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + // Starts the system tracing on Chrome OS.
|
| + // The kernel level tracing is started by debugd via dbus, and the Android
|
| + // framework level tracing is started via mojo interface (ArcTraceBridge).
|
| + //
|
| + // Note that we bind mount /sys/kernel/debug/tracing/trace_marker into the
|
| + // container during initialization. Therefore, both tracing results will be
|
| + // collected by debugd from sysfs.
|
| + chromeos::DebugDaemonClient* debug_daemon =
|
| + chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
|
| + // Starts kernel tracing via debugd.
|
| + if (!debug_daemon)
|
| + return;
|
| + debug_daemon->StartAgentTracing(trace_config, callback);
|
| + // Starts Android framework tracing via ArcTraceBridge.
|
| + auto* arc_trace_bridge = arc::ArcTraceBridge::Get();
|
| + if (!arc_trace_bridge)
|
| + return;
|
| + arc_trace_bridge->StartTracing(trace_config);
|
| +}
|
| +
|
| +void SysTraceAgent::StopAgentTracing(const StopAgentTracingCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + chromeos::DebugDaemonClient* debug_daemon =
|
| + chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
|
| + debug_daemon->StopAgentTracing(callback);
|
| +
|
| + auto* arc_trace_bridge = arc::ArcTraceBridge::Get();
|
| + if (!arc_trace_bridge)
|
| + return
|
| + arc_trace_bridge->StopTracing();
|
| +}
|
| +
|
| +void SysTraceAgent::SetStopAgentTracingTaskRunner(
|
| + scoped_refptr<base::TaskRunner> task_runner) {
|
| + chromeos::DebugDaemonClient* debug_daemon =
|
| + chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
|
| + debug_daemon->SetStopAgentTracingTaskRunner(task_runner);
|
| +}
|
| +
|
| +SysTraceAgent* SysTraceAgent::GetInstance() {
|
| + return base::Singleton<SysTraceAgent>::get();
|
| +}
|
| +
|
| +SysTraceAgent::SysTraceAgent() = default;
|
| +SysTraceAgent::~SysTraceAgent() = default;
|
| +
|
| +} // namespace chromeos
|
|
|