diff options
author | Yabin Cui <yabinc@google.com> | 2017-08-08 15:44:33 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2017-08-08 15:44:33 -0700 |
commit | d8aa2eda659d69c5701281df9c767902a215d7e5 (patch) | |
tree | dcabfa3899564a0e73a47e03c970c806312566b2 | |
parent | f9ed7b5507b4355021acc22adc14451e2e2d63ef (diff) | |
download | extras-d8aa2eda659d69c5701281df9c767902a215d7e5.tar.gz |
simpleperf: fix stat cmd.
Previous CL wrongly makes kernel dump samples for stat cmd.
Bug: http://b/64489160
Test: run simpleperf_unit_test.
Change-Id: I4f5c08839e283b2361e47d61310e5161433824bb
-rw-r--r-- | simpleperf/cmd_stat_test.cpp | 15 | ||||
-rw-r--r-- | simpleperf/event_selection_set.cpp | 16 |
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 |