Chromium Code Reviews| 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 "chromeos/dbus/arc_trace_agent.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 12 #include "dbus/bus.h" | |
| 13 #include "dbus/message.h" | |
| 14 #include "dbus/object_path.h" | |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 16 | |
| 17 namespace chromeos { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 constexpr char kArcTracingAgentName[] = "arc"; | |
| 22 constexpr char kArcTraceLabel[] = "ArcTraceEvents"; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 std::string ArcTraceAgent::GetTracingAgentName() { | |
| 27 return kArcTracingAgentName; | |
| 28 } | |
| 29 | |
| 30 std::string ArcTraceAgent::GetTraceEventLabel() { | |
| 31 return kArcTraceLabel; | |
| 32 } | |
| 33 | |
| 34 void ArcTraceAgent::SetArcTraceBridge(ArcTraceAgent::ArcTraceBridge* bridge) { | |
| 35 arc_trace_bridge_ = bridge; | |
| 36 } | |
| 37 | |
| 38 void ArcTraceAgent::StartAgentTracing( | |
| 39 const base::trace_event::TraceConfig& trace_config, | |
| 40 const StartAgentTracingCallback& callback) { | |
| 41 | |
| 42 // arc_trace_brigde_ may be null if ARC is not enabled on the system. In such | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
s/arc_trace_brigde_/arc_trace_bridge_/
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 43 // case, simply do nothing. | |
| 44 if (arc_trace_bridge_) { | |
| 45 arc_trace_bridge_->StartTracing(trace_config); | |
| 46 | |
| 47 dbus::MethodCall method_call( | |
| 48 debugd::kDebugdInterface, | |
| 49 "ArcTraceStart"); | |
| 50 debugdaemon_proxy_->CallMethod( | |
| 51 &method_call, | |
| 52 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 53 base::Bind(&ArcTraceAgent::OnStartMethod, | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
Shouldn't you run |callback| in OnStartMethod inst
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 54 weak_ptr_factory_.GetWeakPtr())); | |
| 55 } | |
| 56 | |
| 57 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
Why can't you just do
callback.Run(GetTracingAgen
shunhsingou
2016/12/28 09:15:16
I forget to change. Move it to OnStartMethod.
| |
| 58 FROM_HERE, | |
| 59 base::Bind(callback, GetTracingAgentName(), true /* success */)); | |
| 60 } | |
| 61 | |
| 62 // Called when a response for a simple start is received. | |
| 63 void ArcTraceAgent::OnStartMethod(dbus::Response* response) { | |
|
Luis Héctor Chávez
2016/12/27 19:16:00
This can be a standalone function in the anonymous
shunhsingou
2016/12/28 09:15:16
Moved callback call to here. So this function need
| |
| 64 if (!response) { | |
| 65 LOG(ERROR) << "Failed to request start"; | |
| 66 return; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void ArcTraceAgent::StopAgentTracing(const StopAgentTracingCallback& callback) { | |
| 71 DCHECK(stop_agent_tracing_task_runner_); | |
| 72 if (pipe_reader_ != NULL) { | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
Maybe it's better to check if |callback_.is_null()
shunhsingou
2016/12/28 09:15:15
Done.
| |
| 73 LOG(ERROR) << "Busy doing StopAgentTracing"; | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 if (arc_trace_bridge_) { | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
if (!arc_trace_bridge_)
return;
// rest of the
shunhsingou
2016/12/28 09:15:16
Done. Just return empty report here.
| |
| 78 arc_trace_bridge_->StopTracing(); | |
| 79 | |
| 80 pipe_reader_.reset( | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
nit: pipe_reader_ = base::MakeUnique<PipeReaderFor
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 81 new PipeReaderForString(stop_agent_tracing_task_runner_, | |
| 82 base::Bind(&ArcTraceAgent::OnIOComplete, | |
| 83 weak_ptr_factory_.GetWeakPtr()))); | |
| 84 | |
| 85 base::ScopedFD pipe_write_end = pipe_reader_->StartIO(); | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
What thread is this supposed to be run on? Is I/O
shunhsingou
2016/12/28 09:15:15
It's running on 'stop_agent_tracing_task_runner_',
Luis Héctor Chávez
2016/12/28 17:21:58
Can you add comments about which methods run on wh
shunhsingou
2016/12/29 09:40:29
Done.
| |
| 86 DCHECK(pipe_write_end.is_valid()); | |
| 87 // Issue the dbus request to stop system tracing | |
| 88 dbus::MethodCall method_call(debugd::kDebugdInterface, | |
| 89 "ArcTraceStop"); | |
| 90 dbus::MessageWriter writer(&method_call); | |
| 91 writer.AppendFileDescriptor(pipe_write_end.get()); | |
| 92 | |
| 93 callback_ = callback; | |
| 94 | |
| 95 debugdaemon_proxy_->CallMethod( | |
| 96 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 97 base::Bind(&ArcTraceAgent::OnStopAgentTracing, | |
| 98 weak_ptr_factory_.GetWeakPtr())); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 // Called when pipe i/o completes; pass data on and delete the instance. | |
|
Luis Héctor Chávez
2016/12/27 19:16:00
nit: be consistent and use I/O all across the boar
shunhsingou
2016/12/28 09:15:15
Done.
| |
| 103 void ArcTraceAgent::OnIOComplete() { | |
| 104 std::string pipe_data; | |
| 105 pipe_reader_->GetData(&pipe_data); | |
| 106 callback_.Run(GetTracingAgentName(), GetTraceEventLabel(), | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
nit: base::ResetAndReturn(&callback_).Run(...);
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 107 base::RefCountedString::TakeString(&pipe_data)); | |
| 108 pipe_reader_.reset(); | |
|
Luis Héctor Chávez
2016/12/27 19:16:00
maybe reset the pipe_reader_ before calling the ca
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 109 } | |
| 110 | |
| 111 void ArcTraceAgent::OnStopAgentTracing(dbus::Response* response) { | |
| 112 if (!response) { | |
| 113 LOG(ERROR) << "Failed to request arc stop"; | |
| 114 // If debugd crashes or completes I/O before this message is processed | |
| 115 // then pipe_reader_ can be NULL, see OnIOComplete(). | |
| 116 if (pipe_reader_.get()) | |
| 117 pipe_reader_->OnDataReady(-1); // terminate data stream | |
| 118 } | |
| 119 // NB: requester is signaled when i/o completes | |
| 120 } | |
| 121 | |
| 122 void ArcTraceAgent::SetStopAgentTracingTaskRunner( | |
| 123 scoped_refptr<base::TaskRunner> task_runner) { | |
| 124 stop_agent_tracing_task_runner_ = task_runner; | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
alignment. please run `git cl format` and `git cl
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 125 } | |
| 126 | |
| 127 ArcTraceAgent* ArcTraceAgent::Create() { | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
nit: // static
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 128 return new ArcTraceAgent(); | |
| 129 } | |
| 130 | |
| 131 void ArcTraceAgent::Init(dbus::Bus* bus) { | |
| 132 debugdaemon_proxy_ = | |
| 133 bus->GetObjectProxy(debugd::kDebugdServiceName, | |
| 134 dbus::ObjectPath(debugd::kDebugdServicePath)); | |
| 135 } | |
| 136 | |
| 137 ArcTraceAgent::ArcTraceAgent() | |
| 138 : arc_trace_bridge_(NULL), | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
nit: s/NULL/nullptr/ all across the change.
Also,
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 139 debugdaemon_proxy_(NULL), | |
| 140 weak_ptr_factory_(this) {} | |
| 141 | |
| 142 ArcTraceAgent::~ArcTraceAgent() { | |
|
Luis Héctor Chávez
2016/12/27 19:15:59
nit: = default;
shunhsingou
2016/12/28 09:15:16
Done.
| |
| 143 } | |
| 144 | |
| 145 } // namespace chromeos | |
| OLD | NEW |