[PATCH 10/12] perf script: Add support for PERF_SAMPLE_CODE_PAGE_SIZE

2020-11-17 Thread kan . liang
From: Stephane Eranian 

Display sampled code page sizes when PERF_SAMPLE_CODE_PAGE_SIZE was set.

For example,
perf script --fields comm,event,ip,code_page_size
dtlb mem-loads:uP:445777 4K
dtlb mem-loads:uP:40f724 4K
dtlb mem-loads:uP:474926 4K
dtlb mem-loads:uP:401075 4K
dtlb mem-loads:uP:401095 4K
dtlb mem-loads:uP:401095 4K
dtlb mem-loads:uP:4010cc 4K
dtlb mem-loads:uP:440b6f 4K

Signed-off-by: Stephane Eranian 
---
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-script.c  | 13 +++--
 tools/perf/util/session.c|  3 +++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index ac4755727ca1..714b901f9d50 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -118,7 +118,7 @@ OPTIONS
 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output,
brstackinsn, brstackoff, callindent, insn, insnlen, synth, phys_addr,
-   metric, misc, srccode, ipc, data_page_size.
+   metric, misc, srccode, ipc, data_page_size, code_page_size.
 Field list can be prepended with the type, trace, sw or hw,
 to indicate to which event type the field list applies.
 e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index a02a820398d7..24839b050afb 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -117,6 +117,7 @@ enum perf_output_field {
PERF_OUTPUT_IPC = 1ULL << 31,
PERF_OUTPUT_TOD = 1ULL << 32,
PERF_OUTPUT_DATA_PAGE_SIZE  = 1ULL << 33,
+   PERF_OUTPUT_CODE_PAGE_SIZE  = 1ULL << 34,
 };
 
 struct perf_script {
@@ -182,6 +183,7 @@ struct output_option {
{.str = "ipc", .field = PERF_OUTPUT_IPC},
{.str = "tod", .field = PERF_OUTPUT_TOD},
{.str = "data_page_size", .field = PERF_OUTPUT_DATA_PAGE_SIZE},
+   {.str = "code_page_size", .field = PERF_OUTPUT_CODE_PAGE_SIZE},
 };
 
 enum {
@@ -255,7 +257,7 @@ static struct {
  PERF_OUTPUT_DSO | PERF_OUTPUT_PERIOD |
  PERF_OUTPUT_ADDR | PERF_OUTPUT_DATA_SRC |
  PERF_OUTPUT_WEIGHT | PERF_OUTPUT_PHYS_ADDR |
- PERF_OUTPUT_DATA_PAGE_SIZE,
+ PERF_OUTPUT_DATA_PAGE_SIZE | 
PERF_OUTPUT_CODE_PAGE_SIZE,
 
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
},
@@ -507,6 +509,10 @@ static int evsel__check_attr(struct evsel *evsel, struct 
perf_session *session)
evsel__check_stype(evsel, PERF_SAMPLE_DATA_PAGE_SIZE, 
"DATA_PAGE_SIZE", PERF_OUTPUT_DATA_PAGE_SIZE))
return -EINVAL;
 
+   if (PRINT_FIELD(CODE_PAGE_SIZE) &&
+   evsel__check_stype(evsel, PERF_SAMPLE_CODE_PAGE_SIZE, 
"CODE_PAGE_SIZE", PERF_OUTPUT_CODE_PAGE_SIZE))
+   return -EINVAL;
+
return 0;
 }
 
@@ -2020,6 +2026,9 @@ static void process_event(struct perf_script *script,
if (PRINT_FIELD(DATA_PAGE_SIZE))
fprintf(fp, " %s", get_page_size_name(sample->data_page_size, 
str));
 
+   if (PRINT_FIELD(CODE_PAGE_SIZE))
+   fprintf(fp, " %s", get_page_size_name(sample->code_page_size, 
str));
+
perf_sample__fprintf_ipc(sample, attr, fp);
 
fprintf(fp, "\n");
@@ -3519,7 +3528,7 @@ int cmd_script(int argc, const char **argv)
 "addr,symoff,srcline,period,iregs,uregs,brstack,"
 "brstacksym,flags,bpf-output,brstackinsn,brstackoff,"
 
"callindent,insn,insnlen,synth,phys_addr,metric,misc,ipc,tod,"
-"data_page_size",
+"data_page_size,code_page_size",
 parse_output_fields),
