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

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

Issue 2247433002: TabManager: Set OOM scores via a new debugd interface on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unittest Created 4 years, 3 months 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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <unistd.h> 10 #include <unistd.h>
11
12 #include <memory>
11 #include <string> 13 #include <string>
12 #include <vector> 14 #include <vector>
13 15
14 #include "base/bind.h" 16 #include "base/bind.h"
15 #include "base/bind_helpers.h" 17 #include "base/bind_helpers.h"
16 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
17 #include "base/json/json_string_value_serializer.h" 19 #include "base/json/json_string_value_serializer.h"
18 #include "base/location.h" 20 #include "base/location.h"
19 #include "base/macros.h" 21 #include "base/macros.h"
20 #include "base/message_loop/message_loop.h" 22 #include "base/message_loop/message_loop.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 std::string GetTracingAgentName() override { return kCrOSTracingAgentName; } 287 std::string GetTracingAgentName() override { return kCrOSTracingAgentName; }
286 288
287 std::string GetTraceEventLabel() override { return kCrOSTraceLabel; } 289 std::string GetTraceEventLabel() override { return kCrOSTraceLabel; }
288 290
289 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config, 291 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
290 const StartAgentTracingCallback& callback) override { 292 const StartAgentTracingCallback& callback) override {
291 dbus::MethodCall method_call( 293 dbus::MethodCall method_call(
292 debugd::kDebugdInterface, 294 debugd::kDebugdInterface,
293 debugd::kSystraceStart); 295 debugd::kSystraceStart);
294 dbus::MessageWriter writer(&method_call); 296 dbus::MessageWriter writer(&method_call);
295 writer.AppendString("all"); // TODO(sleffler) parameterize category list 297 writer.AppendString("all"); // TODO(sleffler) parameterize category list
296 298
297 DVLOG(1) << "Requesting a systrace start"; 299 DVLOG(1) << "Requesting a systrace start";
298 debugdaemon_proxy_->CallMethod( 300 debugdaemon_proxy_->CallMethod(
299 &method_call, 301 &method_call,
300 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 302 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
301 base::Bind(&DebugDaemonClientImpl::OnStartMethod, 303 base::Bind(&DebugDaemonClientImpl::OnStartMethod,
302 weak_ptr_factory_.GetWeakPtr())); 304 weak_ptr_factory_.GetWeakPtr()));
303 305
304 base::ThreadTaskRunnerHandle::Get()->PostTask( 306 base::ThreadTaskRunnerHandle::Get()->PostTask(
305 FROM_HERE, 307 FROM_HERE,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 base::Bind(&DebugDaemonClientImpl::OnRemoveRootfsVerification, 437 base::Bind(&DebugDaemonClientImpl::OnRemoveRootfsVerification,
436 weak_ptr_factory_.GetWeakPtr(), 438 weak_ptr_factory_.GetWeakPtr(),
437 callback)); 439 callback));
438 } 440 }
439 441
440 void WaitForServiceToBeAvailable( 442 void WaitForServiceToBeAvailable(
441 const WaitForServiceToBeAvailableCallback& callback) override { 443 const WaitForServiceToBeAvailableCallback& callback) override {
442 debugdaemon_proxy_->WaitForServiceToBeAvailable(callback); 444 debugdaemon_proxy_->WaitForServiceToBeAvailable(callback);
443 } 445 }
444 446
447 void SetOomScoreAdj(const std::map<pid_t, int32_t>& pid_to_oom_score_adj,
448 const SetOomScoreAdjCallback& callback) override {
449 dbus::MethodCall method_call(debugd::kDebugdInterface,
450 debugd::kSetOomScoreAdj);
451 dbus::MessageWriter writer(&method_call);
452
453 dbus::MessageWriter sub_writer(nullptr);
454 writer.OpenArray("{ii}", &sub_writer);
455
456 dbus::MessageWriter elem_writer(nullptr);
457 for (const auto& entry : pid_to_oom_score_adj) {
458 sub_writer.OpenDictEntry(&elem_writer);
459 elem_writer.AppendInt32(entry.first);
460 elem_writer.AppendInt32(entry.second);
461 sub_writer.CloseContainer(&elem_writer);
462 }
463 writer.CloseContainer(&sub_writer);
464
465 debugdaemon_proxy_->CallMethod(
466 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
467 base::Bind(&DebugDaemonClientImpl::OnSetOomScoreAdj,
468 weak_ptr_factory_.GetWeakPtr(), callback));
469 }
470
445 protected: 471 protected:
446 void Init(dbus::Bus* bus) override { 472 void Init(dbus::Bus* bus) override {
447 debugdaemon_proxy_ = 473 debugdaemon_proxy_ =
448 bus->GetObjectProxy(debugd::kDebugdServiceName, 474 bus->GetObjectProxy(debugd::kDebugdServiceName,
449 dbus::ObjectPath(debugd::kDebugdServicePath)); 475 dbus::ObjectPath(debugd::kDebugdServicePath));
450 } 476 }
451 477
452 private: 478 private:
453 // Called when a response for GetDebugLogs() is received. 479 // Called when a response for GetDebugLogs() is received.
454 void OnGetDebugLogs(const GetDebugLogsCallback& callback, 480 void OnGetDebugLogs(const GetDebugLogsCallback& callback,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 std::string status; 546 std::string status;
521 if (response && dbus::MessageReader(response).PopString(&status)) 547 if (response && dbus::MessageReader(response).PopString(&status))
522 callback.Run(true, status); 548 callback.Run(true, status);
523 else 549 else
524 callback.Run(false, ""); 550 callback.Run(false, "");
525 } 551 }
526 552
527 void OnGetAllLogs(const GetLogsCallback& callback, 553 void OnGetAllLogs(const GetLogsCallback& callback,
528 dbus::Response* response) { 554 dbus::Response* response) {
529 std::map<std::string, std::string> logs; 555 std::map<std::string, std::string> logs;
530 bool broken = false; // did we see a broken (k,v) pair? 556 bool broken = false; // did we see a broken (k,v) pair?
531 dbus::MessageReader sub_reader(NULL); 557 dbus::MessageReader sub_reader(NULL);
532 if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) { 558 if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) {
533 callback.Run(false, logs); 559 callback.Run(false, logs);
534 return; 560 return;
535 } 561 }
536 while (sub_reader.HasMoreData()) { 562 while (sub_reader.HasMoreData()) {
537 dbus::MessageReader sub_sub_reader(NULL); 563 dbus::MessageReader sub_sub_reader(NULL);
538 std::string key, value; 564 std::string key, value;
539 if (!sub_reader.PopDictEntry(&sub_sub_reader) 565 if (!sub_reader.PopDictEntry(&sub_sub_reader)
540 || !sub_sub_reader.PopString(&key) 566 || !sub_sub_reader.PopString(&key)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 callback.Run(response != NULL); 642 callback.Run(response != NULL);
617 } 643 }
618 644
619 // Called when a response for StopAgentTracing() is received. 645 // Called when a response for StopAgentTracing() is received.
620 void OnStopAgentTracing(dbus::Response* response) { 646 void OnStopAgentTracing(dbus::Response* response) {
621 if (!response) { 647 if (!response) {
622 LOG(ERROR) << "Failed to request systrace stop"; 648 LOG(ERROR) << "Failed to request systrace stop";
623 // If debugd crashes or completes I/O before this message is processed 649 // If debugd crashes or completes I/O before this message is processed
624 // then pipe_reader_ can be NULL, see OnIOComplete(). 650 // then pipe_reader_ can be NULL, see OnIOComplete().
625 if (pipe_reader_.get()) 651 if (pipe_reader_.get())
626 pipe_reader_->OnDataReady(-1); // terminate data stream 652 pipe_reader_->OnDataReady(-1); // terminate data stream
627 } 653 }
628 // NB: requester is signaled when i/o completes 654 // NB: requester is signaled when i/o completes
629 } 655 }
630 656
631 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) { 657 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) {
632 std::string status; 658 std::string status;
633 if (response && dbus::MessageReader(response).PopString(&status)) 659 if (response && dbus::MessageReader(response).PopString(&status))
634 callback.Run(true, status); 660 callback.Run(true, status);
635 else 661 else
636 callback.Run(false, ""); 662 callback.Run(false, "");
637 } 663 }
638 664
639 // Called when pipe i/o completes; pass data on and delete the instance. 665 // Called when pipe i/o completes; pass data on and delete the instance.
640 void OnIOComplete() { 666 void OnIOComplete() {
641 std::string pipe_data; 667 std::string pipe_data;
642 pipe_reader_->GetData(&pipe_data); 668 pipe_reader_->GetData(&pipe_data);
643 callback_.Run(GetTracingAgentName(), GetTraceEventLabel(), 669 callback_.Run(GetTracingAgentName(), GetTraceEventLabel(),
644 base::RefCountedString::TakeString(&pipe_data)); 670 base::RefCountedString::TakeString(&pipe_data));
645 pipe_reader_.reset(); 671 pipe_reader_.reset();
646 } 672 }
647 673
674 void OnSetOomScoreAdj(const SetOomScoreAdjCallback& callback,
675 dbus::Response* response) {
676 std::string output;
677 if (response && dbus::MessageReader(response).PopString(&output))
678 callback.Run(true, output);
679 else
680 callback.Run(false, "");
681 }
682
648 dbus::ObjectProxy* debugdaemon_proxy_; 683 dbus::ObjectProxy* debugdaemon_proxy_;
649 std::unique_ptr<PipeReaderForString> pipe_reader_; 684 std::unique_ptr<PipeReaderForString> pipe_reader_;
650 StopAgentTracingCallback callback_; 685 StopAgentTracingCallback callback_;
651 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_; 686 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_;
652 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; 687 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_;
653 688
654 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); 689 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl);
655 }; 690 };
656 691
657 DebugDaemonClient::DebugDaemonClient() { 692 DebugDaemonClient::DebugDaemonClient() {
658 } 693 }
659 694
660 DebugDaemonClient::~DebugDaemonClient() { 695 DebugDaemonClient::~DebugDaemonClient() {
661 } 696 }
662 697
663 // static 698 // static
664 DebugDaemonClient::StopAgentTracingCallback 699 DebugDaemonClient::StopAgentTracingCallback
665 DebugDaemonClient::EmptyStopAgentTracingCallback() { 700 DebugDaemonClient::EmptyStopAgentTracingCallback() {
666 return base::Bind(&EmptyStopAgentTracingCallbackBody); 701 return base::Bind(&EmptyStopAgentTracingCallbackBody);
667 } 702 }
668 703
669 // static 704 // static
670 DebugDaemonClient* DebugDaemonClient::Create() { 705 DebugDaemonClient* DebugDaemonClient::Create() {
671 return new DebugDaemonClientImpl(); 706 return new DebugDaemonClientImpl();
672 } 707 }
673 708
674 } // namespace chromeos 709 } // 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