diff options
author | Yabin Cui <yabinc@google.com> | 2016-07-13 12:18:18 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2016-07-13 12:27:20 -0700 |
commit | e9f06a6582d70b06a01e8e183081112b109776f6 (patch) | |
tree | f5a978880432edc258bd56ae680bb6a2f8bed05a | |
parent | 6941c09c773560f94e23190ef06390766aaff8fa (diff) | |
download | extras-e9f06a6582d70b06a01e8e183081112b109776f6.tar.gz |
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.
-rw-r--r-- | simpleperf/cmd_record.cpp | 14 | ||||
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 1 |
2 files changed, 13 insertions, 2 deletions
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[,<dump_stack_size>]\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<std::string>& 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<uint32_t>(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 " |