]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - tools/perf/util/evsel.c
perf tools: Move sane ctype stuff from util.h to sane_ctype.h
[karo-tx-linux.git] / tools / perf / util / evsel.c
index 175dc2305aa8211aba29f728d4ef23b97c32539a..757f73c4fa95c596ced7391aab17ac443e4ea1fa 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <byteswap.h>
+#include <inttypes.h>
 #include <linux/bitops.h>
 #include <api/fs/tracing_path.h>
 #include <traceevent/event-parse.h>
@@ -30,6 +31,8 @@
 #include "stat.h"
 #include "util/parse-branch-options.h"
 
+#include "sane_ctype.h"
+
 static struct {
        bool sample_id_all;
        bool exclude_guest;
@@ -236,6 +239,10 @@ void perf_evsel__init(struct perf_evsel *evsel,
        evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
        perf_evsel__calc_id_pos(evsel);
        evsel->cmdline_group_boundary = false;
+       evsel->metric_expr   = NULL;
+       evsel->metric_name   = NULL;
+       evsel->metric_events = NULL;
+       evsel->collect_stat  = false;
 }
 
 struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
@@ -1235,7 +1242,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
        if (FD(evsel, cpu, thread) < 0)
                return -EINVAL;
 
-       if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) < 0)
+       if (readn(FD(evsel, cpu, thread), count, sizeof(*count)) <= 0)
                return -errno;
 
        return 0;
@@ -1253,7 +1260,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
        if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0)
                return -ENOMEM;
 
-       if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
+       if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 0)
                return -errno;
 
        perf_evsel__compute_deltas(evsel, cpu, thread, &count);
@@ -2453,11 +2460,17 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
                              int err, char *msg, size_t size)
 {
        char sbuf[STRERR_BUFSIZE];
+       int printed = 0;
 
        switch (err) {
        case EPERM:
        case EACCES:
-               return scnprintf(msg, size,
+               if (err == EPERM)
+                       printed = scnprintf(msg, size,
+                               "No permission to enable %s event.\n\n",
+                               perf_evsel__name(evsel));
+
+               return scnprintf(msg + printed, size - printed,
                 "You may not have permission to collect %sstats.\n\n"
                 "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n"
                 "which controls use of the performance events system by\n"