linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 08/22] perf script: Add output of IPC ratio
Date: Mon, 20 May 2019 14:37:14 +0300	[thread overview]
Message-ID: <20190520113728.14389-9-adrian.hunter@intel.com> (raw)
In-Reply-To: <20190520113728.14389-1-adrian.hunter@intel.com>

Add field 'ipc' to display instructions-per-cycle.

Example:

 perf record -e intel_pt/cyc/u ls
 perf script --insn-trace --xed -F+ipc,-dso,-cpu,-tid

 ls  2670177.697113434:  7f0dfdbcd090 _start+0x0      mov %rsp, %rdi   IPC: 0.00 (1/877)
 ls  2670177.697113434:  7f0dfdbcd093 _start+0x3      callq  0x7f0dfdbce030
 ls  2670177.697113434:  7f0dfdbce030 _dl_start+0x0   pushq  %rbp
 ls  2670177.697113434:  7f0dfdbce031 _dl_start+0x1   mov %rsp, %rbp
 ls  2670177.697113434:  7f0dfdbce034 _dl_start+0x4   pushq  %r15
 ls  2670177.697113434:  7f0dfdbce036 _dl_start+0x6   pushq  %r14
 ls  2670177.697113434:  7f0dfdbce038 _dl_start+0x8   pushq  %r13
 ls  2670177.697113434:  7f0dfdbce03a _dl_start+0xa   pushq  %r12
 ls  2670177.697113434:  7f0dfdbce03c _dl_start+0xc   mov %rdi, %r12
 ls  2670177.697113434:  7f0dfdbce03f _dl_start+0xf   pushq  %rbx
 ls  2670177.697113434:  7f0dfdbce040 _dl_start+0x10  sub $0x38, %rsp
 ls  2670177.697113434:  7f0dfdbce044 _dl_start+0x14  rdtsc
 ls  2670177.697113434:  7f0dfdbce046 _dl_start+0x16  mov %eax, %eax
 ls  2670177.697113434:  7f0dfdbce048 _dl_start+0x18  shl $0x20, %rdx
 ls  2670177.697113434:  7f0dfdbce04c _dl_start+0x1c  or %rax, %rdx
 ls  2670177.697114471:  7f0dfdbce04f _dl_start+0x1f  movq  0x27e22(%rip), %rax        IPC: 0.00 (15/1685)
 ls  2670177.697116177:  7f0dfdbce056 _dl_start+0x26  movq  %rdx, 0x27683(%rip)        IPC: 0.00 (1/881)

Note, the IPC values are low due to page faults at the beginning of
execution. The additional cycles are due to the time to enter the kernel,
not the actual kernel page fault handler.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-script.txt |  5 ++++-
 tools/perf/builtin-script.c              | 23 ++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 9b0d04dd2a61..3a630dd64916 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,7 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         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.
+        brstackoff, callindent, insn, insnlen, synth, phys_addr, metric, misc, srccode, ipc.
         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
@@ -203,6 +203,9 @@ OPTIONS
 	The synth field is used by synthesized events which may be created when
 	Instruction Trace decoding.
 
