[PATCH 05/12] perf annotate: Add basic support to event group view

2013-03-04 Thread Namhyung Kim
From: Namhyung Kim 

Add --group option to enable event grouping.  When enabled, all the
group members information will be shown with the leader so skip
non-leader events.

It only supports --stdio output currently.  Later patches will extend
additional features.

 $ perf annotate --group --stdio
 ...
  Percent |  Source code & Disassembly of libpthread-2.15.so
 

  :
  :
  :
  :  Disassembly of section .text:
  :
  :  00387dc0aa50 
<__pthread_mutex_unlock_usercnt>:
 8.082.405.29 :387dc0aa50:   mov%rdi,%rdx
 0.000.000.00 :387dc0aa53:   mov0x10(%rdi),%edi
 0.000.000.00 :387dc0aa56:   mov%edi,%eax
 0.000.800.00 :387dc0aa58:   and$0x7f,%eax
 3.032.403.53 :387dc0aa5b:   test   $0x7c,%dil
 0.000.000.00 :387dc0aa5f:   jne387dc0aaa9 
<__pthread_mutex_unlock_use
 0.000.000.00 :387dc0aa61:   test   %eax,%eax
 0.000.000.00 :387dc0aa63:   jne387dc0aa85 
<__pthread_mutex_unlock_use
 0.000.000.00 :387dc0aa65:   and$0x80,%edi
 0.000.000.00 :387dc0aa6b:   test   %esi,%esi
 3.035.607.06 :387dc0aa6d:   movl   $0x0,0x8(%rdx)
 0.000.000.59 :387dc0aa74:   je 387dc0aa7a 
<__pthread_mutex_unlock_use
 0.000.000.00 :387dc0aa76:   subl   $0x1,0xc(%rdx)
 2.025.601.18 :387dc0aa7a:   mov%edi,%esi
 0.000.000.00 :387dc0aa7c:   lock decl (%rdx)
83.84   83.20   82.35 :387dc0aa7f:   jne387dc0aada 
<_L_unlock_586>
 0.000.000.00 :387dc0aa81:   nop
 0.000.000.00 :387dc0aa82:   xor%eax,%eax
 0.000.000.00 :387dc0aa84:   retq
 ...

Signed-off-by: Namhyung Kim 
---
 tools/perf/Documentation/perf-annotate.txt |  3 ++
 tools/perf/builtin-annotate.c  |  7 
 tools/perf/util/annotate.c | 64 +-
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/tools/perf/Documentation/perf-annotate.txt 
b/tools/perf/Documentation/perf-annotate.txt
index 5ad07ef417f0..e9cd39a92dc2 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -93,6 +93,9 @@ OPTIONS
 --skip-missing::
Skip symbols that cannot be annotated.
 
+--group::
+   Show event group information together
+
 SEE ALSO
 
 linkperf:perf-record[1], linkperf:perf-report[1]
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 2f015a99481b..ae36f3cb5410 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -232,6 +232,11 @@ static int __cmd_annotate(struct perf_annotate *ann)
total_nr_samples += nr_samples;
hists__collapse_resort(hists);
hists__output_resort(hists);
+
+   if (symbol_conf.event_group &&
+   !perf_evsel__is_group_leader(pos))
+   continue;
+
hists__find_annotations(hists, pos, ann);
}
}
@@ -314,6 +319,8 @@ int cmd_annotate(int argc, const char **argv, const char 
*prefix __maybe_unused)
   "Specify disassembler style (e.g. -M intel for intel 
syntax)"),
OPT_STRING(0, "objdump", _path, "path",
   "objdump binary to use for disassembly and annotations"),
