From: Yabin Cui Date: Wed, 13 Jul 2016 19:18:18 +0000 (-0700) Subject: simpleperf: check dump stack size and adjust its default value. X-Git-Tag: android-x86-8.1-r1~68^2~140^2^2~19^2~44^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e9f06a6582d70b06a01e8e183081112b109776f6;p=android-x86%2Fsystem-extras.git simpleperf: check dump stack size and adjust its default value. Improve error message by checking if dump stack size > 65528. And adjust the default dump stack size to 65528, because I find that it is the value I always want to use. Bug: 29574526 Change-Id: I8f16dcf3a86a477f17d81fd387bf4dfa0dc0b341 Test: run simpleperf_unit_test. --- diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 9cec453f..050ca854 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -61,6 +61,10 @@ static void signal_handler(int) { signaled = true; } constexpr uint64_t DEFAULT_SAMPLE_FREQ_FOR_NONTRACEPOINT_EVENT = 4000; constexpr uint64_t DEFAULT_SAMPLE_PERIOD_FOR_TRACEPOINT_EVENT = 1; +// The max size of records dumped by kernel is 65535, and dump stack size +// should be a multiply of 8, so MAX_DUMP_STACK_SIZE is 65528. +constexpr uint32_t MAX_DUMP_STACK_SIZE = 65528; + class RecordCommand : public Command { public: RecordCommand() @@ -77,7 +81,7 @@ class RecordCommand : public Command { "--call-graph fp | dwarf[,]\n" " Enable call graph recording. Use frame pointer or dwarf debug\n" " frame as the method to parse call graph in stack.\n" -" Default is dwarf,8192.\n" +" Default is dwarf,65528.\n" "--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" @@ -143,7 +147,7 @@ class RecordCommand : public Command { branch_sampling_(0), fp_callchain_sampling_(false), dwarf_callchain_sampling_(false), - dump_stack_size_in_dwarf_sampling_(8192), + dump_stack_size_in_dwarf_sampling_(MAX_DUMP_STACK_SIZE), unwind_dwarf_callchain_(true), post_unwind_(false), child_inherit_(true), @@ -373,6 +377,12 @@ bool RecordCommand::ParseOptions(const std::vector& args, << " is not 8-byte aligned."; return false; } + if (size >= MAX_DUMP_STACK_SIZE) { + LOG(ERROR) << "dump stack size " << size + << " is bigger than max allowed size " + << MAX_DUMP_STACK_SIZE << "."; + return false; + } dump_stack_size_in_dwarf_sampling_ = static_cast(size); } } else { diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 9313cbe7..31ea173c 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -141,6 +141,7 @@ TEST(record_cmd, dwarf_callchain_sampling) { if (IsDwarfCallChainSamplingSupported()) { ASSERT_TRUE(RunRecordCmd({"--call-graph", "dwarf"})); ASSERT_TRUE(RunRecordCmd({"--call-graph", "dwarf,16384"})); + ASSERT_FALSE(RunRecordCmd({"--call-graph", "dwarf,65536"})); ASSERT_TRUE(RunRecordCmd({"-g"})); } else { GTEST_LOG_(INFO) << "This test does nothing as dwarf callchain sampling is "