| OLD | NEW |
| 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> |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 writer.AppendUint32(duration); | 154 writer.AppendUint32(duration); |
| 155 | 155 |
| 156 debugdaemon_proxy_->CallMethod( | 156 debugdaemon_proxy_->CallMethod( |
| 157 &method_call, | 157 &method_call, |
| 158 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 158 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 159 base::Bind(&DebugDaemonClientImpl::OnGetPerfData, | 159 base::Bind(&DebugDaemonClientImpl::OnGetPerfData, |
| 160 weak_ptr_factory_.GetWeakPtr(), | 160 weak_ptr_factory_.GetWeakPtr(), |
| 161 callback)); | 161 callback)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void GetPerfOutput(uint32_t duration, |
| 165 const GetPerfOutputCallback& callback) override { |
| 166 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 167 debugd::kGetRandomPerfOutput); |
| 168 dbus::MessageWriter writer(&method_call); |
| 169 writer.AppendUint32(duration); |
| 170 |
| 171 debugdaemon_proxy_->CallMethod( |
| 172 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 173 base::Bind(&DebugDaemonClientImpl::OnGetPerfOutput, |
| 174 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 175 } |
| 176 |
| 164 void GetScrubbedLogs(const GetLogsCallback& callback) override { | 177 void GetScrubbedLogs(const GetLogsCallback& callback) override { |
| 165 dbus::MethodCall method_call(debugd::kDebugdInterface, | 178 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 166 debugd::kGetFeedbackLogs); | 179 debugd::kGetFeedbackLogs); |
| 167 debugdaemon_proxy_->CallMethod( | 180 debugdaemon_proxy_->CallMethod( |
| 168 &method_call, | 181 &method_call, |
| 169 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 182 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 170 base::Bind(&DebugDaemonClientImpl::OnGetAllLogs, | 183 base::Bind(&DebugDaemonClientImpl::OnGetAllLogs, |
| 171 weak_ptr_factory_.GetWeakPtr(), | 184 weak_ptr_factory_.GetWeakPtr(), |
| 172 callback)); | 185 callback)); |
| 173 } | 186 } |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 size_t buf_size = 0; | 467 size_t buf_size = 0; |
| 455 if (!reader.PopArrayOfBytes(&buffer, &buf_size)) | 468 if (!reader.PopArrayOfBytes(&buffer, &buf_size)) |
| 456 return; | 469 return; |
| 457 | 470 |
| 458 // TODO(asharif): Figure out a way to avoid this copy. | 471 // TODO(asharif): Figure out a way to avoid this copy. |
| 459 data.insert(data.end(), buffer, buffer + buf_size); | 472 data.insert(data.end(), buffer, buffer + buf_size); |
| 460 | 473 |
| 461 callback.Run(data); | 474 callback.Run(data); |
| 462 } | 475 } |
| 463 | 476 |
| 477 void OnGetPerfOutput(const GetPerfOutputCallback& callback, |
| 478 dbus::Response* response) { |
| 479 if (!response) |
| 480 return; |
| 481 |
| 482 dbus::MessageReader reader(response); |
| 483 |
| 484 int status = 0; |
| 485 if (!reader.PopInt32(&status)) |
| 486 return; |
| 487 |
| 488 const uint8* buffer = nullptr; |
| 489 size_t buf_size = 0; |
| 490 |
| 491 if (!reader.PopArrayOfBytes(&buffer, &buf_size)) |
| 492 return; |
| 493 std::vector<uint8> perf_data; |
| 494 if (buf_size > 0) |
| 495 perf_data.insert(perf_data.end(), buffer, buffer + buf_size); |
| 496 |
| 497 if (!reader.PopArrayOfBytes(&buffer, &buf_size)) |
| 498 return; |
| 499 std::vector<uint8> perf_stat; |
| 500 if (buf_size > 0) |
| 501 perf_stat.insert(perf_stat.end(), buffer, buffer + buf_size); |
| 502 |
| 503 callback.Run(status, perf_data, perf_stat); |
| 504 } |
| 505 |
| 464 void OnGetAllLogs(const GetLogsCallback& callback, | 506 void OnGetAllLogs(const GetLogsCallback& callback, |
| 465 dbus::Response* response) { | 507 dbus::Response* response) { |
| 466 std::map<std::string, std::string> logs; | 508 std::map<std::string, std::string> logs; |
| 467 bool broken = false; // did we see a broken (k,v) pair? | 509 bool broken = false; // did we see a broken (k,v) pair? |
| 468 dbus::MessageReader sub_reader(NULL); | 510 dbus::MessageReader sub_reader(NULL); |
| 469 if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) { | 511 if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) { |
| 470 callback.Run(false, logs); | 512 callback.Run(false, logs); |
| 471 return; | 513 return; |
| 472 } | 514 } |
| 473 while (sub_reader.HasMoreData()) { | 515 while (sub_reader.HasMoreData()) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 DebugDaemonClient::EmptyStopSystemTracingCallback() { | 658 DebugDaemonClient::EmptyStopSystemTracingCallback() { |
| 617 return base::Bind(&EmptyStopSystemTracingCallbackBody); | 659 return base::Bind(&EmptyStopSystemTracingCallbackBody); |
| 618 } | 660 } |
| 619 | 661 |
| 620 // static | 662 // static |
| 621 DebugDaemonClient* DebugDaemonClient::Create() { | 663 DebugDaemonClient* DebugDaemonClient::Create() { |
| 622 return new DebugDaemonClientImpl(); | 664 return new DebugDaemonClientImpl(); |
| 623 } | 665 } |
| 624 | 666 |
| 625 } // namespace chromeos | 667 } // namespace chromeos |
| OLD | NEW |