+   OPT_BOOLEAN(0, "group", _conf.event_group,
+   "Show event group information together"),
OPT_END()
};
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index ae71325d3dc7..0955cff5b0ef 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -638,7 +638,9 @@ static int disasm_line__print(struct disasm_line *dl, 
struct symbol *sym, u64 st
 
if (dl->offset != -1) {
const char *path = NULL;
-   double percent;
+   double percent, max_percent = 0.0;
+   double *ppercents = 
+   int i, nr_percent = 1;
const char *color;
struct annotation *notes = symbol__annotation(sym);
s64 offset = dl->offset;
@@ -647,10 +649,27 @@ static int disasm_line__print(struct disasm_line *dl, 
struct symbol *sym, u64 st
 
next = disasm__get_next_ip_line(>src->source, dl);
 
-   percent = disasm__calc_percent(notes, evsel->idx, offset,
-  next ? next->offset : (s64) len,
-  );
-   

[PATCH 05/12] perf annotate: Add basic support to event group view

2013-03-04 Thread Namhyung Kim
From: Namhyung Kim namhyung@lge.com

Add --group option to enable event grouping.  When enabled, all the
group members information will be shown with the leader so skip
non-leader events.

It only supports --stdio output currently.  Later patches will extend
additional features.

 $ perf annotate --group --stdio
 ...
  Percent |  Source code  Disassembly of libpthread-2.15.so
 

  :
  :
  :
  :  Disassembly of section .text:
  :
  :  00387dc0aa50 
__pthread_mutex_unlock_usercnt:
 8.082.405.29 :387dc0aa50:   mov%rdi,%rdx
 0.000.000.00 :387dc0aa53:   mov0x10(%rdi),%edi
 0.000.000.00 :387dc0aa56:   mov%edi,%eax
 0.000.800.00 :387dc0aa58:   and$0x7f,%eax
 3.032.403.53 :387dc0aa5b:   test   $0x7c,%dil
 0.000.000.00 :387dc0aa5f:   jne387dc0aaa9 
__pthread_mutex_unlock_use
 0.000.000.00 :387dc0aa61:   test   %eax,%eax
 0.000.000.00 :387dc0aa63:   jne387dc0aa85 
__pthread_mutex_unlock_use
 0.000.000.00 :387dc0aa65:   and$0x80,%edi
 0.000.000.00 :387dc0aa6b:   test   %esi,%esi
 3.035.607.06 :387dc0aa6d:   movl   $0x0,0x8(%rdx)
 0.000.000.59 :387dc0aa74:   je 387dc0aa7a 
__pthread_mutex_unlock_use
 0.000.000.00 :387dc0aa76:   subl   $0x1,0xc(%rdx)
 2.025.601.18 :387dc0aa7a:   mov%edi,%esi
 0.000.000.00 :387dc0aa7c:   lock decl (%rdx)
83.84   83.20   82.35 :387dc0aa7f:   jne387dc0aada 
_L_unlock_586
 0.000.000.00 :387dc0aa81:   nop
 0.000.000.00 :387dc0aa82:   xor%eax,%eax
 0.000.000.00 :387dc0aa84:   retq
 ...

Signed-off-by: Namhyung Kim namhy...@kernel.org
---
 tools/perf/Documentation/perf-annotate.txt |  3 ++
 tools/perf/builtin-annotate.c  |  7 
 tools/perf/util/annotate.c | 64 +-
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/tools/perf/Documentation/perf-annotate.txt 
b/tools/perf/Documentation/perf-annotate.txt
index 5ad07ef417f0..e9cd39a92dc2 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -93,6 +93,9 @@ OPTIONS
 --skip-missing::
Skip symbols that cannot be annotated.
 
+--group::
+   Show event group information together
+
 SEE ALSO
 
 linkperf:perf-record[1], linkperf:perf-report[1]
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 2f015a99481b..ae36f3cb5410 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -232,6 +232,11 @@ static int __cmd_annotate(struct perf_annotate *ann)
total_nr_samples += nr_samples;
hists__collapse_resort(hists);
hists__output_resort(hists);
+
+   if (symbol_conf.event_group 
+   !perf_evsel__is_group_leader(pos))
+   continue;
+
hists__find_annotations(hists, pos, ann);
}
}
@@ -314,6 +319,8 @@ int cmd_annotate(int argc, const char **argv, const char 
*prefix __maybe_unused)
   Specify disassembler style (e.g. -M intel for intel 
syntax)),
OPT_STRING(0, objdump, objdump_path, path,
   objdump binary to use for disassembly and annotations),
+   OPT_BOOLEAN(0, group, symbol_conf.event_group,
+   Show event group information together),
OPT_END()
};
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index ae71325d3dc7..0955cff5b0ef 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -638,7 +638,9 @@ static int disasm_line__print(struct disasm_line *dl, 
struct symbol *sym, u64 st
 
if (dl-offset != -1) {
const char *path = NULL;
-   double percent;
+   double percent, max_percent = 0.0;
+   double *ppercents = percent;
+   int i, nr_percent = 1;
const char *color;
struct annotation *notes = symbol__annotation(sym);
s64 offset = dl-offset;
@@ -647,10 +649,27 @@ static int disasm_line__print(struct disasm_line *dl, 
struct symbol *sym, u64 st
 
next = disasm__get_next_ip_line(notes-src-source, dl);
 
-   percent = disasm__calc_percent(notes, evsel-idx, offset,
-  next ? next-offset : (s64) len,
-