summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-10-27 20:48:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-10-27 20:48:01 +0000
commitee865a72f66df3c515a6b51273090397ad9df7f1 (patch)
tree624c9c52d7d8b4c724b1969d8f13b1117a3693b2
parente3a03c7d7e0007ce4a7ffd478847462c9df167a7 (diff)
parentf3f2e32ca98380865930b1ae96bf650abc8a35c1 (diff)
downloadextras-ee865a72f66df3c515a6b51273090397ad9df7f1.tar.gz
Merge changes Ib9ec5c8b,Ieb3abf14
* changes: simpleperf: Add -i option to dump cmd. simpleperf: use PreprocessOptions in dump cmd.
-rw-r--r--simpleperf/cmd_dumprecord.cpp42
-rw-r--r--simpleperf/cmd_dumprecord_test.cpp4
2 files changed, 28 insertions, 18 deletions
diff --git a/simpleperf/cmd_dumprecord.cpp b/simpleperf/cmd_dumprecord.cpp
index 86860f71..debe061a 100644
--- a/simpleperf/cmd_dumprecord.cpp
+++ b/simpleperf/cmd_dumprecord.cpp
@@ -185,6 +185,7 @@ class DumpRecordCommand : public Command {
"Usage: simpleperf dumprecord [options] [perf_record_file]\n"
" Dump different parts of a perf record file. Default file is perf.data.\n"
"--dump-etm type1,type2,... Dump etm data. A type is one of raw, packet and element.\n"
+"-i <record_file> Record file to dump. Default is perf.data.\n"
"--symdir <dir> Look for binaries in a directory recursively.\n"
// clang-format on
) {}
@@ -232,30 +233,35 @@ bool DumpRecordCommand::Run(const std::vector<std::string>& args) {
}
bool DumpRecordCommand::ParseOptions(const std::vector<std::string>& args) {
- size_t i;
- for (i = 0; i < args.size() && !args[i].empty() && args[i][0] == '-'; ++i) {
- if (args[i] == "--dump-etm") {
- if (!NextArgumentOrError(args, &i) || !ParseEtmDumpOption(args[i], &etm_dump_option_)) {
- return false;
- }
- } else if (args[i] == "--symdir") {
- if (!NextArgumentOrError(args, &i)) {
- return false;
- }
- if (!Dso::AddSymbolDir(args[i])) {
- return false;
- }
- } else {
- ReportUnknownOption(args, i);
+ const OptionFormatMap option_formats = {
+ {"--dump-etm", {OptionValueType::STRING, OptionType::SINGLE}},
+ {"-i", {OptionValueType::STRING, OptionType::SINGLE}},
+ {"--symdir", {OptionValueType::STRING, OptionType::MULTIPLE}},
+ };
+ OptionValueMap options;
+ std::vector<std::pair<OptionName, OptionValue>> ordered_options;
+ std::vector<std::string> non_option_args;
+ if (!PreprocessOptions(args, option_formats, &options, &ordered_options, &non_option_args)) {
+ return false;
+ }
+ if (auto value = options.PullValue("--dump-etm"); value) {
+ if (!ParseEtmDumpOption(*value->str_value, &etm_dump_option_)) {
+ return false;
+ }
+ }
+ options.PullStringValue("-i", &record_filename_);
+ for (const OptionValue& value : options.PullValues("--symdir")) {
+ if (!Dso::AddSymbolDir(*value.str_value)) {
return false;
}
}
- if (i + 1 < args.size()) {
+ CHECK(options.values.empty());
+ if (non_option_args.size() > 1) {
LOG(ERROR) << "too many record files";
return false;
}
- if (i + 1 == args.size()) {
- record_filename_ = args[i];
+ if (non_option_args.size() == 1) {
+ record_filename_ = non_option_args[0];
}
return true;
}
diff --git a/simpleperf/cmd_dumprecord_test.cpp b/simpleperf/cmd_dumprecord_test.cpp
index 7309424b..e6dc5c65 100644
--- a/simpleperf/cmd_dumprecord_test.cpp
+++ b/simpleperf/cmd_dumprecord_test.cpp
@@ -30,6 +30,10 @@ TEST(cmd_dump, record_file_option) {
ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf.data")}));
}
+TEST(cmd_dump, input_option) {
+ ASSERT_TRUE(DumpCmd()->Run({"-i", GetTestData("perf.data")}));
+}
+
TEST(cmd_dump, dump_data_generated_by_linux_perf) {
ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_GENERATED_BY_LINUX_PERF)}));
}