]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/perf/util/evsel.c
Merge tag 'uuid-for-4.13-2' of git://git.infradead.org/users/hch/uuid
[linux.git] / tools / perf / util / evsel.c
index cda44b0e821c63baea1f9da52123184768fdd2f4..413f74df08de7cae06b1313ef0ed4c1339ee2093 100644 (file)
 #include <errno.h>
 #include <inttypes.h>
 #include <linux/bitops.h>
+#include <api/fs/fs.h>
 #include <api/fs/tracing_path.h>
 #include <traceevent/event-parse.h>
 #include <linux/hw_breakpoint.h>
 #include <linux/perf_event.h>
+#include <linux/compiler.h>
 #include <linux/err.h>
 #include <sys/ioctl.h>
 #include <sys/resource.h>
+#include <sys/types.h>
+#include <dirent.h>
 #include "asm/bug.h"
 #include "callchain.h"
 #include "cgroup.h"
@@ -269,6 +273,7 @@ struct perf_evsel *perf_evsel__new_cycles(void)
        struct perf_event_attr attr = {
                .type   = PERF_TYPE_HARDWARE,
                .config = PERF_COUNT_HW_CPU_CYCLES,
+               .exclude_kernel = geteuid() != 0,
        };
        struct perf_evsel *evsel;
 
@@ -293,8 +298,10 @@ struct perf_evsel *perf_evsel__new_cycles(void)
                goto out;
 
        /* use asprintf() because free(evsel) assumes name is allocated */
-       if (asprintf(&evsel->name, "cycles%.*s",
-                    attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0)
+       if (asprintf(&evsel->name, "cycles%s%s%.*s",
+                    (attr.precise_ip || attr.exclude_kernel) ? ":" : "",
+                    attr.exclude_kernel ? "u" : "",
+                    attr.precise_ip ? attr.precise_ip + 1 : 0, "ppp") < 0)
                goto error_free;
 out:
        return evsel;
@@ -1441,7 +1448,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 }
 
 static int __open_attr__fprintf(FILE *fp, const char *name, const char *val,
-                               void *priv __attribute__((unused)))
+                               void *priv __maybe_unused)
 {
        return fprintf(fp, "  %-32s %s\n", name, val);
 }
@@ -2471,6 +2478,42 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
        return false;
 }
 
+static bool find_process(const char *name)
+{
+       size_t len = strlen(name);
+       DIR *dir;
+       struct dirent *d;
+       int ret = -1;
+
+       dir = opendir(procfs__mountpoint());
+       if (!dir)
+               return false;
+
+       /* Walk through the directory. */
+       while (ret && (d = readdir(dir)) != NULL) {
+               char path[PATH_MAX];
+               char *data;
+               size_t size;
+
+               if ((d->d_type != DT_DIR) ||
+                    !strcmp(".", d->d_name) ||
+                    !strcmp("..", d->d_name))
+                       continue;
+
+               scnprintf(path, sizeof(path), "%s/%s/comm",
+                         procfs__mountpoint(), d->d_name);
+
+               if (filename__read_str(path, &data, &size))
+                       continue;
+
+               ret = strncmp(name, data, len);
+               free(data);
+       }
+
+       closedir(dir);
+       return ret ? false : true;
+}
+
 int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
                              int err, char *msg, size_t size)
 {