+	The ipc (instructions per cycle) field is synthesized and may have a value when
+	Instruction Trace decoding.
+
 	Finally, a user may not set fields to none for all event types.
 	i.e., -F "" is not allowed.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 61cfd8f70989..331309485368 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -102,6 +102,7 @@ enum perf_output_field {
 	PERF_OUTPUT_METRIC	    = 1U << 28,
 	PERF_OUTPUT_MISC            = 1U << 29,
 	PERF_OUTPUT_SRCCODE	    = 1U << 30,
+	PERF_OUTPUT_IPC             = 1U << 31,
 };
 
 struct output_option {
@@ -139,6 +140,7 @@ struct output_option {
 	{.str = "metric", .field = PERF_OUTPUT_METRIC},
 	{.str = "misc", .field = PERF_OUTPUT_MISC},
 	{.str = "srccode", .field = PERF_OUTPUT_SRCCODE},
+	{.str = "ipc", .field = PERF_OUTPUT_IPC},
 };
 
 enum {
@@ -1268,6 +1270,20 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample,
 	return printed;
 }
 
+static int perf_sample__fprintf_ipc(struct perf_sample *sample,
+				    struct perf_event_attr *attr, FILE *fp)
+{
+	unsigned int ipc;
+
+	if (!PRINT_FIELD(IPC) || !sample->cyc_cnt || !sample->insn_cnt)
+		return 0;
+
+	ipc = (sample->insn_cnt * 100) / sample->cyc_cnt;
+
+	return fprintf(fp, " \t IPC: %u.%02u (%" PRIu64 "/%" PRIu64 ") ",
+		       ipc / 100, ipc % 100, sample->insn_cnt, sample->cyc_cnt);
+}
+
 static int perf_sample__fprintf_bts(struct perf_sample *sample,
 				    struct perf_evsel *evsel,
 				    struct thread *thread,
@@ -1312,6 +1328,8 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample,
 		printed += perf_sample__fprintf_addr(sample, thread, attr, fp);
 	}
 
+	printed += perf_sample__fprintf_ipc(sample, attr, fp);
+
 	if (print_srcline_last)
 		printed += map__fprintf_srcline(al->map, al->addr, "\n  ", fp);
 
@@ -1858,6 +1876,9 @@ static void process_event(struct perf_script *script,
 
 	if (PRINT_FIELD(PHYS_ADDR))
 		fprintf(fp, "%16" PRIx64, sample->phys_addr);
+
+	perf_sample__fprintf_ipc(sample, attr, fp);
+
 	fprintf(fp, "\n");
 
 	if (PRINT_FIELD(SRCCODE)) {
@@ -3392,7 +3413,7 @@ int cmd_script(int argc, const char **argv)
 		     "Fields: 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",
+		     "callindent,insn,insnlen,synth,phys_addr,metric,misc,ipc",
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
-- 
2.17.1


  parent reply	other threads:[~2019-05-20 11:37 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20 11:37 [PATCH 00/22] perf intel-pt: Add support for instructions-per-cycle (IPC) Adrian Hunter
2019-05-20 11:37 ` [PATCH 01/22] perf intel-pt: Fix itrace defaults for perf script Adrian Hunter
2019-05-20 13:58   ` Sasha Levin
2019-05-20 14:45   ` Arnaldo Carvalho de Melo
2019-05-31 16:45     ` Arnaldo Carvalho de Melo
2019-06-04 11:32       ` Adrian Hunter
2019-06-04 13:20         ` Arnaldo Carvalho de Melo
2019-05-30  7:53   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 02/22] perf auxtrace: " Adrian Hunter
2019-05-30  7:54   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 03/22] perf intel-pt: Fix itrace defaults for perf script intel-pt documentation Adrian Hunter
2019-05-30  7:54   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 04/22] perf intel-pt: Factor out intel_pt_update_sample_time Adrian Hunter
2019-06-17 18:59   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 05/22] perf intel-pt: Accumulate cycle count from CYC packets Adrian Hunter
2019-06-17 18:59   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 06/22] perf tools: Add IPC information to perf_sample Adrian Hunter
2019-06-17 19:00   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 07/22] perf intel-pt: Add support for samples to contain IPC ratio Adrian Hunter
2019-06-17 19:01   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` Adrian Hunter [this message]
2019-06-17 19:01   ` [tip:perf/core] perf script: Add output of " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 09/22] perf intel-pt: Record when decoding PSB+ packets Adrian Hunter
2019-06-17 19:02   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 10/22] perf intel-pt: Re-factor TIP cases in intel_pt_walk_to_ip Adrian Hunter
2019-06-17 19:03   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 11/22] perf intel-pt: Accumulate cycle count from TSC/TMA/MTC packets Adrian Hunter
2019-06-17 19:04   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 12/22] perf intel-pt: Document IPC usage Adrian Hunter
2019-06-17 19:04   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 13/22] perf thread-stack: Accumulate IPC information Adrian Hunter
2019-06-17 19:05   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 14/22] perf db-export: Add brief documentation Adrian Hunter
2019-06-17 19:06   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 15/22] perf db-export: Export IPC information Adrian Hunter
2019-06-17 19:07   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 16/22] perf scripts python: export-to-sqlite.py: " Adrian Hunter
2019-06-17 19:07   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 17/22] perf scripts python: export-to-postgresql.py: " Adrian Hunter
2019-06-17 19:08   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 18/22] perf scripts python: exported-sql-viewer.py: Add IPC information to the Branch reports Adrian Hunter
2019-05-31 16:44   ` Arnaldo Carvalho de Melo
2019-06-03  5:50     ` Adrian Hunter
2019-06-17 19:09   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 19/22] perf scripts python: exported-sql-viewer.py: Add CallGraphModelParams Adrian Hunter
2019-06-17 19:09   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 20/22] perf scripts python: exported-sql-viewer.py: Add IPC information to Call Graph Graph Adrian Hunter
2019-06-17 19:10   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 21/22] perf scripts python: exported-sql-viewer.py: Add IPC information to Call Tree Adrian Hunter
2019-06-17 19:11   ` [tip:perf/core] " tip-bot for Adrian Hunter
2019-05-20 11:37 ` [PATCH 22/22] perf scripts python: exported-sql-viewer.py: Select find text when find bar is activated Adrian Hunter
2019-06-17 19:11   ` [tip:perf/core] " tip-bot for Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190520113728.14389-9-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).