From 42f37f04c53f537de748189b1c74e847bb69e934 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Fri, 22 Jan 2016 15:38:46 -0800 Subject: [PATCH] Simpleperf: adjust default mmap_pages used when recording. If running as non-root, there is a limitation on how many mmap pages can be used for profiling per user. So adjust default mmap_pages value to fit the limit, and add option to change it. Change-Id: Ie73f33c473498689234972989fc55b7731366792 --- simpleperf/cmd_record.cpp | 20 +++++++++++++++++--- simpleperf/cmd_record_test.cpp | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 45be4f6e..ee738c00 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -96,6 +96,9 @@ class RecordCommand : public Command { " k: only when the branch target is in the kernel\n" " This option requires at least one branch type among any,\n" " any_call, any_ret, ind_call.\n" + " -m mmap_pages\n" + " Set the size of the buffer used to receiving sample data from\n" + " the kernel. It should be a power of 2. The default value is 16.\n" " --no-inherit\n" " Don't record created child threads/processes.\n" " --no-unwind If `--call-graph dwarf` option is used, then the user's stack will\n" @@ -121,7 +124,7 @@ class RecordCommand : public Command { unwind_dwarf_callchain_(true), post_unwind_(false), child_inherit_(true), - perf_mmap_pages_(256), + perf_mmap_pages_(16), record_filename_("perf.data") { signaled = false; scoped_signal_handler_.reset( @@ -165,8 +168,8 @@ class RecordCommand : public Command { std::vector measured_event_types_; EventSelectionSet event_selection_set_; - // mmap pages used by each perf event file, should be power of 2. - const size_t perf_mmap_pages_; + // mmap pages used by each perf event file, should be a power of 2. + size_t perf_mmap_pages_; std::unique_ptr record_cache_; ThreadTree thread_tree_; @@ -367,6 +370,17 @@ bool RecordCommand::ParseOptions(const std::vector& args, } branch_sampling_ |= it->second; } + } else if (args[i] == "-m") { + if (!NextArgumentOrError(args, &i)) { + return false; + } + char* endptr; + uint64_t pages = strtoull(args[i].c_str(), &endptr, 0); + if (*endptr != '\0' || !IsPowerOfTwo(pages)) { + LOG(ERROR) << "Invalid mmap_pages: '" << args[i] << "'"; + return false; + } + perf_mmap_pages_ = pages; } 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 0a9dfde2..ca38a050 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -172,3 +172,9 @@ TEST(record_cmd, cpu_option) { ASSERT_TRUE(RecordCmd()->Run({"--cpu", "0", "sleep", "1"})); ASSERT_TRUE(RecordCmd()->Run({"--cpu", "0", "-a", "sleep", "1"})); } + +TEST(record_cmd, mmap_page_option) { + ASSERT_TRUE(RecordCmd()->Run({"-m", "1", "sleep", "1"})); + ASSERT_FALSE(RecordCmd()->Run({"-m", "0", "sleep", "1"})); + ASSERT_FALSE(RecordCmd()->Run({"-m", "7", "sleep", "1"})); +} -- 2.11.0