summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-08-09 01:00:49 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-08-09 01:00:49 +0000
commit45da8349f73acfca7c4c67a77e07d447645a9851 (patch)
treedef17c57ed2ed9d6518da75b63b4e55ffca0cdee
parentd51b8490692c460f3ce21d0157389b2066c94e01 (diff)
parentd8aa2eda659d69c5701281df9c767902a215d7e5 (diff)
downloadextras-45da8349f73acfca7c4c67a77e07d447645a9851.tar.gz
Merge "simpleperf: fix stat cmd."
-rw-r--r--simpleperf/cmd_stat_test.cpp15
-rw-r--r--simpleperf/event_selection_set.cpp16
2 files changed, 24 insertions, 7 deletions
diff --git a/simpleperf/cmd_stat_test.cpp b/simpleperf/cmd_stat_test.cpp
index 3cdb4ebd..e8c722d4 100644
--- a/simpleperf/cmd_stat_test.cpp
+++ b/simpleperf/cmd_stat_test.cpp
@@ -24,6 +24,7 @@
#include "command.h"
#include "environment.h"
+#include "event_selection_set.h"
#include "get_test_data.h"
#include "test_util.h"
@@ -175,3 +176,17 @@ TEST(stat_cmd, stop_when_no_more_targets) {
while (tid == 0);
ASSERT_TRUE(StatCmd()->Run({"-t", std::to_string(tid), "--in-app"}));
}
+
+TEST(stat_cmd, sample_speed_should_be_zero) {
+ EventSelectionSet set(true);
+ ASSERT_TRUE(set.AddEventType("cpu-cycles"));
+ set.AddMonitoredProcesses({getpid()});
+ ASSERT_TRUE(set.OpenEventFiles({-1}));
+ std::vector<EventAttrWithId> attrs = set.GetEventAttrWithId();
+ ASSERT_GT(attrs.size(), 0u);
+ for (auto& attr : attrs) {
+ ASSERT_EQ(attr.attr->sample_period, 0u);
+ ASSERT_EQ(attr.attr->sample_freq, 0u);
+ ASSERT_EQ(attr.attr->freq, 0u);
+ }
+}
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index e0af5863..d128920d 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -128,13 +128,15 @@ bool EventSelectionSet::BuildAndCheckEventSelection(
selection->event_attr.exclude_host = event_type->exclude_host;
selection->event_attr.exclude_guest = event_type->exclude_guest;
selection->event_attr.precise_ip = event_type->precise_ip;
- if (event_type->event_type.type == PERF_TYPE_TRACEPOINT) {
- selection->event_attr.freq = 0;
- 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);
+ if (!for_stat_cmd_) {
+ if (event_type->event_type.type == PERF_TYPE_TRACEPOINT) {
+ selection->event_attr.freq = 0;
+ 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);
+ }
}
if (!IsEventAttrSupported(selection->event_attr)) {
LOG(ERROR) << "Event type '" << event_type->name