[PATCH v6 2/5] perf, tools, script: Make itrace script default to all calls

2018-09-20 Thread Andi Kleen
From: Andi Kleen 

By default perf script for itrace outputs sampled instructions or
branches. In my experience this is confusing to users because it's
hard to correlate with real program behavior. The sampling makes
sense for tools like report that actually sample to reduce
the run time, but run time is normally not a problem for perf script.
It's better to give an accurate representation of the program flow.

Default perf script to output all calls for itrace. That's a much saner
default. The old behavior can be still requested with
perf script --itrace=ibxwpe10

v2: Fix ETM build failure
v3: Really fix ETM build failure (Kim Phillips)
Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/itrace.txt |  7 ---
 tools/perf/builtin-script.c |  5 -
 tools/perf/util/auxtrace.c  | 17 -
 tools/perf/util/auxtrace.h  |  5 -
 tools/perf/util/cs-etm.c|  3 ++-
 tools/perf/util/intel-bts.c |  3 ++-
 tools/perf/util/intel-pt.c  |  3 ++-
 7 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt 
b/tools/perf/Documentation/itrace.txt
index a3abe04c779d..c2182cbabde3 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -11,10 +11,11 @@
l   synthesize last branch entries (use with i or x)
s   skip initial number of events
 
-   The default is all events i.e. the same as --itrace=ibxwpe
+   The default is all events i.e. the same as --itrace=ibxwpe,
+   except for perf script where it is --itrace=ce
 
-   In addition, the period (default 10) for instructions events
-   can be specified in units of:
+   In addition, the period (default 10, except for perf script where 
it is 1)
+   for instructions events can be specified in units of:
 
