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

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

Powered by Google App Engine
This is Rietveld 408576698