OSDN Git Service

simpleperf: check if dwarf callgraph is supported by kernel before testing.
authorYabin Cui <yabinc@google.com>
Thu, 10 Mar 2016 19:49:57 +0000 (11:49 -0800)
committerYabin Cui <yabinc@google.com>
Thu, 10 Mar 2016 21:50:23 +0000 (13:50 -0800)
Move inclusion of poll.h from header files to source files,
as event_selection_set.h is used by cmd_report_test.cpp, which
can be built on windows.

Bug: 27590546
Change-Id: Ic6b141a93d96610f911ab52da1d927b7f619ccb2

simpleperf/cmd_report_test.cpp
simpleperf/event_fd.cpp
simpleperf/event_fd.h
simpleperf/event_selection_set.cpp
simpleperf/event_selection_set.h

index a5ece01..e27f71e 100644 (file)
@@ -24,6 +24,7 @@
 #include <android-base/test_utils.h>
 
 #include "command.h"
+#include "event_selection_set.h"
 #include "get_test_data.h"
 #include "read_apk.h"
 #include "test_util.h"
@@ -252,17 +253,22 @@ TEST_F(ReportCommandTest, use_branch_address) {
             hit_set.end());
 }
 
-#if defined(__ANDROID__) || defined(__linux__)
+#if defined(__linux__)
 
 static std::unique_ptr<Command> RecordCmd() {
   return CreateCommandInstance("record");
 }
 
 TEST_F(ReportCommandTest, dwarf_callgraph) {
-  TemporaryFile tmp_file;
-  ASSERT_TRUE(RecordCmd()->Run({"-g", "-o", tmp_file.path, "sleep", SLEEP_SEC}));
-  ReportRaw(tmp_file.path, {"-g"});
-  ASSERT_TRUE(success);
+  if (IsDwarfCallChainSamplingSupported()) {
+    TemporaryFile tmp_file;
+    ASSERT_TRUE(RecordCmd()->Run({"-g", "-o", tmp_file.path, "sleep", SLEEP_SEC}));
+    ReportRaw(tmp_file.path, {"-g"});
+    ASSERT_TRUE(success);
+  } else {
+    GTEST_LOG_(INFO)
+        << "This test does nothing as dwarf callchain sampling is not supported on this device.";
+  }
 }
 
 #endif
index ec06f6f..808639b 100644 (file)
@@ -17,6 +17,7 @@
 #include "event_fd.h"
 
 #include <fcntl.h>
+#include <poll.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/ioctl.h>
index cc0c061..c1a7d75 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef SIMPLE_PERF_EVENT_FD_H_
 #define SIMPLE_PERF_EVENT_FD_H_
 
-#include <poll.h>
 #include <sys/types.h>
 
 #include <memory>
@@ -35,6 +34,8 @@ struct PerfCounter {
   uint64_t id;            // The id of the perf_event_file.
 };
 
+struct pollfd;
+
 // EventFd represents an opened perf_event_file.
 class EventFd {
  public:
index df731f1..d99966a 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "event_selection_set.h"
 
+#include <poll.h>
+
 #include <android-base/logging.h>
 #include <android-base/stringprintf.h>
 
index cba9dc6..746abfa 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef SIMPLE_PERF_EVENT_SELECTION_SET_H_
 #define SIMPLE_PERF_EVENT_SELECTION_SET_H_
 
-#include <poll.h>
 #include <functional>
 #include <map>
 #include <vector>
@@ -38,6 +37,8 @@ struct CountersInfo {
   std::vector<CounterInfo> counters;
 };
 
+struct pollfd;
+
 // EventSelectionSet helps to monitor events.
 // Firstly, the user creates an EventSelectionSet, and adds the specific event types to monitor.
 // Secondly, the user defines how to monitor the events (by setting enable_on_exec flag,