OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/trace/sys_trace_agent.h" |
| 6 |
| 7 #include <string> |
| 8 #include <utility> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/memory/singleton.h" |
| 12 #include "base/trace_event/trace_event.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/debug_daemon_client.h" |
| 15 #include "components/arc/trace/arc_trace_bridge.h" |
| 16 #include "content/public/browser/browser_thread.h" |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 namespace { |
| 21 |
| 22 constexpr char kCrosTracingAgentName[] = "cros"; |
| 23 constexpr char kCrosTraceLabel[] = "systemTraceEvents"; |
| 24 |
| 25 } // namespace |
| 26 |
| 27 std::string SysTraceAgent::GetTracingAgentName() { |
| 28 return kCrosTracingAgentName; |
| 29 } |
| 30 |
| 31 std::string SysTraceAgent::GetTraceEventLabel() { |
| 32 return kCrosTraceLabel; |
| 33 } |
| 34 |
| 35 void SysTraceAgent::StartAgentTracing( |
| 36 const base::trace_event::TraceConfig& trace_config, |
| 37 const StartAgentTracingCallback& callback) { |
| 38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 39 // Starts the system tracing on Chrome OS. |
| 40 // The kernel level tracing is started by debugd via dbus, and the Android |
| 41 // framework level tracing is started via mojo interface (ArcTraceBridge). |
| 42 // |
| 43 // Note that we bind mount /sys/kernel/debug/tracing/trace_marker into the |
| 44 // container during initialization. Therefore, both tracing results will be |
| 45 // collected by debugd from sysfs. |
| 46 chromeos::DebugDaemonClient* debug_daemon = |
| 47 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 48 // Starts kernel tracing via debugd. |
| 49 if (!debug_daemon) |
| 50 return; |
| 51 debug_daemon->StartAgentTracing(trace_config, callback); |
| 52 // Starts Android framework tracing via ArcTraceBridge. |
| 53 auto* arc_trace_bridge = arc::ArcTraceBridge::Get(); |
| 54 if (!arc_trace_bridge) |
| 55 return; |
| 56 arc_trace_bridge->StartTracing(trace_config); |
| 57 } |
| 58 |
| 59 void SysTraceAgent::StopAgentTracing(const StopAgentTracingCallback& callback) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 61 chromeos::DebugDaemonClient* debug_daemon = |
| 62 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 63 debug_daemon->StopAgentTracing(callback); |
| 64 |
| 65 auto* arc_trace_bridge = arc::ArcTraceBridge::Get(); |
| 66 if (!arc_trace_bridge) |
| 67 return |
| 68 arc_trace_bridge->StopTracing(); |
| 69 } |
| 70 |
| 71 void SysTraceAgent::SetStopAgentTracingTaskRunner( |
| 72 scoped_refptr<base::TaskRunner> task_runner) { |
| 73 chromeos::DebugDaemonClient* debug_daemon = |
| 74 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 75 debug_daemon->SetStopAgentTracingTaskRunner(task_runner); |
| 76 } |
| 77 |
| 78 SysTraceAgent* SysTraceAgent::GetInstance() { |
| 79 return base::Singleton<SysTraceAgent>::get(); |
| 80 } |
| 81 |
| 82 SysTraceAgent::SysTraceAgent() = default; |
| 83 SysTraceAgent::~SysTraceAgent() = default; |
| 84 |
| 85 } // namespace chromeos |
OLD | NEW |