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

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

Powered by Google App Engine
This is Rietveld 408576698