浏览代码

perf tests attr: Add test_attr__ready function

We create many test events before the real ones just to test specific
features. But there's no way for attr tests to separate those test
events from those it needs to check.

Adding 'ready' call from the events open interface to trigger/start
events collection for attr test.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Richter <tmricht@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20170703145030.12903-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Jiri Olsa 8 年之前
父节点
当前提交
10213e2ff2
共有 3 个文件被更改,包括 15 次插入0 次删除
  1. 1 0
      tools/perf/perf.h
  2. 10 0
      tools/perf/tests/attr.c
  3. 4 0
      tools/perf/util/evsel.c

+ 1 - 0
tools/perf/perf.h

@@ -7,6 +7,7 @@
 #include <linux/perf_event.h>
 #include <linux/perf_event.h>
 
 
 extern bool test_attr__enabled;
 extern bool test_attr__enabled;
+void test_attr__ready(void);
 void test_attr__init(void);
 void test_attr__init(void);
 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
 		     int fd, int group_fd, unsigned long flags);
 		     int fd, int group_fd, unsigned long flags);

+ 10 - 0
tools/perf/tests/attr.c

@@ -36,6 +36,7 @@
 #define ENV "PERF_TEST_ATTR"
 #define ENV "PERF_TEST_ATTR"
 
 
 static char *dir;
 static char *dir;
+static bool ready;
 
 
 void test_attr__init(void)
 void test_attr__init(void)
 {
 {
@@ -67,6 +68,9 @@ static int store_event(struct perf_event_attr *attr, pid_t pid, int cpu,
 	FILE *file;
 	FILE *file;
 	char path[PATH_MAX];
 	char path[PATH_MAX];
 
 
+	if (!ready)
+		return 0;
+
 	snprintf(path, PATH_MAX, "%s/event-%d-%llu-%d", dir,
 	snprintf(path, PATH_MAX, "%s/event-%d-%llu-%d", dir,
 		 attr->type, attr->config, fd);
 		 attr->type, attr->config, fd);
 
 
@@ -144,6 +148,12 @@ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
 	errno = errno_saved;
 	errno = errno_saved;
 }
 }
 
 
+void test_attr__ready(void)
+{
+	if (unlikely(test_attr__enabled) && !ready)
+		ready = true;
+}
+
 static int run_dir(const char *d, const char *perf)
 static int run_dir(const char *d, const char *perf)
 {
 {
 	char v[] = "-vvvvv";
 	char v[] = "-vvvvv";

+ 4 - 0
tools/perf/util/evsel.c

@@ -58,6 +58,8 @@ static int perf_evsel__no_extra_init(struct perf_evsel *evsel __maybe_unused)
 	return 0;
 	return 0;
 }
 }
 
 
+void __weak test_attr__ready(void) { }
+
 static void perf_evsel__no_extra_fini(struct perf_evsel *evsel __maybe_unused)
 static void perf_evsel__no_extra_fini(struct perf_evsel *evsel __maybe_unused)
 {
 {
 }
 }
@@ -1572,6 +1574,8 @@ retry_open:
 			pr_debug2("sys_perf_event_open: pid %d  cpu %d  group_fd %d  flags %#lx",
 			pr_debug2("sys_perf_event_open: pid %d  cpu %d  group_fd %d  flags %#lx",
 				  pid, cpus->map[cpu], group_fd, flags);
 				  pid, cpus->map[cpu], group_fd, flags);
 
 
+			test_attr__ready();
+
 			fd = sys_perf_event_open(&evsel->attr, pid, cpus->map[cpu],
 			fd = sys_perf_event_open(&evsel->attr, pid, cpus->map[cpu],
 						 group_fd, flags);
 						 group_fd, flags);