summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2017-11-01 15:03:38 -0700
committerYabin Cui <yabinc@google.com>2017-11-01 15:27:12 -0700
commitb9214820bb9348e54fcb5013ae7ca8cc1c793141 (patch)
treed19eb41018a9f1a6199be2a0d3bfb7e3626d45e4
parent29c0043b5334432afc01584f435585c2d2da49fe (diff)
downloadextras-b9214820bb9348e54fcb5013ae7ca8cc1c793141.tar.gz
simpleperf: avoid warning for default freq.
When max_freq = 1800, and run `simpleperf record -e cpu-cycles -f 1000`, it prints warning for default freq: Sample frequency 4000 is out of range [1, 1800], adjust it to 1800 This patch removes the unproper warning. Also remove AdjustSampleFrequency() because the freq will be adjusted in event_fd.cpp. Bug: http://b/29574526 Test: run `simpleperf record -e cpu-cycles -f 1000`. Test: run simpleperf_unit_test. Change-Id: Ieed106fb539b7deb9fee3208f00228c6e0520acb
-rw-r--r--simpleperf/cmd_record.cpp2
-rw-r--r--simpleperf/environment.cpp18
-rw-r--r--simpleperf/environment.h1
-rw-r--r--simpleperf/event_selection_set.cpp9
4 files changed, 8 insertions, 22 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index 7152ab5f..902d2bcb 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -467,7 +467,7 @@ bool RecordCommand::ParseOptions(const std::vector<std::string>& args,
if (args[i-1] == "-c") {
sample_speed_.reset(new SampleSpeed(0, value));
} else {
- sample_speed_.reset(new SampleSpeed(AdjustSampleFrequency(value), 0));
+ sample_speed_.reset(new SampleSpeed(value, 0));
}
for (auto group_id : wait_setting_speed_event_groups_) {
event_selection_set_.SetSampleSpeed(group_id, *sample_speed_);
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index c244b468..49d3514c 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -432,24 +432,6 @@ bool GetMaxSampleFrequency(uint64_t* max_sample_freq) {
return true;
}
-uint64_t AdjustSampleFrequency(uint64_t sample_freq) {
- if (sample_freq == 0) {
- LOG(WARNING) << "Sample frequency can't be zero, adjust it to 1";
- return 1u;
- }
- uint64_t max_sample_freq;
- if (!GetMaxSampleFrequency(&max_sample_freq)) {
- // Omit the check if can't read perf_event_max_sample_rate.
- return sample_freq;
- }
- if (sample_freq > max_sample_freq) {
- LOG(WARNING) << "Sample frequency " << sample_freq << " is out of range [1, "
- << max_sample_freq << "], adjust it to " << max_sample_freq;
- return max_sample_freq;
- }
- return sample_freq;
-}
-
bool CheckKernelSymbolAddresses() {
const std::string kptr_restrict_file = "/proc/sys/kernel/kptr_restrict";
std::string s;
diff --git a/simpleperf/environment.h b/simpleperf/environment.h
index 0f121465..f49e8abb 100644
--- a/simpleperf/environment.h
+++ b/simpleperf/environment.h
@@ -70,7 +70,6 @@ bool GetValidThreadsFromThreadString(const std::string& tid_str, std::set<pid_t>
bool CheckPerfEventLimit();
bool GetMaxSampleFrequency(uint64_t* max_sample_freq);
-uint64_t AdjustSampleFrequency(uint64_t sample_freq);
bool CheckKernelSymbolAddresses();
bool CanRecordRawData();
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index 75cb9063..646de404 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -16,6 +16,7 @@
#include "event_selection_set.h"
+#include <algorithm>
#include <atomic>
#include <thread>
@@ -147,8 +148,12 @@ bool EventSelectionSet::BuildAndCheckEventSelection(
selection->event_attr.sample_period = DEFAULT_SAMPLE_PERIOD_FOR_TRACEPOINT_EVENT;
} else {
selection->event_attr.freq = 1;
- selection->event_attr.sample_freq =
- AdjustSampleFrequency(DEFAULT_SAMPLE_FREQ_FOR_NONTRACEPOINT_EVENT);
+ uint64_t freq = DEFAULT_SAMPLE_FREQ_FOR_NONTRACEPOINT_EVENT;
+ uint64_t max_freq;
+ if (GetMaxSampleFrequency(&max_freq)) {
+ freq = std::min(freq, max_freq);
+ }
+ selection->event_attr.sample_freq = freq;
}
}
if (!IsEventAttrSupported(selection->event_attr)) {