]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - tools/perf/builtin-stat.c
perf tools: Add signal.h to places using its definitions
[karo-tx-linux.git] / tools / perf / builtin-stat.c
index 01b589e3c3a6467615e836b98cd454cfd400627c..e3837febb4ffb796e55fdf3349ad95de3218e92d 100644 (file)
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/group.h"
+#include "util/string2.h"
 #include "asm/bug.h"
 
 #include <linux/time64.h>
 #include <api/fs/fs.h>
+#include <errno.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <sys/prctl.h>
+#include <inttypes.h>
 #include <locale.h>
 #include <math.h>
 
+#include "sane_ctype.h"
+
 #define DEFAULT_SEPARATOR      " "
 #define CNTR_NOT_SUPPORTED     "<not supported>"
 #define CNTR_NOT_COUNTED       "<not counted>"
@@ -312,8 +318,12 @@ static int read_counter(struct perf_evsel *counter)
                        struct perf_counts_values *count;
 
                        count = perf_counts(counter->counts, cpu, thread);
-                       if (perf_evsel__read(counter, cpu, thread, count))
+                       if (perf_evsel__read(counter, cpu, thread, count)) {
+                               counter->counts->scaled = -1;
+                               perf_counts(counter->counts, cpu, thread)->ena = 0;
+                               perf_counts(counter->counts, cpu, thread)->run = 0;
                                return -1;
+                       }
 
                        if (STAT_RECORD) {
                                if (perf_evsel__write_stat_event(counter, cpu, thread, count)) {
@@ -338,12 +348,14 @@ static int read_counter(struct perf_evsel *counter)
 static void read_counters(void)
 {
        struct perf_evsel *counter;
+       int ret;
 
        evlist__for_each_entry(evsel_list, counter) {
-               if (read_counter(counter))
+               ret = read_counter(counter);
+               if (ret)
                        pr_debug("failed to read counter %s\n", counter->name);
 
-               if (perf_stat_process_counter(&stat_config, counter))
+               if (ret == 0 && perf_stat_process_counter(&stat_config, counter))
                        pr_warning("failed to process counter %s\n", counter->name);
        }
 }
@@ -875,10 +887,7 @@ static void print_metric_csv(void *ctx,
                return;
        }
        snprintf(buf, sizeof(buf), fmt, val);
-       vals = buf;
-       while (isspace(*vals))
-               vals++;
-       ends = vals;
+       ends = vals = ltrim(buf);
        while (isdigit(*ends) || *ends == '.')
                ends++;
        *ends = 0;
@@ -950,10 +959,7 @@ static void print_metric_only_csv(void *ctx, const char *color __maybe_unused,
                return;
        unit = fixunit(tbuf, os->evsel, unit);
        snprintf(buf, sizeof buf, fmt, val);
-       vals = buf;
-       while (isspace(*vals))
-               vals++;
-       ends = vals;
+       ends = vals = ltrim(buf);
        while (isdigit(*ends) || *ends == '.')
                ends++;
        *ends = 0;
@@ -2478,7 +2484,7 @@ static void setup_system_wide(int forks)
        }
 }
 
-int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
+int cmd_stat(int argc, const char **argv)
 {
        const char * const stat_usage[] = {
                "perf stat [<options>] [<command>]",