i   instructions
t   ticks
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 311f5b53dd83..519ebb5a1f96 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3128,7 +3128,10 @@ int cmd_script(int argc, const char **argv)
char *rec_script_path = NULL;
char *rep_script_path = NULL;
struct perf_session *session;
-   struct itrace_synth_opts itrace_synth_opts = { .set = false, };
+   struct itrace_synth_opts itrace_synth_opts = {
+   .set = false,
+   .default_no_sample = true,
+   };
char *script_path = NULL;
const char **__argv;
int i, j, err = 0;
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index c4617bcfd521..72d5ba2479bf 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -962,16 +962,23 @@ s64 perf_event__process_auxtrace(struct perf_session 
*session,
 #define PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ 64
 #define PERF_ITRACE_MAX_LAST_BRANCH_SZ 1024
 
-void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
+void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
+   bool no_sample)
 {
-   synth_opts->instructions = true;
synth_opts->branches = true;
synth_opts->transactions = true;
synth_opts->ptwrites = true;
synth_opts->pwr_events = true;
synth_opts->errors = true;
-   synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
-   synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
+   if (no_sample) {
+   synth_opts->period_type = PERF_ITRACE_PERIOD_INSTRUCTIONS;
+   synth_opts->period = 1;
+   synth_opts->calls = true;
+   } else {
+   synth_opts->instructions = true;
+   synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
+   synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
+   }
synth_opts->callchain_sz = PERF_ITRACE_DEFAULT_CALLCHAIN_SZ;
synth_opts->last_branch_sz = PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ;
synth_opts->initial_skip = 0;
@@ -999,7 +1006,7 @@ int itrace_parse_synth_opts(const struct option *opt, 
const char *str,
}
 
if (!str) {
-   itrace_synth_opts__set_default(synth_opts);
+   itrace_synth_opts__set_default(synth_opts, false);
return 0;
}
 
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 0a6ce9c4fc11..f6df30187e1c 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -57,6 +57,7 @@ enum itrace_period_type {
 /**
  * struct itrace_synth_opts - AUX area tracing synthesis options.
  * @set: indicates whether or not options have been set
+ * @default_no_sample: Default to no sampling.
  * @inject: indicates the event (not just the sample) must be fully synthesized
  *  because 'perf inject' will write it out
  * @instructions: whether to synthesize 

[PATCH v6 2/5] perf, tools, script: Make itrace script default to all calls

2018-09-20 Thread Andi Kleen
From: Andi Kleen 

By default perf script for itrace outputs sampled instructions or
branches. In my experience this is confusing to users because it's
hard to correlate with real program behavior. The sampling makes
sense for tools like report that actually sample to reduce
the run time, but run time is normally not a problem for perf script.
It's better to give an accurate representation of the program flow.

Default perf script to output all calls for itrace. That's a much saner
default. The old behavior can be still requested with
perf script --itrace=ibxwpe10

v2: Fix ETM build failure
v3: Really fix ETM build failure (Kim Phillips)
Signed-off-by: Andi Kleen 
---
 tools/perf/Documentation/itrace.txt |  7 ---
 tools/perf/builtin-script.c |  5 -
 tools/perf/util/auxtrace.c  | 17 -
 tools/perf/util/auxtrace.h  |  5 -
 tools/perf/util/cs-etm.c|  3 ++-
 tools/perf/util/intel-bts.c |  3 ++-
 tools/perf/util/intel-pt.c  |  3 ++-
 7 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt 
b/tools/perf/Documentation/itrace.txt
index a3abe04c779d..c2182cbabde3 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -11,10 +11,11 @@
l   synthesize last branch entries (use with i or x)
s   skip initial number of events
 
-   The default is all events i.e. the same as --itrace=ibxwpe
+   The default is all events i.e. the same as --itrace=ibxwpe,
+   except for perf script where it is --itrace=ce
 
-   In addition, the period (default 10) for instructions events
-   can be specified in units of:
+   In addition, the period (default 10, except for perf script where 
it is 1)
+   for instructions events can be specified in units of:
 
i   instructions
t   ticks
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 311f5b53dd83..519ebb5a1f96 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3128,7 +3128,10 @@ int cmd_script(int argc, const char **argv)
char *rec_script_path = NULL;
char *rep_script_path = NULL;
struct perf_session *session;
-   struct itrace_synth_opts itrace_synth_opts = { .set = false, };
+   struct itrace_synth_opts itrace_synth_opts = {
+   .set = false,
+   .default_no_sample = true,
+   };
char *script_path = NULL;
const char **__argv;
int i, j, err = 0;
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index c4617bcfd521..72d5ba2479bf 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -962,16 +962,23 @@ s64 perf_event__process_auxtrace(struct perf_session 
*session,
 #define PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ 64
 #define PERF_ITRACE_MAX_LAST_BRANCH_SZ 1024
 
-void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
+void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
+   bool no_sample)
 {
-   synth_opts->instructions = true;
synth_opts->branches = true;
synth_opts->transactions = true;
synth_opts->ptwrites = true;
synth_opts->pwr_events = true;
synth_opts->errors = true;
-   synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
-   synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
+   if (no_sample) {
+   synth_opts->period_type = PERF_ITRACE_PERIOD_INSTRUCTIONS;
+   synth_opts->period = 1;
+   synth_opts->calls = true;
+   } else {
+   synth_opts->instructions = true;
+   synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
+   synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
+   }
synth_opts->callchain_sz = PERF_ITRACE_DEFAULT_CALLCHAIN_SZ;
synth_opts->last_branch_sz = PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ;
synth_opts->initial_skip = 0;
@@ -999,7 +1006,7 @@ int itrace_parse_synth_opts(const struct option *opt, 
const char *str,
}
 
if (!str) {
-   itrace_synth_opts__set_default(synth_opts);
+   itrace_synth_opts__set_default(synth_opts, false);
return 0;
}
 
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 0a6ce9c4fc11..f6df30187e1c 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -57,6 +57,7 @@ enum itrace_period_type {
 /**
  * struct itrace_synth_opts - AUX area tracing synthesis options.
  * @set: indicates whether or not options have been set
+ * @default_no_sample: Default to no sampling.
  * @inject: indicates the event (not just the sample) must be fully synthesized
  *  because 'perf inject' will write it out
  * @instructions: whether to synthesize