OSDN Git Service

simpleperf: fix stat cmd.
authorYabin Cui <yabinc@google.com>
Tue, 8 Aug 2017 22:44:33 +0000 (15:44 -0700)
committerYabin Cui <yabinc@google.com>
Tue, 8 Aug 2017 22:44:33 +0000 (15:44 -0700)
Previous CL wrongly makes kernel dump samples for stat cmd.

Bug: http://b/64489160
Test: run simpleperf_unit_test.
Change-Id: I4f5c08839e283b2361e47d61310e5161433824bb

simpleperf/cmd_stat_test.cpp
simpleperf/event_selection_set.cpp

index 3cdb4eb..e8c722d 100644 (file)
@@ -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);
+  }
+}
index e0af586..d128920 100644 (file)
@@ -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