perf auxtrace: Add itrace option flag d+e to log on error
authorAdrian Hunter <adrian.hunter@intel.com>
Mon, 5 Sep 2022 07:34:20 +0000 (10:34 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 4 Oct 2022 11:55:21 +0000 (08:55 -0300)
Add flag +e to the itrace d (decoder debug log) option to get output only
on decoding errors.

The log can be very big so reducing the output to where there are decoding
errors can be useful for analyzing errors.

By default, the log size in that case is 16384 bytes, but can be altered by
perf config e.g. perf config itrace.debug-log-buffer-size=30000

Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20220905073424.3971-3-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/itrace.txt
tools/perf/Documentation/perf-config.txt
tools/perf/util/auxtrace.c
tools/perf/util/auxtrace.h

index 6b189669c450e7030f8cf371dfe8bbfdabda539f..0916bbfe64cb7873d7433055f352518f208b6e5b 100644 (file)
@@ -64,6 +64,7 @@
        debug messages will or will not be logged. Each flag must be preceded
        by either '+' or '-'. The flags are:
                a       all perf events
+               e       output only on errors (size configurable - see linkperf:perf-config[1])
                o       output to stdout
 
        If supported, the 'q' option may be repeated to increase the effect.
index 0420e71698ee4f9234eda381d7633805216848ca..39c890ead2dc0045a018268fcd5afc006e1ad5b4 100644 (file)
@@ -729,6 +729,13 @@ auxtrace.*::
                If the directory does not exist or has the wrong file type,
                the current directory is used.
 
+itrace.*::
+
+       debug-log-buffer-size::
+               Log size in bytes to output when using the option --itrace=d+e
+               Refer 'itrace' option of linkperf:perf-script[1] or
+               linkperf:perf-report[1]. The default is 16384.
+
 daemon.*::
 
        daemon.base::
index 6edab8a16de6af1e0d27f4475947d2c563687369..b59c278fe9edef78ae780751f0d8a4beeb7850f2 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/list.h>
 #include <linux/zalloc.h>
 
+#include "config.h"
 #include "evlist.h"
 #include "dso.h"
 #include "map.h"
@@ -1434,6 +1435,16 @@ static int get_flags(const char **ptr, unsigned int *plus_flags, unsigned int *m
        }
 }
 
+#define ITRACE_DFLT_LOG_ON_ERROR_SZ 16384
+
+static unsigned int itrace_log_on_error_size(void)
+{
+       unsigned int sz = 0;
+
+       perf_config_scan("itrace.debug-log-buffer-size", "%u", &sz);
+       return sz ?: ITRACE_DFLT_LOG_ON_ERROR_SZ;
+}
+
 /*
  * Please check tools/perf/Documentation/perf-script.txt for information
  * about the options parsed here, which is introduced after this cset,
@@ -1532,6 +1543,8 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
                        if (get_flags(&p, &synth_opts->log_plus_flags,
                                      &synth_opts->log_minus_flags))
                                goto out_err;
+                       if (synth_opts->log_plus_flags & AUXTRACE_LOG_FLG_ON_ERROR)
+                               synth_opts->log_on_error_size = itrace_log_on_error_size();
                        break;
                case 'c':
                        synth_opts->branches = true;
index 6a4fbfd34c6ba41333a40c9eb670965634925ef0..cb8e0a01abb6e89aafbb953a2ca7cabbde5c63e1 100644 (file)
@@ -60,6 +60,7 @@ enum itrace_period_type {
 #define AUXTRACE_ERR_FLG_DATA_LOST     (1 << ('l' - 'a'))
 
 #define AUXTRACE_LOG_FLG_ALL_PERF_EVTS (1 << ('a' - 'a'))
+#define AUXTRACE_LOG_FLG_ON_ERROR      (1 << ('e' - 'a'))
 #define AUXTRACE_LOG_FLG_USE_STDOUT    (1 << ('o' - 'a'))
 
 /**
@@ -110,6 +111,7 @@ enum itrace_period_type {
  * @log_plus_flags: flags to affect what is logged
  * @log_minus_flags: flags to affect what is logged
  * @quick: quicker (less detailed) decoding
+ * @log_on_error_size: size of log to keep for outputting log only on errors
  */
 struct itrace_synth_opts {
        bool                    set;
@@ -155,6 +157,7 @@ struct itrace_synth_opts {
        unsigned int            log_plus_flags;
        unsigned int            log_minus_flags;
        unsigned int            quick;
+       unsigned int            log_on_error_size;
 };
 
 /**