Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: chromeos/dbus/debug_daemon_client.cc

Issue 1468173003: [Tracing Clock Sync] Add TracingAgent interface in Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/dbus/debug_daemon_client.h ('k') | chromeos/dbus/fake_debug_daemon_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/debug_daemon_client.h" 5 #include "chromeos/dbus/debug_daemon_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/task_runner_util.h" 19 #include "base/task_runner_util.h"
20 #include "chromeos/dbus/pipe_reader.h" 20 #include "chromeos/dbus/pipe_reader.h"
21 #include "dbus/bus.h" 21 #include "dbus/bus.h"
22 #include "dbus/message.h" 22 #include "dbus/message.h"
23 #include "dbus/object_path.h" 23 #include "dbus/object_path.h"
24 #include "dbus/object_proxy.h" 24 #include "dbus/object_proxy.h"
25 25
26 namespace { 26 namespace {
27 27
28 // Used in DebugDaemonClient::EmptySystemStopTracingCallback(). 28 const char kCrOSTracingAgentName[] = "cros";
29 void EmptyStopSystemTracingCallbackBody( 29 const char kCrOSTraceLabel[] = "systemTraceEvents";
30 const scoped_refptr<base::RefCountedString>& unused_result) { 30
31 } 31 // Used in DebugDaemonClient::EmptyStopAgentTracingCallback().
32 void EmptyStopAgentTracingCallbackBody(
33 const std::string& agent_name,
34 const std::string& events_label,
35 const scoped_refptr<base::RefCountedString>& unused_result) {}
32 36
33 } // namespace 37 } // namespace
34 38
35 namespace chromeos { 39 namespace chromeos {
36 40
37 // The DebugDaemonClient implementation used in production. 41 // The DebugDaemonClient implementation used in production.
38 class DebugDaemonClientImpl : public DebugDaemonClient { 42 class DebugDaemonClientImpl : public DebugDaemonClient {
39 public: 43 public:
40 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} 44 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {}
41 45
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 dbus::MethodCall method_call(debugd::kDebugdInterface, 191 dbus::MethodCall method_call(debugd::kDebugdInterface,
188 debugd::kGetUserLogFiles); 192 debugd::kGetUserLogFiles);
189 debugdaemon_proxy_->CallMethod( 193 debugdaemon_proxy_->CallMethod(
190 &method_call, 194 &method_call,
191 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 195 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
192 base::Bind(&DebugDaemonClientImpl::OnGetUserLogFiles, 196 base::Bind(&DebugDaemonClientImpl::OnGetUserLogFiles,
193 weak_ptr_factory_.GetWeakPtr(), 197 weak_ptr_factory_.GetWeakPtr(),
194 callback)); 198 callback));
195 } 199 }
196 200
197 void StartSystemTracing() override { 201 // base::trace_event::TracingAgent implementation.
202 std::string GetTracingAgentName() override { return kCrOSTracingAgentName; }
203
204 std::string GetTraceEventLabel() override { return kCrOSTraceLabel; }
205
206 bool StartAgentTracing(
207 const base::trace_event::TraceConfig& trace_config) override {
198 dbus::MethodCall method_call( 208 dbus::MethodCall method_call(
199 debugd::kDebugdInterface, 209 debugd::kDebugdInterface,
200 debugd::kSystraceStart); 210 debugd::kSystraceStart);
201 dbus::MessageWriter writer(&method_call); 211 dbus::MessageWriter writer(&method_call);
202 writer.AppendString("all"); // TODO(sleffler) parameterize category list 212 writer.AppendString("all"); // TODO(sleffler) parameterize category list
203 213
204 DVLOG(1) << "Requesting a systrace start"; 214 DVLOG(1) << "Requesting a systrace start";
205 debugdaemon_proxy_->CallMethod( 215 debugdaemon_proxy_->CallMethod(
206 &method_call, 216 &method_call,
207 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 217 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
208 base::Bind(&DebugDaemonClientImpl::OnStartMethod, 218 base::Bind(&DebugDaemonClientImpl::OnStartMethod,
209 weak_ptr_factory_.GetWeakPtr())); 219 weak_ptr_factory_.GetWeakPtr()));
220 return true;
210 } 221 }
211 222
212 bool RequestStopSystemTracing( 223 void StopAgentTracing(const StopAgentTracingCallback& callback) override {
213 scoped_refptr<base::TaskRunner> task_runner, 224 DCHECK(stop_agent_tracing_task_runner_);
214 const StopSystemTracingCallback& callback) override {
215 if (pipe_reader_ != NULL) { 225 if (pipe_reader_ != NULL) {
216 LOG(ERROR) << "Busy doing StopSystemTracing"; 226 LOG(ERROR) << "Busy doing StopSystemTracing";
217 return false; 227 return;
218 } 228 }
219 229
220 pipe_reader_.reset(new PipeReaderForString( 230 pipe_reader_.reset(
221 task_runner, 231 new PipeReaderForString(stop_agent_tracing_task_runner_,
222 base::Bind(&DebugDaemonClientImpl::OnIOComplete, 232 base::Bind(&DebugDaemonClientImpl::OnIOComplete,
223 weak_ptr_factory_.GetWeakPtr()))); 233 weak_ptr_factory_.GetWeakPtr())));
224 234
225 base::File pipe_write_end = pipe_reader_->StartIO(); 235 base::File pipe_write_end = pipe_reader_->StartIO();
226 // Create dbus::FileDescriptor on the worker thread; on return we'll 236 // Create dbus::FileDescriptor on the worker thread; on return we'll
227 // issue the D-Bus request to stop tracing and collect results. 237 // issue the D-Bus request to stop tracing and collect results.
228 base::PostTaskAndReplyWithResult( 238 base::PostTaskAndReplyWithResult(
229 task_runner.get(), 239 stop_agent_tracing_task_runner_.get(), FROM_HERE,
230 FROM_HERE,
231 base::Bind( 240 base::Bind(
232 &DebugDaemonClientImpl::CreateFileDescriptorToStopSystemTracing, 241 &DebugDaemonClientImpl::CreateFileDescriptorToStopSystemTracing,
233 base::Passed(&pipe_write_end)), 242 base::Passed(&pipe_write_end)),
234 base::Bind( 243 base::Bind(
235 &DebugDaemonClientImpl::OnCreateFileDescriptorRequestStopSystem, 244 &DebugDaemonClientImpl::OnCreateFileDescriptorRequestStopSystem,
236 weak_ptr_factory_.GetWeakPtr(), 245 weak_ptr_factory_.GetWeakPtr(), callback));
237 callback)); 246 }
238 return true; 247
248 void SetStopAgentTracingTaskRunner(
249 scoped_refptr<base::TaskRunner> task_runner) override {
250 stop_agent_tracing_task_runner_ = task_runner;
239 } 251 }
240 252
241 void TestICMP(const std::string& ip_address, 253 void TestICMP(const std::string& ip_address,
242 const TestICMPCallback& callback) override { 254 const TestICMPCallback& callback) override {
243 dbus::MethodCall method_call(debugd::kDebugdInterface, 255 dbus::MethodCall method_call(debugd::kDebugdInterface,
244 debugd::kTestICMP); 256 debugd::kTestICMP);
245 dbus::MessageWriter writer(&method_call); 257 dbus::MessageWriter writer(&method_call);
246 writer.AppendString(ip_address); 258 writer.AppendString(ip_address);
247 debugdaemon_proxy_->CallMethod( 259 debugdaemon_proxy_->CallMethod(
248 &method_call, 260 &method_call,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 // TODO(sleffler) if this fails AppendFileDescriptor will abort 562 // TODO(sleffler) if this fails AppendFileDescriptor will abort
551 } 563 }
552 scoped_ptr<dbus::FileDescriptor> file_descriptor(new dbus::FileDescriptor); 564 scoped_ptr<dbus::FileDescriptor> file_descriptor(new dbus::FileDescriptor);
553 file_descriptor->PutValue(pipe_write_end.TakePlatformFile()); 565 file_descriptor->PutValue(pipe_write_end.TakePlatformFile());
554 file_descriptor->CheckValidity(); 566 file_descriptor->CheckValidity();
555 return file_descriptor.Pass(); 567 return file_descriptor.Pass();
556 } 568 }
557 569
558 // Called when a CheckValidity response is received. 570 // Called when a CheckValidity response is received.
559 void OnCreateFileDescriptorRequestStopSystem( 571 void OnCreateFileDescriptorRequestStopSystem(
560 const StopSystemTracingCallback& callback, 572 const StopAgentTracingCallback& callback,
561 scoped_ptr<dbus::FileDescriptor> file_descriptor) { 573 scoped_ptr<dbus::FileDescriptor> file_descriptor) {
562 DCHECK(file_descriptor); 574 DCHECK(file_descriptor);
563 575
564 // Issue the dbus request to stop system tracing 576 // Issue the dbus request to stop system tracing
565 dbus::MethodCall method_call( 577 dbus::MethodCall method_call(
566 debugd::kDebugdInterface, 578 debugd::kDebugdInterface,
567 debugd::kSystraceStop); 579 debugd::kSystraceStop);
568 dbus::MessageWriter writer(&method_call); 580 dbus::MessageWriter writer(&method_call);
569 writer.AppendFileDescriptor(*file_descriptor); 581 writer.AppendFileDescriptor(*file_descriptor);
570 582
571 callback_ = callback; 583 callback_ = callback;
572 584
573 DVLOG(1) << "Requesting a systrace stop"; 585 DVLOG(1) << "Requesting a systrace stop";
574 debugdaemon_proxy_->CallMethod( 586 debugdaemon_proxy_->CallMethod(
575 &method_call, 587 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
576 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 588 base::Bind(&DebugDaemonClientImpl::OnStopAgentTracing,
577 base::Bind(&DebugDaemonClientImpl::OnRequestStopSystemTracing,
578 weak_ptr_factory_.GetWeakPtr())); 589 weak_ptr_factory_.GetWeakPtr()));
579 } 590 }
580 591
581 // Called when a response for RequestStopSystemTracing() is received. 592 // Called when a response for StopAgentTracing() is received.
582 void OnRequestStopSystemTracing(dbus::Response* response) { 593 void OnStopAgentTracing(dbus::Response* response) {
583 if (!response) { 594 if (!response) {
584 LOG(ERROR) << "Failed to request systrace stop"; 595 LOG(ERROR) << "Failed to request systrace stop";
585 // If debugd crashes or completes I/O before this message is processed 596 // If debugd crashes or completes I/O before this message is processed
586 // then pipe_reader_ can be NULL, see OnIOComplete(). 597 // then pipe_reader_ can be NULL, see OnIOComplete().
587 if (pipe_reader_.get()) 598 if (pipe_reader_.get())
588 pipe_reader_->OnDataReady(-1); // terminate data stream 599 pipe_reader_->OnDataReady(-1); // terminate data stream
589 } 600 }
590 // NB: requester is signaled when i/o completes 601 // NB: requester is signaled when i/o completes
591 } 602 }
592 603
593 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) { 604 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) {
594 std::string status; 605 std::string status;
595 if (response && dbus::MessageReader(response).PopString(&status)) 606 if (response && dbus::MessageReader(response).PopString(&status))
596 callback.Run(true, status); 607 callback.Run(true, status);
597 else 608 else
598 callback.Run(false, ""); 609 callback.Run(false, "");
599 } 610 }
600 611
601 // Called when pipe i/o completes; pass data on and delete the instance. 612 // Called when pipe i/o completes; pass data on and delete the instance.
602 void OnIOComplete() { 613 void OnIOComplete() {
603 std::string pipe_data; 614 std::string pipe_data;
604 pipe_reader_->GetData(&pipe_data); 615 pipe_reader_->GetData(&pipe_data);
605 callback_.Run(base::RefCountedString::TakeString(&pipe_data)); 616 callback_.Run(GetTracingAgentName(), GetTraceEventLabel(),
617 base::RefCountedString::TakeString(&pipe_data));
606 pipe_reader_.reset(); 618 pipe_reader_.reset();
607 } 619 }
608 620
609 dbus::ObjectProxy* debugdaemon_proxy_; 621 dbus::ObjectProxy* debugdaemon_proxy_;
610 scoped_ptr<PipeReaderForString> pipe_reader_; 622 scoped_ptr<PipeReaderForString> pipe_reader_;
611 StopSystemTracingCallback callback_; 623 StopAgentTracingCallback callback_;
624 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_;
612 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; 625 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_;
613 626
614 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); 627 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl);
615 }; 628 };
616 629
617 DebugDaemonClient::DebugDaemonClient() { 630 DebugDaemonClient::DebugDaemonClient() {
618 } 631 }
619 632
620 DebugDaemonClient::~DebugDaemonClient() { 633 DebugDaemonClient::~DebugDaemonClient() {
621 } 634 }
622 635
623 // static 636 // static
624 DebugDaemonClient::StopSystemTracingCallback 637 DebugDaemonClient::StopAgentTracingCallback
625 DebugDaemonClient::EmptyStopSystemTracingCallback() { 638 DebugDaemonClient::EmptyStopAgentTracingCallback() {
626 return base::Bind(&EmptyStopSystemTracingCallbackBody); 639 return base::Bind(&EmptyStopAgentTracingCallbackBody);
627 } 640 }
628 641
629 // static 642 // static
630 DebugDaemonClient* DebugDaemonClient::Create() { 643 DebugDaemonClient* DebugDaemonClient::Create() {
631 return new DebugDaemonClientImpl(); 644 return new DebugDaemonClientImpl();
632 } 645 }
633 646
634 } // namespace chromeos 647 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/debug_daemon_client.h ('k') | chromeos/dbus/fake_debug_daemon_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698