Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/metrics/perf/perf_output.h" | 5 #include "chrome/browser/metrics/perf/perf_output.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/location.h" | |
| 11 #include "base/task_runner_util.h" | |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/debug_daemon_client.h" | 9 #include "chromeos/dbus/debug_daemon_client.h" |
| 14 | 10 |
| 15 namespace { | |
| 16 | |
| 17 // Create a dbus::FileDescriptor from a base::File. | |
| 18 dbus::ScopedFileDescriptor CreateFileDescriptor(base::File pipe_write_end) { | |
| 19 dbus::ScopedFileDescriptor file_descriptor(new dbus::FileDescriptor); | |
| 20 file_descriptor->PutValue(pipe_write_end.TakePlatformFile()); | |
| 21 file_descriptor->CheckValidity(); | |
| 22 return file_descriptor; | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 PerfOutputCall::PerfOutputCall( | 11 PerfOutputCall::PerfOutputCall( |
| 28 scoped_refptr<base::TaskRunner> blocking_task_runner, | 12 scoped_refptr<base::TaskRunner> blocking_task_runner, |
| 29 base::TimeDelta duration, | 13 base::TimeDelta duration, |
| 30 const std::vector<std::string>& perf_args, | 14 const std::vector<std::string>& perf_args, |
| 31 const DoneCallback& callback) | 15 const DoneCallback& callback) |
| 32 : blocking_task_runner_(blocking_task_runner), | 16 : blocking_task_runner_(blocking_task_runner), |
| 33 duration_(duration), | 17 duration_(duration), |
| 34 perf_args_(perf_args), | 18 perf_args_(perf_args), |
| 35 done_callback_(callback), | 19 done_callback_(callback), |
| 36 weak_factory_(this) { | 20 weak_factory_(this) { |
| 37 DCHECK(thread_checker_.CalledOnValidThread()); | 21 DCHECK(thread_checker_.CalledOnValidThread()); |
| 38 | 22 |
| 39 perf_data_pipe_reader_.reset(new chromeos::PipeReaderForString( | 23 perf_data_pipe_reader_.reset(new chromeos::PipeReaderForString( |
| 40 blocking_task_runner_, | 24 blocking_task_runner_, |
| 41 base::Bind(&PerfOutputCall::OnIOComplete, weak_factory_.GetWeakPtr()))); | 25 base::Bind(&PerfOutputCall::OnIOComplete, weak_factory_.GetWeakPtr()))); |
| 42 | 26 |
| 43 base::File pipe_write_end = perf_data_pipe_reader_->StartIO(); | 27 base::File pipe_write_end = perf_data_pipe_reader_->StartIO(); |
| 44 base::PostTaskAndReplyWithResult( | 28 |
| 45 blocking_task_runner_.get(), FROM_HERE, | 29 chromeos::DebugDaemonClient* client = |
| 46 base::Bind(&CreateFileDescriptor, base::Passed(&pipe_write_end)), | 30 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 47 base::Bind(&PerfOutputCall::OnFileDescriptorCreated, | 31 |
| 48 weak_factory_.GetWeakPtr())); | 32 client->GetPerfOutput(duration_, perf_args_, pipe_write_end.GetPlatformFile(), |
| 33 base::Bind(&PerfOutputCall::OnGetPerfOutputError, | |
| 34 weak_factory_.GetWeakPtr())); | |
| 49 } | 35 } |
|
satorux1
2016/08/23 04:43:37
|pipe_write_end| is deleted here hence closed? is
hashimoto
2016/08/23 06:38:50
Closing a pipe FD doesn't result in disk IO so it
satorux1
2016/08/23 07:02:02
Ah OK. I thought it'd be caught by AssertIOAllowed
hashimoto
2016/08/23 07:41:27
Good point.
This actually would cause a DCHECK fai
| |
| 50 | 36 |
| 51 PerfOutputCall::~PerfOutputCall() {} | 37 PerfOutputCall::~PerfOutputCall() {} |
| 52 | 38 |
| 53 void PerfOutputCall::OnFileDescriptorCreated( | |
| 54 dbus::ScopedFileDescriptor file_descriptor) { | |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 56 DCHECK(file_descriptor); | |
| 57 | |
| 58 chromeos::DebugDaemonClient* client = | |
| 59 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 60 | |
| 61 client->GetPerfOutput(duration_, perf_args_, std::move(file_descriptor), | |
| 62 base::Bind(&PerfOutputCall::OnGetPerfOutputError, | |
| 63 weak_factory_.GetWeakPtr())); | |
| 64 } | |
| 65 | |
| 66 void PerfOutputCall::OnIOComplete() { | 39 void PerfOutputCall::OnIOComplete() { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 40 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 | 41 |
| 69 std::string stdout_data; | 42 std::string stdout_data; |
| 70 perf_data_pipe_reader_->GetData(&stdout_data); | 43 perf_data_pipe_reader_->GetData(&stdout_data); |
| 71 | 44 |
| 72 done_callback_.Run(stdout_data); | 45 done_callback_.Run(stdout_data); |
| 73 // The callback may delete us, so it's hammertime: Can't touch |this|. | 46 // The callback may delete us, so it's hammertime: Can't touch |this|. |
| 74 } | 47 } |
| 75 | 48 |
| 76 void PerfOutputCall::OnGetPerfOutputError(const std::string& error_name, | 49 void PerfOutputCall::OnGetPerfOutputError(const std::string& error_name, |
| 77 const std::string& error_message) { | 50 const std::string& error_message) { |
| 78 DCHECK(thread_checker_.CalledOnValidThread()); | 51 DCHECK(thread_checker_.CalledOnValidThread()); |
| 79 | 52 |
| 80 // Signal pipe reader to shut down. This will cause | 53 // Signal pipe reader to shut down. This will cause |
| 81 // OnIOComplete to be called, probably with an empty string. | 54 // OnIOComplete to be called, probably with an empty string. |
| 82 perf_data_pipe_reader_->OnDataReady(-1); | 55 perf_data_pipe_reader_->OnDataReady(-1); |
| 83 } | 56 } |
| OLD | NEW |