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

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: 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
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 // Used in DebugDaemonClient::EmptyStopAgentTracingCallback().
29 void EmptyStopSystemTracingCallbackBody( 29 void EmptyStopAgentTracingCallbackBody(
30 const scoped_refptr<base::RefCountedString>& unused_result) { 30 const scoped_refptr<base::RefCountedString>& unused_result) {}
31 }
32 31
33 } // namespace 32 } // namespace
34 33
35 namespace chromeos { 34 namespace chromeos {
36 35
37 // The DebugDaemonClient implementation used in production. 36 // The DebugDaemonClient implementation used in production.
38 class DebugDaemonClientImpl : public DebugDaemonClient { 37 class DebugDaemonClientImpl : public DebugDaemonClient {
39 public: 38 public:
40 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} 39 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {}
41 40
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 dbus::MethodCall method_call(debugd::kDebugdInterface, 186 dbus::MethodCall method_call(debugd::kDebugdInterface,
188 debugd::kGetUserLogFiles); 187 debugd::kGetUserLogFiles);
189 debugdaemon_proxy_->CallMethod( 188 debugdaemon_proxy_->CallMethod(
190 &method_call, 189 &method_call,
191 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 190 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
192 base::Bind(&DebugDaemonClientImpl::OnGetUserLogFiles, 191 base::Bind(&DebugDaemonClientImpl::OnGetUserLogFiles,
193 weak_ptr_factory_.GetWeakPtr(), 192 weak_ptr_factory_.GetWeakPtr(),
194 callback)); 193 callback));
195 } 194 }
196 195
197 void StartSystemTracing() override { 196 std::string GetTracingAgentName() override { return kCrOSTracingAgentName; }
197
198 bool StartAgentTracing(
199 const base::trace_event::TraceConfig& trace_config) override {
198 dbus::MethodCall method_call( 200 dbus::MethodCall method_call(
199 debugd::kDebugdInterface, 201 debugd::kDebugdInterface,
200 debugd::kSystraceStart); 202 debugd::kSystraceStart);
201 dbus::MessageWriter writer(&method_call); 203 dbus::MessageWriter writer(&method_call);
202 writer.AppendString("all"); // TODO(sleffler) parameterize category list 204 writer.AppendString("all"); // TODO(sleffler) parameterize category list
203 205
204 DVLOG(1) << "Requesting a systrace start"; 206 DVLOG(1) << "Requesting a systrace start";
205 debugdaemon_proxy_->CallMethod( 207 debugdaemon_proxy_->CallMethod(
206 &method_call, 208 &method_call,
207 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 209 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
208 base::Bind(&DebugDaemonClientImpl::OnStartMethod, 210 base::Bind(&DebugDaemonClientImpl::OnStartMethod,
209 weak_ptr_factory_.GetWeakPtr())); 211 weak_ptr_factory_.GetWeakPtr()));
212 return true;
210 } 213 }
211 214
212 bool RequestStopSystemTracing( 215 void StopAgentTracing(const StopAgentTracingCallback& callback) override {
213 scoped_refptr<base::TaskRunner> task_runner, 216 DCHECK(stop_agent_tracing_task_runner_);
214 const StopSystemTracingCallback& callback) override {
215 if (pipe_reader_ != NULL) { 217 if (pipe_reader_ != NULL) {
216 LOG(ERROR) << "Busy doing StopSystemTracing"; 218 LOG(ERROR) << "Busy doing StopSystemTracing";
217 return false; 219 return;
218 } 220 }
219 221
220 pipe_reader_.reset(new PipeReaderForString( 222 pipe_reader_.reset(
221 task_runner, 223 new PipeReaderForString(stop_agent_tracing_task_runner_,
222 base::Bind(&DebugDaemonClientImpl::OnIOComplete, 224 base::Bind(&DebugDaemonClientImpl::OnIOComplete,
223 weak_ptr_factory_.GetWeakPtr()))); 225 weak_ptr_factory_.GetWeakPtr())));
224 226
225 base::File pipe_write_end = pipe_reader_->StartIO(); 227 base::File pipe_write_end = pipe_reader_->StartIO();
226 // Create dbus::FileDescriptor on the worker thread; on return we'll 228 // Create dbus::FileDescriptor on the worker thread; on return we'll
227 // issue the D-Bus request to stop tracing and collect results. 229 // issue the D-Bus request to stop tracing and collect results.
228 base::PostTaskAndReplyWithResult( 230 base::PostTaskAndReplyWithResult(
229 task_runner.get(), 231 stop_agent_tracing_task_runner_.get(), FROM_HERE,
230 FROM_HERE,
231 base::Bind( 232 base::Bind(
232 &DebugDaemonClientImpl::CreateFileDescriptorToStopSystemTracing, 233 &DebugDaemonClientImpl::CreateFileDescriptorToStopSystemTracing,
233 base::Passed(&pipe_write_end)), 234 base::Passed(&pipe_write_end)),
234 base::Bind( 235 base::Bind(
235 &DebugDaemonClientImpl::OnCreateFileDescriptorRequestStopSystem, 236 &DebugDaemonClientImpl::OnCreateFileDescriptorRequestStopSystem,
236 weak_ptr_factory_.GetWeakPtr(), 237 weak_ptr_factory_.GetWeakPtr(), callback));
237 callback)); 238 }
238 return true; 239
240 bool SupportsExplicitClockSync() override { return false; }
241
242 void RecordClockSyncMarker(
243 scoped_ptr<base::DictionaryValue> marker) override {
244 DCHECK(SupportsExplicitClockSync());
245 }
246
247 void IssueClockSyncMarker() override { DCHECK(SupportsExplicitClockSync()); }
248
249 void SetStopAgentTracingTaskRunner(
250 scoped_refptr<base::TaskRunner> task_runner) override {
251 stop_agent_tracing_task_runner_ = task_runner;
239 } 252 }
240 253
241 void TestICMP(const std::string& ip_address, 254 void TestICMP(const std::string& ip_address,
242 const TestICMPCallback& callback) override { 255 const TestICMPCallback& callback) override {
243 dbus::MethodCall method_call(debugd::kDebugdInterface, 256 dbus::MethodCall method_call(debugd::kDebugdInterface,
244 debugd::kTestICMP); 257 debugd::kTestICMP);
245 dbus::MessageWriter writer(&method_call); 258 dbus::MessageWriter writer(&method_call);
246 writer.AppendString(ip_address); 259 writer.AppendString(ip_address);
247 debugdaemon_proxy_->CallMethod( 260 debugdaemon_proxy_->CallMethod(
248 &method_call, 261 &method_call,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 // TODO(sleffler) if this fails AppendFileDescriptor will abort 563 // TODO(sleffler) if this fails AppendFileDescriptor will abort
551 } 564 }
552 scoped_ptr<dbus::FileDescriptor> file_descriptor(new dbus::FileDescriptor); 565 scoped_ptr<dbus::FileDescriptor> file_descriptor(new dbus::FileDescriptor);
553 file_descriptor->PutValue(pipe_write_end.TakePlatformFile()); 566 file_descriptor->PutValue(pipe_write_end.TakePlatformFile());
554 file_descriptor->CheckValidity(); 567 file_descriptor->CheckValidity();
555 return file_descriptor.Pass(); 568 return file_descriptor.Pass();
556 } 569 }
557 570
558 // Called when a CheckValidity response is received. 571 // Called when a CheckValidity response is received.
559 void OnCreateFileDescriptorRequestStopSystem( 572 void OnCreateFileDescriptorRequestStopSystem(
560 const StopSystemTracingCallback& callback, 573 const StopAgentTracingCallback& callback,
561 scoped_ptr<dbus::FileDescriptor> file_descriptor) { 574 scoped_ptr<dbus::FileDescriptor> file_descriptor) {
562 DCHECK(file_descriptor); 575 DCHECK(file_descriptor);
563 576
564 // Issue the dbus request to stop system tracing 577 // Issue the dbus request to stop system tracing
565 dbus::MethodCall method_call( 578 dbus::MethodCall method_call(
566 debugd::kDebugdInterface, 579 debugd::kDebugdInterface,
567 debugd::kSystraceStop); 580 debugd::kSystraceStop);
568 dbus::MessageWriter writer(&method_call); 581 dbus::MessageWriter writer(&method_call);
569 writer.AppendFileDescriptor(*file_descriptor); 582 writer.AppendFileDescriptor(*file_descriptor);
570 583
571 callback_ = callback; 584 callback_ = callback;
572 585
573 DVLOG(1) << "Requesting a systrace stop"; 586 DVLOG(1) << "Requesting a systrace stop";
574 debugdaemon_proxy_->CallMethod( 587 debugdaemon_proxy_->CallMethod(
575 &method_call, 588 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
576 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 589 base::Bind(&DebugDaemonClientImpl::OnStopAgentTracing,
577 base::Bind(&DebugDaemonClientImpl::OnRequestStopSystemTracing,
578 weak_ptr_factory_.GetWeakPtr())); 590 weak_ptr_factory_.GetWeakPtr()));
579 } 591 }
580 592
581 // Called when a response for RequestStopSystemTracing() is received. 593 // Called when a response for StopAgentTracing() is received.
582 void OnRequestStopSystemTracing(dbus::Response* response) { 594 void OnStopAgentTracing(dbus::Response* response) {
583 if (!response) { 595 if (!response) {
584 LOG(ERROR) << "Failed to request systrace stop"; 596 LOG(ERROR) << "Failed to request systrace stop";
585 // If debugd crashes or completes I/O before this message is processed 597 // If debugd crashes or completes I/O before this message is processed
586 // then pipe_reader_ can be NULL, see OnIOComplete(). 598 // then pipe_reader_ can be NULL, see OnIOComplete().
587 if (pipe_reader_.get()) 599 if (pipe_reader_.get())
588 pipe_reader_->OnDataReady(-1); // terminate data stream 600 pipe_reader_->OnDataReady(-1); // terminate data stream
589 } 601 }
590 // NB: requester is signaled when i/o completes 602 // NB: requester is signaled when i/o completes
591 } 603 }
592 604
593 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) { 605 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) {
594 std::string status; 606 std::string status;
595 if (response && dbus::MessageReader(response).PopString(&status)) 607 if (response && dbus::MessageReader(response).PopString(&status))
596 callback.Run(true, status); 608 callback.Run(true, status);
597 else 609 else
598 callback.Run(false, ""); 610 callback.Run(false, "");
599 } 611 }
600 612
601 // Called when pipe i/o completes; pass data on and delete the instance. 613 // Called when pipe i/o completes; pass data on and delete the instance.
602 void OnIOComplete() { 614 void OnIOComplete() {
603 std::string pipe_data; 615 std::string pipe_data;
604 pipe_reader_->GetData(&pipe_data); 616 pipe_reader_->GetData(&pipe_data);
605 callback_.Run(base::RefCountedString::TakeString(&pipe_data)); 617 callback_.Run(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

Powered by Google App Engine
This is Rietveld 408576698