diff options
author | Yabin Cui <yabinc@google.com> | 2017-04-19 17:48:18 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-19 17:48:18 +0000 |
commit | e0e4e2c085fa6441f7946cef6eefc28f49d73e7e (patch) | |
tree | e8af19f1391087e710ee5c4eb32468a33531c93b | |
parent | 13fe8a113fc99dd3542f94e795a5d3c342fe2f9a (diff) | |
parent | ad46983ee86c482dd61e7cc9639ce377ab5b3177 (diff) | |
download | extras-e0e4e2c085fa6441f7946cef6eefc28f49d73e7e.tar.gz |
Merge "simpleperf: add --start_profiling_fd option for record cmd." am: faa89a17fd
am: ad46983ee8
Change-Id: Ife0a346b79bb89be325d439476f0cd993e9994a3
-rw-r--r-- | simpleperf/cmd_record.cpp | 20 | ||||
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 21 |
2 files changed, 40 insertions, 1 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index f1bf7aad..3376af06 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -137,6 +137,8 @@ class RecordCommand : public Command { " will be unwound while recording by default. But it may lose\n" " records as stacking unwinding can be time consuming. Use this\n" " option to unwind the user's stack after recording.\n" +"--start_profiling_fd fd_no After starting profiling, write \"STARTED\" to\n" +" <fd_no>, then close <fd_no>.\n" "--symfs <dir> Look for files with symbols relative to this directory.\n" " This option is used to provide files with symbol table and\n" " debug information, which are used by --dump-symbols and -g.\n" @@ -163,7 +165,8 @@ class RecordCommand : public Command { record_filename_("perf.data"), start_sampling_time_in_ns_(0), sample_record_count_(0), - lost_record_count_(0) { + lost_record_count_(0), + start_profiling_fd_(-1) { // Stop profiling if parent exits. prctl(PR_SET_PDEATHSIG, SIGHUP, 0, 0, 0); } @@ -219,6 +222,7 @@ class RecordCommand : public Command { uint64_t sample_record_count_; uint64_t lost_record_count_; + int start_profiling_fd_; }; bool RecordCommand::Run(const std::vector<std::string>& args) { @@ -321,6 +325,12 @@ bool RecordCommand::Run(const std::vector<std::string>& args) { if (workload != nullptr && !workload->IsStarted() && !workload->Start()) { return false; } + if (start_profiling_fd_ != -1) { + if (!android::base::WriteStringToFd("STARTED", start_profiling_fd_)) { + PLOG(ERROR) << "failed to write to start_profiling_fd_"; + } + close(start_profiling_fd_); + } if (!loop->RunLoop()) { return false; } @@ -512,6 +522,14 @@ bool RecordCommand::ParseOptions(const std::vector<std::string>& args, event_selection_set_.AddMonitoredProcesses(pids); } else if (args[i] == "--post-unwind") { post_unwind_ = true; + } else if (args[i] == "--start_profiling_fd") { + if (!NextArgumentOrError(args, &i)) { + return false; + } + if (!android::base::ParseInt(args[i].c_str(), &start_profiling_fd_, 0)) { + LOG(ERROR) << "Invalid start_profiling_fd: " << args[i]; + return false; + } } else if (args[i] == "--symfs") { if (!NextArgumentOrError(args, &i)) { return false; diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 2cfa57c5..85bbe34b 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -16,6 +16,9 @@ #include <gtest/gtest.h> +#include <unistd.h> + +#include <android-base/file.h> #include <android-base/stringprintf.h> #include <android-base/test_utils.h> @@ -407,3 +410,21 @@ TEST(record_cmd, donot_stop_when_having_targets) { uint64_t end_time_in_ns = GetSystemClock(); ASSERT_GT(end_time_in_ns - start_time_in_ns, static_cast<uint64_t>(2e9)); } + +TEST(record_cmd, start_profiling_fd_option) { + int pipefd[2]; + ASSERT_EQ(0, pipe(pipefd)); + int read_fd = pipefd[0]; + int write_fd = pipefd[1]; + ASSERT_EXIT( + { + close(read_fd); + exit(RunRecordCmd({"--start_profiling_fd", std::to_string(write_fd)}) ? 0 : 1); + }, + testing::ExitedWithCode(0), ""); + close(write_fd); + std::string s; + ASSERT_TRUE(android::base::ReadFdToString(read_fd, &s)); + close(read_fd); + ASSERT_EQ("STARTED", s); +} |