linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/2] perf annotate: add max/min cycles
@ 2018-05-17 14:58 Jin Yao
  2018-05-17 14:58 ` [PATCH v1 1/2] perf annotate: Record the " Jin Yao
  2018-05-17 14:58 ` [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles Jin Yao
  0 siblings, 2 replies; 7+ messages in thread
From: Jin Yao @ 2018-05-17 14:58 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Currently perf has a feature to account cycles for LBRs

For example, on skylake,

perf record -b ...
perf report or
perf annotate

And then browsing the annotate browser gives average cycle counts
for program blocks.

For some analysis it would be useful if we could know not only
the average cycles but also the max and min cycles.

Now, for example, when press 'c', the annotate view is:

Percent│ IPC     Cycle(max/min)
       │
       │
       │                             Disassembly of section .text:
       │
       │                             000000000003aab0 <random@@GLIBC_2.2.5>:
  8.22 │3.92                           sub    $0x18,%rsp
       │3.92                           mov    $0x1,%esi
       │3.92                           xor    %eax,%eax
       │3.92                           cmpl   $0x0,argp_program_version_hook@@G
       │3.92             1(2/1)      ↓ je     20
       │                               lock   cmpxchg %esi,__abort_msg@@GLIBC_P
       │                             ↓ jne    29
       │                             ↓ jmp    43
       │1.10                     20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+
  8.93 │1.10             1(5/1)      ↓ je     43

When press 'c' again, the annotate view is switched back:

Percent│ IPC Cycle
       │
       │
       │                Disassembly of section .text:
       │
       │                000000000003aab0 <random@@GLIBC_2.2.5>:
  8.22 │3.92              sub    $0x18,%rsp
       │3.92              mov    $0x1,%esi
       │3.92              xor    %eax,%eax
       │3.92              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x
       │3.92     1      ↓ je     20
       │                  lock   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
       │                ↓ jne    29
       │                ↓ jmp    43
       │1.10        20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
  8.93 │1.10     1      ↓ je     43

Jin Yao (2):
  perf annotate: Record the max/min cycles
  perf annotate: Create hotkey 'c' to show max/min cycles

 tools/perf/ui/browsers/annotate.c |  8 ++++++
 tools/perf/util/annotate.c        | 51 +++++++++++++++++++++++++++++++++------
 tools/perf/util/annotate.h        | 11 ++++++++-
 3 files changed, 62 insertions(+), 8 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v1 1/2] perf annotate: Record the max/min cycles
  2018-05-17 14:58 [PATCH v1 0/2] perf annotate: add max/min cycles Jin Yao
@ 2018-05-17 14:58 ` Jin Yao
  2018-05-19 11:46   ` [tip:perf/core] perf annotate: Record the min/max cycles tip-bot for Jin Yao
  2018-05-17 14:58 ` [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles Jin Yao
  1 sibling, 1 reply; 7+ messages in thread
From: Jin Yao @ 2018-05-17 14:58 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

Currently perf has a feature to account cycles for LBRs

For example, on skylake,
perf record -b ...
perf report or perf annotate

And then browsing the annotate browser gives average cycle counts
for program blocks.

For some analysis it would be useful if we could know not only
the average cycles but also the max and min cycles.

This patch records the max and min cycles.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/util/annotate.c | 14 +++++++++++++-
 tools/perf/util/annotate.h |  4 ++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 536ee14..934a172 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -760,6 +760,15 @@ static int __symbol__account_cycles(struct annotation *notes,
 	ch[offset].num_aggr++;
 	ch[offset].cycles_aggr += cycles;
 
+	if (cycles > ch[offset].cycles_max)
+		ch[offset].cycles_max = cycles;
+
+	if (ch[offset].cycles_min) {
+		if (cycles && cycles < ch[offset].cycles_min)
+			ch[offset].cycles_min = cycles;
+	} else
+		ch[offset].cycles_min = cycles;
+
 	if (!have_start && ch[offset].have_start)
 		return 0;
 	if (ch[offset].num) {
@@ -953,8 +962,11 @@ void annotation__compute_ipc(struct annotation *notes, size_t size)
 			if (ch->have_start)
 				annotation__count_and_fill(notes, ch->start, offset, ch);
 			al = notes->offsets[offset];
-			if (al && ch->num_aggr)
+			if (al && ch->num_aggr) {
 				al->cycles = ch->cycles_aggr / ch->num_aggr;
+				al->cycles_max = ch->cycles_max;
+				al->cycles_min = ch->cycles_min;
+			}
 			notes->have_cycles = true;
 		}
 	}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index f28a9e4..d50363d 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -105,6 +105,8 @@ struct annotation_line {
 	int			 jump_sources;
 	float			 ipc;
 	u64			 cycles;
+	u64			 cycles_max;
+	u64			 cycles_min;
 	size_t			 privsize;
 	char			*path;
 	u32			 idx;
@@ -186,6 +188,8 @@ struct cyc_hist {
 	u64	start;
 	u64	cycles;
 	u64	cycles_aggr;
+	u64	cycles_max;
+	u64	cycles_min;
 	u32	num;
 	u32	num_aggr;
 	u8	have_start;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles
  2018-05-17 14:58 [PATCH v1 0/2] perf annotate: add max/min cycles Jin Yao
  2018-05-17 14:58 ` [PATCH v1 1/2] perf annotate: Record the " Jin Yao
