summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2017-11-02 17:31:58 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-11-02 17:31:58 +0000
commit6e0851e917f7dc4b1a97f9d08971ee9670bf5cd0 (patch)
tree7901b006265956c027b5bdb66ced5af2ad69fda1
parent647ad93f06dbcf18f114d1e70c27a2b4171c97f6 (diff)
parentb9214820bb9348e54fcb5013ae7ca8cc1c793141 (diff)
downloadextras-6e0851e917f7dc4b1a97f9d08971ee9670bf5cd0.tar.gz
Merge "simpleperf: avoid warning for default freq."
-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)) {