diff options
author | Yabin Cui <yabinc@google.com> | 2017-05-18 17:11:32 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2017-05-18 18:35:26 -0700 |
commit | dcb2a3e580f155bb28621c4cbad019d104e8f300 (patch) | |
tree | fa795a0a463d2d219e83281844b3ea3bc7f24361 | |
parent | bc3f1c9f57f749cc616f9aa5b390bc2f70b15507 (diff) | |
download | extras-dcb2a3e580f155bb28621c4cbad019d104e8f300.tar.gz |
simpleperf: enable two options by default.
Enable dumping symbols in record cmd by default,
and change --dump-symbols option into --no-dump-symbols option.
Show brief call graph in report cmd by default,
and change --brief-callgraph option into --full-callgraph option.
Make the change because these two behaviors are always recommended.
Bug: None.
Test: run simpleperf_unit_test.
Change-Id: Icff6a843a7f46c56313500f4da119aa5118a57e5
-rw-r--r-- | simpleperf/README.md | 16 | ||||
-rw-r--r-- | simpleperf/cmd_record.cpp | 15 | ||||
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 20 | ||||
-rw-r--r-- | simpleperf/cmd_report.cpp | 11 | ||||
-rw-r--r-- | simpleperf/cmd_report_test.cpp | 19 | ||||
-rw-r--r-- | simpleperf/demo/README.md | 4 | ||||
-rw-r--r-- | simpleperf/get_test_data.h | 4 | ||||
-rw-r--r-- | simpleperf/scripts/app_profiler.config | 2 | ||||
-rw-r--r-- | simpleperf/scripts/report.py | 2 |
9 files changed, 48 insertions, 45 deletions
diff --git a/simpleperf/README.md b/simpleperf/README.md index 1ac99ef0..a5da2204 100644 --- a/simpleperf/README.md +++ b/simpleperf/README.md @@ -600,7 +600,7 @@ please replace this number with what you get by running `ps` command. **5. Record perf.data** - $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ./simpleperf record -p 6885 --duration 10 --dump-symbols + $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ./simpleperf record -p 6885 --duration 10 simpleperf I 04-27 20:41:11 6940 6940 cmd_record.cpp:357] Samples recorded: 40008. Samples lost: 0. $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ls -lh perf.data @@ -641,7 +641,7 @@ results and native binaries on host. It is configured by `app-profiler.config`. Change `app_package_name` line to app_package_name="com.example.simpleperf.simpleperfexamplepurejava" Change `apk_file_path` line to apk_file_path = "../SimpleperfExamplePureJava/app/build/outputs/apk/app-profiling.apk" Change `android_studio_project_dir` line to android_studio_project_dir = "../SimpleperfExamplePureJava/" - Change `record_options` line to record_options = "--dump-symbols --duration 10" + Change `record_options` line to record_options = "--duration 10" `apk_file_path` is needed to fully compile the application on Android L/M. It is not necessary on Android >= N. @@ -693,11 +693,11 @@ A call graph is a tree showing function call relations. Below is an example. When using command lines, add `-g` option like below: - $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ./simpleperf record -g -p 6685 --duration 10 --dump-symbols + $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ./simpleperf record -g -p 6685 --duration 10 When using python scripts, change `app-profiler.config` as below: - Change `record_options` line to record_options = "--dump-symbols --duration 10 -g" + Change `record_options` line to record_options = "--duration 10 -g" Recording dwarf based call graph needs support of debug information in native binaries. So if using native libraries in the application, @@ -708,11 +708,11 @@ it is better to contain non-stripped native libraries in the apk. When using command lines, add `--call-graph fp` option like below: - $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ./simpleperf record --call-graph fp -p 6685 --duration 10 --dump-symbols + $ adb shell run-as com.example.simpleperf.simpleperfexamplepurejava ./simpleperf record --call-graph fp -p 6685 --duration 10 When using python scripts, change `app-profiler.config` as below: - Change `record_options` line to record_options = "--dump-symbols --duration 10 --call-graph fp" + Change `record_options` line to record_options = "--duration 10 --call-graph fp" Recording stack frame based call graphs needs support of stack frame register. Notice that on arm architecture, the stack frame register @@ -724,9 +724,9 @@ architecture, or profiling in arm64 environment.** #### Report call graph -To report call graph using command lines, add `-g --brief-callgraph` option. +To report call graph using command lines, add `-g` option. - $ bin/linux/x86_64/simpleperf report -g --brief-callgraph + $ bin/linux/x86_64/simpleperf report -g ... Children Self Command Pid Tid Shared Object Symbol 99.97% 0.00% Thread-2 10859 10876 /system/framework/arm64/boot.oat java.lang.Thread.run diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 78e0a95d..27c089c3 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -75,6 +75,7 @@ class RecordCommand : public Command { "Usage: simpleperf record [options] [command [command-args]]\n" " Gather sampling information of running [command]. And -a/-p/-t option\n" " can be used to change target of sampling information.\n" +" The default options are: -e cpu-cycles -f 4000 -o perf.data.\n" "-a System-wide collection.\n" "-b Enable take branch stack sampling. Same as '-j any'\n" "-c count Set event sample period. It means recording one sample when\n" @@ -87,9 +88,6 @@ class RecordCommand : public Command { "--cpu cpu_item1,cpu_item2,...\n" " Collect samples only on the selected cpus. cpu_item can be cpu\n" " number like 1, or cpu range like 0-3.\n" -"--dump-symbols Dump symbols in perf.data. By default perf.data doesn't contain\n" -" symbol information for samples. This option is used when there\n" -" is no symbol information in report environment.\n" "--duration time_in_sec Monitor for time_in_sec seconds instead of running\n" " [command]. Here time_in_sec may be any positive\n" " floating point number.\n" @@ -126,6 +124,9 @@ class RecordCommand : public Command { " possible value <= 1024 will be used.\n" "--no-dump-kernel-symbols Don't dump kernel symbols in perf.data. By default\n" " kernel symbols will be dumped when needed.\n" +"--no-dump-symbols Don't dump symbols in perf.data. By default symbols are\n" +" dumped in perf.data, to support reporting in another\n" +" environment.\n" "--no-inherit Don't record created child threads/processes.\n" "--no-unwind If `--call-graph dwarf` option is used, then the user's stack\n" " will be unwound by default. Use this option to disable the\n" @@ -141,7 +142,7 @@ class RecordCommand : public Command { " <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" +" debug information, which are used for unwinding and dumping symbols.\n" "-t tid1,tid2,... Record events on existing threads. Mutually exclusive with -a.\n" // clang-format on ), @@ -159,7 +160,7 @@ class RecordCommand : public Command { child_inherit_(true), duration_in_sec_(0), can_dump_kernel_symbols_(true), - dump_symbols_(false), + dump_symbols_(true), event_selection_set_(false), mmap_page_range_(std::make_pair(1, DESIRED_PAGES_IN_MAPPED_BUFFER)), record_filename_("perf.data"), @@ -431,8 +432,6 @@ bool RecordCommand::ParseOptions(const std::vector<std::string>& args, return false; } cpus_ = GetCpusFromString(args[i]); - } else if (args[i] == "--dump-symbols") { - dump_symbols_ = true; } else if (args[i] == "--duration") { if (!NextArgumentOrError(args, &i)) { return false; @@ -502,6 +501,8 @@ bool RecordCommand::ParseOptions(const std::vector<std::string>& args, mmap_page_range_.first = mmap_page_range_.second = pages; } else if (args[i] == "--no-dump-kernel-symbols") { can_dump_kernel_symbols_ = false; + } else if (args[i] == "--no-dump-symbols") { + dump_symbols_ = false; } else if (args[i] == "--no-inherit") { child_inherit_ = false; } else if (args[i] == "--no-unwind") { diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index ec0605a4..0d0c44a7 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -254,11 +254,11 @@ static void CheckKernelSymbol(const std::string& path, bool need_kallsyms, TEST(record_cmd, kernel_symbol) { TemporaryFile tmpfile; - ASSERT_TRUE(RunRecordCmd({}, tmpfile.path)); + ASSERT_TRUE(RunRecordCmd({"--no-dump-symbols"}, tmpfile.path)); bool success; CheckKernelSymbol(tmpfile.path, true, &success); ASSERT_TRUE(success); - ASSERT_TRUE(RunRecordCmd({"--no-dump-kernel-symbols"}, tmpfile.path)); + ASSERT_TRUE(RunRecordCmd({"--no-dump-symbols", "--no-dump-kernel-symbols"}, tmpfile.path)); CheckKernelSymbol(tmpfile.path, false, &success); ASSERT_TRUE(success); } @@ -303,26 +303,26 @@ static void CheckDsoSymbolRecords(const std::string& path, *success = true; } -TEST(record_cmd, dump_symbols) { +TEST(record_cmd, no_dump_symbols) { TemporaryFile tmpfile; ASSERT_TRUE(RunRecordCmd({}, tmpfile.path)); bool success; - CheckDsoSymbolRecords(tmpfile.path, false, &success); - ASSERT_TRUE(success); - ASSERT_TRUE(RunRecordCmd({"--dump-symbols"}, tmpfile.path)); CheckDsoSymbolRecords(tmpfile.path, true, &success); ASSERT_TRUE(success); + ASSERT_TRUE(RunRecordCmd({"--no-dump-symbols"}, tmpfile.path)); + CheckDsoSymbolRecords(tmpfile.path, false, &success); + ASSERT_TRUE(success); if (IsDwarfCallChainSamplingSupported()) { std::vector<std::unique_ptr<Workload>> workloads; CreateProcesses(1, &workloads); std::string pid = std::to_string(workloads[0]->GetPid()); ASSERT_TRUE(RunRecordCmd({"-p", pid, "-g"}, tmpfile.path)); bool success; - CheckDsoSymbolRecords(tmpfile.path, false, &success); - ASSERT_TRUE(success); - ASSERT_TRUE(RunRecordCmd({"-p", pid, "-g", "--dump-symbols"}, tmpfile.path)); CheckDsoSymbolRecords(tmpfile.path, true, &success); ASSERT_TRUE(success); + ASSERT_TRUE(RunRecordCmd({"-p", pid, "-g", "--no-dump-symbols"}, tmpfile.path)); + CheckDsoSymbolRecords(tmpfile.path, false, &success); + ASSERT_TRUE(success); } } @@ -333,7 +333,7 @@ TEST(record_cmd, dump_kernel_symbols) { } system("echo 0 >/proc/sys/kernel/kptr_restrict"); TemporaryFile tmpfile; - ASSERT_TRUE(RunRecordCmd({"--dump-symbols", "-a", "-o", tmpfile.path, "sleep", "1"})); + ASSERT_TRUE(RunRecordCmd({"-a", "-o", tmpfile.path, "sleep", "1"})); std::unique_ptr<RecordFileReader> reader = RecordFileReader::CreateInstance(tmpfile.path); ASSERT_TRUE(reader != nullptr); std::map<int, SectionDesc> section_map = reader->FeatureSectionDescriptors(); diff --git a/simpleperf/cmd_report.cpp b/simpleperf/cmd_report.cpp index a3f80948..29cf743a 100644 --- a/simpleperf/cmd_report.cpp +++ b/simpleperf/cmd_report.cpp @@ -307,13 +307,15 @@ class ReportCommand : public Command { "report", "report sampling information in perf.data", // clang-format off "Usage: simpleperf report [options]\n" +"The default options are: -i perf.data --sort comm,pid,tid,dso,symbol.\n" "-b Use the branch-to addresses in sampled take branches instead of the\n" " instruction addresses. Only valid for perf.data recorded with -b/-j\n" " option.\n" -"--brief-callgraph Print brief call graph.\n" "--children Print the overhead accumulated by appearing in the callchain.\n" "--comms comm1,comm2,... Report only for selected comms.\n" "--dsos dso1,dso2,... Report only for selected dsos.\n" +"--full-callgraph Print full call graph. Used with -g option. By default,\n" +" brief call graph is printed.\n" "-g [callee|caller] Print call graph. If callee mode is used, the graph\n" " shows how functions are called from others. Otherwise,\n" " the graph shows how functions call others.\n" @@ -363,7 +365,7 @@ class ReportCommand : public Command { callgraph_max_stack_(UINT32_MAX), callgraph_percent_limit_(0), raw_period_(false), - brief_callgraph_(false) {} + brief_callgraph_(true) {} bool Run(const std::vector<std::string>& args); @@ -445,8 +447,6 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) { for (size_t i = 0; i < args.size(); ++i) { if (args[i] == "-b") { use_branch_address_ = true; - } else if (args[i] == "--brief-callgraph") { - brief_callgraph_ = true; } else if (args[i] == "--children") { accumulate_callchain_ = true; } else if (args[i] == "--comms" || args[i] == "--dsos") { @@ -458,7 +458,8 @@ bool ReportCommand::ParseOptions(const std::vector<std::string>& args) { } std::vector<std::string> strs = android::base::Split(args[i], ","); filter.insert(strs.begin(), strs.end()); - + } else if (args[i] == "--full-callgraph") { + brief_callgraph_ = false; } else if (args[i] == "-g") { print_callgraph_ = true; accumulate_callchain_ = true; diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp index 15530e5c..bf690c0f 100644 --- a/simpleperf/cmd_report_test.cpp +++ b/simpleperf/cmd_report_test.cpp @@ -131,10 +131,9 @@ TEST_F(ReportCommandTest, children_option) { static bool CheckCalleeMode(std::vector<std::string>& lines) { bool found = false; - for (size_t i = 0; i + 2 < lines.size(); ++i) { + for (size_t i = 0; i + 1 < lines.size(); ++i) { if (lines[i].find("GlobalFunc") != std::string::npos && - lines[i + 1].find('|') != std::string::npos && - lines[i + 2].find("main") != std::string::npos) { + lines[i + 1].find("main") != std::string::npos) { found = true; break; } @@ -144,10 +143,9 @@ static bool CheckCalleeMode(std::vector<std::string>& lines) { static bool CheckCallerMode(std::vector<std::string>& lines) { bool found = false; - for (size_t i = 0; i + 2 < lines.size(); ++i) { + for (size_t i = 0; i + 1 < lines.size(); ++i) { if (lines[i].find("main") != std::string::npos && - lines[i + 1].find('|') != std::string::npos && - lines[i + 2].find("GlobalFunc") != std::string::npos) { + lines[i + 1].find("GlobalFunc") != std::string::npos) { found = true; break; } @@ -433,7 +431,7 @@ TEST_F(ReportCommandTest, max_stack_and_percent_limit_option) { Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "0"}); ASSERT_TRUE(success); ASSERT_EQ(content.find("89.03"), std::string::npos); - Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "1"}); + Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "2"}); ASSERT_TRUE(success); ASSERT_NE(content.find("89.03"), std::string::npos); @@ -464,10 +462,13 @@ TEST_F(ReportCommandTest, raw_period_option) { ASSERT_EQ(content.find("%"), std::string::npos); } -TEST_F(ReportCommandTest, brief_callgraph_option) { - Report(CALLGRAPH_FP_PERF_DATA, {"-g", "--brief-callgraph"}); +TEST_F(ReportCommandTest, full_callgraph_option) { + Report(CALLGRAPH_FP_PERF_DATA, {"-g"}); ASSERT_TRUE(success); ASSERT_NE(content.find("skipped in brief callgraph mode"), std::string::npos); + Report(CALLGRAPH_FP_PERF_DATA, {"-g", "--full-callgraph"}); + ASSERT_TRUE(success); + ASSERT_EQ(content.find("skipped in brief callgraph mode"), std::string::npos); } #if defined(__linux__) diff --git a/simpleperf/demo/README.md b/simpleperf/demo/README.md index e17c27d8..8530dc62 100644 --- a/simpleperf/demo/README.md +++ b/simpleperf/demo/README.md @@ -54,7 +54,7 @@ $ python app_profiler.py ``` a. show call graph in txt mode # On windows, use "bin\windows\x86\simpleperf" instead. - $ bin/linux/x86_64/simpleperf report -g --brief-callgraph | more + $ bin/linux/x86_64/simpleperf report -g | more If on other hosts, use corresponding simpleperf binary. b. show call graph in gui mode $ python report.py -g @@ -97,7 +97,7 @@ $ python app_profiler.py ``` a. show call graph in txt mode # On windows, use "bin\windows\x86\simpleperf" instead. - $ bin/linux/x86_64/simpleperf report -g --brief-callgraph | more + $ bin/linux/x86_64/simpleperf report -g | more If on other hosts, use corresponding simpleperf binary. b. show call graph in gui mode $ python report.py -g diff --git a/simpleperf/get_test_data.h b/simpleperf/get_test_data.h index 16659dca..963fe006 100644 --- a/simpleperf/get_test_data.h +++ b/simpleperf/get_test_data.h @@ -76,9 +76,9 @@ static const std::string PERF_DATA_WITH_TWO_EVENT_TYPES = "perf_with_two_event_t // perf_with_kernel_symbol.data is generated by `sudo simpleperf record ls -l`. static const std::string PERF_DATA_WITH_KERNEL_SYMBOL = "perf_with_kernel_symbol.data"; -// perf_with_symbols.data is generated by `sudo simpleperf record --dump-symbols` a process calling func2(int,int). +// perf_with_symbols.data is generated by `sudo simpleperf record` a process calling func2(int,int). static const std::string PERF_DATA_WITH_SYMBOLS = "perf_with_symbols.data"; -// perf_with_symbols.data is generated by `sudo simpleperf record --dump-symbols` a process using +// perf_with_symbols.data is generated by `sudo simpleperf record` a process using // a binary having non zero min virtual address. static const std::string PERF_DATA_WITH_SYMBOLS_FOR_NONZERO_MINVADDR_DSO = "perf_with_symbols_for_nonzero_minvaddr_dso.data"; diff --git a/simpleperf/scripts/app_profiler.config b/simpleperf/scripts/app_profiler.config index 4b61edbe..63dbd962 100644 --- a/simpleperf/scripts/app_profiler.config +++ b/simpleperf/scripts/app_profiler.config @@ -50,7 +50,7 @@ if recompile_app and not launch_activity and not launch_inst_test: # Profiling record options that will be passed directly to `simpleperf record` command on device. # As we can't stop profiling by Ctrl-C, we need to set how long to profile using "--duration". -record_options = "-e cpu-cycles:u -f 4000 -g --dump-symbols --duration 10" +record_options = "-e cpu-cycles:u -f 4000 -g --duration 10" # The path to store generated perf.data on host. diff --git a/simpleperf/scripts/report.py b/simpleperf/scripts/report.py index 13104129..908b9e92 100644 --- a/simpleperf/scripts/report.py +++ b/simpleperf/scripts/report.py @@ -281,7 +281,7 @@ def display_report_file(report_file): def call_simpleperf_report(args, report_file): output_fh = open(report_file, 'w') simpleperf_path = get_host_binary_path('simpleperf') - args = [simpleperf_path, 'report'] + args + args = [simpleperf_path, 'report', '--full-callgraph'] + args subprocess.check_call(args, stdout=output_fh) output_fh.close() |