@ 2018-05-17 14:58 ` Jin Yao
  2018-05-17 20:06   ` Arnaldo Carvalho de Melo
  2018-05-19 11:46   ` [tip:perf/core] perf annotate: Create hotkey 'c' to show min/max cycles tip-bot for Jin Yao
  1 sibling, 2 replies; 7+ messages in thread
From: Jin Yao @ 2018-05-17 14:58 UTC (permalink / raw)
  To: acme, jolsa, peterz, mingo, alexander.shishkin
  Cc: Linux-kernel, ak, kan.liang, yao.jin, Jin Yao

In perf annotate view, a new hotkey 'c' is created for
showing the max/min cycles.

For example, when press 'c', the annotate view is:

Percent│ IPC     Cycle(max/min)
       │
       │
       │                             Disassembly of section .text:
       │
       │                             000000000003aab0 <random@@GLIBC_2.2.5>:
  8.22 │3.92                           sub    $0x18,%rsp
       │3.92                           mov    $0x1,%esi
       │3.92                           xor    %eax,%eax
       │3.92                           cmpl   $0x0,argp_program_version_hook@@G
       │3.92             1(2/1)      ↓ je     20
       │                               lock   cmpxchg %esi,__abort_msg@@GLIBC_P
       │                             ↓ jne    29
       │                             ↓ jmp    43
       │1.10                     20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+
  8.93 │1.10             1(5/1)      ↓ je     43

When press 'c' again, the annotate view is switched back:

Percent│ IPC Cycle
       │
       │
       │                Disassembly of section .text:
       │
       │                000000000003aab0 <random@@GLIBC_2.2.5>:
  8.22 │3.92              sub    $0x18,%rsp
       │3.92              mov    $0x1,%esi
       │3.92              xor    %eax,%eax
       │3.92              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x
       │3.92     1      ↓ je     20
       │                  lock   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
       │                ↓ jne    29
       │                ↓ jmp    43
       │1.10        20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
  8.93 │1.10     1      ↓ je     43

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/ui/browsers/annotate.c |  8 ++++++++
 tools/perf/util/annotate.c        | 37 +++++++++++++++++++++++++++++++------
 tools/perf/util/annotate.h        |  7 ++++++-
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 3781d74..f202a3f 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -695,6 +695,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
 		"O             Bump offset level (jump targets -> +call -> all -> cycle thru)\n"
 		"s             Toggle source code view\n"
 		"t             Circulate percent, total period, samples view\n"
+		"c             Show max/min cycle\n"
 		"/             Search string\n"
 		"k             Toggle line numbers\n"
 		"P             Print to [symbol_name].annotation file.\n"
@@ -791,6 +792,13 @@ static int annotate_browser__run(struct annotate_browser *browser,
 				notes->options->show_total_period = true;
 			annotation__update_column_widths(notes);
 			continue;
+		case 'c':
+			if (notes->options->show_maxmin_cycle)
+				notes->options->show_maxmin_cycle = false;
+			else
+				notes->options->show_maxmin_cycle = true;
+			annotation__update_column_widths(notes);
+			continue;
 		case K_LEFT:
 		case K_ESC:
 		case 'q':
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 934a172..17fff6f 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2495,13 +2495,38 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		else
 			obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC");
 
-		if (al->cycles)
-			obj__printf(obj, "%*" PRIu64 " ",
+		if (!notes->options->show_maxmin_cycle) {
+			if (al->cycles)
+				obj__printf(obj, "%*" PRIu64 " ",
 					   ANNOTATION__CYCLES_WIDTH - 1, al->cycles);
-		else if (!show_title)
-			obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " ");
-		else
-			obj__printf(obj, "%*s ", ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
+			else if (!show_title)
+				obj__printf(obj, "%*s",
+					    ANNOTATION__CYCLES_WIDTH, " ");
+			else
+				obj__printf(obj, "%*s ",
+					    ANNOTATION__CYCLES_WIDTH - 1,
+					    "Cycle");
+		} else {
+			if (al->cycles) {
+				char str[32];
+
+				scnprintf(str, sizeof(str),
+					"%" PRIu64 "(%" PRIu64 "/%" PRIu64 ")",
+					al->cycles, al->cycles_max,
+					al->cycles_min);
+
+				obj__printf(obj, "%*s ",
+					    ANNOTATION__MAXMIN_CYCLES_WIDTH - 1,
+					    str);
+			} else if (!show_title)
+				obj__printf(obj, "%*s",
+					    ANNOTATION__MAXMIN_CYCLES_WIDTH,
+					    " ");
+			else
+				obj__printf(obj, "%*s ",
+					    ANNOTATION__MAXMIN_CYCLES_WIDTH - 1,
+					    "Cycle(max/min)");
+		}
 	}
 
 	obj__printf(obj, " ");
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index d50363d..4cafd63 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -61,6 +61,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
 
 #define ANNOTATION__IPC_WIDTH 6
 #define ANNOTATION__CYCLES_WIDTH 6
+#define ANNOTATION__MAXMIN_CYCLES_WIDTH 19
 
 struct annotation_options {
 	bool hide_src_code,
@@ -69,7 +70,8 @@ struct annotation_options {
 	     show_linenr,
 	     show_nr_jumps,
 	     show_nr_samples,
-	     show_total_period;
+	     show_total_period,
+	     show_maxmin_cycle;
 	u8   offset_level;
 };
 
@@ -243,6 +245,9 @@ struct annotation {
 
 static inline int annotation__cycles_width(struct annotation *notes)
 {
+	if (notes->have_cycles && notes->options->show_maxmin_cycle)
+		return ANNOTATION__IPC_WIDTH + ANNOTATION__MAXMIN_CYCLES_WIDTH;
+
 	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles
  2018-05-17 14:58 ` [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles Jin Yao
@ 2018-05-17 20:06   ` Arnaldo Carvalho de Melo
  2018-05-18  0:15     ` Jin, Yao
  2018-05-19 11:46   ` [tip:perf/core] perf annotate: Create hotkey 'c' to show min/max cycles tip-bot for Jin Yao
  1 sibling, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-05-17 20:06 UTC (permalink / raw)
  To: Jin Yao
  Cc: jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin

Em Thu, May 17, 2018 at 10:58:38PM +0800, Jin Yao escreveu:
> In perf annotate view, a new hotkey 'c' is created for
> showing the max/min cycles.

I just changed everything from "max/min" to "min/max", as it looked
strange print the max first, thanks, applying.

- Arnaldo
 
> For example, when press 'c', the annotate view is:
> 
> Percent│ IPC     Cycle(max/min)
>        │
>        │
>        │                             Disassembly of section .text:
>        │
>        │                             000000000003aab0 <random@@GLIBC_2.2.5>:
>   8.22 │3.92                           sub    $0x18,%rsp
>        │3.92                           mov    $0x1,%esi
>        │3.92                           xor    %eax,%eax
>        │3.92                           cmpl   $0x0,argp_program_version_hook@@G
>        │3.92             1(2/1)      ↓ je     20
>        │                               lock   cmpxchg %esi,__abort_msg@@GLIBC_P
>        │                             ↓ jne    29
>        │                             ↓ jmp    43
>        │1.10                     20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+
>   8.93 │1.10             1(5/1)      ↓ je     43
> 
> When press 'c' again, the annotate view is switched back:
> 
> Percent│ IPC Cycle
>        │
>        │
>        │                Disassembly of section .text:
>        │
>        │                000000000003aab0 <random@@GLIBC_2.2.5>:
>   8.22 │3.92              sub    $0x18,%rsp
>        │3.92              mov    $0x1,%esi
>        │3.92              xor    %eax,%eax
>        │3.92              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x
>        │3.92     1      ↓ je     20
>        │                  lock   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
>        │                ↓ jne    29
>        │                ↓ jmp    43
>        │1.10        20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
>   8.93 │1.10     1      ↓ je     43
> 
> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
> ---
>  tools/perf/ui/browsers/annotate.c |  8 ++++++++
>  tools/perf/util/annotate.c        | 37 +++++++++++++++++++++++++++++++------
>  tools/perf/util/annotate.h        |  7 ++++++-
>  3 files changed, 45 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
> index 3781d74..f202a3f 100644
> --- a/tools/perf/ui/browsers/annotate.c
> +++ b/tools/perf/ui/browsers/annotate.c
> @@ -695,6 +695,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
>  		"O             Bump offset level (jump targets -> +call -> all -> cycle thru)\n"
>  		"s             Toggle source code view\n"
>  		"t             Circulate percent, total period, samples view\n"
> +		"c             Show max/min cycle\n"
>  		"/             Search string\n"
>  		"k             Toggle line numbers\n"
>  		"P             Print to [symbol_name].annotation file.\n"
> @@ -791,6 +792,13 @@ static int annotate_browser__run(struct annotate_browser *browser,
>  				notes->options->show_total_period = true;
>  			annotation__update_column_widths(notes);
>  			continue;
> +		case 'c':
> +			if (notes->options->show_maxmin_cycle)
> +				notes->options->show_maxmin_cycle = false;
> +			else
> +				notes->options->show_maxmin_cycle = true;
> +			annotation__update_column_widths(notes);
> +			continue;
>  		case K_LEFT:
>  		case K_ESC:
>  		case 'q':
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 934a172..17fff6f 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -2495,13 +2495,38 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
>  		else
>  			obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC");
>  
> -		if (al->cycles)
> -			obj__printf(obj, "%*" PRIu64 " ",
> +		if (!notes->options->show_maxmin_cycle) {
> +			if (al->cycles)
> +				obj__printf(obj, "%*" PRIu64 " ",
>  					   ANNOTATION__CYCLES_WIDTH - 1, al->cycles);
> -		else if (!show_title)
> -			obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " ");
> -		else
> -			obj__printf(obj, "%*s ", ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
> +			else if (!show_title)
> +				obj__printf(obj, "%*s",
> +					    ANNOTATION__CYCLES_WIDTH, " ");
> +			else
> +				obj__printf(obj, "%*s ",
> +					    ANNOTATION__CYCLES_WIDTH - 1,
> +					    "Cycle");
> +		} else {
> +			if (al->cycles) {
> +				char str[32];
> +
> +				scnprintf(str, sizeof(str),
> +					"%" PRIu64 "(%" PRIu64 "/%" PRIu64 ")",
> +					al->cycles, al->cycles_max,
> +					al->cycles_min);
> +
> +				obj__printf(obj, "%*s ",
> +					    ANNOTATION__MAXMIN_CYCLES_WIDTH - 1,
> +					    str);
> +			} else if (!show_title)
> +				obj__printf(obj, "%*s",
> +					    ANNOTATION__MAXMIN_CYCLES_WIDTH,
> +					    " ");
> +			else
> +				obj__printf(obj, "%*s ",
> +					    ANNOTATION__MAXMIN_CYCLES_WIDTH - 1,
> +					    "Cycle(max/min)");
> +		}
>  	}
>  
>  	obj__printf(obj, " ");
> diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
> index d50363d..4cafd63 100644
> --- a/tools/perf/util/annotate.h
> +++ b/tools/perf/util/annotate.h
> @@ -61,6 +61,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
>  
>  #define ANNOTATION__IPC_WIDTH 6
>  #define ANNOTATION__CYCLES_WIDTH 6
> +#define ANNOTATION__MAXMIN_CYCLES_WIDTH 19
>  
>  struct annotation_options {
>  	bool hide_src_code,
> @@ -69,7 +70,8 @@ struct annotation_options {
>  	     show_linenr,
>  	     show_nr_jumps,
>  	     show_nr_samples,
> -	     show_total_period;
> +	     show_total_period,
> +	     show_maxmin_cycle;
>  	u8   offset_level;
>  };
>  
> @@ -243,6 +245,9 @@ struct annotation {
>  
>  static inline int annotation__cycles_width(struct annotation *notes)
>  {
> +	if (notes->have_cycles && notes->options->show_maxmin_cycle)
> +		return ANNOTATION__IPC_WIDTH + ANNOTATION__MAXMIN_CYCLES_WIDTH;
> +
>  	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
>  }
>  
> -- 
> 2.7.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles
  2018-05-17 20:06   ` Arnaldo Carvalho de Melo
@ 2018-05-18  0:15     ` Jin, Yao
  0 siblings, 0 replies; 7+ messages in thread
From: Jin, Yao @ 2018-05-18  0:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: jolsa, peterz, mingo, alexander.shishkin, Linux-kernel, ak,
	kan.liang, yao.jin



On 5/18/2018 4:06 AM, Arnaldo Carvalho de Melo wrote:
> Em Thu, May 17, 2018 at 10:58:38PM +0800, Jin Yao escreveu:
>> In perf annotate view, a new hotkey 'c' is created for
>> showing the max/min cycles.
> 
> I just changed everything from "max/min" to "min/max", as it looked
> strange print the max first, thanks, applying.
> 
> - Arnaldo
>   

Hi Arnaldo,

Thanks for helping to change from "max/min" to "min/max" and thanks for 
applying the patch. Yes, "min/max" looks better.

Thanks
Jin Yao

>> For example, when press 'c', the annotate view is:
>>
>> Percent│ IPC     Cycle(max/min)
>>         │
>>         │
>>         │                             Disassembly of section .text:
>>         │
>>         │                             000000000003aab0 <random@@GLIBC_2.2.5>:
>>    8.22 │3.92                           sub    $0x18,%rsp
>>         │3.92                           mov    $0x1,%esi
>>         │3.92                           xor    %eax,%eax
>>         │3.92                           cmpl   $0x0,argp_program_version_hook@@G
>>         │3.92             1(2/1)      ↓ je     20
>>         │                               lock   cmpxchg %esi,__abort_msg@@GLIBC_P
>>         │                             ↓ jne    29
>>         │                             ↓ jmp    43
>>         │1.10                     20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+
>>    8.93 │1.10             1(5/1)      ↓ je     43
>>
>> When press 'c' again, the annotate view is switched back:
>>
>> Percent│ IPC Cycle
>>         │
>>         │
>>         │                Disassembly of section .text:
>>         │
>>         │                000000000003aab0 <random@@GLIBC_2.2.5>:
>>    8.22 │3.92              sub    $0x18,%rsp
>>         │3.92              mov    $0x1,%esi
>>         │3.92              xor    %eax,%eax
>>         │3.92              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x
>>         │3.92     1      ↓ je     20
>>         │                  lock   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
>>         │                ↓ jne    29
>>         │                ↓ jmp    43
>>         │1.10        20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
>>    8.93 │1.10     1      ↓ je     43
>>
>> Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
>> ---
>>   tools/perf/ui/browsers/annotate.c |  8 ++++++++
>>   tools/perf/util/annotate.c        | 37 +++++++++++++++++++++++++++++++------
>>   tools/perf/util/annotate.h        |  7 ++++++-
>>   3 files changed, 45 insertions(+), 7 deletions(-)
>>
>> diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
>> index 3781d74..f202a3f 100644
>> --- a/tools/perf/ui/browsers/annotate.c
>> +++ b/tools/perf/ui/browsers/annotate.c
>> @@ -695,6 +695,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
>>   		"O             Bump offset level (jump targets -> +call -> all -> cycle thru)\n"
>>   		"s             Toggle source code view\n"
>>   		"t             Circulate percent, total period, samples view\n"
>> +		"c             Show max/min cycle\n"
>>   		"/             Search string\n"
>>   		"k             Toggle line numbers\n"
>>   		"P             Print to [symbol_name].annotation file.\n"
>> @@ -791,6 +792,13 @@ static int annotate_browser__run(struct annotate_browser *browser,
>>   				notes->options->show_total_period = true;
>>   			annotation__update_column_widths(notes);
>>   			continue;
>> +		case 'c':
>> +			if (notes->options->show_maxmin_cycle)
>> +				notes->options->show_maxmin_cycle = false;
>> +			else
>> +				notes->options->show_maxmin_cycle = true;
>> +			annotation__update_column_widths(notes);
>> +			continue;
>>   		case K_LEFT:
>>   		case K_ESC:
>>   		case 'q':
>> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
>> index 934a172..17fff6f 100644
>> --- a/tools/perf/util/annotate.c
>> +++ b/tools/perf/util/annotate.c
>> @@ -2495,13 +2495,38 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
>>   		else
>>   			obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC");
>>   
>> -		if (al->cycles)
>> -			obj__printf(obj, "%*" PRIu64 " ",
>> +		if (!notes->options->show_maxmin_cycle) {
>> +			if (al->cycles)
>> +				obj__printf(obj, "%*" PRIu64 " ",
>>   					   ANNOTATION__CYCLES_WIDTH - 1, al->cycles);
>> -		else if (!show_title)
>> -			obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " ");
>> -		else
>> -			obj__printf(obj, "%*s ", ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
>> +			else if (!show_title)
>> +				obj__printf(obj, "%*s",
>> +					    ANNOTATION__CYCLES_WIDTH, " ");
>> +			else
>> +				obj__printf(obj, "%*s ",
>> +					    ANNOTATION__CYCLES_WIDTH - 1,
>> +					    "Cycle");
>> +		} else {
>> +			if (al->cycles) {
>> +				char str[32];
>> +
>> +				scnprintf(str, sizeof(str),
>> +					"%" PRIu64 "(%" PRIu64 "/%" PRIu64 ")",
>> +					al->cycles, al->cycles_max,
>> +					al->cycles_min);
>> +
>> +				obj__printf(obj, "%*s ",
>> +					    ANNOTATION__MAXMIN_CYCLES_WIDTH - 1,
>> +					    str);
>> +			} else if (!show_title)
>> +				obj__printf(obj, "%*s",
>> +					    ANNOTATION__MAXMIN_CYCLES_WIDTH,
>> +					    " ");
>> +			else
>> +				obj__printf(obj, "%*s ",
>> +					    ANNOTATION__MAXMIN_CYCLES_WIDTH - 1,
>> +					    "Cycle(max/min)");
>> +		}
>>   	}
>>   
>>   	obj__printf(obj, " ");
>> diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
>> index d50363d..4cafd63 100644
>> --- a/tools/perf/util/annotate.h
>> +++ b/tools/perf/util/annotate.h
>> @@ -61,6 +61,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
>>   
>>   #define ANNOTATION__IPC_WIDTH 6
>>   #define ANNOTATION__CYCLES_WIDTH 6
>> +#define ANNOTATION__MAXMIN_CYCLES_WIDTH 19
>>   
>>   struct annotation_options {
>>   	bool hide_src_code,
>> @@ -69,7 +70,8 @@ struct annotation_options {
>>   	     show_linenr,
>>   	     show_nr_jumps,
>>   	     show_nr_samples,
>> -	     show_total_period;
>> +	     show_total_period,
>> +	     show_maxmin_cycle;
>>   	u8   offset_level;
>>   };
>>   
>> @@ -243,6 +245,9 @@ struct annotation {
>>   
>>   static inline int annotation__cycles_width(struct annotation *notes)
>>   {
>> +	if (notes->have_cycles && notes->options->show_maxmin_cycle)
>> +		return ANNOTATION__IPC_WIDTH + ANNOTATION__MAXMIN_CYCLES_WIDTH;
>> +
>>   	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
>>   }
>>   
>> -- 
>> 2.7.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip:perf/core] perf annotate: Record the min/max cycles
  2018-05-17 14:58 ` [PATCH v1 1/2] perf annotate: Record the " Jin Yao
@ 2018-05-19 11:46   ` tip-bot for Jin Yao
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Jin Yao @ 2018-05-19 11:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, ak, mingo, peterz, tglx, jolsa,
	alexander.shishkin, kan.liang, yao.jin, acme

Commit-ID:  48659ebf37e5d9d23bda6dbf032bdbe9708929f1
Gitweb:     https://git.kernel.org/tip/48659ebf37e5d9d23bda6dbf032bdbe9708929f1
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Thu, 17 May 2018 22:58:37 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 18 May 2018 16:31:41 -0300

perf annotate: Record the min/max cycles

Currently perf has a feature to account cycles for LBRs

For example, on skylake:

  perf record -b ...
  perf report or perf annotate

And then browsing the annotate browser gives average cycle counts for
program blocks.

For some analysis it would be useful if we could know not only the
average cycles but also the min and max cycles.

This patch records the min and max cycles.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1526569118-14217-2-git-send-email-yao.jin@linux.intel.com
[ Switch from max/min to min/max ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 14 +++++++++++++-
 tools/perf/util/annotate.h |  4 ++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 5d74a30fe00f..4fcfefea3bc2 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -760,6 +760,15 @@ static int __symbol__account_cycles(struct annotation *notes,
 	ch[offset].num_aggr++;
 	ch[offset].cycles_aggr += cycles;
 
+	if (cycles > ch[offset].cycles_max)
+		ch[offset].cycles_max = cycles;
+
+	if (ch[offset].cycles_min) {
+		if (cycles && cycles < ch[offset].cycles_min)
+			ch[offset].cycles_min = cycles;
+	} else
+		ch[offset].cycles_min = cycles;
+
 	if (!have_start && ch[offset].have_start)
 		return 0;
 	if (ch[offset].num) {
@@ -953,8 +962,11 @@ void annotation__compute_ipc(struct annotation *notes, size_t size)
 			if (ch->have_start)
 				annotation__count_and_fill(notes, ch->start, offset, ch);
 			al = notes->offsets[offset];
-			if (al && ch->num_aggr)
+			if (al && ch->num_aggr) {
 				al->cycles = ch->cycles_aggr / ch->num_aggr;
+				al->cycles_max = ch->cycles_max;
+				al->cycles_min = ch->cycles_min;
+			}
 			notes->have_cycles = true;
 		}
 	}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index f28a9e43421d..d50363d56f73 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -105,6 +105,8 @@ struct annotation_line {
 	int			 jump_sources;
 	float			 ipc;
 	u64			 cycles;
+	u64			 cycles_max;
+	u64			 cycles_min;
 	size_t			 privsize;
 	char			*path;
 	u32			 idx;
@@ -186,6 +188,8 @@ struct cyc_hist {
 	u64	start;
 	u64	cycles;
 	u64	cycles_aggr;
+	u64	cycles_max;
+	u64	cycles_min;
 	u32	num;
 	u32	num_aggr;
 	u8	have_start;

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [tip:perf/core] perf annotate: Create hotkey 'c' to show min/max cycles
  2018-05-17 14:58 ` [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles Jin Yao
  2018-05-17 20:06   ` Arnaldo Carvalho de Melo
@ 2018-05-19 11:46   ` tip-bot for Jin Yao
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Jin Yao @ 2018-05-19 11:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, alexander.shishkin, jolsa, hpa, acme, ak, yao.jin, mingo,
	kan.liang, linux-kernel, peterz

Commit-ID:  3e71fc0319775723adc08991ba7fbaeff1150347
Gitweb:     https://git.kernel.org/tip/3e71fc0319775723adc08991ba7fbaeff1150347
Author:     Jin Yao <yao.jin@linux.intel.com>
AuthorDate: Thu, 17 May 2018 22:58:38 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sat, 19 May 2018 06:42:49 -0300

perf annotate: Create hotkey 'c' to show min/max cycles

In the 'perf annotate' view, a new hotkey 'c' is created for showing the
min/max cycles.

For example, when press 'c', the annotate view is:

  Percent│ IPC     Cycle(min/max)
         │
         │
         │                             Disassembly of section .text:
         │
         │                             000000000003aab0 <random@@GLIBC_2.2.5>:
    8.22 │3.92                           sub    $0x18,%rsp
         │3.92                           mov    $0x1,%esi
         │3.92                           xor    %eax,%eax
         │3.92                           cmpl   $0x0,argp_program_version_hook@@G
         │3.92             1(2/1)      ↓ je     20
         │                               lock   cmpxchg %esi,__abort_msg@@GLIBC_P
         │                             ↓ jne    29
         │                             ↓ jmp    43
         │1.10                     20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+
    8.93 │1.10             1(5/1)      ↓ je     43

When press 'c' again, the annotate view is switched back:

  Percent│ IPC Cycle
         │
         │
         │                Disassembly of section .text:
         │
         │                000000000003aab0 <random@@GLIBC_2.2.5>:
    8.22 │3.92              sub    $0x18,%rsp
         │3.92              mov    $0x1,%esi
         │3.92              xor    %eax,%eax
         │3.92              cmpl   $0x0,argp_program_version_hook@@GLIBC_2.2.5+0x
         │3.92     1      ↓ je     20
         │                  lock   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
         │                ↓ jne    29
         │                ↓ jmp    43
         │1.10        20:   cmpxchg %esi,__abort_msg@@GLIBC_PRIVATE+0x8a0
    8.93 │1.10     1      ↓ je     43

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1526569118-14217-3-git-send-email-yao.jin@linux.intel.com
[ Rename all maxmin to minmax ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c |  8 ++++++++
 tools/perf/util/annotate.c        | 37 +++++++++++++++++++++++++++++++------
 tools/perf/util/annotate.h        |  7 ++++++-
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 3781d74088a7..8be40fa903aa 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -695,6 +695,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
 		"O             Bump offset level (jump targets -> +call -> all -> cycle thru)\n"
 		"s             Toggle source code view\n"
 		"t             Circulate percent, total period, samples view\n"
+		"c             Show min/max cycle\n"
 		"/             Search string\n"
 		"k             Toggle line numbers\n"
 		"P             Print to [symbol_name].annotation file.\n"
@@ -791,6 +792,13 @@ show_sup_ins:
 				notes->options->show_total_period = true;
 			annotation__update_column_widths(notes);
 			continue;
+		case 'c':
+			if (notes->options->show_minmax_cycle)
+				notes->options->show_minmax_cycle = false;
+			else
+				notes->options->show_minmax_cycle = true;
+			annotation__update_column_widths(notes);
+			continue;
 		case K_LEFT:
 		case K_ESC:
 		case 'q':
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 4fcfefea3bc2..6612c7f90af4 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2498,13 +2498,38 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		else
 			obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC");
 
-		if (al->cycles)
-			obj__printf(obj, "%*" PRIu64 " ",
+		if (!notes->options->show_minmax_cycle) {
+			if (al->cycles)
+				obj__printf(obj, "%*" PRIu64 " ",
 					   ANNOTATION__CYCLES_WIDTH - 1, al->cycles);
-		else if (!show_title)
-			obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " ");
-		else
-			obj__printf(obj, "%*s ", ANNOTATION__CYCLES_WIDTH - 1, "Cycle");
+			else if (!show_title)
+				obj__printf(obj, "%*s",
+					    ANNOTATION__CYCLES_WIDTH, " ");
+			else
+				obj__printf(obj, "%*s ",
+					    ANNOTATION__CYCLES_WIDTH - 1,
+					    "Cycle");
+		} else {
+			if (al->cycles) {
+				char str[32];
+
+				scnprintf(str, sizeof(str),
+					"%" PRIu64 "(%" PRIu64 "/%" PRIu64 ")",
+					al->cycles, al->cycles_min,
+					al->cycles_max);
+
+				obj__printf(obj, "%*s ",
+					    ANNOTATION__MINMAX_CYCLES_WIDTH - 1,
+					    str);
+			} else if (!show_title)
+				obj__printf(obj, "%*s",
+					    ANNOTATION__MINMAX_CYCLES_WIDTH,
+					    " ");
+			else
+				obj__printf(obj, "%*s ",
+					    ANNOTATION__MINMAX_CYCLES_WIDTH - 1,
+					    "Cycle(min/max)");
+		}
 	}
 
 	obj__printf(obj, " ");
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index d50363d56f73..5080b6dd98b8 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -61,6 +61,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
 
 #define ANNOTATION__IPC_WIDTH 6
 #define ANNOTATION__CYCLES_WIDTH 6
+#define ANNOTATION__MINMAX_CYCLES_WIDTH 19
 
 struct annotation_options {
 	bool hide_src_code,
@@ -69,7 +70,8 @@ struct annotation_options {
 	     show_linenr,
 	     show_nr_jumps,
 	     show_nr_samples,
-	     show_total_period;
+	     show_total_period,
+	     show_minmax_cycle;
 	u8   offset_level;
 };
 
@@ -243,6 +245,9 @@ struct annotation {
 
 static inline int annotation__cycles_width(struct annotation *notes)
 {
+	if (notes->have_cycles && notes->options->show_minmax_cycle)
+		return ANNOTATION__IPC_WIDTH + ANNOTATION__MINMAX_CYCLES_WIDTH;
+
 	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
 }
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-05-19 11:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17 14:58 [PATCH v1 0/2] perf annotate: add max/min cycles Jin Yao
2018-05-17 14:58 ` [PATCH v1 1/2] perf annotate: Record the " Jin Yao
2018-05-19 11:46   ` [tip:perf/core] perf annotate: Record the min/max cycles tip-bot for Jin Yao
2018-05-17 14:58 ` [PATCH v1 2/2] perf annotate: Create hotkey 'c' to show max/min cycles Jin Yao
2018-05-17 20:06   ` Arnaldo Carvalho de Melo
2018-05-18  0:15     ` Jin, Yao
2018-05-19 11:46   ` [tip:perf/core] perf annotate: Create hotkey 'c' to show min/max cycles tip-bot for Jin Yao

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).