OPT_BOOLEAN('a', "all-cpus", _wide,
"system-wide collection from all CPUs"),
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 6335deda28f6..fa6ffa6e0d66 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1307,6 +1307,9 @@ static void dump_sample(struct evsel *evsel, union 
perf_event *event,
if (sample_type & PERF_SAMPLE_DATA_PAGE_SIZE)
printf(" .. data page size: %s\n", 
get_page_size_name(sample->data_page_size, str));
 
+   if (sample_type & PERF_SAMPLE_CODE_PAGE_SIZE)
+   printf(" .. code page size: %s\n", 
get_page_size_name(sample->code_page_size, str));
+
if (sample_type & PERF_SAMPLE_TRANSACTION)
printf("... transaction: %" PRIx64 "\n", 

Re: [PATCH 10/12] perf script: Add support for PERF_SAMPLE_CODE_PAGE_SIZE

2019-01-23 Thread Liang, Kan




On 1/22/2019 12:11 PM, Andi Kleen wrote:

+   PERF_OUTPUT_CODE_PAGE_SIZE  = 1UL << 32,


That won't work on 32bit. You need 1ULL

Also might want to audit that noone puts these flags into
an int.



I checked the codes, and there is no one puts the flags into an int.

I will use ULL in V2.

Thanks,
Kan



Re: [PATCH 10/12] perf script: Add support for PERF_SAMPLE_CODE_PAGE_SIZE

2019-01-22 Thread Andi Kleen
> + PERF_OUTPUT_CODE_PAGE_SIZE  = 1UL << 32,

That won't work on 32bit. You need 1ULL

Also might want to audit that noone puts these flags into 
an int.

-Andi


[PATCH 10/12] perf script: Add support for PERF_SAMPLE_CODE_PAGE_SIZE

2019-01-21 Thread kan . liang
From: Stephane Eranian 

Add a new perf script filter called code_page_size. There will be more
than 32 filters. Extend the enum perf_output_field from U to UL.
Display sampled code page sizes when PERF_SAMPLE_CODE_PAGE_SIZE was set.

For example,
perf script --fields comm,event,ip,code_page_size
dtlb mem-loads:uP:445777 4K
dtlb mem-loads:uP:40f724 4K
dtlb mem-loads:uP:474926 4K
dtlb mem-loads:uP:401075 4K
dtlb mem-loads:uP:401095 4K
dtlb mem-loads:uP:401095 4K
dtlb mem-loads:uP:4010cc 4K
dtlb mem-loads:uP:440b6f 4K

Signed-off-by: Stephane Eranian 
Signed-off-by: Kan Liang 
---
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-script.c  | 76 ++--
 tools/perf/util/session.c|  3 ++
 3 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index 14ae84c1..08c6deb 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -118,7 +118,7 @@ OPTIONS
 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
 srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output,
 brstackinsn, brstackoff, callindent, insn, insnlen, synth, phys_addr,
-metric, misc, srccode, data_page_size.
+metric, misc, srccode, data_page_size, code_page_size.
 Field list can be prepended with the type, trace, sw or hw,
 to indicate to which event type the field list applies.
 e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0aa55ca..9a7d93b8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -67,38 +67,39 @@ static int  max_blocks;
 unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH;
 
 enum perf_output_field {
-   PERF_OUTPUT_COMM= 1U << 0,
-   PERF_OUTPUT_TID = 1U << 1,
-   PERF_OUTPUT_PID = 1U << 2,
-   PERF_OUTPUT_TIME= 1U << 3,
-   PERF_OUTPUT_CPU = 1U << 4,
-   PERF_OUTPUT_EVNAME  = 1U << 5,
-   PERF_OUTPUT_TRACE   = 1U << 6,
-   PERF_OUTPUT_IP  = 1U << 7,
-   PERF_OUTPUT_SYM = 1U << 8,
-   PERF_OUTPUT_DSO = 1U << 9,
-   PERF_OUTPUT_ADDR= 1U << 10,
-   PERF_OUTPUT_SYMOFFSET   = 1U << 11,
-   PERF_OUTPUT_SRCLINE = 1U << 12,
-   PERF_OUTPUT_PERIOD  = 1U << 13,
-   PERF_OUTPUT_IREGS   = 1U << 14,
-   PERF_OUTPUT_BRSTACK = 1U << 15,
-   PERF_OUTPUT_BRSTACKSYM  = 1U << 16,
-   PERF_OUTPUT_DATA_SRC= 1U << 17,
-   PERF_OUTPUT_WEIGHT  = 1U << 18,
-   PERF_OUTPUT_BPF_OUTPUT  = 1U << 19,
-   PERF_OUTPUT_CALLINDENT  = 1U << 20,
-   PERF_OUTPUT_INSN= 1U << 21,
-   PERF_OUTPUT_INSNLEN = 1U << 22,
-   PERF_OUTPUT_BRSTACKINSN = 1U << 23,
-   PERF_OUTPUT_BRSTACKOFF  = 1U << 24,
-   PERF_OUTPUT_SYNTH   = 1U << 25,
-   PERF_OUTPUT_PHYS_ADDR   = 1U << 26,
-   PERF_OUTPUT_UREGS   = 1U << 27,
-   PERF_OUTPUT_METRIC  = 1U << 28,
-   PERF_OUTPUT_MISC= 1U << 29,
-   PERF_OUTPUT_SRCCODE = 1U << 30,
-   PERF_OUTPUT_DATA_PAGE_SIZE  = 1U << 31,
+   PERF_OUTPUT_COMM= 1UL << 0,
+   PERF_OUTPUT_TID = 1UL << 1,
+   PERF_OUTPUT_PID = 1UL << 2,
+   PERF_OUTPUT_TIME= 1UL << 3,
+   PERF_OUTPUT_CPU = 1UL << 4,
+   PERF_OUTPUT_EVNAME  = 1UL << 5,
+   PERF_OUTPUT_TRACE   = 1UL << 6,
+   PERF_OUTPUT_IP  = 1UL << 7,
+   PERF_OUTPUT_SYM = 1UL << 8,
+   PERF_OUTPUT_DSO = 1UL << 9,
+   PERF_OUTPUT_ADDR= 1UL << 10,
+   PERF_OUTPUT_SYMOFFSET   = 1UL << 11,
+   PERF_OUTPUT_SRCLINE = 1UL << 12,
+   PERF_OUTPUT_PERIOD  = 1UL << 13,
+   PERF_OUTPUT_IREGS   = 1UL << 14,
+   PERF_OUTPUT_BRSTACK = 1UL << 15,
+   PERF_OUTPUT_BRSTACKSYM  = 1UL << 16,
+   PERF_OUTPUT_DATA_SRC= 1UL << 17,
+   PERF_OUTPUT_WEIGHT  = 1UL << 18,
+   PERF_OUTPUT_BPF_OUTPUT  = 1UL << 19,
+   PERF_OUTPUT_CALLINDENT  = 1UL << 20,
+   PERF_OUTPUT_INSN= 1UL << 21,
+   PERF_OUTPUT_INSNLEN = 1UL << 22,
+   PERF_OUTPUT_BRSTACKINSN = 1UL << 23,
+   PERF_OUTPUT_BRSTACKOFF  = 1UL << 24,
+   PERF_OUTPUT_SYNTH   = 1UL << 25,
+   PERF_OUTPUT_PHYS_ADDR   = 1UL << 26,
+   PERF_OUTPUT_UREGS