perf evlist: Introduce perf_evlist__new_default function
authorJiri Olsa <jolsa@redhat.com>
Sun, 1 Sep 2013 10:36:14 +0000 (12:36 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 9 Oct 2013 14:24:34 +0000 (11:24 -0300)
Adding new common function to create evlist with default event. It
spares some code lines in automated tests.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1378031796-17892-4-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/perf-record.c
tools/perf/tests/task-exit.c
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index b8a7056519ac7c29b430a87d73be85314b4d8082..82ac71550091c4b8e5940c6eb122d88299a0fca6 100644 (file)
@@ -45,7 +45,7 @@ int test__PERF_RECORD(void)
        };
        cpu_set_t cpu_mask;
        size_t cpu_mask_size = sizeof(cpu_mask);
-       struct perf_evlist *evlist = perf_evlist__new();
+       struct perf_evlist *evlist = perf_evlist__new_default();
        struct perf_evsel *evsel;
        struct perf_sample sample;
        const char *cmd = "sleep";
@@ -65,16 +65,6 @@ int test__PERF_RECORD(void)
                goto out;
        }
 
-       /*
-        * We need at least one evsel in the evlist, use the default
-        * one: "cycles".
-        */
-       err = perf_evlist__add_default(evlist);
-       if (err < 0) {
-               pr_debug("Not enough memory to create evsel\n");
-               goto out_delete_evlist;
-       }
-
        /*
         * Create maps of threads and cpus to monitor. In this case
         * we start with all threads and cpus (-1, -1) but then in
index 28fe5894b0618901493100ea0995c8dda093b9ec..b07f8a14e15df58f22de8db3a22cd689dc5c647e 100644 (file)
@@ -37,20 +37,11 @@ int test__task_exit(void)
        signal(SIGCHLD, sig_handler);
        signal(SIGUSR1, sig_handler);
 
-       evlist = perf_evlist__new();
+       evlist = perf_evlist__new_default();
        if (evlist == NULL) {
-               pr_debug("perf_evlist__new\n");
+               pr_debug("perf_evlist__new_default\n");
                return -1;
        }
-       /*
-        * We need at least one evsel in the evlist, use the default
-        * one: "cycles".
-        */
-       err = perf_evlist__add_default(evlist);
-       if (err < 0) {
-               pr_debug("Not enough memory to create evsel\n");
-               goto out_free_evlist;
-       }
 
        /*
         * Create maps of threads and cpus to monitor. In this case
@@ -117,7 +108,6 @@ out_close_evlist:
        perf_evlist__close(evlist);
 out_delete_maps:
        perf_evlist__delete_maps(evlist);
-out_free_evlist:
        perf_evlist__delete(evlist);
        return err;
 }
index d21ab08129264c10859133e6b1da7bce444e4608..f0d71a9d49f467ebbc27551c46ddd12b648863cf 100644 (file)
@@ -50,6 +50,18 @@ struct perf_evlist *perf_evlist__new(void)
        return evlist;
 }
 
+struct perf_evlist *perf_evlist__new_default(void)
+{
+       struct perf_evlist *evlist = perf_evlist__new();
+
+       if (evlist && perf_evlist__add_default(evlist)) {
+               perf_evlist__delete(evlist);
+               evlist = NULL;
+       }
+
+       return evlist;
+}
+
 /**
  * perf_evlist__set_id_pos - set the positions of event ids.
  * @evlist: selected event list
index 4edb5008fd362f29eef2600b0ddcb30fe9c50696..871b55ab5dee56fae7a19eb808ccad5f7175e93d 100644 (file)
@@ -53,6 +53,7 @@ struct perf_evsel_str_handler {
 };
 
 struct perf_evlist *perf_evlist__new(void);
+struct perf_evlist *perf_evlist__new_default(void);
 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
                       struct thread_map *threads);
 void perf_evlist__exit(struct perf_evlist *evlist);