[tip:perf/core] perf tools: Remove const from thread read accessors

2019-05-30 Thread tip-bot for Namhyung Kim
Commit-ID:  7cb10a08df98e643b87d4bc8422e50e9c43b5c60
Gitweb: https://git.kernel.org/tip/7cb10a08df98e643b87d4bc8422e50e9c43b5c60
Author: Namhyung Kim 
AuthorDate: Mon, 27 May 2019 15:11:49 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 28 May 2019 18:37:43 -0300

perf tools: Remove const from thread read accessors

The namespaces and comm fields of a thread are protected by rwsem and
require write access for it.  So it ended up using a cast to remove
the const qualifier.  Let's get rid of the const then.

Signed-off-by: Namhyung Kim 
Suggested-by: Arnaldo Carvalho de Melo 
Cc: Hari Bathini 
Cc: Jiri Olsa 
Cc: Krister Johansen 
Link: http://lkml.kernel.org/r/20190527061149.168640-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/hist.c   |  2 +-
 tools/perf/util/thread.c | 12 ++--
 tools/perf/util/thread.h |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 7ace7a10054d..fb3271fd420c 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -2561,7 +2561,7 @@ int __hists__scnprintf_title(struct hists *hists, char 
*bf, size_t size, bool sh
char unit;
int printed;
const struct dso *dso = hists->dso_filter;
-   const struct thread *thread = hists->thread_filter;
+   struct thread *thread = hists->thread_filter;
int socket_id = hists->socket_filter;
unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
u64 nr_events = hists->stats.total_period;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index b413ba5b9835..aab7807d445f 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -141,13 +141,13 @@ static struct namespaces *__thread__namespaces(const 
struct thread *thread)
return list_first_entry(&thread->namespaces_list, struct namespaces, 
list);
 }
 
-struct namespaces *thread__namespaces(const struct thread *thread)
+struct namespaces *thread__namespaces(struct thread *thread)
 {
struct namespaces *ns;
 
-   down_read((struct rw_semaphore *)&thread->namespaces_lock);
+   down_read(&thread->namespaces_lock);
ns = __thread__namespaces(thread);
-   up_read((struct rw_semaphore *)&thread->namespaces_lock);
+   up_read(&thread->namespaces_lock);
 
return ns;
 }
@@ -271,13 +271,13 @@ static const char *__thread__comm_str(const struct thread 
*thread)
return comm__str(comm);
 }
 
-const char *thread__comm_str(const struct thread *thread)
+const char *thread__comm_str(struct thread *thread)
 {
const char *str;
 
-   down_read((struct rw_semaphore *)&thread->comm_lock);
+   down_read(&thread->comm_lock);
str = __thread__comm_str(thread);
-   up_read((struct rw_semaphore *)&thread->comm_lock);
+   up_read(&thread->comm_lock);
 
return str;
 }
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index cf8375c017a0..e97ef6977eb9 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -76,7 +76,7 @@ static inline void thread__exited(struct thread *thread)
thread->dead = true;
 }
 
-struct namespaces *thread__namespaces(const struct thread *thread);
+struct namespaces *thread__namespaces(struct thread *thread);
 int thread__set_namespaces(struct thread *thread, u64 timestamp,
   struct namespaces_event *event);
 
@@ -93,7 +93,7 @@ int thread__set_comm_from_proc(struct thread *thread);
 int thread__comm_len(struct thread *thread);
 struct comm *thread__comm(const struct thread *thread);
 struct comm *thread__exec_comm(const struct thread *thread);
-const char *thread__comm_str(const struct thread *thread);
+const char *thread__comm_str(struct thread *thread);
 int thread__insert_map(struct thread *thread, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, 
bool do_maps_clone);
 size_t thread__fprintf(struct thread *thread, FILE *fp);


[tip:perf/core] perf top: Add --namespaces option

2019-05-30 Thread tip-bot for Namhyung Kim
Commit-ID:  a0c0a4ac021b017e385d0328541ccfebeef165fc
Gitweb: https://git.kernel.org/tip/a0c0a4ac021b017e385d0328541ccfebeef165fc
Author: Namhyung Kim 
AuthorDate: Wed, 22 May 2019 14:32:50 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 28 May 2019 18:37:43 -0300

perf top: Add --namespaces option

Since 'perf record' already have this option, let's have it for 'perf top'
as well.

Signed-off-by: Namhyung Kim 
Cc: Hari Bathini 
Cc: Jiri Olsa 
Cc: Krister Johansen 
Link: http://lkml.kernel.org/r/20190522053250.207156-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-top.txt | 5 +
 tools/perf/builtin-top.c  | 5 +
 2 files changed, 10 insertions(+)

diff --git a/tools/perf/Documentation/perf-top.txt 
b/tools/perf/Documentation/perf-top.txt
index 44d89fb9c788..cfea87c6f38e 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -262,6 +262,11 @@ Default is to monitor all CPUS.
The number of threads to run when synthesizing events for existing 
processes.
By default, the number of threads equals to the number of online CPUs.
 
+--namespaces::
+   Record events of type PERF_RECORD_NAMESPACES and display it with the
+   'cgroup_id' sort key.
+
+
 INTERACTIVE PROMPTING KEYS
 --
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index fbbb0da43abb..31d78d874fc7 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1208,6 +1208,9 @@ static int __cmd_top(struct perf_top *top)
 
init_process_thread(top);
 
+   if (opts->record_namespaces)
+   top->tool.namespace_events = true;
+
ret = perf_event__synthesize_bpf_events(top->session, 
perf_event__process,
&top->session->machines.host,
&top->record_opts);
@@ -1500,6 +1503,8 @@ int cmd_top(int argc, const char **argv)
OPT_BOOLEAN(0, "force", &symbol_conf.force, "don't complain, do it"),
OPT_UINTEGER(0, "num-thread-synthesize", &top.nr_threads_synthesize,
"number of thread to run event synthesize"),
+   OPT_BOOLEAN(0, "namespaces", &opts->record_namespaces,
+   "Record namespaces events"),
OPT_END()
};
struct perf_evlist *sb_evlist = NULL;


[tip:perf/urgent] perf session: Add missing swap ops for namespace events

2019-05-28 Thread tip-bot for Namhyung Kim
Commit-ID:  acd244b84b80d53fa2cee98659b55d3f09b4f5a7
Gitweb: https://git.kernel.org/tip/acd244b84b80d53fa2cee98659b55d3f09b4f5a7
Author: Namhyung Kim 
AuthorDate: Wed, 22 May 2019 14:32:49 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 28 May 2019 09:52:23 -0300

perf session: Add missing swap ops for namespace events

In case it's recorded in a different arch.

Signed-off-by: Namhyung Kim 
Cc: Hari Bathini  
Cc: Jiri Olsa 
Cc: Krister Johansen 
Fixes: f3b3614a284d ("perf tools: Add PERF_RECORD_NAMESPACES to include 
namespaces related info")
Link: http://lkml.kernel.org/r/20190522053250.207156-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/session.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 2310a1752983..54cf163347f7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -647,6 +647,26 @@ static void perf_event__throttle_swap(union perf_event 
*event,
swap_sample_id_all(event, &event->throttle + 1);
 }
 
+static void perf_event__namespaces_swap(union perf_event *event,
+   bool sample_id_all)
+{
+   u64 i;
+
+   event->namespaces.pid   = bswap_32(event->namespaces.pid);
+   event->namespaces.tid   = bswap_32(event->namespaces.tid);
+   event->namespaces.nr_namespaces = 
bswap_64(event->namespaces.nr_namespaces);
+
+   for (i = 0; i < event->namespaces.nr_namespaces; i++) {
+   struct perf_ns_link_info *ns = &event->namespaces.link_info[i];
+
+   ns->dev = bswap_64(ns->dev);
+   ns->ino = bswap_64(ns->ino);
+   }
+
+   if (sample_id_all)
+   swap_sample_id_all(event, &event->namespaces.link_info[i]);
+}
+
 static u8 revbyte(u8 b)
 {
int rev = (b >> 4) | ((b & 0xf) << 4);
@@ -887,6 +907,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
[PERF_RECORD_LOST_SAMPLES]= perf_event__all64_swap,
[PERF_RECORD_SWITCH]  = perf_event__switch_swap,
[PERF_RECORD_SWITCH_CPU_WIDE] = perf_event__switch_swap,
+   [PERF_RECORD_NAMESPACES]  = perf_event__namespaces_swap,
[PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap,
[PERF_RECORD_HEADER_EVENT_TYPE]   = perf_event__event_type_swap,
[PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,


[tip:perf/urgent] perf namespace: Protect reading thread's namespace

2019-05-28 Thread tip-bot for Namhyung Kim
Commit-ID:  6584140ba9e6762dd7ec73795243289b914f31f9
Gitweb: https://git.kernel.org/tip/6584140ba9e6762dd7ec73795243289b914f31f9
Author: Namhyung Kim 
AuthorDate: Wed, 22 May 2019 14:32:48 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 28 May 2019 09:52:23 -0300

perf namespace: Protect reading thread's namespace

It seems that the current code lacks holding the namespace lock in
thread__namespaces().  Otherwise it can see inconsistent results.

Signed-off-by: Namhyung Kim 
Cc: Hari Bathini 
Cc: Jiri Olsa 
Cc: Krister Johansen 
Link: http://lkml.kernel.org/r/20190522053250.207156-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/thread.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 403045a2bbea..b413ba5b9835 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -133,7 +133,7 @@ void thread__put(struct thread *thread)
}
 }
 
-struct namespaces *thread__namespaces(const struct thread *thread)
+static struct namespaces *__thread__namespaces(const struct thread *thread)
 {
if (list_empty(&thread->namespaces_list))
return NULL;
@@ -141,10 +141,21 @@ struct namespaces *thread__namespaces(const struct thread 
*thread)
return list_first_entry(&thread->namespaces_list, struct namespaces, 
list);
 }
 
+struct namespaces *thread__namespaces(const struct thread *thread)
+{
+   struct namespaces *ns;
+
+   down_read((struct rw_semaphore *)&thread->namespaces_lock);
+   ns = __thread__namespaces(thread);
+   up_read((struct rw_semaphore *)&thread->namespaces_lock);
+
+   return ns;
+}
+
 static int __thread__set_namespaces(struct thread *thread, u64 timestamp,
struct namespaces_event *event)
 {
-   struct namespaces *new, *curr = thread__namespaces(thread);
+   struct namespaces *new, *curr = __thread__namespaces(thread);
 
new = namespaces__new(event);
if (!new)


[tip:perf/urgent] perf machine: Set main kernel end address properly

2018-04-25 Thread tip-bot for Namhyung Kim
Commit-ID:  ee05d21791db6db954bbb7b79bb18d88b5f6b7ff
Gitweb: https://git.kernel.org/tip/ee05d21791db6db954bbb7b79bb18d88b5f6b7ff
Author: Namhyung Kim 
AuthorDate: Mon, 19 Feb 2018 19:05:45 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 23 Apr 2018 10:52:55 -0300

perf machine: Set main kernel end address properly

map_groups__fixup_end() was called to set the end addresses of kernel
and module maps.  But now since machine__create_modules() sets the end
address of modules properly, the only remaining piece is the kernel map.

We can set it with adjacent module's address directly instead of calling
map_groups__fixup_end().  If there's no module after the kernel map, the
end address will be ~0ULL.

Since it also changes the start address of the kernel map, it needs to
re-insert the map to the kmaps in order to keep a correct ordering.  Kim
reported that it caused problems on ARM64.

Reported-by: Kim Phillips 
Tested-by: Kim Phillips 
Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20180419235915.GA19067@sejong
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 30 ++
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 2eca8478e24f..32d50492505d 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1019,13 +1019,6 @@ int machine__load_vmlinux_path(struct machine *machine, 
enum map_type type)
return ret;
 }
 
-static void map_groups__fixup_end(struct map_groups *mg)
-{
-   int i;
-   for (i = 0; i < MAP__NR_TYPES; ++i)
-   __map_groups__fixup_end(mg, i);
-}
-
 static char *get_kernel_version(const char *root_dir)
 {
char version[PATH_MAX];
@@ -1233,6 +1226,7 @@ int machine__create_kernel_maps(struct machine *machine)
 {
struct dso *kernel = machine__get_kernel(machine);
const char *name = NULL;
+   struct map *map;
u64 addr = 0;
int ret;
 
@@ -1259,13 +1253,25 @@ int machine__create_kernel_maps(struct machine *machine)
machine__destroy_kernel_maps(machine);
return -1;
}
-   machine__set_kernel_mmap(machine, addr, 0);
+
+   /* we have a real start address now, so re-order the kmaps */
+   map = machine__kernel_map(machine);
+
+   map__get(map);
+   map_groups__remove(&machine->kmaps, map);
+
+   /* assume it's the last in the kmaps */
+   machine__set_kernel_mmap(machine, addr, ~0ULL);
+
+   map_groups__insert(&machine->kmaps, map);
+   map__put(map);
}
 
-   /*
-* Now that we have all the maps created, just set the ->end of them:
-*/
-   map_groups__fixup_end(&machine->kmaps);
+   /* update end address of the kernel map using adjacent module address */
+   map = map__next(machine__kernel_map(machine));
+   if (map)
+   machine__set_kernel_mmap(machine, addr, map->start);
+
return 0;
 }
 


[tip:perf/core] perf machine: Fix paranoid check in machine__set_kernel_mmap()

2018-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  1d12cec6ce99614297e10945d917fd8a62cd2b09
Gitweb: https://git.kernel.org/tip/1d12cec6ce99614297e10945d917fd8a62cd2b09
Author: Namhyung Kim 
AuthorDate: Mon, 19 Feb 2018 19:00:46 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 19 Feb 2018 09:17:46 -0300

perf machine: Fix paranoid check in machine__set_kernel_mmap()

The machine__set_kernel_mmap() is to setup addresses of the kernel map
using external info.  But it has a check when the address is given from
an incorrect input which should have the start and end address of 0
(i.e. machine__process_kernel_mmap_event).

But we also use the end address of 0 for a valid input so change it to
check both start and end addresses.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20180219101936.GD1583@sejong
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index fe27ef5..12b7427 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1226,7 +1226,7 @@ static void machine__set_kernel_mmap(struct machine 
*machine,
 * Be a bit paranoid here, some perf.data file came with
 * a zero sized synthesized MMAP event for the kernel.
 */
-   if (machine->vmlinux_maps[i]->end == 0)
+   if (start == 0 && end == 0)
machine->vmlinux_maps[i]->end = ~0ULL;
}
 }


[tip:perf/core] perf help: Fix a bug during strstart() conversion

2017-11-28 Thread tip-bot for Namhyung Kim
Commit-ID:  af98f2273fd0af31ce327cd1406b67c7be0b6734
Gitweb: https://git.kernel.org/tip/af98f2273fd0af31ce327cd1406b67c7be0b6734
Author: Namhyung Kim 
AuthorDate: Tue, 14 Nov 2017 09:15:42 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 28 Nov 2017 14:21:18 -0300

perf help: Fix a bug during strstart() conversion

The commit 8e99b6d4533c changed prefixcmp() to strstart() but missed to
change the return value in some place.  It makes perf help print
annoying output even for sane config items like below:

  $ perf help
  '.root': unsupported man viewer sub key.
  ...

Reported-by: Arnaldo Carvalho de Melo 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Taeung Song 
Cc: Jiri Olsa 
Cc: Sihyeon Jang 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20171114001542.GA16464@sejong
Fixes: 8e99b6d4533c ("tools include: Adopt strstarts() from the kernel")
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-help.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index bd1fede..a0f7ed2 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -284,7 +284,7 @@ static int perf_help_config(const char *var, const char 
*value, void *cb)
add_man_viewer(value);
return 0;
}
-   if (!strstarts(var, "man."))
+   if (strstarts(var, "man."))
return add_man_viewer_info(var, value);
 
return 0;
@@ -314,7 +314,7 @@ static const char *cmd_to_page(const char *perf_cmd)
 
if (!perf_cmd)
return "perf";
-   else if (!strstarts(perf_cmd, "perf"))
+   else if (strstarts(perf_cmd, "perf"))
return perf_cmd;
 
return asprintf(&s, "perf-%s", perf_cmd) < 0 ? NULL : s;


[tip:perf/core] perf help: Fix a bug during strstart() conversion

2017-11-18 Thread tip-bot for Namhyung Kim
Commit-ID:  2f0af8600e82e9f950fc32908386b9c639f88d48
Gitweb: https://git.kernel.org/tip/2f0af8600e82e9f950fc32908386b9c639f88d48
Author: Namhyung Kim 
AuthorDate: Tue, 14 Nov 2017 09:15:42 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 16 Nov 2017 14:49:59 -0300

perf help: Fix a bug during strstart() conversion

The commit 8e99b6d4533c changed prefixcmp() to strstart() but missed to
change the return value in some place.  It makes perf help print
annoying output even for sane config items like below:

  $ perf help
  '.root': unsupported man viewer sub key.
  ...

Reported-by: Arnaldo Carvalho de Melo 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Taeung Song 
Cc: Jiri Olsa 
Cc: Sihyeon Jang 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20171114001542.GA16464@sejong
Fixes: 8e99b6d4533c ("tools include: Adopt strstarts() from the kernel")
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-help.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index bd1fede..a0f7ed2 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -284,7 +284,7 @@ static int perf_help_config(const char *var, const char 
*value, void *cb)
add_man_viewer(value);
return 0;
}
-   if (!strstarts(var, "man."))
+   if (strstarts(var, "man."))
return add_man_viewer_info(var, value);
 
return 0;
@@ -314,7 +314,7 @@ static const char *cmd_to_page(const char *perf_cmd)
 
if (!perf_cmd)
return "perf";
-   else if (!strstarts(perf_cmd, "perf"))
+   else if (strstarts(perf_cmd, "perf"))
return perf_cmd;
 
return asprintf(&s, "perf-%s", perf_cmd) < 0 ? NULL : s;


[tip:perf/core] perf srcline: Show correct function name for srcline of callchains

2017-11-03 Thread tip-bot for Namhyung Kim
Commit-ID:  7285cf3325b4a1dfb336d31eebc27dfbc30fb9aa
Gitweb: https://git.kernel.org/tip/7285cf3325b4a1dfb336d31eebc27dfbc30fb9aa
Author: Namhyung Kim 
AuthorDate: Tue, 31 Oct 2017 11:06:54 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 1 Nov 2017 11:44:38 -0300

perf srcline: Show correct function name for srcline of callchains

When libbfd is not used, it doesn't show proper function name and reuse
the original symbol of the sample.  That's because it passes the
original sym to inline_list__append().  As `addr2line -f` returns
function names as well, use that to create an inline_sym and pass it to
inline_list__append().

For example, following data shows that inlined entries of main have same
name (main).

Before:
  $ perf report -g srcline -q | head
  45.22%  inlining libm-2.26.so  [.] __hypot_finite
  |
  ---__hypot_finite ??:0
 |
 |--44.15%--hypot ??:0
 |  main complex:589
 |  main complex:597
 |  main complex:654
 |  main complex:664
 |  main inlining.cpp:14

After:
  $ perf report -g srcline -q | head
  45.22%  inlining libm-2.26.so  [.] __hypot_finite
  |
  ---__hypot_finite
 |
 |--44.15%--hypot
 |  std::__complex_abs complex:589 (inlined)
 |  std::abs complex:597 (inlined)
 |  std::_Norm_helper::_S_do_it 
complex:654 (inlined)
 |  std::norm complex:664 (inlined)
 |  main inlining.cpp:14

Signed-off-by: Namhyung Kim 
Reviewed-by: Jiri Olsa 
Reviewed-by: Milian Wolff 
Cc: Jin Yao 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20171031020654.31163-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/srcline.c | 95 +++
 1 file changed, 55 insertions(+), 40 deletions(-)

diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 51dc49c..ad1b46f 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -10,7 +10,7 @@
 #include "util/debug.h"
 #include "util/callchain.h"
 #include "srcline.h"
-
+#include "string2.h"
 #include "symbol.h"
 
 bool srcline_full_filename;
@@ -77,6 +77,41 @@ static char *srcline_from_fileline(const char *file, 
unsigned int line)
return srcline;
 }
 
+static struct symbol *new_inline_sym(struct dso *dso,
+struct symbol *base_sym,
+const char *funcname)
+{
+   struct symbol *inline_sym;
+   char *demangled = NULL;
+
+   if (dso) {
+   demangled = dso__demangle_sym(dso, 0, funcname);
+   if (demangled)
+   funcname = demangled;
+   }
+
+   if (base_sym && strcmp(funcname, base_sym->name) == 0) {
+   /* reuse the real, existing symbol */
+   inline_sym = base_sym;
+   /* ensure that we don't alias an inlined symbol, which could
+* lead to double frees in inline_node__delete
+*/
+   assert(!base_sym->inlined);
+   } else {
+   /* create a fake symbol for the inline frame */
+   inline_sym = symbol__new(base_sym ? base_sym->start : 0,
+base_sym ? base_sym->end : 0,
+base_sym ? base_sym->binding : 0,
+funcname);
+   if (inline_sym)
+   inline_sym->inlined = 1;
+   }
+
+   free(demangled);
+
+   return inline_sym;
+}
+
 #ifdef HAVE_LIBBFD_SUPPORT
 
 /*
@@ -219,41 +254,6 @@ static void addr2line_cleanup(struct a2l_data *a2l)
 
 #define MAX_INLINE_NEST 1024
 
-static struct symbol *new_inline_sym(struct dso *dso,
-struct symbol *base_sym,
-const char *funcname)
-{
-   struct symbol *inline_sym;
-   char *demangled = NULL;
-
-   if (dso) {
-   demangled = dso__demangle_sym(dso, 0, funcname);
-   if (demangled)
-   funcname = demangled;
-   }
-
-   if (base_sym && strcmp(funcname, base_sym->name) == 0) {
-   /* reuse the real, existing symbol */
-   inline_sym = base_sym;
-   /* ensure that we don't alias an inlined symbol, which could
-* lead to double frees in inline_node__delete
-*/
-   assert(!base_sym->inlined);
-   } else {
-   /* create a fake symbol for the inline frame */
-   inline_sym = symbol__new(base_sym ? base_sym->start : 0,
-base_sym ? base_sym->end : 0,
-   

[tip:perf/core] perf srcline: Fix memory leak in addr2inlines()

2017-11-03 Thread tip-bot for Namhyung Kim
Commit-ID:  b7b75a60b291cc699ca9bb2a8517a1b3b08bbeb1
Gitweb: https://git.kernel.org/tip/b7b75a60b291cc699ca9bb2a8517a1b3b08bbeb1
Author: Namhyung Kim 
AuthorDate: Tue, 31 Oct 2017 11:06:53 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 1 Nov 2017 11:43:56 -0300

perf srcline: Fix memory leak in addr2inlines()

When libbfd is not used, addr2inlines() executes `addr2line -i` and
process output line by line.  But it resets filename to NULL in the loop
so getline() allocates additional memory everytime instead of realloc.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Jin Yao 
Cc: Milian Wolff 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20171031020654.31163-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/srcline.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index c143c3b..51dc49c 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -456,20 +456,17 @@ static struct inline_node *addr2inlines(const char 
*dso_name, u64 addr,
while (getline(&filename, &len, fp) != -1) {
char *srcline;
 
-   if (filename_split(filename, &line_nr) != 1) {
-   free(filename);
+   if (filename_split(filename, &line_nr) != 1)
goto out;
-   }
 
srcline = srcline_from_fileline(filename, line_nr);
if (inline_list__append(sym, srcline, node) != 0)
goto out;
-
-   filename = NULL;
}
 
 out:
pclose(fp);
+   free(filename);
 
return node;
 }


[tip:perf/core] perf callchain: Fix double mapping al->addr for children without self period

2017-11-03 Thread tip-bot for Namhyung Kim
Commit-ID:  d6332a176b869df1839abb26c8f80026a66d21d6
Gitweb: https://git.kernel.org/tip/d6332a176b869df1839abb26c8f80026a66d21d6
Author: Namhyung Kim 
AuthorDate: Fri, 20 Oct 2017 14:15:33 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 31 Oct 2017 16:14:50 -0300

perf callchain: Fix double mapping al->addr for children without self period

Milian Wolff found a problem he described in [1] and that for him would
get fixed:

"Note how most of the large offset values are now gone. Most notably, we
get proper srcline resolution for the random.h and complex headers."

Then Namhyung found the root cause:

"I looked into it and found a bug handling cumulative (children)
entries.  For children entries that have no self period, the al->addr (so
he->ip) ends up having an doubly-mapped address.

It seems to be there from the beginning but only affects entries that
have no srclines - finding srcline itself is done using a different
address but it will show the invalid address if no srcline was found.  I
think we should fix the commit c7405d85d7a3 ("perf tools: Update cpumode
for each cumulative entry")."

[1] https://lkml.kernel.org/r/20171018185350.14893-7-milian.wo...@kdab.com

Reported-by: Milian Wolff 
Signed-off-by: Namhyung Kim 
Tested-by: Milian Wolff 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: kernel-t...@lge.com
Fixes: c7405d85d7a3 ("perf tools: Update cpumode for each cumulative entry")
Link: https://lkml.kernel.org/r/20171020051533.GA2746@sejong
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/callchain.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 3a39169..8370121 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -1091,10 +1091,7 @@ int fill_callchain_info(struct addr_location *al, struct 
callchain_cursor_node *
al->map = node->map;
al->sym = node->sym;
al->srcline = node->srcline;
-   if (node->map)
-   al->addr = node->map->map_ip(node->map, node->ip);
-   else
-   al->addr = node->ip;
+   al->addr = node->ip;
 
if (al->sym == NULL) {
if (hide_unresolved)


[tip:perf/urgent] perf buildid-list: Fix crash when processing PERF_RECORD_NAMESPACE

2017-10-20 Thread tip-bot for Namhyung Kim
Commit-ID:  7f0cd23615040b9e53bb4980c986b721cba08bbc
Gitweb: https://git.kernel.org/tip/7f0cd23615040b9e53bb4980c986b721cba08bbc
Author: Namhyung Kim 
AuthorDate: Tue, 17 Oct 2017 22:29:00 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 17 Oct 2017 11:09:19 -0300

perf buildid-list: Fix crash when processing PERF_RECORD_NAMESPACE

Thomas reported that 'perf buildid-list' gets a SEGFAULT due to NULL
pointer deref when he ran it on a data with namespace events.  It was
because the buildid_id__mark_dso_hit_ops lacks the namespace event
handler and perf_too__fill_default() didn't set it.

  Program received signal SIGSEGV, Segmentation fault.
  0x in ?? ()
  Missing separate debuginfos, use: dnf debuginfo-install 
audit-libs-2.7.7-1.fc25.s390x bzip2-libs-1.0.6-21.fc25.s390x 
elfutils-libelf-0.169-1.fc25.s390x
  +elfutils-libs-0.169-1.fc25.s390x libcap-ng-0.7.8-1.fc25.s390x 
numactl-libs-2.0.11-2.ibm.fc25.s390x openssl-libs-1.1.0e-1.1.ibm.fc25.s390x 
perl-libs-5.24.1-386.fc25.s390x
  +python-libs-2.7.13-2.fc25.s390x slang-2.3.0-7.fc25.s390x 
xz-libs-5.2.3-2.fc25.s390x zlib-1.2.8-10.fc25.s390x
  (gdb) where
  #0  0x in ?? ()
  #1  0x010fad6a in machines__deliver_event (machines=, 
machines@entry=0x2c6fd18,
  evlist=, event=event@entry=0x3fffdf00470, 
sample=0x3ffe880, sample@entry=0x3ffe888,
  tool=tool@entry=0x1312968 , file_offset=1136) 
at util/session.c:1287
  #2  0x010fbf4e in perf_session__deliver_event (file_offset=1136, 
tool=0x1312968 ,
  sample=0x3ffe888, event=0x3fffdf00470, session=0x2c6fc30) at 
util/session.c:1340
  #3  perf_session__process_event (session=0x2c6fc30, session@entry=0x0, 
event=event@entry=0x3fffdf00470,
  file_offset=file_offset@entry=1136) at util/session.c:1522
  #4  0x010fddde in __perf_session__process_events (file_size=11880, 
data_size=,
  data_offset=, session=0x0) at util/session.c:1899
  #5  perf_session__process_events (session=0x0, session@entry=0x2c6fc30) at 
util/session.c:1953
  #6  0x0103b2ac in perf_session__list_build_ids (with_hits=, force=)
  at builtin-buildid-list.c:83
  #7  cmd_buildid_list (argc=, argv=) at 
builtin-buildid-list.c:115
  #8  0x010a026c in run_builtin (p=0x1311f78 , 
argc=argc@entry=2, argv=argv@entry=0x3fff3c0)
  at perf.c:296
  #9  0x0102bc00 in handle_internal_command (argv=, 
argc=2) at perf.c:348
  #10 run_argv (argcp=, argv=) at 
perf.c:392
  #11 main (argc=, argv=0x3fff3c0) at perf.c:536
  (gdb)

Fix it by adding a stub event handler for namespace event.

Committer testing:

Further clarifying, plain using 'perf buildid-list' will not end up in a
SEGFAULT when processing a perf.data file with namespace info:

  # perf record -a --namespaces sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 2.024 MB perf.data (1058 samples) ]
  # perf buildid-list | wc -l
  38
  # perf buildid-list | head -5
  e2a171c7b905826fc8494f0711ba76ab6abbd604 
/lib/modules/4.14.0-rc3+/build/vmlinux
  874840a02d8f8a31cedd605d0b8653145472ced3 
/lib/modules/4.14.0-rc3+/kernel/arch/x86/kvm/kvm-intel.ko
  ea7223776730cd8a22f320040aae4d54312984bc 
/lib/modules/4.14.0-rc3+/kernel/drivers/gpu/drm/i915/i915.ko
  5961535e6732a8edb7f22b3f148bb2fa2e0be4b9 
/lib/modules/4.14.0-rc3+/kernel/drivers/gpu/drm/drm.ko
  f045f54aa78cf1931cc893f78b6cbc52c72a8cb1 /usr/lib64/libc-2.25.so
  #

It is only when one asks for checking what of those entries actually had
samples, i.e. when we use either -H or --with-hits, that we will process
all the PERF_RECORD_ events, and since tools/perf/builtin-buildid-list.c
neither explicitely set a perf_tool.namespaces() callback nor the
default stub was set that we end up, when processing a
PERF_RECORD_NAMESPACE record, causing a SEGFAULT:

  # perf buildid-list -H
  Segmentation fault (core dumped)
  ^C
  #

Reported-and-Tested-by: Thomas-Mich Richter 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Hari Bathini 
Cc: Hendrik Brueckner 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Thomas-Mich Richter 
Fixes: f3b3614a284d ("perf tools: Add PERF_RECORD_NAMESPACES to include 
namespaces related info")
Link: http://lkml.kernel.org/r/20171017132900.11043-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/session.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a7ebd9f..76ab070 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -374,6 +374,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
tool->mmap2 = process_event_stub;
if (tool->comm == NULL)
tool->comm = process_event_stub;
+   if (tool->namespaces == NULL)
+   tool->namespaces = process_event_stub;
if (tool->fork == NULL)
tool->fork = process_event_stub;
if (tool->exit == NULL)


[tip:perf/core] perf ftrace: Add option for function filtering

2017-06-20 Thread tip-bot for Namhyung Kim
Commit-ID:  78b83e8b12b4467540ca501c7c019e9d46051957
Gitweb: http://git.kernel.org/tip/78b83e8b12b4467540ca501c7c019e9d46051957
Author: Namhyung Kim 
AuthorDate: Sun, 18 Jun 2017 23:23:01 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 19 Jun 2017 22:05:53 -0300

perf ftrace: Add option for function filtering

The -T/--trace-funcs and -N/--notrace-funcs options are to specify
functions to enable/disable tracing dynamically.

The -G/--graph-funcs and -g/--nograph-funcs options are to set filters
for function graph tracer.

For example, to trace fault handling functions only:

  $ sudo perf ftrace -T *fault hello
   0)   |  __do_page_fault() {
   0)   |handle_mm_fault() {
   0)   2.117 us|  __handle_mm_fault();
   0)   3.627 us|}
   0)   7.811 us|  }
   0)   |  __do_page_fault() {
   0)   |handle_mm_fault() {
   0)   2.014 us|  __handle_mm_fault();
   0)   2.424 us|}
   0)   2.951 us|  }
   ...

To trace all functions executed in __do_page_fault:

  $ sudo perf ftrace -G __do_page_fault hello
   2)   |  __do_page_fault() {
   3)   0.060 us|down_read_trylock();
   3)   |find_vma() {
   3)   0.075 us|  vmacache_find();
   3)   0.053 us|  vmacache_update();
   3)   1.246 us|}
   3)   |handle_mm_fault() {
   3)   0.063 us|  __rcu_read_lock();
   3)   0.056 us|  mem_cgroup_from_task();
   3)   0.057 us|  __rcu_read_unlock();
   3)   |  __handle_mm_fault() {
   3)   |filemap_map_pages() {
   3)   0.058 us|  __rcu_read_lock();
   3)   |  alloc_set_pte() {
   ...

But don't want to show details in handle_mm_fault:

  $ sudo perf ftrace -G __do_page_fault -g handle_mm_fault hello
   3)   |  __do_page_fault() {
   3)   0.049 us|down_read_trylock();
   3)   |find_vma() {
   3)   0.048 us|  vmacache_find();
   3)   0.041 us|  vmacache_update();
   3)   0.680 us|}
   3)   0.036 us|up_read();
   3)   4.547 us|  } /* __do_page_fault */
   ...

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170618142302.25390-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-ftrace.txt |  30 
 tools/perf/builtin-ftrace.c  | 117 +--
 2 files changed, 141 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-ftrace.txt 
b/tools/perf/Documentation/perf-ftrace.txt
index 6e6a8b2..78d6126 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -48,6 +48,36 @@ OPTIONS
Ranges of CPUs are specified with -: 0-2.
Default is to trace on all online CPUs.
 
+-T::
+--trace-funcs=::
+   Only trace functions given by the argument.  Multiple functions
+   can be given by using this option more than once.  The function
+   argument also can be a glob pattern.  It will be passed to
+   'set_ftrace_filter' in tracefs.
+
+-N::
+--notrace-funcs=::
+   Do not trace functions given by the argument.  Like -T option,
+   this can be used more than once to specify multiple functions
+   (or glob patterns).  It will be passed to 'set_ftrace_notrace'
+   in tracefs.
+
+-G::
+--graph-funcs=::
+   Set graph filter on the given function (or a glob pattern).
+   This is useful for the function_graph tracer only and enables
+   tracing for functions executed from the given function.
+   This can be used more than once to specify multiple functions.
+   It will be passed to 'set_graph_function' in tracefs.
+
+-g::
+--nograph-funcs=::
+   Set graph notrace filter on the given function (or a glob pattern).
+   Like -G option, this is useful for the function_graph tracer only
+   and disables tracing for function executed from the given function.
+   This can be used more than once to specify multiple functions.
+   It will be passed to 'set_graph_notrace' in tracefs.
+
 
 SEE ALSO
 
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 982b98e..3285375 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -28,9 +28,18 @@
 #define DEFAULT_TRACER  "function_graph"
 
 struct perf_ftrace {
-   struct perf_evlist *evlist;
-   struct target target;
-   const char *tracer;
+   struct perf_evlist  *evlist;
+   struct target   target;
+   const char  *tracer;
+   struct list_headfilters;
+   struct list_headnotrace;
+   struct list_headgraph_funcs;
+   struct list_head  

[tip:perf/core] perf ftrace: Add -D option for depth filter

2017-06-20 Thread tip-bot for Namhyung Kim
Commit-ID:  1096c35aa821cc4789a64232a0e210bb87a0e5e8
Gitweb: http://git.kernel.org/tip/1096c35aa821cc4789a64232a0e210bb87a0e5e8
Author: Namhyung Kim 
AuthorDate: Sun, 18 Jun 2017 23:23:02 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 19 Jun 2017 22:05:54 -0300

perf ftrace: Add -D option for depth filter

The -D/--graph-depth option is to set max graph depth.  The following
example traces max 2-depth of page fault handler.

  $ sudo perf ftrace -G __do_page_fault -D 2 -- hello
   ...
   0)   |  __do_page_fault() {
   0)   0.063 us|down_read_trylock();
   0)   0.251 us|find_vma();
   0)   5.374 us|handle_mm_fault();
   0)   0.054 us|up_read();
   0)   7.463 us|  }
   ...

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170618142302.25390-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-ftrace.txt |  3 +++
 tools/perf/builtin-ftrace.c  | 31 +++
 2 files changed, 34 insertions(+)

diff --git a/tools/perf/Documentation/perf-ftrace.txt 
b/tools/perf/Documentation/perf-ftrace.txt
index 78d6126..721a447 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -78,6 +78,9 @@ OPTIONS
This can be used more than once to specify multiple functions.
It will be passed to 'set_graph_notrace' in tracefs.
 
+-D::
+--graph-depth=::
+   Set max depth for function graph tracer to follow
 
 SEE ALSO
 
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 3285375..dd26c62 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -35,6 +35,7 @@ struct perf_ftrace {
struct list_headnotrace;
struct list_headgraph_funcs;
struct list_headnograph_funcs;
+   int graph_depth;
 };
 
 struct filter_entry {
@@ -129,6 +130,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace 
__maybe_unused)
if (reset_tracing_cpu() < 0)
return -1;
 
+   if (write_tracing_file("max_graph_depth", "0") < 0)
+   return -1;
+
reset_tracing_filters();
return 0;
 }
@@ -237,6 +241,26 @@ static void reset_tracing_filters(void)
write_tracing_file("set_graph_notrace", " ");
 }
 
+static int set_tracing_depth(struct perf_ftrace *ftrace)
+{
+   char buf[16];
+
+   if (ftrace->graph_depth == 0)
+   return 0;
+
+   if (ftrace->graph_depth < 0) {
+   pr_err("invalid graph depth: %d\n", ftrace->graph_depth);
+   return -1;
+   }
+
+   snprintf(buf, sizeof(buf), "%d", ftrace->graph_depth);
+
+   if (write_tracing_file("max_graph_depth", buf) < 0)
+   return -1;
+
+   return 0;
+}
+
 static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char 
**argv)
 {
char *trace_file;
@@ -284,6 +308,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
goto out_reset;
}
 
+   if (set_tracing_depth(ftrace) < 0) {
+   pr_err("failed to set graph depth\n");
+   goto out_reset;
+   }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -425,6 +454,8 @@ int cmd_ftrace(int argc, const char **argv)
 "Set graph filter on given functions", parse_filter_func),
OPT_CALLBACK('g', "nograph-funcs", &ftrace.nograph_funcs, "func",
 "Set nograph filter on given functions", 
parse_filter_func),
+   OPT_INTEGER('D', "graph-depth", &ftrace.graph_depth,
+   "Max depth for function graph tracer"),
OPT_END()
};
 


[tip:perf/core] perf ftrace: Move setup_pager before opening trace_pipe

2017-06-20 Thread tip-bot for Namhyung Kim
Commit-ID:  29681bc5bb4326c2f9eac5dc68d8fad3e88b4bb5
Gitweb: http://git.kernel.org/tip/29681bc5bb4326c2f9eac5dc68d8fad3e88b4bb5
Author: Namhyung Kim 
AuthorDate: Sun, 18 Jun 2017 23:23:00 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 19 Jun 2017 22:05:52 -0300

perf ftrace: Move setup_pager before opening trace_pipe

The 'perf ftrace' command fails to reset tracer after finishing
recording like below:

  $ sudo perf ftrace -v hello
  write 'nop' to tracing/current_tracer failed: Device or resource busy
  ...

This is because the trace_pipe file is open in pager process.  Move the
pager setup to before opening the file.

Signed-off-by: Namhyung Kim 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Fixes: 583359646fde ("perf ftrace: Use pager for displaying result")
Link: http://lkml.kernel.org/r/20170618142302.25390-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-ftrace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 966a94f..982b98e 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -231,6 +231,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
goto out_reset;
}
 
+   setup_pager();
+
trace_file = get_tracing_file("trace_pipe");
if (!trace_file) {
pr_err("failed to open trace_pipe\n");
@@ -254,8 +256,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
goto out_close_fd;
}
 
-   setup_pager();
-
perf_evlist__start_workload(ftrace->evlist);
 
while (!done) {


[tip:perf/core] perf ftrace: Show error message when fails to set ftrace files

2017-06-20 Thread tip-bot for Namhyung Kim
Commit-ID:  e7bd9ba20a9ec7024a0566a93c22b9571a48939a
Gitweb: http://git.kernel.org/tip/e7bd9ba20a9ec7024a0566a93c22b9571a48939a
Author: Namhyung Kim 
AuthorDate: Sun, 18 Jun 2017 23:22:59 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 19 Jun 2017 22:05:51 -0300

perf ftrace: Show error message when fails to set ftrace files

It'd be better for debugging to show an error message when it fails to
setup ftrace for some reason.

Signed-off-by: Namhyung Kim 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Masami Hiramatsu 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170618142302.25390-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-ftrace.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 9e0b35c..966a94f 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -61,6 +61,7 @@ static int __write_tracing_file(const char *name, const char 
*val, bool append)
int fd, ret = -1;
ssize_t size = strlen(val);
int flags = O_WRONLY;
+   char errbuf[512];
 
file = get_tracing_file(name);
if (!file) {
@@ -75,14 +76,16 @@ static int __write_tracing_file(const char *name, const 
char *val, bool append)
 
fd = open(file, flags);
if (fd < 0) {
-   pr_debug("cannot open tracing file: %s\n", name);
+   pr_debug("cannot open tracing file: %s: %s\n",
+name, str_error_r(errno, errbuf, sizeof(errbuf)));
goto out;
}
 
if (write(fd, val, size) == size)
ret = 0;
else
-   pr_debug("write '%s' to tracing/%s failed\n", val, name);
+   pr_debug("write '%s' to tracing/%s failed: %s\n",
+val, name, str_error_r(errno, errbuf, sizeof(errbuf)));
 
close(fd);
 out:


[tip:perf/urgent] perf symbols: Kill dso__build_id_is_kmod()

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  b89fe63fbafe307fb72546f7a2320380bf41bdd4
Gitweb: http://git.kernel.org/tip/b89fe63fbafe307fb72546f7a2320380bf41bdd4
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:09 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:39:34 -0300

perf symbols: Kill dso__build_id_is_kmod()

The commit e7ee40475760 ("perf symbols: Fix symbols searching for module
in buildid-cache") added the function to check kernel modules reside in
the build-id cache.  This was because there's no way to identify a DSO
which is actually a kernel module.  So it searched linkname of the file
and find ".ko" suffix.

But this does not work for compressed kernel modules and now such DSOs
hCcave correct symtab_type now.  So no need to check it anymore.  This
patch essentially reverts the commit.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-10-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/build-id.c | 45 -
 tools/perf/util/build-id.h |  1 -
 tools/perf/util/symbol.c   |  4 
 3 files changed, 50 deletions(-)

diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 168cc49..e0148b0 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -278,51 +278,6 @@ char *dso__build_id_filename(const struct dso *dso, char 
*bf, size_t size)
return bf;
 }
 
-bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size)
-{
-   char *id_name = NULL, *ch;
-   struct stat sb;
-   char sbuild_id[SBUILD_ID_SIZE];
-
-   if (!dso->has_build_id)
-   goto err;
-
-   build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
-   id_name = build_id_cache__linkname(sbuild_id, NULL, 0);
-   if (!id_name)
-   goto err;
-   if (access(id_name, F_OK))
-   goto err;
-   if (lstat(id_name, &sb) == -1)
-   goto err;
-   if ((size_t)sb.st_size > size - 1)
-   goto err;
-   if (readlink(id_name, bf, size - 1) < 0)
-   goto err;
-
-   bf[sb.st_size] = '\0';
-
-   /*
-* link should be:
-* 
../../lib/modules/4.4.0-rc4/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko/a09fe3eb3147dafa4e3b31dbd6257e4d696bdc92
-*/
-   ch = strrchr(bf, '/');
-   if (!ch)
-   goto err;
-   if (ch - 3 < bf)
-   goto err;
-
-   free(id_name);
-   return strncmp(".ko", ch - 3, 3) == 0;
-err:
-   pr_err("Invalid build id: %s\n", id_name ? :
-dso->long_name ? :
-dso->short_name ? :
-"[unknown]");
-   free(id_name);
-   return false;
-}
-
 #define dsos__for_each_with_build_id(pos, head)\
list_for_each_entry(pos, head, node)\
if (!pos->has_build_id) \
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 8a89b19..96690a5 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -17,7 +17,6 @@ char *build_id_cache__kallsyms_path(const char *sbuild_id, 
char *bf,
size_t size);
 
 char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size);
-bool dso__build_id_is_kmod(const struct dso *dso, char *bf, size_t size);
 
 int build_id__mark_dso_hit(struct perf_tool *tool, union perf_event *event,
   struct perf_sample *sample, struct perf_evsel *evsel,
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 8f2b068..e7a98db 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1562,10 +1562,6 @@ int dso__load(struct dso *dso, struct map *map)
if (!runtime_ss && syms_ss)
runtime_ss = syms_ss;
 
-   if (syms_ss && syms_ss->type == DSO_BINARY_TYPE__BUILD_ID_CACHE)
-   if (dso__build_id_is_kmod(dso, name, PATH_MAX))
-   kmod = true;
-
if (syms_ss)
ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
else


[tip:perf/urgent] perf tests: Decompress kernel module before objdump

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  94df1040b1e6aacd8dec0ba3c61d7e77cd695f26
Gitweb: http://git.kernel.org/tip/94df1040b1e6aacd8dec0ba3c61d7e77cd695f26
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:07 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:39:19 -0300

perf tests: Decompress kernel module before objdump

If a kernel modules is compressed, it should be decompressed before
running objdump to parse binary data correctly.  This fixes a failure of
object code reading test for me.

Signed-off-by: Namhyung Kim 
Acked-by: Adrian Hunter 
Acked-by: Jiri Olsa 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-8-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/code-reading.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 1f14e76..94b7c7b 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -229,6 +229,8 @@ static int read_object_code(u64 addr, size_t len, u8 
cpumode,
unsigned char buf2[BUFSZ];
size_t ret_len;
u64 objdump_addr;
+   const char *objdump_name;
+   char decomp_name[KMOD_DECOMP_LEN];
int ret;
 
pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
@@ -289,9 +291,25 @@ static int read_object_code(u64 addr, size_t len, u8 
cpumode,
state->done[state->done_cnt++] = al.map->start;
}
 
+   objdump_name = al.map->dso->long_name;
+   if (dso__needs_decompress(al.map->dso)) {
+   if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
+decomp_name,
+sizeof(decomp_name)) < 0) {
+   pr_debug("decompression failed\n");
+   return -1;
+   }
+
+   objdump_name = decomp_name;
+   }
+
/* Read the object code using objdump */
objdump_addr = map__rip_2objdump(al.map, al.addr);
-   ret = read_via_objdump(al.map->dso->long_name, objdump_addr, buf2, len);
+   ret = read_via_objdump(objdump_name, objdump_addr, buf2, len);
+
+   if (dso__needs_decompress(al.map->dso))
+   unlink(objdump_name);
+
if (ret > 0) {
/*
 * The kernel maps are inaccurate - assume objdump is right in


[tip:perf/urgent] perf symbols: Keep DSO->symtab_type after decompress

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  c25ec42f846f702f8f532fbc890171e3a1f6ec85
Gitweb: http://git.kernel.org/tip/c25ec42f846f702f8f532fbc890171e3a1f6ec85
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:08 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:39:26 -0300

perf symbols: Keep DSO->symtab_type after decompress

The symsrc__init() overwrites dso->symtab_type as symsrc->type in
dso__load_sym().  But for compressed kernel modules in the build-id
cache, it should have original symtab type to be decompressed as needed.

This fixes perf annotate to show disassembly of the function properly.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-9-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/symbol-elf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index d342e77..502505c 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -671,6 +671,8 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const 
char *name,
fd = dso__decompress_kmodule_fd(dso, name);
if (fd < 0)
return -1;
+
+   type = dso->symtab_type;
} else {
fd = open(name, O_RDONLY);
if (fd < 0) {


[tip:perf/urgent] perf tools: Consolidate error path in __open_dso()

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  8ba29adf9a7cdff3c7283d5fc0dcf5e777d3b40f
Gitweb: http://git.kernel.org/tip/8ba29adf9a7cdff3c7283d5fc0dcf5e777d3b40f
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:06 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:39:13 -0300

perf tools: Consolidate error path in __open_dso()

On failure, it should free the 'name', so clean up the error path using
goto.

Signed-off-by: Namhyung Kim 
Suggested-by: Arnaldo Carvalho de Melo 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-7-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index c63525d..4e7ab61 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -454,7 +454,7 @@ static int do_open(char *name)
 
 static int __open_dso(struct dso *dso, struct machine *machine)
 {
-   int fd;
+   int fd = -EINVAL;
char *root_dir = (char *)"";
char *name = malloc(PATH_MAX);
 
@@ -465,23 +465,19 @@ static int __open_dso(struct dso *dso, struct machine 
*machine)
root_dir = machine->root_dir;
 
if (dso__read_binary_type_filename(dso, dso->binary_type,
-   root_dir, name, PATH_MAX)) {
-   free(name);
-   return -EINVAL;
-   }
+   root_dir, name, PATH_MAX))
+   goto out;
 
-   if (!is_regular_file(name)) {
-   free(name);
-   return -EINVAL;
-   }
+   if (!is_regular_file(name))
+   goto out;
 
if (dso__needs_decompress(dso)) {
char newpath[KMOD_DECOMP_LEN];
size_t len = sizeof(newpath);
 
if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
-   free(name);
-   return -dso->load_errno;
+   fd = -dso->load_errno;
+   goto out;
}
 
strcpy(name, newpath);
@@ -492,6 +488,7 @@ static int __open_dso(struct dso *dso, struct machine 
*machine)
if (dso__needs_decompress(dso))
unlink(name);
 
+out:
free(name);
return fd;
 }


[tip:perf/urgent] perf tools: Decompress kernel module when reading DSO data

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  1d6b3c9ba756a5134fd7ad1959acac776d17404b
Gitweb: http://git.kernel.org/tip/1d6b3c9ba756a5134fd7ad1959acac776d17404b
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:05 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:39:07 -0300

perf tools: Decompress kernel module when reading DSO data

Currently perf decompresses kernel modules when loading the symbol table
but it missed to do it when reading raw data.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-6-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index b346b8e..c63525d 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -475,7 +475,23 @@ static int __open_dso(struct dso *dso, struct machine 
*machine)
return -EINVAL;
}
 
+   if (dso__needs_decompress(dso)) {
+   char newpath[KMOD_DECOMP_LEN];
+   size_t len = sizeof(newpath);
+
+   if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
+   free(name);
+   return -dso->load_errno;
+   }
+
+   strcpy(name, newpath);
+   }
+
fd = do_open(name);
+
+   if (dso__needs_decompress(dso))
+   unlink(name);
+
free(name);
return fd;
 }


[tip:perf/urgent] perf annotate: Use dso__decompress_kmodule_path()

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  3c84fd53044f98017271101b59a21ddb20fb312b
Gitweb: http://git.kernel.org/tip/3c84fd53044f98017271101b59a21ddb20fb312b
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:04 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:39:02 -0300

perf annotate: Use dso__decompress_kmodule_path()

Convert open-coded decompress routine to use the function.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-5-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/annotate.c | 27 +++
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index df4486c..ddbd56d 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1431,31 +1431,10 @@ int symbol__disassemble(struct symbol *sym, struct map 
*map, const char *arch_na
sizeof(symfs_filename));
}
} else if (dso__needs_decompress(dso)) {
-   char tmp[PATH_MAX];
-   struct kmod_path m;
-   int fd;
-   bool ret;
+   char tmp[KMOD_DECOMP_LEN];
 
-   if (kmod_path__parse_ext(&m, symfs_filename))
-   goto out;
-
-   snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XX");
-
-   fd = mkstemp(tmp);
-   if (fd < 0) {
-   free(m.ext);
-   goto out;
-   }
-
-   ret = decompress_to_file(m.ext, symfs_filename, fd);
-
-   if (ret)
-   pr_err("Cannot decompress %s %s\n", m.ext, 
symfs_filename);
-
-   free(m.ext);
-   close(fd);
-
-   if (!ret)
+   if (dso__decompress_kmodule_path(dso, symfs_filename,
+tmp, sizeof(tmp)) < 0)
goto out;
 
strcpy(symfs_filename, tmp);


[tip:perf/urgent] perf tools: Introduce dso__decompress_kmodule_{fd,path}

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  42b3fa670825983fc8bd0ac7b80cc84ae3abb75b
Gitweb: http://git.kernel.org/tip/42b3fa670825983fc8bd0ac7b80cc84ae3abb75b
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:03 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:38:55 -0300

perf tools: Introduce dso__decompress_kmodule_{fd,path}

Move decompress_kmodule() to util/dso.c and split it into two functions
returning fd and (decompressed) file path.  The existing user only wants
the fd version but the path version will be used soon.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c| 58 
 tools/perf/util/dso.h|  6 +
 tools/perf/util/symbol-elf.c | 36 +--
 3 files changed, 65 insertions(+), 35 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 1f29e4f..b346b8e 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -248,6 +248,64 @@ bool dso__needs_decompress(struct dso *dso)
dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
 }
 
+static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf)
+{
+   int fd = -1;
+   struct kmod_path m;
+
+   if (!dso__needs_decompress(dso))
+   return -1;
+
+   if (kmod_path__parse_ext(&m, dso->long_name))
+   return -1;
+
+   if (!m.comp)
+   goto out;
+
+   fd = mkstemp(tmpbuf);
+   if (fd < 0) {
+   dso->load_errno = errno;
+   goto out;
+   }
+
+   if (!decompress_to_file(m.ext, name, fd)) {
+   dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
+   close(fd);
+   fd = -1;
+   }
+
+out:
+   free(m.ext);
+   return fd;
+}
+
+int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
+{
+   char tmpbuf[] = KMOD_DECOMP_NAME;
+   int fd;
+
+   fd = decompress_kmodule(dso, name, tmpbuf);
+   unlink(tmpbuf);
+   return fd;
+}
+
+int dso__decompress_kmodule_path(struct dso *dso, const char *name,
+char *pathname, size_t len)
+{
+   char tmpbuf[] = KMOD_DECOMP_NAME;
+   int fd;
+
+   fd = decompress_kmodule(dso, name, tmpbuf);
+   if (fd < 0) {
+   unlink(tmpbuf);
+   return -1;
+   }
+
+   strncpy(pathname, tmpbuf, len);
+   close(fd);
+   return 0;
+}
+
 /*
  * Parses kernel module specified in @path and updates
  * @m argument like:
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 5fe2ab5..bd061ba 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -244,6 +244,12 @@ bool is_supported_compression(const char *ext);
 bool is_kernel_module(const char *pathname, int cpumode);
 bool decompress_to_file(const char *ext, const char *filename, int output_fd);
 bool dso__needs_decompress(struct dso *dso);
+int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
+int dso__decompress_kmodule_path(struct dso *dso, const char *name,
+char *pathname, size_t len);
+
+#define KMOD_DECOMP_NAME  "/tmp/perf-kmod-XX"
+#define KMOD_DECOMP_LEN   sizeof(KMOD_DECOMP_NAME)
 
 struct kmod_path {
char *name;
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 1fb2efa..d342e77 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -637,40 +637,6 @@ static int dso__swap_init(struct dso *dso, unsigned char 
eidata)
return 0;
 }
 
-static int decompress_kmodule(struct dso *dso, const char *name,
- enum dso_binary_type type)
-{
-   int fd = -1;
-   char tmpbuf[] = "/tmp/perf-kmod-XX";
-   struct kmod_path m;
-
-   if (type != DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP &&
-   type != DSO_BINARY_TYPE__GUEST_KMODULE_COMP &&
-   type != DSO_BINARY_TYPE__BUILD_ID_CACHE)
-   return -1;
-
-   if (kmod_path__parse_ext(&m, dso->long_name) || !m.comp)
-   return -1;
-
-   fd = mkstemp(tmpbuf);
-   if (fd < 0) {
-   dso->load_errno = errno;
-   goto out;
-   }
-
-   if (!decompress_to_file(m.ext, name, fd)) {
-   dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
-   close(fd);
-   fd = -1;
-   }
-
-   unlink(tmpbuf);
-
-out:
-   free(m.ext);
-   return fd;
-}
-
 bool symsrc__possibly_runtime(struct symsrc *ss)
 {
return ss->dynsym || ss->opdsec;
@@ -702,7 +668,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const 
char *name,
int fd;
 
if (dso__needs_decompress(dso)) {
-   fd = decompress_km

[tip:perf/urgent] perf tools: Fix a memory leak in __open_dso()

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  44ad6b8852529eb39066edbedc027a6901da6803
Gitweb: http://git.kernel.org/tip/44ad6b8852529eb39066edbedc027a6901da6803
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:02 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:38:47 -0300

perf tools: Fix a memory leak in __open_dso()

The 'name' variable should be freed on the error path.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170608073109.30699-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index b27d127..1f29e4f 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -412,8 +412,10 @@ static int __open_dso(struct dso *dso, struct machine 
*machine)
return -EINVAL;
}
 
-   if (!is_regular_file(name))
+   if (!is_regular_file(name)) {
+   free(name);
return -EINVAL;
+   }
 
fd = do_open(name);
free(name);


[tip:perf/urgent] perf annotate: Fix symbolic link of build-id cache

2017-06-08 Thread tip-bot for Namhyung Kim
Commit-ID:  3619ef76b37d4803bc9daee9d03d82c8526db378
Gitweb: http://git.kernel.org/tip/3619ef76b37d4803bc9daee9d03d82c8526db378
Author: Namhyung Kim 
AuthorDate: Thu, 8 Jun 2017 16:31:01 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 8 Jun 2017 15:38:41 -0300

perf annotate: Fix symbolic link of build-id cache

The commit 6ebd2547dd24 ("perf annotate: Fix a bug following symbolic
link of a build-id file") changed to use dirname to follow the symlink.
But it only considers new-style build-id cache names so old names fail
on readlink() and force to use system path which might not available.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Taeung Song 
Cc: Wang Nan 
Cc: kernel-t...@lge.com
Fixes: 6ebd2547dd24 ("perf annotate: Fix a bug following symbolic link of a 
build-id file")
Link: http://lkml.kernel.org/r/20170608073109.30699-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/annotate.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 1367d7e..df4486c 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1321,6 +1321,7 @@ static int dso__disassemble_filename(struct dso *dso, 
char *filename, size_t fil
char linkname[PATH_MAX];
char *build_id_filename;
char *build_id_path = NULL;
+   char *pos;
 
if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
!dso__is_kcore(dso))
@@ -1340,7 +1341,14 @@ static int dso__disassemble_filename(struct dso *dso, 
char *filename, size_t fil
if (!build_id_path)
return -1;
 
-   dirname(build_id_path);
+   /*
+* old style build-id cache has name of XX/XXX.. while
+* new style has XX/XXX../{elf,kallsyms,vdso}.
+* extract the build-id part of dirname in the new style only.
+*/
+   pos = strrchr(build_id_path, '/');
+   if (pos && strlen(pos) < SBUILD_ID_SIZE - 2)
+   dirname(build_id_path);
 
if (dso__is_kcore(dso) ||
readlink(build_id_path, linkname, sizeof(linkname)) < 0 ||


[tip:perf/urgent] perf symbols: Use correct filename for compressed modules in build-id cache

2017-06-07 Thread tip-bot for Namhyung Kim
Commit-ID:  a09935b878dc8efd4b030ed1ffa0553fc9011fb8
Gitweb: http://git.kernel.org/tip/a09935b878dc8efd4b030ed1ffa0553fc9011fb8
Author: Namhyung Kim 
AuthorDate: Wed, 31 May 2017 21:01:05 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 5 Jun 2017 14:17:59 -0300

perf symbols: Use correct filename for compressed modules in build-id cache

The decompress_kmodule() decompresses kernel modules in order to load
symbols from it.  In the DSO_BINARY_TYPE__BUILD_ID_CACHE case, it needs
the full file path to extract the file extension to determine the
decompression method.  But overwriting 'name' will fail the
decompression since it might point to a non-existing old file.

Instead, use dso->long_name for having the correct extension and use the
real filename to decompress.

In the DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP case, both names should
be the same.  This allows resolving symbols in the old modules.

Before:

  $ perf report -i perf.data.old | grep scsi_mod
 0.00%  cc1  [scsi_mod][k] 0x4aa6
 0.00%  as   [scsi_mod][k] 0x99e1
 0.00%  cc1  [scsi_mod][k] 0x9830
 0.00%  cc1  [scsi_mod][k] 0x1b8f

After:

 0.00%  cc1  [scsi_mod][k] scsi_handle_queue_ramp_up
 0.00%  as   [scsi_mod][k] scsi_sg_alloc
 0.00%  cc1  [scsi_mod][k] scsi_setup_cmnd
 0.00%  cc1  [scsi_mod][k] scsi_get_command

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170531120105.21731-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/symbol-elf.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index e7ee47f..1fb2efa 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -649,10 +649,7 @@ static int decompress_kmodule(struct dso *dso, const char 
*name,
type != DSO_BINARY_TYPE__BUILD_ID_CACHE)
return -1;
 
-   if (type == DSO_BINARY_TYPE__BUILD_ID_CACHE)
-   name = dso->long_name;
-
-   if (kmod_path__parse_ext(&m, name) || !m.comp)
+   if (kmod_path__parse_ext(&m, dso->long_name) || !m.comp)
return -1;
 
fd = mkstemp(tmpbuf);


[tip:perf/urgent] perf symbols: Set module info when build-id event found

2017-06-07 Thread tip-bot for Namhyung Kim
Commit-ID:  6b335e8f545591c07df0f34231bd7ff7506c98c1
Gitweb: http://git.kernel.org/tip/6b335e8f545591c07df0f34231bd7ff7506c98c1
Author: Namhyung Kim 
AuthorDate: Wed, 31 May 2017 21:01:04 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 5 Jun 2017 14:17:58 -0300

perf symbols: Set module info when build-id event found

Like machine__findnew_module_dso(), it should set necessary info for
kernel modules to find symbol info from the file.  Factor out
dso__set_module_info() to do it.

This is needed for dso__needs_decompress() to detect such DSOs.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170531120105.21731-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c | 15 +++
 tools/perf/util/dso.h |  3 +++
 tools/perf/util/header.c  |  2 +-
 tools/perf/util/machine.c | 11 +--
 4 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index a96a99d..b27d127 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -335,6 +335,21 @@ int __kmod_path__parse(struct kmod_path *m, const char 
*path,
return 0;
 }
 
+void dso__set_module_info(struct dso *dso, struct kmod_path *m,
+ struct machine *machine)
+{
+   if (machine__is_host(machine))
+   dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
+   else
+   dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
+
+   /* _KMODULE_COMP should be next to _KMODULE */
+   if (m->kmod && m->comp)
+   dso->symtab_type++;
+
+   dso__set_short_name(dso, strdup(m->name), true);
+}
+
 /*
  * Global list of open DSOs and the counter.
  */
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 12350b1..5fe2ab5 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -259,6 +259,9 @@ int __kmod_path__parse(struct kmod_path *m, const char 
*path,
 #define kmod_path__parse_name(__m, __p) __kmod_path__parse(__m, __p, true , 
false)
 #define kmod_path__parse_ext(__m, __p)  __kmod_path__parse(__m, __p, false, 
true)
 
+void dso__set_module_info(struct dso *dso, struct kmod_path *m,
+ struct machine *machine);
+
 /*
  * The dso__data_* external interface provides following functions:
  *   dso__data_get_fd
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index c40a4d8..5cac8d5 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1473,7 +1473,7 @@ static int __event_process_build_id(struct build_id_event 
*bev,
struct kmod_path m = { .name = NULL, };
 
if (!kmod_path__parse_name(&m, filename) && m.kmod)
-   dso__set_short_name(dso, strdup(m.name), true);
+   dso__set_module_info(dso, &m, machine);
else
dso->kernel = dso_type;
 
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index d97e014..d7f31cb 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -572,16 +572,7 @@ static struct dso *machine__findnew_module_dso(struct 
machine *machine,
if (dso == NULL)
goto out_unlock;
 
-   if (machine__is_host(machine))
-   dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
-   else
-   dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
-
-   /* _KMODULE_COMP should be next to _KMODULE */
-   if (m->kmod && m->comp)
-   dso->symtab_type++;
-
-   dso__set_short_name(dso, strdup(m->name), true);
+   dso__set_module_info(dso, m, machine);
dso__set_long_name(dso, strdup(filename), true);
}
 


[tip:perf/urgent] perf header: Set proper module name when build-id event found

2017-06-07 Thread tip-bot for Namhyung Kim
Commit-ID:  1deec1bd96ccd8beb04d2112a6d12fe20505c3a6
Gitweb: http://git.kernel.org/tip/1deec1bd96ccd8beb04d2112a6d12fe20505c3a6
Author: Namhyung Kim 
AuthorDate: Wed, 31 May 2017 21:01:03 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 5 Jun 2017 14:16:49 -0300

perf header: Set proper module name when build-id event found

When perf processes build-id event, it creates DSOs with the build-id.
But it didn't set the module short name (like '[module-name]') so when
processing a kernel mmap event of the module, it cannot found the DSO as
it only checks the short names.

That leads for perf to create a same DSO without the build-id info and
it'll lookup the system path even if the DSO is already in the build-id
cache.  After kernel was updated, perf cannot find the DSO  and cannot
show symbols in it anymore.

You can see this if you have an old data file (w/ old kernel version):

  $ perf report -i perf.data.old -v |& grep scsi_mod
  build id event received for 
/lib/modules/3.19.2-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz : 
cafe1ce6ca13a98a5d9ed3425cde249e57a27fc1
  Failed to open /lib/modules/3.19.2-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz, 
continuing without symbols
  ...

The second message didn't show the build-id.  With this patch:

  $ perf report -i perf.data.old -v |& grep scsi_mod
  build id event received for 
/lib/modules/3.19.2-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz: 
cafe1ce6ca13a98a5d9ed3425cde249e57a27fc1
  /lib/modules/3.19.2-1-ARCH/kernel/drivers/scsi/scsi_mod.ko.gz with build id 
cafe1ce6ca13a98a5d9ed3425cde249e57a27fc1 not found, continuing without symbols
  ...

Now it shows the build-id but still cannot load the symbol table.  This
is a different problem which will be fixed in the next patch.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170531120105.21731-1-namhy...@kernel.org
[ Fix the build on older compilers (debian <= 8, fedora <= 21, etc) wrt 
kmod_path var init ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/header.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 314a071..c40a4d8 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1469,8 +1469,16 @@ static int __event_process_build_id(struct 
build_id_event *bev,
 
dso__set_build_id(dso, &bev->build_id);
 
-   if (!is_kernel_module(filename, cpumode))
-   dso->kernel = dso_type;
+   if (dso_type != DSO_TYPE_USER) {
+   struct kmod_path m = { .name = NULL, };
+
+   if (!kmod_path__parse_name(&m, filename) && m.kmod)
+   dso__set_short_name(dso, strdup(m.name), true);
+   else
+   dso->kernel = dso_type;
+
+   free(m.name);
+   }
 
build_id__sprintf(dso->build_id, sizeof(dso->build_id),
  sbuild_id);


[tip:perf/urgent] perf tools: Put caller above callee in --children mode

2017-05-24 Thread tip-bot for Namhyung Kim
Commit-ID:  711160a68f55d864200cd6c7677319e5c242
Gitweb: http://git.kernel.org/tip/711160a68f55d864200cd6c7677319e5c242
Author: Namhyung Kim 
AuthorDate: Wed, 24 May 2017 15:21:29 +0900
Committer:  Ingo Molnar 
CommitDate: Wed, 24 May 2017 08:41:49 +0200

perf tools: Put caller above callee in --children mode

The __hpp__sort_acc() sorts entries using callchain depth in order to
put callers above in children mode.  But it assumed the callchain order
was callee-first.  Now default (for children) is caller-first so the
order of entries is reverted.

For example, consider following case:

  $ perf report --no-children
  ..l
  # Overhead  Command  Shared ObjectSymbol
  #   ...  ...  ..
  #
  99.44%  a.outa.out[.] main
  |
  ---main
 __libc_start_main
 _start

Then children mode should show 'start' above '__libc_start_main' since
it's the caller (parent) of the __libc_start_main.  But it's reversed:

  # Children  Self  Command  Shared ObjectSymbol
  #     ...  ...  .
  #
  99.61% 0.00%  a.outlibc-2.25.so [.] __libc_start_main
  99.61% 0.00%  a.outa.out[.] _start
  99.54%99.44%  a.outa.out[.] main

This patch fixes it.

  # Children  Self  Command  Shared ObjectSymbol
  #     ...  ...  .
  #
  99.61% 0.00%  a.outa.out[.] _start
  99.61% 0.00%  a.outlibc-2.25.so [.] __libc_start_main
  99.54%99.44%  a.outa.out[.] main

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Linus Torvalds 
Cc: Milian Wolff 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Yao Jin 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170524062129.32529-8-namhy...@kernel.org
Signed-off-by: Ingo Molnar 
---
 tools/perf/ui/hist.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 59addd5..ddb2c6f 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -210,6 +210,8 @@ static int __hpp__sort_acc(struct hist_entry *a, struct 
hist_entry *b,
return 0;
 
ret = b->callchain->max_depth - a->callchain->max_depth;
+   if (callchain_param.order == ORDER_CALLER)
+   ret = -ret;
}
return ret;
 }


[tip:perf/urgent] perf script: Add --inline option for debugging

2017-05-24 Thread tip-bot for Namhyung Kim
Commit-ID:  325fbff51f961491adff4037d0e0a94d6132bd9b
Gitweb: http://git.kernel.org/tip/325fbff51f961491adff4037d0e0a94d6132bd9b
Author: Namhyung Kim 
AuthorDate: Wed, 24 May 2017 15:21:26 +0900
Committer:  Ingo Molnar 
CommitDate: Wed, 24 May 2017 08:41:48 +0200

perf script: Add --inline option for debugging

The --inline option is to show inlined functions in callchains.

For example:

  $ perf script
  a.out  5644 11611.467597: 309961 cycles:u:
 790 main (/home/namhyung/tmp/perf/a.out)
   20511 __libc_start_main (/usr/lib/libc-2.25.so)
 8ba _start (/home/namhyung/tmp/perf/a.out)
  ...

  $ perf script --inline
  a.out  5644 11611.467597: 309961 cycles:u:
 790 main (/home/namhyung/tmp/perf/a.out)
 
std::__detail::_Adaptor, double>::operator()
 
std::uniform_real_distribution::operator() >
 
std::uniform_real_distribution::operator() >
 main
   20511 __libc_start_main (/usr/lib/libc-2.25.so)
 8ba _start (/home/namhyung/tmp/perf/a.out)
  ...

Reviewed-and-tested-by: Milian Wolff 
Signed-off-by: Namhyung Kim 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Jiri Olsa 
Cc: Linus Torvalds 
Cc: Milian Wolff 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170524062129.32529-5-namhy...@kernel.org
Signed-off-by: Ingo Molnar 
---
 tools/perf/Documentation/perf-script.txt |  4 
 tools/perf/builtin-script.c  |  2 ++
 tools/perf/util/evsel_fprintf.c  | 33 
 3 files changed, 39 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index cb0eda3..3517e20 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -311,6 +311,10 @@ include::itrace.txt[]
Set the maximum number of program blocks to print with brstackasm for
each sample.
 
+--inline::
+   If a callgraph address belongs to an inlined function, the inline stack
+   will be printed. Each entry has function name and file/line.
+
 SEE ALSO
 
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d05aec4..4761b0d 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2494,6 +2494,8 @@ int cmd_script(int argc, const char **argv)
"Enable kernel symbol demangling"),
OPT_STRING(0, "time", &script.time_str, "str",
   "Time span of interest (start,stop)"),
+   OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
+   "Show inline function"),
OPT_END()
};
const char * const script_subcommands[] = { "record", "report", NULL };
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index e415aee..583f3a6 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -7,6 +7,7 @@
 #include "map.h"
 #include "strlist.h"
 #include "symbol.h"
+#include "srcline.h"
 
 static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
 {
@@ -168,6 +169,38 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
if (!print_oneline)
printed += fprintf(fp, "\n");
 
+   if (symbol_conf.inline_name && node->map) {
+   struct inline_node *inode;
+
+   addr = map__rip_2objdump(node->map, node->ip),
+   inode = dso__parse_addr_inlines(node->map->dso, 
addr);
+
+   if (inode) {
+   struct inline_list *ilist;
+
+   list_for_each_entry(ilist, &inode->val, 
list) {
+   if (print_arrow)
+   printed += fprintf(fp, 
" <-");
+
+   /* IP is same, just skip it */
+   if (print_ip)
+   printed += fprintf(fp, 
"%c%16s",
+  s, 
"");
+   if (print_sym)
+   printed += fprintf(fp, 
" %s",
+  
ilist->funcname);
+   if (print_srcline)
+   printed += fprintf(fp, 
"\n  %s:%d",
+   

[tip:perf/core] perf c2c: Fix display bug when using pipe

2017-03-15 Thread tip-bot for Namhyung Kim
Commit-ID:  1936feae54a6724a27a6ca1b948fd0e80371f7b0
Gitweb: http://git.kernel.org/tip/1936feae54a6724a27a6ca1b948fd0e80371f7b0
Author: Namhyung Kim 
AuthorDate: Wed, 8 Mar 2017 00:08:33 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 7 Mar 2017 12:48:46 -0300

perf c2c: Fix display bug when using pipe

Currently 'perf c2c report' determines display mode using the --stdio
option, but it could be a problem if stdout is not a tty since
setup_browser falls back to stdio in this case.

But perf c2c didn't know this and tried to use TUI browser anyway.  It
should check "use_browser" variable instead.

For example, the following command showed nothing and broke terminal
setting.  Now it's fixed..

  $ perf c2c report | head
  =
  Trace Event Information
  =
Total records :136
Locked Load/Store Operations  :  6
Load Operations   : 62
Loads - uncacheable   :  0
Loads - IO:  1
Loads - Miss  :  7
Loads - no mapping:  2

Committer notes:

When trying it without a proper perf.data file it results in a stuck
terminal, just as Namhyung reported above:

  [acme@jouet ~]$ perf c2c report | head
  WARNING: no sample cpu value[acme@jouet ~]$

One has to kill it from some other xterm. Confirm that this patch fixes
it:

After:

  $ perf c2c report | head
  WARNING: no sample cpu value=
  Trace Event Information
  =
Total records : 14
Locked Load/Store Operations  :  0
Load Operations   :  0
Loads - uncacheable   :  0
Loads - IO:  0
Loads - Miss  :  0
Loads - no mapping:  0
  $

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170307150851.22304-6-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-c2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 3fac30e..5cd6d7a 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2334,7 +2334,7 @@ out:
 
 static void perf_c2c_display(struct perf_session *session)
 {
-   if (c2c.use_stdio)
+   if (use_browser == 0)
perf_c2c__hists_fprintf(stdout, session);
else
perf_c2c__hists_browse(&c2c.hists.hists);


[tip:perf/core] perf c2c: Clarify help message of --stats option

2017-03-15 Thread tip-bot for Namhyung Kim
Commit-ID:  f75d2895e053efb2a69194d98754e4d5f4fa3a28
Gitweb: http://git.kernel.org/tip/f75d2895e053efb2a69194d98754e4d5f4fa3a28
Author: Namhyung Kim 
AuthorDate: Wed, 8 Mar 2017 00:08:32 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 7 Mar 2017 12:48:41 -0300

perf c2c: Clarify help message of --stats option

As it is not strictly asking for only stdio output, but will imply using
it.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170307150851.22304-5-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-c2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index e2b2172..3fac30e 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2536,7 +2536,7 @@ static int perf_c2c__report(int argc, const char **argv)
OPT_BOOLEAN(0, "stdio", &c2c.use_stdio, "Use the stdio interface"),
 #endif
OPT_BOOLEAN(0, "stats", &c2c.stats_only,
-   "Use the stdio interface"),
+   "Display only statistic tables (implies --stdio)"),
OPT_BOOLEAN(0, "full-symbols", &c2c.symbol_full,
"Display full length of symbols"),
OPT_BOOLEAN(0, "no-source", &no_source,


[tip:perf/core] perf report: Hide tip message when -q option is given

2017-03-15 Thread tip-bot for Namhyung Kim
Commit-ID:  8b53dbef2aeaad6bf532bd4db2f4b2beefd42e49
Gitweb: http://git.kernel.org/tip/8b53dbef2aeaad6bf532bd4db2f4b2beefd42e49
Author: Namhyung Kim 
AuthorDate: Wed, 8 Mar 2017 00:08:29 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 7 Mar 2017 12:25:27 -0300

perf report: Hide tip message when -q option is given

The tip message at the end was printed regardless of the -q option.

Originally, the message suggested only '-s comm,dso' option for higher
level view when no sort option and parent option were given.

Now it shows random help message regardless of the options so the
condition can be simplified to honor the -q option.

Committer notes:

Before:

  $ perf report --stdio -q
42.77%  ls   ls[.] _init
13.21%  ls   ld-2.24.so[.] match_symbol
12.55%  ls   libc-2.24.so  [.] __strcoll_l
11.94%  ls   libc-2.24.so  [.] _init

  #
  # (Tip: Show current config key-value pairs: perf config --list)
  #
  $

After:

  $ perf report --stdio -q
42.77%  ls   ls[.] _init
13.21%  ls   ld-2.24.so[.] match_symbol
12.55%  ls   libc-2.24.so  [.] __strcoll_l
11.94%  ls   libc-2.24.so  [.] _init

  $

We still have those two extra lines tho (that git commit insists in
turning into one, or git commit --amend doesn't make me add), food for
another patch...

Reported-and-Tested-by: Arnaldo Carvalho de Melo 
Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170307150851.22304-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-report.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 0a88670..f03a5ea 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -394,8 +394,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist 
*evlist,
fprintf(stdout, "\n\n");
}
 
-   if (sort_order == NULL &&
-   parent_pattern == default_parent_pattern)
+   if (!quiet)
fprintf(stdout, "#\n# (%s)\n#\n", help);
 
if (rep->show_threads) {


[tip:perf/core] perf ftrace: Add support for --pid option

2017-03-07 Thread tip-bot for Namhyung Kim
Commit-ID:  a9af6be5bc25214f7870fef2b6d3490fe8b87bf7
Gitweb: http://git.kernel.org/tip/a9af6be5bc25214f7870fef2b6d3490fe8b87bf7
Author: Namhyung Kim 
AuthorDate: Fri, 24 Feb 2017 10:12:48 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 3 Mar 2017 19:07:16 -0300

perf ftrace: Add support for --pid option

The -p (--pid) option enables to trace existing process by its pid.

Committer notes:

Testing it:

Using the function_graph tracer on a process that is just waiting for user
input and thus will make 'perf ftrace' sit there waiting for that, then press
any key on that mutt session and see what happens:

  # perf ftrace -t function_graph -p `pidof mutt` | head -40
  2)   1.038 us|  switch_mm_irqs_off();
  --
  2)-0=>   mutt-3595
  --

  2)   |  finish_task_switch() {
  2)   |smp_irq_work_interrupt() {
  2)   |  irq_enter() {
  2)   0.180 us|rcu_irq_enter();
  2)   1.248 us|  }
  2)   |  __wake_up() {
  2)   0.126 us|_raw_spin_lock_irqsave();
  2)   |__wake_up_common() {
  2)   |  pollwake() {
  2)   |default_wake_function() {
  2)   |  try_to_wake_up() {
  2)   0.662 us|_raw_spin_lock_irqsave();
  2)   |select_task_rq_fair() {
  2)   1.719 us|  effective_load.isra.41();
  2)   1.343 us|  effective_load.isra.41();
  2)   |  select_idle_sibling() {
  2)   0.331 us|idle_cpu();
  2)   1.458 us|  }
  2)   8.350 us|}
  2)   0.200 us|_raw_spin_lock();
  2)   |ttwu_do_activate() {
  2)   |  activate_task() {
  2)   0.136 us|update_rq_clock.part.77();
  2)   |enqueue_task_fair() {
  2)   |  enqueue_entity() {
  2)   0.146 us|update_curr();
  2)   0.330 us|
account_entity_enqueue();
  2)   0.280 us|update_cfs_shares();
  2)   0.321 us|place_entity();
  2)   0.206 us|__enqueue_entity();
  2)   6.926 us|  }
  2)   |  enqueue_entity() {
  2)   0.105 us|update_curr();
  2)   0.175 us|
account_entity_enqueue();
  2)   0.531 us|update_cfs_shares();
 #

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170224011251.14946-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-ftrace.txt |  4 ++
 tools/perf/builtin-ftrace.c  | 91 ++--
 2 files changed, 68 insertions(+), 27 deletions(-)

diff --git a/tools/perf/Documentation/perf-ftrace.txt 
b/tools/perf/Documentation/perf-ftrace.txt
index 2d96de6..2d39397 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -30,6 +30,10 @@ OPTIONS
 --verbose=::
 Verbosity level.
 
+-p::
+--pid=::
+   Trace on existing process id (comma separated list).
+
 
 SEE ALSO
 
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index c3e6436..85eee9c 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 
 #include "debug.h"
 #include 
@@ -50,11 +51,12 @@ static void ftrace__workload_exec_failed_signal(int signo 
__maybe_unused,
done = true;
 }
 
-static int write_tracing_file(const char *name, const char *val)
+static int __write_tracing_file(const char *name, const char *val, bool append)
 {
char *file;
int fd, ret = -1;
ssize_t size = strlen(val);
+   int flags = O_WRONLY;
 
file = get_tracing_file(name);
if (!file) {
@@ -62,7 +64,12 @@ static int write_tracing_file(const char *name, const char 
*val)
return -1;
}
 
-   fd = open(file, O_WRONLY);
+   if (append)
+   flags |= O_APPEND;
+   else
+  

[tip:perf/core] perf cpumap: Introduce cpu_map__snprint_mask()

2017-03-07 Thread tip-bot for Namhyung Kim
Commit-ID:  4400ac8a9a900318f8516dc0fb94075cb3fdb50d
Gitweb: http://git.kernel.org/tip/4400ac8a9a900318f8516dc0fb94075cb3fdb50d
Author: Namhyung Kim 
AuthorDate: Fri, 24 Feb 2017 10:12:49 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 3 Mar 2017 19:07:17 -0300

perf cpumap: Introduce cpu_map__snprint_mask()

The cpu_map__snprint_mask() generates a string representation of a
cpumask bitmap.  For cpu 0 to 11, it'll return "fff".

Committer notes:

Fix compiler warning on some toolchains:

19 fedora:24-x-ARC-uClibc: FAIL

CC   /tmp/build/perf/util/cpumap.o
  util/cpumap.c: In function 'hex_char':
  util/cpumap.c:679:2: error: comparison is always true due to limited range of 
data type [-Werror=type-limits]
if (0 <= val && val <= 9)
^
  cc1: all warnings being treated as errors

Applying patch from Namhyung that makes function receive an 'unsigned
char', that is what the callers are passing to this function.

Signed-off-by: Namhyung Kim 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170224011251.14946-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/cpumap.c | 46 ++
 tools/perf/util/cpumap.h |  1 +
 2 files changed, 47 insertions(+)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 39ad2ca..061018b 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -673,3 +673,49 @@ size_t cpu_map__snprint(struct cpu_map *map, char *buf, 
size_t size)
pr_debug("cpumask list: %s\n", buf);
return ret;
 }
+
+static char hex_char(unsigned char val)
+{
+   if (val < 10)
+   return val + '0';
+   if (val < 16)
+   return val - 10 + 'a';
+   return '?';
+}
+
+size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size)
+{
+   int i, cpu;
+   char *ptr = buf;
+   unsigned char *bitmap;
+   int last_cpu = cpu_map__cpu(map, map->nr - 1);
+
+   bitmap = zalloc((last_cpu + 7) / 8);
+   if (bitmap == NULL) {
+   buf[0] = '\0';
+   return 0;
+   }
+
+   for (i = 0; i < map->nr; i++) {
+   cpu = cpu_map__cpu(map, i);
+   bitmap[cpu / 8] |= 1 << (cpu % 8);
+   }
+
+   for (cpu = last_cpu / 4 * 4; cpu >= 0; cpu -= 4) {
+   unsigned char bits = bitmap[cpu / 8];
+
+   if (cpu % 8)
+   bits >>= 4;
+   else
+   bits &= 0xf;
+
+   *ptr++ = hex_char(bits);
+   if ((cpu % 32) == 0 && cpu > 0)
+   *ptr++ = ',';
+   }
+   *ptr = '\0';
+   free(bitmap);
+
+   buf[size - 1] = '\0';
+   return ptr - buf;
+}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index e844916..6b8bff8 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -20,6 +20,7 @@ struct cpu_map *cpu_map__dummy_new(void);
 struct cpu_map *cpu_map__new_data(struct cpu_map_data *data);
 struct cpu_map *cpu_map__read(FILE *file);
 size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size);
+size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size);
 size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
 int cpu_map__get_socket_id(int cpu);
 int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);


[tip:perf/core] perf ftrace: Use pager for displaying result

2017-03-07 Thread tip-bot for Namhyung Kim
Commit-ID:  583359646fde8526ea9456618cc24dc359b34094
Gitweb: http://git.kernel.org/tip/583359646fde8526ea9456618cc24dc359b34094
Author: Namhyung Kim 
AuthorDate: Fri, 24 Feb 2017 10:12:51 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 3 Mar 2017 19:07:17 -0300

perf ftrace: Use pager for displaying result

It's convenient to use the pager when seeing many lines of result.

Note that setup_pager() should be called after perf_evlist__prepare_workload()
since they can interfere each other regarding shared stdio streams.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170224011251.14946-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-ftrace.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index d5b566e..6087295 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -195,6 +195,7 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
signal(SIGINT, sig_handler);
signal(SIGUSR1, sig_handler);
signal(SIGCHLD, sig_handler);
+   signal(SIGPIPE, sig_handler);
 
if (reset_tracing_files(ftrace) < 0)
goto out;
@@ -247,6 +248,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
goto out_close_fd;
}
 
+   setup_pager();
+
perf_evlist__start_workload(ftrace->evlist);
 
while (!done) {


[tip:perf/core] perf ftrace: Add support for -a and -C option

2017-03-07 Thread tip-bot for Namhyung Kim
Commit-ID:  dc23103278c5ad53c177a25e209ef687e6d5d293
Gitweb: http://git.kernel.org/tip/dc23103278c5ad53c177a25e209ef687e6d5d293
Author: Namhyung Kim 
AuthorDate: Fri, 24 Feb 2017 10:12:50 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 3 Mar 2017 19:07:17 -0300

perf ftrace: Add support for -a and -C option

The -a/--all-cpus and -C/--cpu option is for controlling tracing cpus.

Signed-off-by: Namhyung Kim 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170224011251.14946-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-ftrace.txt | 14 
 tools/perf/builtin-ftrace.c  | 60 
 2 files changed, 74 insertions(+)

diff --git a/tools/perf/Documentation/perf-ftrace.txt 
b/tools/perf/Documentation/perf-ftrace.txt
index 2d39397..6e6a8b2 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -34,6 +34,20 @@ OPTIONS
 --pid=::
Trace on existing process id (comma separated list).
 
+-a::
+--all-cpus::
+   Force system-wide collection.  Scripts run without a 
+   normally use -a by default, while scripts run with a 
+   normally don't - this option allows the latter to be run in
+   system-wide mode.
+
+-C::
+--cpu=::
+   Only trace for the list of CPUs provided.  Multiple CPUs can
+   be provided as a comma separated list with no space like: 0,1.
+   Ranges of CPUs are specified with -: 0-2.
+   Default is to trace on all online CPUs.
+
 
 SEE ALSO
 
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 85eee9c..d5b566e 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -17,6 +17,7 @@
 #include 
 #include "evlist.h"
 #include "target.h"
+#include "cpumap.h"
 #include "thread_map.h"
 #include "util/config.h"
 
@@ -96,6 +97,8 @@ static int append_tracing_file(const char *name, const char 
*val)
return __write_tracing_file(name, val, true);
 }
 
+static int reset_tracing_cpu(void);
+
 static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
 {
if (write_tracing_file("tracing_on", "0") < 0)
@@ -107,6 +110,9 @@ static int reset_tracing_files(struct perf_ftrace *ftrace 
__maybe_unused)
if (write_tracing_file("set_ftrace_pid", " ") < 0)
return -1;
 
+   if (reset_tracing_cpu() < 0)
+   return -1;
+
return 0;
 }
 
@@ -127,6 +133,51 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
return 0;
 }
 
+static int set_tracing_cpumask(struct cpu_map *cpumap)
+{
+   char *cpumask;
+   size_t mask_size;
+   int ret;
+   int last_cpu;
+
+   last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1);
+   mask_size = (last_cpu + 3) / 4 + 1;
+   mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
+
+   cpumask = malloc(mask_size);
+   if (cpumask == NULL) {
+   pr_debug("failed to allocate cpu mask\n");
+   return -1;
+   }
+
+   cpu_map__snprint_mask(cpumap, cpumask, mask_size);
+
+   ret = write_tracing_file("tracing_cpumask", cpumask);
+
+   free(cpumask);
+   return ret;
+}
+
+static int set_tracing_cpu(struct perf_ftrace *ftrace)
+{
+   struct cpu_map *cpumap = ftrace->evlist->cpus;
+
+   if (!target__has_cpu(&ftrace->target))
+   return 0;
+
+   return set_tracing_cpumask(cpumap);
+}
+
+static int reset_tracing_cpu(void)
+{
+   struct cpu_map *cpumap = cpu_map__new(NULL);
+   int ret;
+
+   ret = set_tracing_cpumask(cpumap);
+   cpu_map__put(cpumap);
+   return ret;
+}
+
 static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char 
**argv)
 {
char *trace_file;
@@ -163,6 +214,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int 
argc, const char **argv)
goto out_reset;
}
 
+   if (set_tracing_cpu(ftrace) < 0) {
+   pr_err("failed to set tracing cpumask\n");
+   goto out_reset;
+   }
+
if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
goto out_reset;
@@ -264,6 +320,10 @@ int cmd_ftrace(int argc, const char **argv, const char 
*prefix __maybe_unused)
   "trace on existing process id"),
OPT_INCR('v', "verbose", &verbose,
 "be more verbose"),
+   OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide,
+   "system-wide collection from all CPUs"),
+   OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu",
+   "list of cpus to monitor"),
OPT_END()
};
 


[tip:perf/urgent] perf record: Honor --quiet option properly

2017-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  68ba32352d51474d163d58e084b62a12bb610b21
Gitweb: http://git.kernel.org/tip/68ba32352d51474d163d58e084b62a12bb610b21
Author: Namhyung Kim 
AuthorDate: Fri, 17 Feb 2017 17:17:42 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 20 Feb 2017 11:50:36 -0300

perf record: Honor --quiet option properly

It should call perf_quiet_option() to suppress messages.

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-7-namhy...@kernel.org
[ Fix merge clash with 483635a9d080 ("perf record: Add -a as default target") ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 451b11e..bc84a37 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1677,6 +1677,8 @@ int cmd_record(int argc, const char **argv, const char 
*prefix __maybe_unused)
 
argc = parse_options(argc, argv, record_options, record_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
+   if (quiet)
+   perf_quiet_option();
 
/* Make system wide (-a) the default target. */
if (!argc && target__none(&rec->opts.target))


[tip:perf/urgent] perf annotate: Add -q/--quiet option

2017-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  eddaef88961bbf2c0301f3216689d51fa7d0d472
Gitweb: http://git.kernel.org/tip/eddaef88961bbf2c0301f3216689d51fa7d0d472
Author: Namhyung Kim 
AuthorDate: Fri, 17 Feb 2017 17:17:41 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 20 Feb 2017 11:47:18 -0300

perf annotate: Add -q/--quiet option

The -q/--quiet option is to suppress any message.  Sometimes users just
want to see the numbers and it can be used for that case.

Signed-off-by: Namhyung Kim 
Suggested-and-Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-6-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-annotate.txt | 4 
 tools/perf/builtin-annotate.c  | 4 
 2 files changed, 8 insertions(+)

diff --git a/tools/perf/Documentation/perf-annotate.txt 
b/tools/perf/Documentation/perf-annotate.txt
index 8ffbd27..a89273d 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -39,6 +39,10 @@ OPTIONS
 --verbose::
 Be more verbose. (Show symbol address, etc)
 
+-q::
+--quiet::
+   Do not show any message.  (Suppress -v)
+
 -D::
 --dump-raw-trace::
 Dump raw trace in ASCII.
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index ebb6283..4f52d85 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -410,6 +410,7 @@ int cmd_annotate(int argc, const char **argv, const char 
*prefix __maybe_unused)
OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
+   OPT_BOOLEAN('q', "quiet", &quiet, "do now show any message"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
@@ -463,6 +464,9 @@ int cmd_annotate(int argc, const char **argv, const char 
*prefix __maybe_unused)
annotate.sym_hist_filter = argv[0];
}
 
+   if (quiet)
+   perf_quiet_option();
+
file.path  = input_name;
 
annotate.session = perf_session__new(&file, false, &annotate.tool);


[tip:perf/urgent] perf diff: Add -q/--quiet option

2017-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  63b42fce864a468ee02e6647474c4df9bfdc6166
Gitweb: http://git.kernel.org/tip/63b42fce864a468ee02e6647474c4df9bfdc6166
Author: Namhyung Kim 
AuthorDate: Fri, 17 Feb 2017 17:17:40 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 20 Feb 2017 11:47:08 -0300

perf diff: Add -q/--quiet option

The -q/--quiet option is to suppress any message.  Sometimes users just
want to see the numbers and it can be used for that case.

Committer notes:

Before:

  # perf diff | head -10
  Failed to open /tmp/perf-6678.map, continuing without symbols
  Failed to open /tmp/perf-6678.map, continuing without symbols
  Failed to open /tmp/perf-2646.map, continuing without symbols
  # Event 'cycles'
  #
  # Baseline  Delta Abs  Shared Object   Symbol
  #   .  ..  

  #
   5.36% -1.76%  [kernel.vmlinux][k] intel_idle
   2.80% +1.48%  firefox [.] 0x000101fe
  57.12% -1.25%  libxul.so   [.] 0x009bea92
   1.36% -1.11%  [kernel.vmlinux][k] __schedule
   4.26% -1.00%  perf-6678.map   [.] 0x7fac4b0e9320

After:

  # perf diff -q | head -10
   5.36% -1.76%  [kernel.vmlinux][k] intel_idle
   2.80% +1.48%  firefox [.] 0x000101fe
  57.12% -1.25%  libxul.so   [.] 0x009bea92
   1.36% -1.11%  [kernel.vmlinux][k] __schedule
   4.26% -1.00%  perf-6678.map   [.] 0x7fac4b0e9320
   1.86% +0.95%  [kernel.vmlinux][k] update_blocked_averages
   0.80% -0.70%  [kernel.vmlinux][k] native_sched_clock
   0.74% -0.58%  [kernel.vmlinux][k] native_write_msr
   0.76% -0.56%  qemu-system-x86_64  [.] 0x002395c0
 +0.54%  libpulsecommon-10.0.so  [.] 0x0002d91b
  #

Signed-off-by: Namhyung Kim 
Suggested-and-Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-5-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-diff.txt |  4 
 tools/perf/builtin-diff.c  | 14 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-diff.txt 
b/tools/perf/Documentation/perf-diff.txt
index 66dbe3de..a79c84a 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -73,6 +73,10 @@ OPTIONS
Be verbose, for instance, show the raw counts in addition to the
diff.
 
+-q::
+--quiet::
+   Do not show any message.  (Suppress -v)
+
 -f::
 --force::
 Don't do ownership validation.
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 7ad0d78..1b96a31 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -691,7 +691,7 @@ static void hists__process(struct hists *hists)
hists__precompute(hists);
hists__output_resort(hists, NULL);
 
-   hists__fprintf(hists, true, 0, 0, 0, stdout,
+   hists__fprintf(hists, !quiet, 0, 0, 0, stdout,
   symbol_conf.use_callchain);
 }
 
@@ -739,12 +739,14 @@ static void data_process(void)
hists__link(hists_base, hists);
}
 
-   fprintf(stdout, "%s# Event '%s'\n#\n", first ? "" : "\n",
-   perf_evsel__name(evsel_base));
+   if (!quiet) {
+   fprintf(stdout, "%s# Event '%s'\n#\n", first ? "" : 
"\n",
+   perf_evsel__name(evsel_base));
+   }
 
first = false;
 
-   if (verbose > 0 || data__files_cnt > 2)
+   if (verbose > 0 || ((data__files_cnt > 2) && !quiet))
data__fprintf();
 
/* Don't sort callchain for perf diff */
@@ -807,6 +809,7 @@ static const char * const diff_usage[] = {
 static const struct option options[] = {
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
+   OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
"Show only items with match in baseline"),
OPT_CALLBACK('c', "compute", &compute,
@@ -1328,6 +1331,9 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix __maybe_unused)
 
argc = parse_options(argc, argv, options, diff_usage, 0);
 
+   if (quiet)
+   perf_quiet_option();
+
if (symbol__init(NULL) < 0)
return -1;
 


[tip:perf/urgent] perf report: Add -q/--quiet option

2017-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  27fafab59a60b6f02491f2ff44cafd4f2335e487
Gitweb: http://git.kernel.org/tip/27fafab59a60b6f02491f2ff44cafd4f2335e487
Author: Namhyung Kim 
AuthorDate: Fri, 17 Feb 2017 17:17:39 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 20 Feb 2017 11:46:58 -0300

perf report: Add -q/--quiet option

The -q/--quiet option is to suppress any message.  Sometimes users just
want to see the numbers and it can be used for that case.

Before:

  $ perf report | head -15
  Failed to open /lib/modules/3.19.3-3-ARCH/kernel/fs/ext4/ext4.ko.gz, 
continuing without symbols
  Failed to open /lib/modules/3.19.3-3-ARCH/kernel/fs/jbd2/jbd2.ko.gz, 
continuing without symbols
  Failed to open /tmp/perf-14507.map, continuing without symbols
  ...
  # To display the perf.data header info, please use --header/--header-only 
options.
  #
  #
  # Total Lost Samples: 0
  #
  # Samples: 39K of event 'cycles'
  # Event count (approx.): 30444796573
  #
  # Overhead  Command  Shared ObjectSymbol
  #   ...  ...  .
  #
   9.28%  swapper  [kernel.vmlinux] [k] intel_idle
   5.64%  swapper  [kernel.vmlinux] [k] native_write_msr_safe
   1.93%  swapper  [kernel.vmlinux] [k] __switch_to
   1.89%  swapper  [kernel.vmlinux] [k] menu_select
   1.75%  sched-pipe   [kernel.vmlinux] [k] __switch_to

After:

  $ perf report -q | head
   9.28%  swapper  [kernel.vmlinux] [k] intel_idle
   5.64%  swapper  [kernel.vmlinux] [k] native_write_msr_safe
   1.93%  swapper  [kernel.vmlinux] [k] __switch_to
   1.89%  swapper  [kernel.vmlinux] [k] menu_select
   1.75%  sched-pipe   [kernel.vmlinux] [k] __switch_to
   1.67%  swapper  [kernel.vmlinux] [k] cpu_startup_entry
   1.48%  sched-pipe   [kernel.vmlinux] [k] enqueue_entity
   1.46%  swapper  [kernel.vmlinux] [k] __schedule
   1.36%  swapper  [kernel.vmlinux] [k] native_read_tsc
   1.34%  sched-pipe   [kernel.vmlinux] [k] __schedule

Signed-off-by: Namhyung Kim 
Suggested-and-Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-4-namhy...@kernel.org
[ Removed builtin-report.c verbose > 0 hunk added to the previous patch ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt |  4 
 tools/perf/builtin-report.c  | 19 +++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index f2914f0..c04cc06 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -25,6 +25,10 @@ OPTIONS
 --verbose::
 Be more verbose. (show symbol address, etc)
 
+-q::
+--quiet::
+   Do not show any message.  (Suppress -v)
+
 -n::
 --show-nr-samples::
Show the number of samples for each symbol
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index a944881..0a88670 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -320,6 +320,9 @@ static size_t hists__fprintf_nr_sample_events(struct hists 
*hists, struct report
size_t size = sizeof(buf);
int socked_id = hists->socket_filter;
 
+   if (quiet)
+   return 0;
+
if (symbol_conf.filter_relative) {
nr_samples = hists->stats.nr_non_filtered_samples;
nr_events = hists->stats.total_non_filtered_period;
@@ -372,7 +375,11 @@ static int perf_evlist__tty_browse_hists(struct 
perf_evlist *evlist,
 {
struct perf_evsel *pos;
 
-   fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", 
evlist->stats.total_lost_samples);
+   if (!quiet) {
+   fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n",
+   evlist->stats.total_lost_samples);
+   }
+
evlist__for_each_entry(evlist, pos) {
struct hists *hists = evsel__hists(pos);
const char *evname = perf_evsel__name(pos);
@@ -382,7 +389,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist 
*evlist,
continue;
 
hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
-   hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout,
+   hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout,
   symbol_conf.use_callchain);
fprintf(stdout, "\n\n");
}
@@ -716,6 +723,7 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
"input file name"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
+   OPT_BOOLEAN('q', "quiet", &quiet, "Do not show 

[tip:perf/urgent] perf utils: Check verbose flag properly

2017-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  bb963e16507ca7670f0bb47ccaada8874b2ba6a1
Gitweb: http://git.kernel.org/tip/bb963e16507ca7670f0bb47ccaada8874b2ba6a1
Author: Namhyung Kim 
AuthorDate: Fri, 17 Feb 2017 17:17:38 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 20 Feb 2017 11:35:54 -0300

perf utils: Check verbose flag properly

It now can have negative value to suppress the message entirely.  So it
needs to check it being positive.

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-3-namhy...@kernel.org
[ Adjust fuzz on tools/perf/util/pmu.c, add > 0 checks in many other places ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-diff.c   |  2 +-
 tools/perf/builtin-mem.c|  4 ++--
 tools/perf/builtin-record.c |  2 +-
 tools/perf/builtin-report.c |  2 +-
 tools/perf/builtin-sched.c  | 12 ++--
 tools/perf/builtin-stat.c   |  6 +++---
 tools/perf/builtin-top.c|  2 +-
 tools/perf/builtin-trace.c  |  6 +++---
 tools/perf/pmu-events/json.c|  2 +-
 tools/perf/tests/attr.c |  2 +-
 tools/perf/tests/builtin-test.c |  2 +-
 tools/perf/tests/code-reading.c |  2 +-
 tools/perf/tests/fdarray.c  |  2 +-
 tools/perf/tests/llvm.c |  2 +-
 tools/perf/tests/parse-events.c |  2 +-
 tools/perf/tests/perf-record.c  |  4 ++--
 tools/perf/tests/python-use.c   |  2 +-
 tools/perf/tests/thread-map.c   |  6 +++---
 tools/perf/tests/vmlinux-kallsyms.c |  2 +-
 tools/perf/ui/browsers/map.c|  6 +++---
 tools/perf/ui/hist.c|  2 +-
 tools/perf/util/annotate.c  |  2 +-
 tools/perf/util/dso.c   |  2 +-
 tools/perf/util/hist.c  |  6 +++---
 tools/perf/util/pmu.c   |  8 
 tools/perf/util/probe-event.c   |  2 +-
 tools/perf/util/sort.c  |  8 
 tools/perf/util/stat.c  |  2 +-
 tools/perf/util/symbol-elf.c|  2 +-
 29 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 70a2893..7ad0d78 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -744,7 +744,7 @@ static void data_process(void)
 
first = false;
 
-   if (verbose || data__files_cnt > 2)
+   if (verbose > 0 || data__files_cnt > 2)
data__fprintf();
 
/* Don't sort callchain for perf diff */
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index cd7bc4d..6114e07 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -42,8 +42,8 @@ static int parse_record_events(const struct option *opt,
 
fprintf(stderr, "%-13s%-*s%s\n",
e->tag,
-   verbose ? 25 : 0,
-   verbose ? perf_mem_events__name(j) : "",
+   verbose > 0 ? 25 : 0,
+   verbose > 0 ? perf_mem_events__name(j) : "",
e->supported ? ": available" : "");
}
exit(0);
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index b87bbef..451b11e 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -432,7 +432,7 @@ static int record__open(struct record *rec)
 try_again:
if (perf_evsel__open(pos, pos->cpus, pos->threads) < 0) {
if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) 
{
-   if (verbose)
+   if (verbose > 0)
ui__warning("%s\n", msg);
goto try_again;
}
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index dbd7fa0..a944881 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1009,7 +1009,7 @@ repeat:
 * providing it only in verbose mode not to bloat too
 * much struct symbol.
 */
-   if (verbose) {
+   if (verbose > 0) {
/*
 * XXX: Need to provide a less kludgy way to ask for
 * more space per symbol, the u32 is for the index on
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 270eb2d..b94cf0d 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -460,7 +460,7 @@ static struct task_desc *register_pid(struct perf_sched 
*sched,
BUG_ON(!sched->tasks);
sched->tasks[task->nr] = task;
 
-   if (verbose)
+   if (verbose > 0)
printf("registered task #%ld, PID %ld (%s)\n", sched->nr_tasks, 
pid, comm);
 
return task;
@@ -794,7 +794,7 @@ replay_wakeup_event(struct perf_sched *sched,
const u32 pid= perf_evs

[tip:perf/urgent] perf utils: Add perf_quiet_option()

2017-02-21 Thread tip-bot for Namhyung Kim
Commit-ID:  80df1988201ac6648609eba13d48aef9f7974c10
Gitweb: http://git.kernel.org/tip/80df1988201ac6648609eba13d48aef9f7974c10
Author: Namhyung Kim 
AuthorDate: Fri, 17 Feb 2017 17:17:37 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 20 Feb 2017 11:16:32 -0300

perf utils: Add perf_quiet_option()

The perf_quiet_option() is to suppress all messages.  It's intended to
be called just after parsing options.

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: kernel-t...@lge.com
Link: http://lkml.kernel.org/r/20170217081742.17417-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/debug.c | 17 +
 tools/perf/util/debug.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index c1838b6..03eb81f 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -203,11 +203,28 @@ int perf_debug_option(const char *str)
v = (v < 0) || (v > 10) ? 0 : v;
}
 
+   if (quiet)
+   v = -1;
+
*var->ptr = v;
free(s);
return 0;
 }
 
+int perf_quiet_option(void)
+{
+   struct debug_variable *var = &debug_variables[0];
+
+   /* disable all debug messages */
+   while (var->name) {
+   *var->ptr = -1;
+   var++;
+   }
+
+   quiet = true;
+   return 0;
+}
+
 #define DEBUG_WRAPPER(__n, __l)\
 static int pr_ ## __n ## _wrapper(const char *fmt, ...)\
 {  \
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index d242adc..98832f5 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -54,5 +54,6 @@ int veprintf(int level, int var, const char *fmt, va_list 
args);
 
 int perf_debug_option(const char *str);
 void perf_debug_setup(void);
+int perf_quiet_option(void);
 
 #endif /* __PERF_DEBUG_H */


[tip:perf/core] perf diff: Change default setting to "delta-abs"

2017-02-13 Thread tip-bot for Namhyung Kim
Commit-ID:  be57b3fd218ad4a19725ac4bd53e67b2ede42a9d
Gitweb: http://git.kernel.org/tip/be57b3fd218ad4a19725ac4bd53e67b2ede42a9d
Author: Namhyung Kim 
AuthorDate: Sat, 11 Feb 2017 01:18:56 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 13 Feb 2017 14:29:38 -0300

perf diff: Change default setting to "delta-abs"

The "delta-abs" compute method will show most changed entries on top.
So users can easily see how much effect between the data.  Note that it
also changes the default of -o option to 1 in order to apply the compute
method.  To see original-style (sorted by baseline) use -o 0 option.

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20170210161856.18422-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-diff.txt | 4 ++--
 tools/perf/builtin-diff.c  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-diff.txt 
b/tools/perf/Documentation/perf-diff.txt
index 7391299..66dbe3de 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -87,7 +87,7 @@ OPTIONS
 -c::
 --compute::
 Differential computation selection - delta, ratio, wdiff, delta-abs
-(default is delta).  Default can be changed using diff.compute
+(default is delta-abs).  Default can be changed using diff.compute
 config option.  See COMPARISON METHODS section for more info.
 
 -p::
@@ -101,7 +101,7 @@ OPTIONS
 -o::
 --order::
Specify compute sorting column number.  0 means sorting by baseline
-   overhead (default) and 1 means sorting by computed value of column 1
+   overhead and 1 (default) means sorting by computed value of column 1
(data from the first file other base baseline).  Values more than 1
can be used only if enough data files are provided.
The default value can be set using the diff.order config option.
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index e68cc76..70a2893 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -66,7 +66,7 @@ static bool force;
 static bool show_period;
 static bool show_formula;
 static bool show_baseline_only;
-static unsigned int sort_compute;
+static unsigned int sort_compute = 1;
 
 static s64 compute_wdiff_w1;
 static s64 compute_wdiff_w2;
@@ -86,7 +86,7 @@ const char *compute_names[COMPUTE_MAX] = {
[COMPUTE_WEIGHTED_DIFF] = "wdiff",
 };
 
-static int compute = COMPUTE_DELTA;
+static int compute = COMPUTE_DELTA_ABS;
 
 static int compute_2_hpp[COMPUTE_MAX] = {
[COMPUTE_DELTA] = PERF_HPP_DIFF__DELTA,
@@ -810,7 +810,7 @@ static const struct option options[] = {
OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
"Show only items with match in baseline"),
OPT_CALLBACK('c', "compute", &compute,
-"delta,delta-abs,ratio,wdiff:w1,w2 (default delta)",
+"delta,delta-abs,ratio,wdiff:w1,w2 (default delta-abs)",
 "Entries differential computation selection",
 setup_compute),
OPT_BOOLEAN('p', "period", &show_period,


[tip:perf/core] perf diff: Add diff.compute config option

2017-02-13 Thread tip-bot for Namhyung Kim
Commit-ID:  4b35994abe459f08f58b4b3855abf4ba80308680
Gitweb: http://git.kernel.org/tip/4b35994abe459f08f58b4b3855abf4ba80308680
Author: Namhyung Kim 
AuthorDate: Fri, 10 Feb 2017 16:36:13 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 13 Feb 2017 14:29:37 -0300

perf diff: Add diff.compute config option

The diff.compute config variable is to set the default compute method of
perf diff command (-c option).  Possible values 'delta' (default),
'delta-abs', 'ratio' and 'wdiff'.

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Taeung Song 
Link: http://lkml.kernel.org/r/20170210073614.24584-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-config.txt |  5 +
 tools/perf/Documentation/perf-diff.txt   |  5 +++--
 tools/perf/builtin-diff.c| 16 +++-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-config.txt 
b/tools/perf/Documentation/perf-config.txt
index 49ab79d..5b4fff3 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -505,6 +505,11 @@ diff.*::
Setting it to 1 will sort the result by delta (or other
compute method selected).
 
+   diff.compute::
+   This options sets the method for computing the diff result.
+   Possible values are 'delta', 'delta-abs', 'ratio' and
+   'wdiff'.  Default is 'delta'.
+
 SEE ALSO
 
 linkperf:perf[1]
diff --git a/tools/perf/Documentation/perf-diff.txt 
b/tools/perf/Documentation/perf-diff.txt
index 7c014c9..7391299 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -86,8 +86,9 @@ OPTIONS
 
 -c::
 --compute::
-Differential computation selection - delta,ratio,wdiff,delta-abs 
(default is delta).
-See COMPARISON METHODS section for more info.
+Differential computation selection - delta, ratio, wdiff, delta-abs
+(default is delta).  Default can be changed using diff.compute
+config option.  See COMPARISON METHODS section for more info.
 
 -p::
 --period::
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 181ff99..e68cc76 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -86,7 +86,7 @@ const char *compute_names[COMPUTE_MAX] = {
[COMPUTE_WEIGHTED_DIFF] = "wdiff",
 };
 
-static int compute;
+static int compute = COMPUTE_DELTA;
 
 static int compute_2_hpp[COMPUTE_MAX] = {
[COMPUTE_DELTA] = PERF_HPP_DIFF__DELTA,
@@ -1299,6 +1299,20 @@ static int diff__config(const char *var, const char 
*value,
sort_compute = perf_config_int(var, value);
return 0;
}
+   if (!strcmp(var, "diff.compute")) {
+   if (!strcmp(value, "delta")) {
+   compute = COMPUTE_DELTA;
+   } else if (!strcmp(value, "delta-abs")) {
+   compute = COMPUTE_DELTA_ABS;
+   } else if (!strcmp(value, "ratio")) {
+   compute = COMPUTE_RATIO;
+   } else if (!strcmp(value, "wdiff")) {
+   compute = COMPUTE_WEIGHTED_DIFF;
+   } else {
+   pr_err("Invalid compute method: %s\n", value);
+   return -1;
+   }
+   }
 
return 0;
 }


[tip:perf/core] perf diff: Add diff.order config option

2017-02-13 Thread tip-bot for Namhyung Kim
Commit-ID:  d49dd15d69731589de4436a6dcfca59567320fdf
Gitweb: http://git.kernel.org/tip/d49dd15d69731589de4436a6dcfca59567320fdf
Author: Namhyung Kim 
AuthorDate: Fri, 10 Feb 2017 16:36:12 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 13 Feb 2017 14:29:37 -0300

perf diff: Add diff.order config option

In many cases, I need to look at differences between two data so I often
used the -o option to sort the result base on the difference first.
It'd be nice to have a config option to set it by default.

The diff.order config option is to set the default value of -o/--order
option.

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Taeung Song 
Link: http://lkml.kernel.org/r/20170210073614.24584-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-config.txt |  7 +++
 tools/perf/Documentation/perf-diff.txt   |  6 +-
 tools/perf/builtin-diff.c| 14 ++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-config.txt 
b/tools/perf/Documentation/perf-config.txt
index 9365b75..49ab79d 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -498,6 +498,13 @@ record.*::
But if this option is 'no-cache', it will not update the 
build-id cache.
'skip' skips post-processing and does not update the cache.
 
+diff.*::
+   diff.order::
+   This option sets the number of columns to sort the result.
+   The default is 0, which means sorting by baseline.
+   Setting it to 1 will sort the result by delta (or other
+   compute method selected).
+
 SEE ALSO
 
 linkperf:perf[1]
diff --git a/tools/perf/Documentation/perf-diff.txt 
b/tools/perf/Documentation/perf-diff.txt
index af80284..7c014c9 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -99,7 +99,11 @@ OPTIONS
 
 -o::
 --order::
-   Specify compute sorting column number.
+   Specify compute sorting column number.  0 means sorting by baseline
+   overhead (default) and 1 means sorting by computed value of column 1
+   (data from the first file other base baseline).  Values more than 1
+   can be used only if enough data files are provided.
+   The default value can be set using the diff.order config option.
 
 --percentage::
Determine how to display the overhead percentage of filtered entries.
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 781c9e6..181ff99 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -17,6 +17,7 @@
 #include "util/symbol.h"
 #include "util/util.h"
 #include "util/data.h"
+#include "util/config.h"
 
 #include 
 #include 
@@ -1291,6 +1292,17 @@ static int data_init(int argc, const char **argv)
return 0;
 }
 
+static int diff__config(const char *var, const char *value,
+   void *cb __maybe_unused)
+{
+   if (!strcmp(var, "diff.order")) {
+   sort_compute = perf_config_int(var, value);
+   return 0;
+   }
+
+   return 0;
+}
+
 int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
 {
int ret = hists__init();
@@ -1298,6 +1310,8 @@ int cmd_diff(int argc, const char **argv, const char 
*prefix __maybe_unused)
if (ret < 0)
return ret;
 
+   perf_config(diff__config, NULL);
+
argc = parse_options(argc, argv, options, diff_usage, 0);
 
if (symbol__init(NULL) < 0)


[tip:perf/core] perf diff: Add 'delta-abs' compute method

2017-02-13 Thread tip-bot for Namhyung Kim
Commit-ID:  a1668c25a8e1b53d00b2997ef5bc5e25c7a77235
Gitweb: http://git.kernel.org/tip/a1668c25a8e1b53d00b2997ef5bc5e25c7a77235
Author: Namhyung Kim 
AuthorDate: Fri, 10 Feb 2017 16:36:11 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 13 Feb 2017 14:29:36 -0300

perf diff: Add 'delta-abs' compute method

The 'delta-abs' compute method is same as 'delta' but shows entries with
bigger absolute delta first instead of sorting numerically.  This is
only useful together with -o option.

Below is default output (-c delta):

  $ perf diff -o 1 -c delta | grep -v ^# | head
42.22%   +4.97%  [kernel.kallsyms]  [k] cfb_imageblit
 0.62%   +1.23%  [kernel.kallsyms]  [k] mutex_lock
 +1.15%  [kernel.kallsyms]  [k] copy_user_generic_string
 2.40%   +0.95%  [kernel.kallsyms]  [k] bit_putcs
 0.31%   +0.79%  [kernel.kallsyms]  [k] link_path_walk
 +0.64%  [kernel.kallsyms]  [k] kmem_cache_alloc
 0.00%   +0.57%  [kernel.kallsyms]  [k] __rcu_read_unlock
 +0.45%  [kernel.kallsyms]  [k] alloc_set_pte
 0.16%   +0.45%  [kernel.kallsyms]  [k] menu_select
 +0.41%  ld-2.24.so [.] do_lookup_x

Now with 'delta-abs' it shows entries have bigger delta value either
positive or negative.

  $ perf diff -o 1 -c delta-abs | grep -v ^# | head
42.22%   +4.97%  [kernel.kallsyms]  [k] cfb_imageblit
12.72%   -3.01%  [kernel.kallsyms]  [k] intel_idle
 9.72%   -1.31%  [unknown]  [.] 0x00411343
 0.62%   +1.23%  [kernel.kallsyms]  [k] mutex_lock
 2.40%   +0.95%  [kernel.kallsyms]  [k] bit_putcs
 0.31%   +0.79%  [kernel.kallsyms]  [k] link_path_walk
 1.35%   -0.71%  [kernel.kallsyms]  [k] smp_call_function_single
 0.00%   +0.57%  [kernel.kallsyms]  [k] __rcu_read_unlock
 0.16%   +0.45%  [kernel.kallsyms]  [k] menu_select
 0.72%   -0.44%  [kernel.kallsyms]  [k] lookup_fast

Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20170210073614.24584-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-diff.txt |  6 -
 tools/perf/builtin-diff.c  | 46 --
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-diff.txt 
b/tools/perf/Documentation/perf-diff.txt
index 3e9490b..af80284 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -86,7 +86,7 @@ OPTIONS
 
 -c::
 --compute::
-Differential computation selection - delta,ratio,wdiff (default is 
delta).
+Differential computation selection - delta,ratio,wdiff,delta-abs 
(default is delta).
 See COMPARISON METHODS section for more info.
 
 -p::
@@ -181,6 +181,10 @@ with:
 relative to how entries are filtered.  Use --percentage=absolute to
 prevent such fluctuation.
 
+delta-abs
+~
+Same as 'delta` method, but sort the result with the absolute values.
+
 ratio
 ~
 If specified the 'Ratio' column is displayed with value 'r' computed as:
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 933aeec..781c9e6 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -30,6 +30,7 @@ enum {
PERF_HPP_DIFF__RATIO,
PERF_HPP_DIFF__WEIGHTED_DIFF,
PERF_HPP_DIFF__FORMULA,
+   PERF_HPP_DIFF__DELTA_ABS,
 
PERF_HPP_DIFF__MAX_INDEX
 };
@@ -73,11 +74,13 @@ enum {
COMPUTE_DELTA,
COMPUTE_RATIO,
COMPUTE_WEIGHTED_DIFF,
+   COMPUTE_DELTA_ABS,
COMPUTE_MAX,
 };
 
 const char *compute_names[COMPUTE_MAX] = {
[COMPUTE_DELTA] = "delta",
+   [COMPUTE_DELTA_ABS] = "delta-abs",
[COMPUTE_RATIO] = "ratio",
[COMPUTE_WEIGHTED_DIFF] = "wdiff",
 };
@@ -86,6 +89,7 @@ static int compute;
 
 static int compute_2_hpp[COMPUTE_MAX] = {
[COMPUTE_DELTA] = PERF_HPP_DIFF__DELTA,
+   [COMPUTE_DELTA_ABS] = PERF_HPP_DIFF__DELTA_ABS,
[COMPUTE_RATIO] = PERF_HPP_DIFF__RATIO,
[COMPUTE_WEIGHTED_DIFF] = PERF_HPP_DIFF__WEIGHTED_DIFF,
 };
@@ -111,6 +115,10 @@ static struct header_column {
.name  = "Delta",
.width = 7,
},
+   [PERF_HPP_DIFF__DELTA_ABS] = {
+   .name  = "Delta Abs",
+   .width = 7,
+   },
[PERF_HPP_DIFF__RATIO] = {
.name  = "Ratio",
.width = 14,
@@ -298,6 +306,7 @@ static int formula_fprintf(struct hist_entry *he, struct 
hist_entry *pair,
 {
switch (compute) {
case COMPUTE_DELTA:
+   case COMPUTE_DELTA_ABS:
return formula_delta(he, pair, buf, size);
case COMPUTE_RATIO:
return formula_ratio(he, pair, buf, size);
@@ -461,6 +470,7 @@ static void hists__precompute(struct hists *hists)
 
switch (compute) {
case COMPUTE_DELTA:
+   c

[tip:perf/urgent] perf diff: Fix -o/--order option behavior (again)

2017-02-03 Thread tip-bot for Namhyung Kim
Commit-ID:  a1c9f97f0b64e6337d9cfcc08c134450934fdd90
Gitweb: http://git.kernel.org/tip/a1c9f97f0b64e6337d9cfcc08c134450934fdd90
Author: Namhyung Kim 
AuthorDate: Wed, 18 Jan 2017 14:14:57 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 2 Feb 2017 11:39:09 -0300

perf diff: Fix -o/--order option behavior (again)

Commit 21e6d8428664 ("perf diff: Use perf_hpp__register_sort_field
interface") changed list_add() to perf_hpp__register_sort_field().

This resulted in a behavior change since the field was added to the tail
instead of the head.  So the -o option is mostly ignored due to its
order in the list.

This patch fixes it by adding perf_hpp__prepend_sort_field().

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: 21e6d8428664 ("perf diff: Use perf_hpp__register_sort_field interface")
Link: http://lkml.kernel.org/r/20170118051457.30946-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-diff.c | 2 +-
 tools/perf/ui/hist.c  | 6 ++
 tools/perf/util/hist.h| 7 +++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 9ff0db4..933aeec 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -1199,7 +1199,7 @@ static int ui_init(void)
BUG_ON(1);
}
 
-   perf_hpp__register_sort_field(fmt);
+   perf_hpp__prepend_sort_field(fmt);
return 0;
 }
 
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 4ec79b2..18cfcdc9 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -521,6 +521,12 @@ void perf_hpp_list__register_sort_field(struct 
perf_hpp_list *list,
list_add_tail(&format->sort_list, &list->sorts);
 }
 
+void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
+  struct perf_hpp_fmt *format)
+{
+   list_add(&format->sort_list, &list->sorts);
+}
+
 void perf_hpp__column_unregister(struct perf_hpp_fmt *format)
 {
list_del(&format->list);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index d4b6514..28c216e 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -283,6 +283,8 @@ void perf_hpp_list__column_register(struct perf_hpp_list 
*list,
struct perf_hpp_fmt *format);
 void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,
struct perf_hpp_fmt *format);
+void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
+  struct perf_hpp_fmt *format);
 
 static inline void perf_hpp__column_register(struct perf_hpp_fmt *format)
 {
@@ -294,6 +296,11 @@ static inline void perf_hpp__register_sort_field(struct 
perf_hpp_fmt *format)
perf_hpp_list__register_sort_field(&perf_hpp_list, format);
 }
 
+static inline void perf_hpp__prepend_sort_field(struct perf_hpp_fmt *format)
+{
+   perf_hpp_list__prepend_sort_field(&perf_hpp_list, format);
+}
+
 #define perf_hpp_list__for_each_format(_list, format) \
list_for_each_entry(format, &(_list)->fields, list)
 


[tip:perf/urgent] perf diff: Fix segfault on 'perf diff -o N' option

2017-02-03 Thread tip-bot for Namhyung Kim
Commit-ID:  8381cdd0e32dd748bd34ca3ace476949948bd793
Gitweb: http://git.kernel.org/tip/8381cdd0e32dd748bd34ca3ace476949948bd793
Author: Namhyung Kim 
AuthorDate: Wed, 18 Jan 2017 14:14:56 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 2 Feb 2017 11:39:04 -0300

perf diff: Fix segfault on 'perf diff -o N' option

The -o/--order option is to select column number to sort a diff result.

It does the job by adding a hpp field at the beginning of the sort list.
But it should not be added to the output field list as it has no
callbacks required by a output field.

During the setup_sorting(), the perf_hpp__setup_output_field() appends
the given sort keys to the output field if it's not there already.

Originally it was checked by fmt->list being non-empty.  But commit
3f931f2c4274 ("perf hists: Make hpp setup function generic") changed it
to check the ->equal callback.

Anyways, we don't need to add the pseudo hpp field to the output field
list since it won't be used for output.  So just skip fields if they
have no ->color or ->entry callbacks.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: 3f931f2c4274 ("perf hists: Make hpp setup function generic")
Link: http://lkml.kernel.org/r/20170118051457.30946-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/hist.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 3738839..4ec79b2 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -560,6 +560,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list 
*list)
perf_hpp_list__for_each_sort_list(list, fmt) {
struct perf_hpp_fmt *pos;
 
+   /* skip sort-only fields ("sort_compute" in perf diff) */
+   if (!fmt->entry && !fmt->color)
+   continue;
+
perf_hpp_list__for_each_format(list, pos) {
if (fmt_equal(fmt, pos))
goto next;


[tip:perf/core] perf ftrace: Introduce new 'ftrace' tool

2017-01-26 Thread tip-bot for Namhyung Kim
Commit-ID:  d01f4e8db22cf4d04f6c86351d959b584eb1f5f7
Gitweb: http://git.kernel.org/tip/d01f4e8db22cf4d04f6c86351d959b584eb1f5f7
Author: Namhyung Kim 
AuthorDate: Thu, 7 Mar 2013 21:45:20 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 26 Jan 2017 11:43:01 -0300

perf ftrace: Introduce new 'ftrace' tool

The 'perf ftrace' command is a simple wrapper of kernel's ftrace
functionality.  It only supports single thread tracing currently and
just reads trace_pipe in text and then write it to stdout.

Committer notes:

Testing it:

  # perf ftrace -f function_graph usleep 123456
  
  2)   |  SyS_nanosleep() {
  2)   |_copy_from_user() {
  
  2)   0.900 us|  }
  2)   1.354 us|}
  2)   |hrtimer_nanosleep() {
  2)   0.062 us|  __hrtimer_init();
  2)   |  do_nanosleep() {
  2)   |hrtimer_start_range_ns() {
  
  2)   5.025 us|}
  2)   |schedule() {
  2)   0.125 us|  rcu_note_context_switch();
  2)   0.057 us|  _raw_spin_lock();
  2)   |  deactivate_task() {
  2)   0.369 us|update_rq_clock.part.77();
  2)   |dequeue_task_fair() {
  
  2) + 22.453 us   |}
  2) + 23.736 us   |  }
  2)   |  pick_next_task_fair() {
  
  2) + 47.167 us   |  }
  2)   |  pick_next_task_idle() {
  
  2)   4.462 us|  }
  --
  2)  usleep-20387  =>-0
  --

  2)   0.806 us|  switch_mm_irqs_off();
  --
  2)-0=>  usleep-20387
  --

  2)   0.151 us|  finish_task_switch();
  2) @ 123597.2 us |}
  2)   0.037 us|_cond_resched();
  2)   |hrtimer_try_to_cancel() {
  2)   0.064 us|  hrtimer_active();
  2)   0.353 us|}
  2) @ 123605.3 us |  }
  2) @ 123606.2 us |}
  2) @ 123608.3 us |  } /* SyS_nanosleep */
  2)   |  __do_page_fault() {
 

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Masami Hiramatsu 
Cc: Frederic Weisbecker 
Cc: Jeremy Eder 
Cc: Jiri Olsa ,
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/n/tip-r1hgmsj4dxny8arn3o9mw...@git.kernel.org
[ Various foward port fixes, add man page ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Build |   1 +
 tools/perf/Documentation/perf-ftrace.txt |  36 +
 tools/perf/builtin-ftrace.c  | 242 +++
 tools/perf/builtin.h |   1 +
 tools/perf/command-list.txt  |   1 +
 tools/perf/perf.c|   1 +
 6 files changed, 282 insertions(+)

diff --git a/tools/perf/Build b/tools/perf/Build
index 7039ecb..9b79f8d 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -3,6 +3,7 @@ perf-y += builtin-annotate.o
 perf-y += builtin-config.o
 perf-y += builtin-diff.o
 perf-y += builtin-evlist.o
+perf-y += builtin-ftrace.o
 perf-y += builtin-help.o
 perf-y += builtin-sched.o
 perf-y += builtin-buildid-list.o
diff --git a/tools/perf/Documentation/perf-ftrace.txt 
b/tools/perf/Documentation/perf-ftrace.txt
new file mode 100644
index 000..2d96de6
--- /dev/null
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -0,0 +1,36 @@
+perf-ftrace(1)
+=
+
+NAME
+
+perf-ftrace - simple wrapper for kernel's ftrace functionality
+
+
+SYNOPSIS
+
+[verse]
+'perf ftrace' 
+
+DESCRIPTION
+---
+The 'perf ftrace' command is a simple wrapper of kernel's ftrace
+functionality.  It only supports single thread tracing currently and
+just reads trace_pipe in text and then write it to stdout.
+
+The following options apply to perf ftrace.
+
+OPTIONS
+---
+
+-t::
+--tracer=::
+   Tracer to use: function_graph or function.
+
+-v::
+--verbose=::
+Verbosity level.
+
+
+SEE ALSO
+
+linkperf:perf-record[1], linkperf:perf-trace[1]
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
new file mode 100644
index 000..c320ae2
--- /dev/null
+++ b/tools/perf/builtin-ftrace.c
@@ -0,0 +1,242 @@
+/*
+ * builtin-ftrace.c
+ *
+ * Copyright (c) 2013  LG Electronics,  Namhyung Kim 
+ *
+ * Released under the GPL v2.
+ */
+
+#include "builtin.h"
+#include "perf.h"
+
+#include 
+#include 
+
+#include "debug.h"
+#include 
+#include "evlist.h"
+#include "target.h"
+#include "thread_map.h"
+
+
+#define DEFAULT_TRACER  "function_graph"
+
+struct perf_ftrace {
+   struct perf_evlist *evlist;
+   struct target target;
+   const char *tracer;
+};
+
+static bool done;
+
+static void sig_handler(int sig __maybe_unused)
+{
+   done = true;
+}
+
+/*
+ * perf_evlist__prepare_workload will send a S

[tip:perf/core] perf util: Add more debug message on failure path

2017-01-26 Thread tip-bot for Namhyung Kim
Commit-ID:  a7619aef6dca913d830675dd914ca6fe7241a730
Gitweb: http://git.kernel.org/tip/a7619aef6dca913d830675dd914ca6fe7241a730
Author: Namhyung Kim 
AuthorDate: Thu, 18 Apr 2013 21:24:16 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 26 Jan 2017 11:43:00 -0300

perf util: Add more debug message on failure path

It's helpful for debugging on tracing features.

Signed-off-by: Namhyung Kim 
Tested-by: Masami Hiramatsu 
Cc: Frederic Weisbecker 
Cc: Jeremy Eder 
Cc: Jiri Olsa ,
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/n/tip-rjysr9ljiesymgk4qblte...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/header.c   |  4 ++-
 tools/perf/util/trace-event-read.c | 53 ++
 2 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 00fd8a8..c567d9f 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2803,8 +2803,10 @@ static int perf_evsel__prepare_tracepoint_event(struct 
perf_evsel *evsel,
}
 
event = pevent_find_event(pevent, evsel->attr.config);
-   if (event == NULL)
+   if (event == NULL) {
+   pr_debug("cannot find event format for %d\n", 
(int)evsel->attr.config);
return -1;
+   }
 
if (!evsel->name) {
snprintf(bf, sizeof(bf), "%s:%s", event->system, event->name);
diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index 61c7162..2742015 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -260,39 +260,53 @@ static int read_header_files(struct pevent *pevent)
 
 static int read_ftrace_file(struct pevent *pevent, unsigned long long size)
 {
+   int ret;
char *buf;
 
buf = malloc(size);
-   if (buf == NULL)
+   if (buf == NULL) {
+   pr_debug("memory allocation failure\n");
return -1;
+   }
 
-   if (do_read(buf, size) < 0) {
-   free(buf);
-   return -1;
+   ret = do_read(buf, size);
+   if (ret < 0) {
+   pr_debug("error reading ftrace file.\n");
+   goto out;
}
 
-   parse_ftrace_file(pevent, buf, size);
+   ret = parse_ftrace_file(pevent, buf, size);
+   if (ret < 0)
+   pr_debug("error parsing ftrace file.\n");
+out:
free(buf);
-   return 0;
+   return ret;
 }
 
 static int read_event_file(struct pevent *pevent, char *sys,
unsigned long long size)
 {
+   int ret;
char *buf;
 
buf = malloc(size);
-   if (buf == NULL)
+   if (buf == NULL) {
+   pr_debug("memory allocation failure\n");
return -1;
+   }
 
-   if (do_read(buf, size) < 0) {
+   ret = do_read(buf, size);
+   if (ret < 0) {
free(buf);
-   return -1;
+   goto out;
}
 
-   parse_event_file(pevent, buf, size, sys);
+   ret = parse_event_file(pevent, buf, size, sys);
+   if (ret < 0)
+   pr_debug("error parsing event file.\n");
+out:
free(buf);
-   return 0;
+   return ret;
 }
 
 static int read_ftrace_files(struct pevent *pevent)
@@ -345,6 +359,7 @@ static int read_saved_cmdline(struct pevent *pevent)
 {
unsigned long long size;
char *buf;
+   int ret;
 
/* it can have 0 size */
size = read8(pevent);
@@ -352,18 +367,22 @@ static int read_saved_cmdline(struct pevent *pevent)
return 0;
 
buf = malloc(size + 1);
-   if (buf == NULL)
+   if (buf == NULL) {
+   pr_debug("memory allocation failure\n");
return -1;
+   }
 
-   if (do_read(buf, size) < 0) {
-   free(buf);
-   return -1;
+   ret = do_read(buf, size);
+   if (ret < 0) {
+   pr_debug("error reading saved cmdlines\n");
+   goto out;
}
 
parse_saved_cmdline(pevent, buf, size);
-
+   ret = 0;
+out:
free(buf);
-   return 0;
+   return ret;
 }
 
 ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)


[tip:perf/core] perf util: Save pid-cmdline mapping into tracing header

2017-01-26 Thread tip-bot for Namhyung Kim
Commit-ID:  cd4ceb63438e9e28299f4352ae7b75d2967a772d
Gitweb: http://git.kernel.org/tip/cd4ceb63438e9e28299f4352ae7b75d2967a772d
Author: Namhyung Kim 
AuthorDate: Thu, 11 Apr 2013 17:25:04 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 26 Jan 2017 11:42:59 -0300

perf util: Save pid-cmdline mapping into tracing header

Current trace info data lacks the saved cmdline mapping which is needed
for pevent to find out the comm of a task.  Add this and bump up the
version number so that perf can determine its presence when reading.

This is mostly corresponding to trace.dat file version 6, but still
lacks 4 byte of number of cpus, and 10 bytes of type string - and I
think we don't need those anyway.

Signed-off-by: Namhyung Kim 
Tested-by: Masami Hiramatsu 
Cc: Frederic Weisbecker 
Cc: Jeremy Eder 
Cc: Jiri Olsa ,
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Steven Rostedt 
[ Change version test from == to >= ]
Link: http://lkml.kernel.org/n/tip-vaooqpxsikxbb3359p0co...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-info.c  | 33 -
 tools/perf/util/trace-event-parse.c | 17 +
 tools/perf/util/trace-event-read.c  | 36 ++--
 tools/perf/util/trace-event.h   |  1 +
 4 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/trace-event-info.c 
b/tools/perf/util/trace-event-info.c
index d995743..ceb0e27 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -42,7 +42,7 @@
 #include "evsel.h"
 #include "debug.h"
 
-#define VERSION "0.5"
+#define VERSION "0.6"
 
 static int output_fd;
 
@@ -379,6 +379,34 @@ out:
return err;
 }
 
+static int record_saved_cmdline(void)
+{
+   unsigned int size;
+   char *path;
+   struct stat st;
+   int ret, err = 0;
+
+   path = get_tracing_file("saved_cmdlines");
+   if (!path) {
+   pr_debug("can't get tracing/saved_cmdline");
+   return -ENOMEM;
+   }
+
+   ret = stat(path, &st);
+   if (ret < 0) {
+   /* not found */
+   size = 0;
+   if (write(output_fd, &size, 8) != 8)
+   err = -EIO;
+   goto out;
+   }
+   err = record_file(path, 8);
+
+out:
+   put_tracing_file(path);
+   return err;
+}
+
 static void
 put_tracepoints_path(struct tracepoint_path *tps)
 {
@@ -539,6 +567,9 @@ struct tracing_data *tracing_data_get(struct list_head 
*pattrs,
if (err)
goto out;
err = record_ftrace_printk();
+   if (err)
+   goto out;
+   err = record_saved_cmdline();
 
 out:
/*
diff --git a/tools/perf/util/trace-event-parse.c 
b/tools/perf/util/trace-event-parse.c
index 33b52ea..de0078e 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -160,6 +160,23 @@ void parse_ftrace_printk(struct pevent *pevent,
}
 }
 
+void parse_saved_cmdline(struct pevent *pevent,
+char *file, unsigned int size __maybe_unused)
+{
+   char *comm;
+   char *line;
+   char *next = NULL;
+   int pid;
+
+   line = strtok_r(file, "\n", &next);
+   while (line) {
+   sscanf(line, "%d %ms", &pid, &comm);
+   pevent_register_comm(pevent, comm, pid);
+   free(comm);
+   line = strtok_r(NULL, "\n", &next);
+   }
+}
+
 int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size)
 {
return pevent_parse_event(pevent, buf, size, "ftrace");
diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index b67a0cc..61c7162 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -341,6 +341,31 @@ static int read_event_files(struct pevent *pevent)
return 0;
 }
 
+static int read_saved_cmdline(struct pevent *pevent)
+{
+   unsigned long long size;
+   char *buf;
+
+   /* it can have 0 size */
+   size = read8(pevent);
+   if (!size)
+   return 0;
+
+   buf = malloc(size + 1);
+   if (buf == NULL)
+   return -1;
+
+   if (do_read(buf, size) < 0) {
+   free(buf);
+   return -1;
+   }
+
+   parse_saved_cmdline(pevent, buf, size);
+
+   free(buf);
+   return 0;
+}
+
 ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe)
 {
char buf[BUFSIZ];
@@ -379,10 +404,11 @@ ssize_t trace_report(int fd, struct trace_event *tevent, 
bool __repipe)
return -1;
if (show_version)
printf("version = %s\n", version);
-   free(version);
 
-   if (do_read(buf, 1) < 0)
+   if (do_read(buf, 1) < 0) {
+   free(version);
return -1;
+   }
file_bigendian = buf[0];
host_bigendian = bigendian(

[tip:perf/core] perf sched timehist: Account thread wait time separately

2017-01-18 Thread tip-bot for Namhyung Kim
Commit-ID:  941bdea79e194dec7e7b42780aa5620020548f8a
Gitweb: http://git.kernel.org/tip/941bdea79e194dec7e7b42780aa5620020548f8a
Author: Namhyung Kim 
AuthorDate: Fri, 13 Jan 2017 19:45:21 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 17 Jan 2017 11:35:44 -0300

perf sched timehist: Account thread wait time separately

Separate thread wait time into 3 parts - sleep, iowait and preempt based
on the prev_state of the last event.

Signed-off-by: Namhyung Kim 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20170113104523.31212-1-namhy...@kernel.org
[ Fix the build on centos:5 where 'wait' shadows a global declaration ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 50 --
 1 file changed, 44 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 5b134b0..6d3c3e8 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -77,6 +77,22 @@ struct sched_atom {
 
 #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP"
 
+/* task state bitmask, copied from include/linux/sched.h */
+#define TASK_RUNNING   0
+#define TASK_INTERRUPTIBLE 1
+#define TASK_UNINTERRUPTIBLE   2
+#define __TASK_STOPPED 4
+#define __TASK_TRACED  8
+/* in tsk->exit_state */
+#define EXIT_DEAD  16
+#define EXIT_ZOMBIE32
+#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD)
+/* in tsk->state again */
+#define TASK_DEAD  64
+#define TASK_WAKEKILL  128
+#define TASK_WAKING256
+#define TASK_PARKED512
+
 enum thread_state {
THREAD_SLEEPING = 0,
THREAD_WAIT_CPU,
@@ -216,13 +232,16 @@ struct perf_sched {
 struct thread_runtime {
u64 last_time;  /* time of previous sched in/out event */
u64 dt_run; /* run time */
-   u64 dt_wait;/* time between CPU access (off cpu) */
+   u64 dt_sleep;   /* time between CPU access by sleep (off cpu) */
+   u64 dt_iowait;  /* time between CPU access by iowait (off cpu) */
+   u64 dt_preempt; /* time between CPU access by preempt (off cpu) */
u64 dt_delay;   /* time between wakeup and sched-in */
u64 ready_to_run;   /* time of wakeup */
 
struct stats run_stats;
u64 total_run_time;
 
+   int last_state;
u64 migrations;
 };
 
@@ -1858,6 +1877,7 @@ static void timehist_print_sample(struct perf_sched 
*sched,
struct thread_runtime *tr = thread__priv(thread);
u32 max_cpus = sched->max_cpu + 1;
char tstr[64];
+   u64 wait_time;
 
timestamp__scnprintf_usec(t, tstr, sizeof(tstr));
printf("%15s [%04d] ", tstr, sample->cpu);
@@ -1880,7 +1900,9 @@ static void timehist_print_sample(struct perf_sched 
*sched,
 
printf(" %-*s ", comm_width, timehist_get_commstr(thread));
 
-   print_sched_time(tr->dt_wait, 6);
+   wait_time = tr->dt_sleep + tr->dt_iowait + tr->dt_preempt;
+   print_sched_time(wait_time, 6);
+
print_sched_time(tr->dt_delay, 6);
print_sched_time(tr->dt_run, 6);
 
@@ -1930,8 +1952,11 @@ static void timehist_update_runtime_stats(struct 
thread_runtime *r,
 u64 t, u64 tprev)
 {
r->dt_delay   = 0;
-   r->dt_wait= 0;
+   r->dt_sleep   = 0;
+   r->dt_iowait  = 0;
+   r->dt_preempt = 0;
r->dt_run = 0;
+
if (tprev) {
r->dt_run = t - tprev;
if (r->ready_to_run) {
@@ -1943,8 +1968,16 @@ static void timehist_update_runtime_stats(struct 
thread_runtime *r,
 
if (r->last_time > tprev)
pr_debug("time travel: last sched out time for task > 
previous sched_switch event\n");
-   else if (r->last_time)
-   r->dt_wait = tprev - r->last_time;
+   else if (r->last_time) {
+   u64 dt_wait = tprev - r->last_time;
+
+   if (r->last_state == TASK_RUNNING)
+   r->dt_preempt = dt_wait;
+   else if (r->last_state == TASK_UNINTERRUPTIBLE)
+   r->dt_iowait = dt_wait;
+   else
+   r->dt_sleep = dt_wait;
+   }
}
 
update_stats(&r->run_stats, r->dt_run);
@@ -2447,8 +2480,10 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
 * time.  we only care total run time and run stat.
 */
last_tr->dt_run = 0;
-   last_tr->dt_wait = 0;
last_tr->dt_delay = 0;
+   last_tr->dt_sleep = 0;
+   last_tr->dt_iowait = 0;
+   last_tr->dt_preempt = 0;
 
if (itr->cursor.nr)

[tip:perf/core] perf sched timehist: Show total wait times for summary

2017-01-18 Thread tip-bot for Namhyung Kim
Commit-ID:  587782c52a83b35673201fd9a54364fa2b189b33
Gitweb: http://git.kernel.org/tip/587782c52a83b35673201fd9a54364fa2b189b33
Author: Namhyung Kim 
AuthorDate: Fri, 13 Jan 2017 19:45:23 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 17 Jan 2017 11:36:44 -0300

perf sched timehist: Show total wait times for summary

When --state option is given, the summary will show total run, sleep,
iowait, preempt and delay time instead of statistics of runtime.

  $ perf sched timehist -s --state

  Wait-time summary
comm  parent sched-in run-time  sleep iowait preempt delay
  (count)   (msec) (msec) (msec)  (msec) (msec)
  -
   systemd[1]  030.497   1.685 0.000   0.000 0.061
   ksoftirqd/0[3]  2   210.434 989.948 0.000   0.000 0.325
   rcu_preempt[7]  2   280.386 993.211 0.000   0.000 0.712
  migration/0[10]  2   120.126  50.174 0.000   0.000 0.044
   watchdog/0[11]  210.009   0.000 0.000   0.000 0.016
  migration/1[13]  220.029  11.755 0.000   0.000 0.007
  

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20170113104523.31212-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 44 +---
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index a8ac766..daceb32 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -241,6 +241,10 @@ struct thread_runtime {
 
struct stats run_stats;
u64 total_run_time;
+   u64 total_sleep_time;
+   u64 total_iowait_time;
+   u64 total_preempt_time;
+   u64 total_delay_time;
 
int last_state;
u64 migrations;
@@ -2008,7 +2012,12 @@ static void timehist_update_runtime_stats(struct 
thread_runtime *r,
}
 
update_stats(&r->run_stats, r->dt_run);
-   r->total_run_time += r->dt_run;
+
+   r->total_run_time += r->dt_run;
+   r->total_delay_time   += r->dt_delay;
+   r->total_sleep_time   += r->dt_sleep;
+   r->total_iowait_time  += r->dt_iowait;
+   r->total_preempt_time += r->dt_preempt;
 }
 
 static bool is_idle_sample(struct perf_sample *sample,
@@ -2593,7 +2602,26 @@ static void print_thread_runtime(struct thread *t,
printf("\n");
 }
 
+static void print_thread_waittime(struct thread *t,
+ struct thread_runtime *r)
+{
+   printf("%*s   %5d  %9" PRIu64 " ",
+  comm_width, timehist_get_commstr(t), t->ppid,
+  (u64) r->run_stats.n);
+
+   print_sched_time(r->total_run_time, 8);
+   print_sched_time(r->total_sleep_time, 6);
+   printf(" ");
+   print_sched_time(r->total_iowait_time, 6);
+   printf(" ");
+   print_sched_time(r->total_preempt_time, 6);
+   printf(" ");
+   print_sched_time(r->total_delay_time, 6);
+   printf("\n");
+}
+
 struct total_run_stats {
+   struct perf_sched *sched;
u64  sched_count;
u64  task_count;
u64  total_run_time;
@@ -2612,7 +2640,11 @@ static int __show_thread_runtime(struct thread *t, void 
*priv)
stats->task_count++;
stats->sched_count += r->run_stats.n;
stats->total_run_time += r->total_run_time;
-   print_thread_runtime(t, r);
+
+   if (stats->sched->show_state)
+   print_thread_waittime(t, r);
+   else
+   print_thread_runtime(t, r);
}
 
return 0;
@@ -2700,18 +2732,24 @@ static void timehist_print_summary(struct perf_sched 
*sched,
u64 hist_time = sched->hist_time.end - sched->hist_time.start;
 
memset(&totals, 0, sizeof(totals));
+   totals.sched = sched;
 
if (sched->idle_hist) {
printf("\nIdle-time summary\n");
printf("%*s  parent  sched-out  ", comm_width, "comm");
printf("  idle-time   min-idleavg-idlemax-idle  stddev  
migrations\n");
+   } else if (sched->show_state) {
+   printf("\nWait-time summary\n");
+   printf("%*s  parent   sched-in  ", comm_width, "comm");
+   printf("   run-time  sleep  iowait preempt   
delay\n");
} else {
printf("\nRuntime summary\n");
printf("%*s  parent   sched-in  ", comm_width, "comm");
printf("   run-timemin-run avg-run max-run  stddev  
migrations\n");
}
printf("%*s(count)  ", comm_width, "");
-   printf(" (msec) (msec)  (msec)  (msec)   %%\n");
+   printf(" (msec) (msec)  (msec)  (msec)  

[tip:perf/core] perf sched timehist: Add --state option

2017-01-18 Thread tip-bot for Namhyung Kim
Commit-ID:  414e050c68ec2a3dd815544ea48ff6016f1a7a11
Gitweb: http://git.kernel.org/tip/414e050c68ec2a3dd815544ea48ff6016f1a7a11
Author: Namhyung Kim 
AuthorDate: Fri, 13 Jan 2017 19:45:22 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 17 Jan 2017 11:36:44 -0300

perf sched timehist: Add --state option

The --state option is to show task state when switched out.  The state
is printed as a single character like in the /proc but I added 'I' for
idle state rather than 'R'.

  $ perf sched timehist --state | head
  Samples do not have callchains.
  time cpu task name  wait time sch delay run time state
   [tid/pid] (msec)(msec)   (msec)
   --- ---  -- -
  1.753791 [3]  0.000 0.0000.000 I
  1.753834 [1] perf[27469]0.000 0.0000.000 S
  1.753904 [3] perf[27470]0.000 0.0060.112 S
  1.753914 [1]  0.000 0.0000.079 I
  1.753915 [3] migration/3[23]0.000 0.0020.011 S
  1.754287 [2]  0.000 0.0000.000 I
  1.754335 [2] transmission[1773/1739]0.000 0.0040.047 S

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20170113104523.31212-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-sched.txt |  2 ++
 tools/perf/builtin-sched.c  | 38 +
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt 
b/tools/perf/Documentation/perf-sched.txt
index 7617396..d33dedd 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -143,6 +143,8 @@ OPTIONS for 'perf sched timehist'
stop time is not given (i.e, time string is 'x.y,') then analysis goes
to end of file.
 
+--state::
+   Show task state when it switched out.
 
 SEE ALSO
 
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 6d3c3e8..a8ac766 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -222,6 +222,7 @@ struct perf_sched {
boolshow_cpu_visual;
boolshow_wakeups;
boolshow_migrations;
+   boolshow_state;
u64 skipped_samples;
const char  *time_str;
struct perf_time_interval ptime;
@@ -1840,6 +1841,9 @@ static void timehist_header(struct perf_sched *sched)
printf(" %-*s  %9s  %9s  %9s", comm_width,
"task name", "wait time", "sch delay", "run time");
 
+   if (sched->show_state)
+   printf("  %s", "state");
+
printf("\n");
 
/*
@@ -1850,9 +1854,14 @@ static void timehist_header(struct perf_sched *sched)
if (sched->show_cpu_visual)
printf(" %*s ", ncpus, "");
 
-   printf(" %-*s  %9s  %9s  %9s\n", comm_width,
+   printf(" %-*s  %9s  %9s  %9s", comm_width,
   "[tid/pid]", "(msec)", "(msec)", "(msec)");
 
+   if (sched->show_state)
+   printf("  %5s", "");
+
+   printf("\n");
+
/*
 * separator
 */
@@ -1865,14 +1874,29 @@ static void timehist_header(struct perf_sched *sched)
graph_dotted_line, graph_dotted_line, graph_dotted_line,
graph_dotted_line);
 
+   if (sched->show_state)
+   printf("  %.5s", graph_dotted_line);
+
printf("\n");
 }
 
+static char task_state_char(struct thread *thread, int state)
+{
+   static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
+   unsigned bit = state ? ffs(state) : 0;
+
+   /* 'I' for idle */
+   if (thread->tid == 0)
+   return 'I';
+
+   return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
+}
+
 static void timehist_print_sample(struct perf_sched *sched,
  struct perf_sample *sample,
  struct addr_location *al,
  struct thread *thread,
- u64 t)
+ u64 t, int state)
 {
struct thread_runtime *tr = thread__priv(thread);
u32 max_cpus = sched->max_cpu + 1;
@@ -1906,6 +1930,9 @@ static void timehist_print_sample(struct perf_sched 
*sched,
print_sched_time(tr->dt_delay, 6);
print_sched_time(tr->dt_run, 6);
 
+   if (sched->show_state)
+   printf(" %5c ", task_state_char(thread, state));
+
if (sched->show_wakeups)
printf("  %-*s", comm_width, "");
 
@@ -2406,6 +2433,8 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
struct thread_runtime *tr = NULL;
u64 tpre

[tip:perf/urgent] perf sched timehist: Show total scheduling time

2017-01-04 Thread tip-bot for Namhyung Kim
Commit-ID:  9396c9cb0d9534ca67bda8a34b2413a2ca1c67e9
Gitweb: http://git.kernel.org/tip/9396c9cb0d9534ca67bda8a34b2413a2ca1c67e9
Author: Namhyung Kim 
AuthorDate: Thu, 22 Dec 2016 15:03:50 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 27 Dec 2016 21:47:57 -0300

perf sched timehist: Show total scheduling time

Show length of analyzed sample time and rate of idle task running.
This also takes care of time range given by --time option.

  $ perf sched timehist -sI | tail
  Samples do not have callchains.
  Idle stats:
  CPU  0 idle for930.316  msec  ( 92.93%)
  CPU  1 idle for963.614  msec  ( 96.25%)
  CPU  2 idle for885.482  msec  ( 88.45%)
  CPU  3 idle for938.635  msec  ( 93.76%)

  Total number of unique tasks: 118
  Total number of context switches: 2337
 Total run time (msec): 3718.048
  Total scheduling time (msec): 1001.131  (x 4)

Suggested-by: David Ahern 
Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161222060350.17655-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index d53e706..5b134b0 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -209,6 +209,7 @@ struct perf_sched {
u64 skipped_samples;
const char  *time_str;
struct perf_time_interval ptime;
+   struct perf_time_interval hist_time;
 };
 
 /* per thread run time data */
@@ -2460,6 +2461,11 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
timehist_print_sample(sched, sample, &al, thread, t);
 
 out:
+   if (sched->hist_time.start == 0 && t >= ptime->start)
+   sched->hist_time.start = t;
+   if (ptime->end == 0 || t <= ptime->end)
+   sched->hist_time.end = t;
+
if (tr) {
/* time of this sched_switch event becomes last time task seen 
*/
tr->last_time = sample->time;
@@ -2624,6 +2630,7 @@ static void timehist_print_summary(struct perf_sched 
*sched,
struct thread *t;
struct thread_runtime *r;
int i;
+   u64 hist_time = sched->hist_time.end - sched->hist_time.start;
 
memset(&totals, 0, sizeof(totals));
 
@@ -2665,7 +2672,7 @@ static void timehist_print_summary(struct perf_sched 
*sched,
totals.sched_count += r->run_stats.n;
printf("CPU %2d idle for ", i);
print_sched_time(r->total_run_time, 6);
-   printf(" msec\n");
+   printf(" msec  (%6.2f%%)\n", 100.0 * r->total_run_time 
/ hist_time);
} else
printf("CPU %2d idle entire time window\n", i);
}
@@ -2701,12 +2708,16 @@ static void timehist_print_summary(struct perf_sched 
*sched,
 
printf("\n"
   "Total number of unique tasks: %" PRIu64 "\n"
-  "Total number of context switches: %" PRIu64 "\n"
-  "   Total run time (msec): ",
+  "Total number of context switches: %" PRIu64 "\n",
   totals.task_count, totals.sched_count);
 
+   printf("   Total run time (msec): ");
print_sched_time(totals.total_run_time, 2);
printf("\n");
+
+   printf("Total scheduling time (msec): ");
+   print_sched_time(hist_time, 2);
+   printf(" (x %d)\n", sched->max_cpu);
 }
 
 typedef int (*sched_handler)(struct perf_tool *tool,


[tip:perf/urgent] perf sched timehist: Remove hardcoded 'comm_width' check at print_summary

2016-12-23 Thread tip-bot for Namhyung Kim
Commit-ID:  4fa0d1aa2711a5053fb2422331bdf6bce99b5f87
Gitweb: http://git.kernel.org/tip/4fa0d1aa2711a5053fb2422331bdf6bce99b5f87
Author: Namhyung Kim 
AuthorDate: Thu, 22 Dec 2016 15:03:48 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 22 Dec 2016 16:35:46 -0300

perf sched timehist: Remove hardcoded 'comm_width' check at print_summary

Now that the default 'comm_width' value is 30, no need to check that at
print_summary,

Signed-off-by: Namhyung Kim 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161222060350.17655-1-namhy...@kernel.org
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c65f16c..5052caa 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2627,9 +2627,6 @@ static void timehist_print_summary(struct perf_sched 
*sched,
 
memset(&totals, 0, sizeof(totals));
 
-   if (comm_width < 30)
-   comm_width = 30;
-
if (sched->idle_hist) {
printf("\nIdle-time summary\n");
printf("%*s  parent  sched-out  ", comm_width, "comm");


[tip:perf/urgent] perf sched timehist: Enlarge default 'comm_width'

2016-12-23 Thread tip-bot for Namhyung Kim
Commit-ID:  9b8087d72086b249ff744cee237ad12cc5e9255d
Gitweb: http://git.kernel.org/tip/9b8087d72086b249ff744cee237ad12cc5e9255d
Author: Namhyung Kim 
AuthorDate: Thu, 22 Dec 2016 15:03:48 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 22 Dec 2016 16:35:45 -0300

perf sched timehist: Enlarge default 'comm_width'

Current default value is 20 but it's easily changed to a bigger value as
task has a long name and different tid and pid.  And it makes the output
not aligned.  So change it to have a large value as summary shows.

Committer notes:

Before:

  # perf sched record
  ^C
  # perf sched timehist
  
40602.770537 [0001]  rcuos/2[29]   7.970  0.002  0.020
40602.771512 [0003]  0.003  0.000  0.986
40602.771586 [0001]  0.020  0.000  1.049
40602.771606 [0001]  qemu-system-x86[3593/3510]  0.000  0.002  
0.020
40602.771629 [0003]  qemu-system-x86[3510]   0.000  0.003  
0.116
40602.771776 []0.001  0.000  
1.892
  

After:

  # perf sched timehist
  
   40602.770537 [0001]  rcuos/2[29] 7.970  0.002
  0.020
   40602.771512 [0003]0.003  0.000
  0.986
   40602.771586 [0001]0.020  0.000
  1.049
   40602.771606 [0001]  qemu-system-x86[3593/3510]  0.000  0.002
  0.020
   40602.771629 [0003]  qemu-system-x86[3510]   0.000  0.003
  0.116
  

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161222060350.17655-1-namhy...@kernel.org
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 020f9c9..c65f16c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1775,7 +1775,7 @@ static u64 perf_evsel__get_time(struct perf_evsel *evsel, 
u32 cpu)
return r->last_time[cpu];
 }
 
-static int comm_width = 20;
+static int comm_width = 30;
 
 static char *timehist_get_commstr(struct thread *thread)
 {


[tip:perf/urgent] perf sched timehist: Fix invalid period calculation

2016-12-23 Thread tip-bot for Namhyung Kim
Commit-ID:  bdd75729e5d279d734e8d3fb41ef4818ac1598ab
Gitweb: http://git.kernel.org/tip/bdd75729e5d279d734e8d3fb41ef4818ac1598ab
Author: Namhyung Kim 
AuthorDate: Thu, 22 Dec 2016 15:03:49 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 22 Dec 2016 16:35:46 -0300

perf sched timehist: Fix invalid period calculation

When --time option is given with a value outside recorded time, the last
sample time (tprev) was set to that value and run time calculation might
be incorrect.  This is a problem of the first samples for each cpus
since it would skip the runtime update when tprev is 0.  But with --time
option it had non-zero (which is invalid) value so the calculation is
also incorrect.

For example, let's see the followging:

  $ perf sched timehist
 timecpu  task name   wait time  sch delay  
 run time
  [tid/pid]  (msec) (msec)  
   (msec)
  --- --  --  -  -  
-
  3195.968367 [0003]0.000  0.000  
0.000
  3195.968386 [0002]  Timer[4306/4277]0.000  0.000  
0.018
  3195.968397 [0002]  Web Content[4277]   0.000  0.000  
0.000
  3195.968595 [0001]  JS Helper[4302/4277]0.000  0.000  
0.000
  3195.969217 []0.000  0.000  
0.621
  3195.969251 [0001]  kworker/1:1H[291]   0.000  0.000  
0.033

The sample starts at 3195.968367 but when I gave a time interval from
3194 to 3196 (in sec) it will calculate the whole 2 second as runtime.
In below, 2 cpus accounted it as runtime, other 2 cpus accounted it as
idle time.

Before:

  $ perf sched timehist --time 3194,3196 -s | tail
  Idle stats:
  CPU  0 idle for   1995.991  msec
  CPU  1 idle for 20.793  msec
  CPU  2 idle for 30.191  msec
  CPU  3 idle for   1999.852  msec

  Total number of unique tasks: 23
  Total number of context switches: 128
 Total run time (msec): 3724.940

After:

  $ perf sched timehist --time 3194,3196 -s | tail
  Idle stats:
  CPU  0 idle for 10.811  msec
  CPU  1 idle for 20.793  msec
  CPU  2 idle for 30.191  msec
  CPU  3 idle for 18.337  msec

  Total number of unique tasks: 23
  Total number of context switches: 128
 Total run time (msec): 18.139

Committer notes:

Further testing:

Before:

  Idle stats:
  CPU  0 idle for229.785  msec
  CPU  1 idle for937.944  msec
  CPU  2 idle for188.931  msec
  CPU  3 idle for986.185  msec

  After:

  # perf sched timehist --time 40602,40603 -s | tail

  Idle stats:
  CPU  0 idle for229.785  msec
  CPU  1 idle for175.407  msec
  CPU  2 idle for188.931  msec
  CPU  3 idle for223.657  msec

  Total number of unique tasks: 68
  Total number of context switches: 814
 Total run time (msec): 97.688

  # for cpu in `seq 0 3` ; do echo -n "CPU $cpu idle for " ; perf sched 
timehist --time 40602,40603 | grep "\[000${cpu}\].*\" | tr -s ' ' | cut 
-d' ' -f7 | awk '{entries++ ; s+=$1} END {print s " msec (entries: " entries 
")"}' ; done
  CPU 0 idle for 229.721 msec (entries: 123)
  CPU 1 idle for 175.381 msec (entries: 65)
  CPU 2 idle for 188.903 msec (entries: 56)
  CPU 3 idle for 223.61 msec (entries: 102)

Difference due to the idle stats being accounted at nanoseconds precision while
the  entries in 'perf sched timehist' are trucated at msec.usec.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: 853b74071110 ("perf sched timehist: Add option to specify time window of 
interest")
Link: http://lkml.kernel.org/r/20161222060350.17655-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 5052caa..d53e706 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2405,7 +2405,7 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
if (ptime->start && ptime->start > t)
goto out;
 
-   if (ptime->start > tprev)
+   if (tprev && ptime->start > tprev)
tprev = ptime->start;
 
/*


[tip:perf/urgent] perf sched timehist: Honour 'comm_width' when aligning the headers

2016-12-23 Thread tip-bot for Namhyung Kim
Commit-ID:  0e6758e8231d5905c2e267566e9bd679a68a7b00
Gitweb: http://git.kernel.org/tip/0e6758e8231d5905c2e267566e9bd679a68a7b00
Author: Namhyung Kim 
AuthorDate: Thu, 22 Dec 2016 15:03:48 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 22 Dec 2016 16:35:45 -0300

perf sched timehist: Honour 'comm_width' when aligning the headers

Current default value is 20, but that may change in the future, so make
places where we have 20 hardcoded use 'comm_width'.

Signed-off-by: Namhyung Kim 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161222060350.17655-1-namhy...@kernel.org
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c1c07bf..020f9c9 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1817,7 +1817,7 @@ static void timehist_header(struct perf_sched *sched)
printf(" ");
}
 
-   printf(" %-20s  %9s  %9s  %9s",
+   printf(" %-*s  %9s  %9s  %9s", comm_width,
"task name", "wait time", "sch delay", "run time");
 
printf("\n");
@@ -1830,7 +1830,8 @@ static void timehist_header(struct perf_sched *sched)
if (sched->show_cpu_visual)
printf(" %*s ", ncpus, "");
 
-   printf(" %-20s  %9s  %9s  %9s\n", "[tid/pid]", "(msec)", "(msec)", 
"(msec)");
+   printf(" %-*s  %9s  %9s  %9s\n", comm_width,
+  "[tid/pid]", "(msec)", "(msec)", "(msec)");
 
/*
 * separator
@@ -1840,7 +1841,7 @@ static void timehist_header(struct perf_sched *sched)
if (sched->show_cpu_visual)
printf(" %.*s ", ncpus, graph_dotted_line);
 
-   printf(" %.20s  %.9s  %.9s  %.9s",
+   printf(" %.*s  %.9s  %.9s  %.9s", comm_width,
graph_dotted_line, graph_dotted_line, graph_dotted_line,
graph_dotted_line);
 


[tip:perf/urgent] perf sched timehist: Save callchain when entering idle

2016-12-20 Thread tip-bot for Namhyung Kim
Commit-ID:  699b5b920db04a6ff5c03a519e4c182aeb350952
Gitweb: http://git.kernel.org/tip/699b5b920db04a6ff5c03a519e4c182aeb350952
Author: Namhyung Kim 
AuthorDate: Thu, 8 Dec 2016 23:47:52 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 15 Dec 2016 16:25:44 -0300

perf sched timehist: Save callchain when entering idle

In order to investigate the idleness reason, it is necessary to keep the
callchains when entering idle.  This can be identified by the
sched:sched_switch event having the next_pid field as 0.

Signed-off-by: Namhyung Kim 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161208144755.16673-4-namhy...@kernel.org
Link: http://lkml.kernel.org/r/20161213080632.19099-1-namhy...@kernel.org
[ Merged fix from Namhyung, see second Link: tag ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index e108b0f..dc83b80 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -200,6 +200,7 @@ struct perf_sched {
/* options for timehist command */
boolsummary;
boolsummary_only;
+   boolidle_hist;
boolshow_callchain;
unsigned intmax_stack;
boolshow_cpu_visual;
@@ -2101,6 +2102,15 @@ static struct thread *get_idle_thread(int cpu)
return idle_threads[cpu];
 }
 
+static void save_idle_callchain(struct idle_thread_runtime *itr,
+   struct perf_sample *sample)
+{
+   if (!symbol_conf.use_callchain || sample->callchain == NULL)
+   return;
+
+   callchain_cursor__copy(&itr->cursor, &callchain_cursor);
+}
+
 /*
  * handle runtime stats saved per thread
  */
@@ -2154,6 +2164,26 @@ static struct thread *timehist_get_thread(struct 
perf_sched *sched,
}
 
save_task_callchain(sched, sample, evsel, machine);
+   if (sched->idle_hist) {
+   struct thread *idle;
+   struct idle_thread_runtime *itr;
+
+   idle = get_idle_thread(sample->cpu);
+   if (idle == NULL) {
+   pr_err("Failed to get idle thread for cpu 
%d.\n", sample->cpu);
+   return NULL;
+   }
+
+   itr = thread__priv(idle);
+   if (itr == NULL)
+   return NULL;
+
+   itr->last_thread = thread;
+
+   /* copy task callchain when entering to idle */
+   if (perf_evsel__intval(evsel, sample, "next_pid") == 0)
+   save_idle_callchain(itr, sample);
+   }
}
 
return thread;


[tip:perf/urgent] perf sched timehist: Introduce struct idle_time_data

2016-12-20 Thread tip-bot for Namhyung Kim
Commit-ID:  3bc2fa9cb829ccf6527e7117d9af769d93ee6d39
Gitweb: http://git.kernel.org/tip/3bc2fa9cb829ccf6527e7117d9af769d93ee6d39
Author: Namhyung Kim 
AuthorDate: Thu, 8 Dec 2016 23:47:51 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 15 Dec 2016 16:25:44 -0300

perf sched timehist: Introduce struct idle_time_data

The struct idle_time_data is to keep idle stats with callchains entering
to the idle task.  The normal thread_runtime calculation is done
transparently since it extends the struct thread_runtime.

Signed-off-by: Namhyung Kim 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161208144755.16673-3-namhy...@kernel.org
[ Align struct field names ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 37 +
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 966eddc..e108b0f 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -230,6 +230,15 @@ struct evsel_runtime {
u32 ncpu;   /* highest cpu slot allocated */
 };
 
+/* per cpu idle time data */
+struct idle_thread_runtime {
+   struct thread_runtime   tr;
+   struct thread   *last_thread;
+   struct rb_root  sorted_root;
+   struct callchain_root   callchain;
+   struct callchain_cursor cursor;
+};
+
 /* track idle times per cpu */
 static struct thread **idle_threads;
 static int idle_max_cpu;
@@ -1997,13 +2006,31 @@ static void save_task_callchain(struct perf_sched 
*sched,
}
 }
 
+static int init_idle_thread(struct thread *thread)
+{
+   struct idle_thread_runtime *itr;
+
+   thread__set_comm(thread, idle_comm, 0);
+
+   itr = zalloc(sizeof(*itr));
+   if (itr == NULL)
+   return -ENOMEM;
+
+   init_stats(&itr->tr.run_stats);
+   callchain_init(&itr->callchain);
+   callchain_cursor_reset(&itr->cursor);
+   thread__set_priv(thread, itr);
+
+   return 0;
+}
+
 /*
  * Track idle stats per cpu by maintaining a local thread
  * struct for the idle task on each cpu.
  */
 static int init_idle_threads(int ncpu)
 {
-   int i;
+   int i, ret;
 
idle_threads = zalloc(ncpu * sizeof(struct thread *));
if (!idle_threads)
@@ -2017,7 +2044,9 @@ static int init_idle_threads(int ncpu)
if (idle_threads[i] == NULL)
return -ENOMEM;
 
-   thread__set_comm(idle_threads[i], idle_comm, 0);
+   ret = init_idle_thread(idle_threads[i]);
+   if (ret < 0)
+   return ret;
}
 
return 0;
@@ -2064,8 +2093,8 @@ static struct thread *get_idle_thread(int cpu)
idle_threads[cpu] = thread__new(0, 0);
 
if (idle_threads[cpu]) {
-   idle_threads[cpu]->tid = 0;
-   thread__set_comm(idle_threads[cpu], idle_comm, 0);
+   if (init_idle_thread(idle_threads[cpu]) < 0)
+   return NULL;
}
}
 


[tip:perf/urgent] perf sched timehist: Skip non-idle events when necessary

2016-12-20 Thread tip-bot for Namhyung Kim
Commit-ID:  a4b2b6f56e0cfe729cf89318d44b6a875b31d95a
Gitweb: http://git.kernel.org/tip/a4b2b6f56e0cfe729cf89318d44b6a875b31d95a
Author: Namhyung Kim 
AuthorDate: Thu, 8 Dec 2016 23:47:53 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 15 Dec 2016 16:25:44 -0300

perf sched timehist: Skip non-idle events when necessary

Sometimes it only focuses on idle-related events like upcoming idle-hist
feature.  In this case we don't want to see other event to reduce noise.

Signed-off-by: Namhyung Kim 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161208144755.16673-5-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index dc83b80..c8e7848 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2190,7 +2190,9 @@ static struct thread *timehist_get_thread(struct 
perf_sched *sched,
 }
 
 static bool timehist_skip_sample(struct perf_sched *sched,
-struct thread *thread)
+struct thread *thread,
+struct perf_evsel *evsel,
+struct perf_sample *sample)
 {
bool rc = false;
 
@@ -2199,10 +2201,19 @@ static bool timehist_skip_sample(struct perf_sched 
*sched,
sched->skipped_samples++;
}
 
+   if (sched->idle_hist) {
+   if (strcmp(perf_evsel__name(evsel), "sched:sched_switch"))
+   rc = true;
+   else if (perf_evsel__intval(evsel, sample, "prev_pid") != 0 &&
+perf_evsel__intval(evsel, sample, "next_pid") != 0)
+   rc = true;
+   }
+
return rc;
 }
 
 static void timehist_print_wakeup_event(struct perf_sched *sched,
+   struct perf_evsel *evsel,
struct perf_sample *sample,
struct machine *machine,
struct thread *awakened)
@@ -2215,8 +2226,8 @@ static void timehist_print_wakeup_event(struct perf_sched 
*sched,
return;
 
/* show wakeup unless both awakee and awaker are filtered */
-   if (timehist_skip_sample(sched, thread) &&
-   timehist_skip_sample(sched, awakened)) {
+   if (timehist_skip_sample(sched, thread, evsel, sample) &&
+   timehist_skip_sample(sched, awakened, evsel, sample)) {
return;
}
 
@@ -2261,7 +2272,7 @@ static int timehist_sched_wakeup_event(struct perf_tool 
*tool,
/* show wakeups if requested */
if (sched->show_wakeups &&
!perf_time__skip_sample(&sched->ptime, sample->time))
-   timehist_print_wakeup_event(sched, sample, machine, thread);
+   timehist_print_wakeup_event(sched, evsel, sample, machine, 
thread);
 
return 0;
 }
@@ -2288,8 +2299,8 @@ static void timehist_print_migration_event(struct 
perf_sched *sched,
if (thread == NULL)
return;
 
-   if (timehist_skip_sample(sched, thread) &&
-   timehist_skip_sample(sched, migrated)) {
+   if (timehist_skip_sample(sched, thread, evsel, sample) &&
+   timehist_skip_sample(sched, migrated, evsel, sample)) {
return;
}
 
@@ -2374,7 +2385,7 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
goto out;
}
 
-   if (timehist_skip_sample(sched, thread))
+   if (timehist_skip_sample(sched, thread, evsel, sample))
goto out;
 
tr = thread__get_runtime(thread);


[tip:perf/urgent] perf sched timehist: Split is_idle_sample()

2016-12-20 Thread tip-bot for Namhyung Kim
Commit-ID:  96039c7c52e03b7d6dd773664e74b79e3ae9856a
Gitweb: http://git.kernel.org/tip/96039c7c52e03b7d6dd773664e74b79e3ae9856a
Author: Namhyung Kim 
AuthorDate: Thu, 8 Dec 2016 23:47:50 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 15 Dec 2016 16:25:44 -0300

perf sched timehist: Split is_idle_sample()

The is_idle_sample() function actually does more than determining
whether sample come from idle task.  Split the callchain part into
save_task_callchain() to make it clearer.

Also checking prev_pid from trace data looks preferred than just
checking sample->pid since it's possible, although rare, to have invalid
0 pid/tid on scheduling an exiting task.

Signed-off-by: Namhyung Kim 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161208144755.16673-2-namhy...@kernel.org
[ Remove some needless () in some return statements ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 39 ---
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 1a3f1be..966eddc 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1939,39 +1939,40 @@ static void timehist_update_runtime_stats(struct 
thread_runtime *r,
r->total_run_time += r->dt_run;
 }
 
-static bool is_idle_sample(struct perf_sched *sched,
-  struct perf_sample *sample,
-  struct perf_evsel *evsel,
-  struct machine *machine)
+static bool is_idle_sample(struct perf_sample *sample,
+  struct perf_evsel *evsel)
 {
-   struct thread *thread;
-   struct callchain_cursor *cursor = &callchain_cursor;
-
/* pid 0 == swapper == idle task */
-   if (sample->pid == 0)
-   return true;
+   if (strcmp(perf_evsel__name(evsel), "sched:sched_switch") == 0)
+   return perf_evsel__intval(evsel, sample, "prev_pid") == 0;
 
-   if (strcmp(perf_evsel__name(evsel), "sched:sched_switch") == 0) {
-   if (perf_evsel__intval(evsel, sample, "prev_pid") == 0)
-   return true;
-   }
+   return sample->pid == 0;
+}
+
+static void save_task_callchain(struct perf_sched *sched,
+   struct perf_sample *sample,
+   struct perf_evsel *evsel,
+   struct machine *machine)
+{
+   struct callchain_cursor *cursor = &callchain_cursor;
+   struct thread *thread;
 
/* want main thread for process - has maps */
thread = machine__findnew_thread(machine, sample->pid, sample->pid);
if (thread == NULL) {
pr_debug("Failed to get thread for pid %d.\n", sample->pid);
-   return false;
+   return;
}
 
if (!symbol_conf.use_callchain || sample->callchain == NULL)
-   return false;
+   return;
 
if (thread__resolve_callchain(thread, cursor, evsel, sample,
  NULL, NULL, sched->max_stack + 2) != 0) {
if (verbose)
error("Failed to resolve callchain. Skipping\n");
 
-   return false;
+   return;
}
 
callchain_cursor_commit(cursor);
@@ -1994,8 +1995,6 @@ static bool is_idle_sample(struct perf_sched *sched,
 
callchain_cursor_advance(cursor);
}
-
-   return false;
 }
 
 /*
@@ -2111,7 +2110,7 @@ static struct thread *timehist_get_thread(struct 
perf_sched *sched,
 {
struct thread *thread;
 
-   if (is_idle_sample(sched, sample, evsel, machine)) {
+   if (is_idle_sample(sample, evsel)) {
thread = get_idle_thread(sample->cpu);
if (thread == NULL)
pr_err("Failed to get idle thread for cpu %d.\n", 
sample->cpu);
@@ -2124,6 +2123,8 @@ static struct thread *timehist_get_thread(struct 
perf_sched *sched,
pr_debug("Failed to get thread for tid %d. skipping 
sample.\n",
 sample->tid);
}
+
+   save_task_callchain(sched, sample, evsel, machine);
}
 
return thread;


[tip:perf/urgent] perf sched timehist: Add -I/--idle-hist option

2016-12-20 Thread tip-bot for Namhyung Kim
Commit-ID:  07235f84ece6b66f43334881806aad3467cf3d84
Gitweb: http://git.kernel.org/tip/07235f84ece6b66f43334881806aad3467cf3d84
Author: Namhyung Kim 
AuthorDate: Thu, 8 Dec 2016 23:47:54 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 15 Dec 2016 16:25:45 -0300

perf sched timehist: Add -I/--idle-hist option

The --idle-hist option is to analyze system idle state so which process
makes cpu to go idle.  If this option is specified, non-idle events will
be skipped and processes switching to/from idle will be shown.

This option is mostly useful when used with --summary(-only) option.  In
the idle-time summary view, idle time is accounted to previous thread
which is run before idle task.

The example output looks like following:

  Idle-time summary
  comm parent sched-out idle-time min-idle avg-idle max-idle 
stddev migrations
(count)(msec)   (msec)   (msec)   (msec)
  %
  

rcu_preempt[7]  295   550.8720.0115.798   23.146   
7.63  0
   migration/1[16]  2 115.558   15.558   15.558   15.558   
0.00  0
khugepaged[39]  2 1 3.0623.0623.0623.062   
0.00  0
 kworker/0:1H[124]  2 2 4.7280.6112.3644.116  
74.12  0
  systemd-journal[167]  1 1 4.5104.5104.5104.510   
0.00  0
kworker/u16:3[558]  21374.7370.0805.749   12.960  
21.96  0
   irq/34-iwlwifi[628]  221   118.4030.0325.638   23.990  
24.00  0
kworker/u17:0[673]  2 1 3.5233.5233.5233.523   
0.00  0
  dbus-daemon[722]  1 1 6.7436.7436.7436.743   
0.00  0
  ifplugd[741]  1 158.826   58.826   58.826   58.826   
0.00  0
  wpa_supplicant[1490]  1 113.302   13.302   13.302   13.302   
0.00  0
 wpa_actiond[1492]  1 2 4.0640.1682.0323.896  
91.72  0
 dockerd[1500]  1 1 0.0550.0550.0550.055   
0.00  0
  ...

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161208144755.16673-6-namhy...@kernel.org
Link: http://lkml.kernel.org/r/20161213080632.19099-2-namhy...@kernel.org
[ Merged fix sent by Namhyumg, as posted in the second Link: tag ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-sched.txt |  4 +++
 tools/perf/builtin-sched.c  | 46 +
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt 
b/tools/perf/Documentation/perf-sched.txt
index 7775b1e..7617396 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -132,6 +132,10 @@ OPTIONS for 'perf sched timehist'
 --migrations::
Show migration events.
 
+-I::
+--idle-hist::
+   Show idle-related events only.
+
 --time::
Only analyze samples within given time window: ,. Times
have the format seconds.microseconds. If start is not given (i.e., time
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c8e7848..0b14265 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2421,7 +2421,36 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
t = ptime->end;
}
 
-   timehist_update_runtime_stats(tr, t, tprev);
+   if (!sched->idle_hist || thread->tid == 0) {
+   timehist_update_runtime_stats(tr, t, tprev);
+
+   if (sched->idle_hist) {
+   struct idle_thread_runtime *itr = (void *)tr;
+   struct thread_runtime *last_tr;
+
+   BUG_ON(thread->tid != 0);
+
+   if (itr->last_thread == NULL)
+   goto out;
+
+   /* add current idle time as last thread's runtime */
+   last_tr = thread__get_runtime(itr->last_thread);
+   if (last_tr == NULL)
+   goto out;
+
+   timehist_update_runtime_stats(last_tr, t, tprev);
+   /*
+* remove delta time of last thread as it's not updated
+* and otherwise it will show an invalid value next
+* time.  we only care total run time and run stat.
+*/
+   last_tr->dt_run = 0;
+   last_tr->dt_wait = 0;
+   last_tr->dt_delay = 0;
+
+   itr->last_thread = NULL;
+   }
+ 

[tip:perf/urgent] perf sched timehist: Show callchains for idle stat

2016-12-20 Thread tip-bot for Namhyung Kim
Commit-ID:  ba957ebb54893acaf3dc846031073a63f021cee1
Gitweb: http://git.kernel.org/tip/ba957ebb54893acaf3dc846031073a63f021cee1
Author: Namhyung Kim 
AuthorDate: Thu, 8 Dec 2016 23:47:55 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 15 Dec 2016 16:25:45 -0300

perf sched timehist: Show callchains for idle stat

When --idle-hist option is used with --summary, it now shows idle stats
with callchains like below:

  Idle stats by callchain:
  CPU  0:   902.195 msec
  Idle time (msec)Count Callchains
    --- --
   370.589   69 futex_wait_queue_me <- futex_wait <- do_futex <- 
sys_futex <- entry_SYSCALL_64_fastpath
   178.799   17 worker_thread <- kthread <- ret_from_fork
   128.352   17 schedule_timeout <- rcu_gp_kthread <- kthread <- 
ret_from_fork
   125.111   19 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- poll_schedule_timeout <- do_select <- 
core_sys_select
71.599   50 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- poll_schedule_timeout <- do_sys_poll <- sys_poll
23.1461 rcu_gp_kthread <- kthread <- ret_from_fork
 4.5101 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- ep_poll <- sys_epoll_wait <- do_syscall_64
 0.0851 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- poll_schedule_timeout <- do_sys_poll <- 
do_restart_poll
  ...

Committer notes:

Extra testing:

  # uname -a
  Linux jouet 4.8.8-300.fc25.x86_64 #1 SMP Tue Nov 15 18:10:06 UTC 2016 x86_64 
x86_64 x86_64 GNU/Linux

1) Run 'perf sched record -g'

2) Run 'perf sched timehist --idle --summary'


  Idle stats by callchain:
  CPU  0: 13456.840 msec
  Idle time (msec) Count Callchains
   - --
  5386.637  3283 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- poll_schedule_timeout <- do_sys_poll <- sys_poll
  2750.238  2299 futex_wait_queue_me <- futex_wait <- do_futex <- 
sys_futex <- do_syscall_64
  1275.672  1287 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- ep_poll <- sys_epoll_wait <- 
entry_SYSCALL_64_fastpath
   936.322   452 worker_thread <- kthread <- ret_from_fork
   741.311   385 rcu_nocb_kthread <- kthread <- ret_from_fork
   729.385   248 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- poll_schedule_timeout <- do_sys_poll <- sys_ppoll
   365.386   229 irq_thread <- kthread <- ret_from_fork
   338.934   265 futex_wait_queue_me <- futex_wait <- do_futex <- 
sys_futex <- entry_SYSCALL_64_fastpath
   219.488   201 schedule_timeout <- rcu_gp_kthread <- kthread <- 
ret_from_fork
   186.839   410 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- ep_poll <- sys_epoll_wait <- do_syscall_64
   142.54159 kvm_vcpu_block <- kvm_arch_vcpu_ioctl_run <- 
kvm_vcpu_ioctl <- do_vfs_ioctl <- sys_ioctl
83.88792 smpboot_thread_fn <- kthread <- ret_from_fork
62.72296 do_exit <- do_group_exit <- 0x2a5594 <- 
entry_SYSCALL_64_fastpath
47.89483 pipe_wait <- pipe_read <- __vfs_read <- vfs_read <- 
sys_read
46.55461 rcu_gp_kthread <- kthread <- ret_from_fork
34.33721 schedule_timeout <- intel_fbc_work_fn <- 
process_one_work <- worker_thread <- kthread
29.52114 schedule_hrtimeout_range_clock <- 
schedule_hrtimeout_range <- poll_schedule_timeout <- do_select <- 
core_sys_select
20.27410 schedule_timeout <- io_schedule_timeout <- bit_wait_io 
<- __wait_on_bit <- out_of_line_wait_on_bit
15.08555 schedule_timeout <- unix_stream_read_generic <- 
unix_stream_recvmsg <- sock_recvmsg <- SYSC_recvfrom


Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161208144755.16673-7-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 86 ++
 1 file changed, 86 insertions(+)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 0b14265..c1c07bf 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2448,6 +2448,9 @@ static int timehist_sched_change_event(struct perf_tool 
*tool,
last_tr->dt_wait = 0;
last_tr->dt_delay = 0;
 
+   if (itr->cursor.nr)
+   callchain_append(&itr->callchain, &itr->cursor, 
t - tprev);
+
itr->last_thread = NULL;
}
}
@@ -2557,6 +2560,60 @@ static int show_deadthread_runtime(struct thread *t, 
void *priv)
return __show_thread_run

[tip:perf/core] perf sched: Cleanup option processing

2016-12-07 Thread tip-bot for Namhyung Kim
Commit-ID:  6fa94258ce2673adc707b2ec5668464f2cf83ed3
Gitweb: http://git.kernel.org/tip/6fa94258ce2673adc707b2ec5668464f2cf83ed3
Author: Namhyung Kim 
AuthorDate: Tue, 6 Dec 2016 12:40:01 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 7 Dec 2016 12:00:33 -0300

perf sched: Cleanup option processing

The -D/--dump-raw-trace option is in the parent option so no need to
repeat it.  Also move -f/--force option to parent as it's common to
handle data file.

Signed-off-by: Namhyung Kim 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161206034010.6499-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 84c39f1..634d8cf 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2583,6 +2583,7 @@ static int perf_sched__timehist(struct perf_sched *sched)
struct perf_data_file file = {
.path = input_name,
.mode = PERF_DATA_MODE_READ,
+   .force = sched->force,
};
 
struct perf_session *session;
@@ -2988,6 +2989,7 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
"be more verbose (show symbol address, etc)"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
+   OPT_BOOLEAN('f', "force", &sched.force, "don't complain, do it"),
OPT_END()
};
const struct option latency_options[] = {
@@ -2995,8 +2997,6 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
   "sort by key(s): runtime, switch, avg, max"),
OPT_INTEGER('C', "CPU", &sched.profile_cpu,
"CPU to profile on"),
-   OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
-   "dump raw trace in ASCII"),
OPT_BOOLEAN('p', "pids", &sched.skip_merge,
"latency stats per pid instead of per comm"),
OPT_PARENT(sched_options)
@@ -3004,9 +3004,6 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
const struct option replay_options[] = {
OPT_UINTEGER('r', "repeat", &sched.replay_repeat,
 "repeat the workload replay N times (-1: infinite)"),
-   OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
-   "dump raw trace in ASCII"),
-   OPT_BOOLEAN('f', "force", &sched.force, "don't complain, do it"),
OPT_PARENT(sched_options)
};
const struct option map_options[] = {


[tip:perf/core] perf callchain: Introduce callchain_cursor__copy()

2016-12-07 Thread tip-bot for Namhyung Kim
Commit-ID:  571f1eb9b967a52732d2e1f41f1b62e27c900325
Gitweb: http://git.kernel.org/tip/571f1eb9b967a52732d2e1f41f1b62e27c900325
Author: Namhyung Kim 
AuthorDate: Tue, 6 Dec 2016 12:40:02 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 7 Dec 2016 12:00:33 -0300

perf callchain: Introduce callchain_cursor__copy()

The callchain_cursor__copy() function is to save current callchain
captured by a cursor.  It'll be used to keep callchains when switching
to idle task for each cpu.

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161206034010.6499-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/callchain.c | 27 +++
 tools/perf/util/callchain.h |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 823befd..4292251 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -1234,3 +1234,30 @@ out:
}
return -ENOMEM;
 }
+
+int callchain_cursor__copy(struct callchain_cursor *dst,
+  struct callchain_cursor *src)
+{
+   int rc = 0;
+
+   callchain_cursor_reset(dst);
+   callchain_cursor_commit(src);
+
+   while (true) {
+   struct callchain_cursor_node *node;
+
+   node = callchain_cursor_current(src);
+   if (node == NULL)
+   break;
+
+   rc = callchain_cursor_append(dst, node->ip, node->map, 
node->sym,
+node->branch, &node->branch_flags,
+node->nr_loop_iter, node->samples);
+   if (rc)
+   break;
+
+   callchain_cursor_advance(src);
+   }
+
+   return rc;
+}
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index d9c70dc..35c8e37 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -216,6 +216,9 @@ static inline void callchain_cursor_advance(struct 
callchain_cursor *cursor)
cursor->pos++;
 }
 
+int callchain_cursor__copy(struct callchain_cursor *dst,
+  struct callchain_cursor *src);
+
 struct option;
 struct hist_entry;
 


[tip:perf/core] perf sched timehist: Handle zero sample->tid properly

2016-12-07 Thread tip-bot for Namhyung Kim
Commit-ID:  5d92d96a947a5d0d83710d11750bb29a0c1b985d
Gitweb: http://git.kernel.org/tip/5d92d96a947a5d0d83710d11750bb29a0c1b985d
Author: Namhyung Kim 
AuthorDate: Tue, 6 Dec 2016 12:40:03 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 7 Dec 2016 12:00:34 -0300

perf sched timehist: Handle zero sample->tid properly

Sometimes samples have tid of 0 but non-0 pid.  It ends up having a new
thread of 0 tid/pid (instead of referring idle task) since tid is used
to search matching task.  But I guess it's wrong to use 0 as a tid when
pid is set.  This patch uses tid only if it has a non-zero value or same
as pid (of 0).

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161206034010.6499-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 634d8cf..c8b3e6c 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2118,7 +2118,9 @@ static struct thread *timehist_get_thread(struct 
perf_sched *sched,
pr_err("Failed to get idle thread for cpu %d.\n", 
sample->cpu);
 
} else {
-   thread = machine__findnew_thread(machine, sample->pid, 
sample->tid);
+   /* there were samples with tid 0 but non-zero pid */
+   thread = machine__findnew_thread(machine, sample->pid,
+sample->tid ?: sample->pid);
if (thread == NULL) {
pr_debug("Failed to get thread for tid %d. skipping 
sample.\n",
 sample->tid);


[tip:perf/core] perf sched timehist: Cleanup idle_max_cpu handling

2016-12-07 Thread tip-bot for Namhyung Kim
Commit-ID:  b336352b417edd8c058c9e09d136728b6e2ff56d
Gitweb: http://git.kernel.org/tip/b336352b417edd8c058c9e09d136728b6e2ff56d
Author: Namhyung Kim 
AuthorDate: Tue, 6 Dec 2016 12:40:05 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 7 Dec 2016 12:00:34 -0300

perf sched timehist: Cleanup idle_max_cpu handling

It treats the idle_max_cpu little bit confusingly IMHO.  Let's make it
more straight forward.

Signed-off-by: Namhyung Kim 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Minchan Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161206034010.6499-6-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c8b3e6c..1a3f1be 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2010,7 +2010,7 @@ static int init_idle_threads(int ncpu)
if (!idle_threads)
return -ENOMEM;
 
-   idle_max_cpu = ncpu - 1;
+   idle_max_cpu = ncpu;
 
/* allocate the actual thread struct if needed */
for (i = 0; i < ncpu; ++i) {
@@ -2031,7 +2031,7 @@ static void free_idle_threads(void)
if (idle_threads == NULL)
return;
 
-   for (i = 0; i <= idle_max_cpu; ++i) {
+   for (i = 0; i < idle_max_cpu; ++i) {
if ((idle_threads[i]))
thread__delete(idle_threads[i]);
}
@@ -2054,8 +2054,7 @@ static struct thread *get_idle_thread(int cpu)
return NULL;
 
idle_threads = (struct thread **) p;
-   i = idle_max_cpu ? idle_max_cpu + 1 : 0;
-   for (; i < j; ++i)
+   for (i = idle_max_cpu; i < j; ++i)
idle_threads[i] = NULL;
 
idle_max_cpu = j;
@@ -2495,7 +2494,7 @@ static void timehist_print_summary(struct perf_sched 
*sched,
return;
 
printf("\nIdle stats:\n");
-   for (i = 0; i <= idle_max_cpu; ++i) {
+   for (i = 0; i < idle_max_cpu; ++i) {
t = idle_threads[i];
if (!t)
continue;


[tip:perf/core] perf sched timehist: Enlarge max stack depth by 2

2016-11-25 Thread tip-bot for Namhyung Kim
Commit-ID:  8388deb3ba4d36ffcae91a2a01cb2ea6f27553e6
Gitweb: http://git.kernel.org/tip/8388deb3ba4d36ffcae91a2a01cb2ea6f27553e6
Author: Namhyung Kim 
AuthorDate: Thu, 24 Nov 2016 10:11:14 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 25 Nov 2016 10:50:57 -0300

perf sched timehist: Enlarge max stack depth by 2

When it records callchains, they will always have 2 scheduler functions
(__schedule + schedule or __schedule + preempt_schedule) and get
ignored.  So it should collect 2 more functions to show the expected
number of callchains to user.

Committer Notes:

Example of final result, using the same perf.data file as in the
previous cset comment, but this time redirecting the output of 'perf
sched timehist' to a file instead of copy'n'pasting from xterm:

  [root@jouet experimental]# perf sched timehist > /tmp/bla
  [root@jouet experimental]# cat /tmp/bla
  time  cpu task namewait time sch delay run time
 [tid/pid](msec) (msec) (msec)
      -- -- -
  6.494998 [01] 0.000  0.000  0.000
  6.495027 [02] perf[519] 0.000  0.000  0.000 
schedule_hrtimeout_range_clock <- schedule_hrtimeout_range <- 
poll_schedule_timeout <- do_sys_poll <- sys_poll
  6.495096 [03] 0.000  0.000  0.000
  6.495100 [03] rcuos/0[9]0.000  0.005  0.003 rcu_nocb_kthread <- 
kthread <- ret_from_fork
  6.495113 [01] perf[520] 0.000  0.008  0.114 
preempt_schedule_common <- _cond_resched <- wait_for_completion <- stop_one_cpu 
<- sched_exec <- do_execveat_common.isra.35
  6.495121 [00] 0.000  0.000  0.000
  6.495129 [01] migration/1[17]   0.000  0.003  0.016 smpboot_thread_fn <- 
kthread <- ret_from_fork
  6.496085 [02] 0.000  0.000  1.057
  6.496096 [02] kworker/u16:1[31169]  0.000  0.004  0.011 worker_thread <- 
kthread <- ret_from_fork
  6.496096 [03] 0.003  0.000  0.996
  6.496169 [02] 0.011  0.000  0.072
  6.496171 [00] ls[520]   0.008  0.000  1.049 do_exit <- 
do_group_exit <- [unknown] <- entry_SYSCALL_64_fastpath
  6.496172 [03] gnome-terminal-[4391] 0.000  0.003  0.076 
schedule_hrtimeout_range_clock <- schedule_hrtimeout_range <- 
poll_schedule_timeout <- do_sys_poll <- sys_poll

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/2016112404.7102-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 06be809..a49a032 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1960,7 +1960,7 @@ static bool is_idle_sample(struct perf_sched *sched,
return false;
 
if (thread__resolve_callchain(thread, cursor, evsel, sample,
- NULL, NULL, sched->max_stack) != 0) {
+ NULL, NULL, sched->max_stack + 2) != 0) {
if (verbose)
error("Failed to resolve callchain. Skipping\n");
 


[tip:perf/core] perf sched timehist: Mark schedule function in callchains

2016-11-25 Thread tip-bot for Namhyung Kim
Commit-ID:  cdeb01bf7863718dac2a2c3a12b62366757a
Gitweb: http://git.kernel.org/tip/cdeb01bf7863718dac2a2c3a12b62366757a
Author: Namhyung Kim 
AuthorDate: Thu, 24 Nov 2016 10:11:12 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 25 Nov 2016 10:49:43 -0300

perf sched timehist: Mark schedule function in callchains

The sched_switch event always captured from the scheduler function.  So
it'd be great omit them from the callchain.  This patch marks the
functions to be omitted by later patch.

Committer notes:

Testing it:

Before:

  [root@jouet experimental]# perf sched record -g ls
  Dockerfile  perf.data  x-mips64
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 1.355 MB perf.data (29 samples) ]
  [root@jouet experimental]# perf sched timehist
  time  cpu  task name wait time sch delay run time
 [tid/pid] (msec) (msec) (msec)
  --- -  - -- -- --
  6.494998 [001] 0.000  0.000  0.000
  6.495027 [002] perf[519] 0.000  0.000  0.000 __schedule <- 
schedule <- schedule_hrtimeout_range_clock <- schedule_hrtimeou
  6.495096 [003] 0.000  0.000  0.000
  6.495100 [003] rcuos/0[9]0.000  0.005  0.003 __schedule <- 
schedule <- rcu_nocb_kthread <- kthread <- ret_from_fork
  6.495113 [001] perf[520] 0.000  0.008  0.114 __schedule <- 
preempt_schedule_common <- _cond_resched <- wait_for_completion
  6.495121 [000] 0.000  0.000  0.000
  6.495129 [001] migration/1[17]   0.000  0.003  0.016 __schedule <- 
schedule <- smpboot_thread_fn <- kthread <- ret_from_fork
  6.496085 [002] 0.000  0.000  1.057
  6.496096 [002] kworker/u16:1[31169]  0.000  0.004  0.011 __schedule <- 
schedule <- worker_thread <- kthread <- ret_from_fork
  6.496096 [003] 0.003  0.000  0.996
  6.496169 [002] 0.011  0.000  0.072
  6.496171 [000] ls[520]   0.008  0.000  1.049 __schedule <- 
schedule <- do_exit <- do_group_exit <- [unknown]
  6.496172 [003] gnome-terminal-[4391] 0.000  0.003  0.076 __schedule <- 
schedule <- schedule_hrtimeout_range_clock <- schedule_hrtimeo

After:

  [root@jouet experimental]# perf sched timehist
  time  cpu  task name wait time sch delay run time
 [tid/pid](msec)  (msec)  (msec)
  --- -  - -  -  --
  6.494998 [001] 0.000  0.000  0.000
  6.495027 [002] perf[519] 0.000  0.000  0.000 
schedule_hrtimeout_range_clock <- schedule_hrtimeout_range <- poll_schedule_t
  6.495096 [003] 0.000  0.000  0.000
  6.495100 [003] rcuos/0[9]0.000  0.005  0.003 rcu_nocb_kthread <- 
kthread <- ret_from_fork
  6.495113 [001] perf[520] 0.000  0.008  0.114 
preempt_schedule_common <- _cond_resched <- wait_for_completion <- stop_one_c
  6.495121 [000] 0.000  0.000  0.000
  6.495129 [001] migration/1[17]   0.000  0.003  0.016 smpboot_thread_fn <- 
kthread <- ret_from_fork
  6.496085 [002] 0.000  0.000  1.057
  6.496096 [002] kworker/u16:1[31169]  0.000  0.004  0.011 worker_thread <- 
kthread <- ret_from_fork
  6.496096 [003] 0.003  0.000  0.996
  6.496169 [002] 0.011  0.000  0.072
  6.496171 [000] ls[520]   0.008  0.000  1.049 do_exit <- 
do_group_exit <- [unknown]
  6.496172 [003] gnome-terminal-[4391] 0.000  0.003  0.076 
schedule_hrtimeout_range_clock <- schedule_hrtimeout_range <- poll_schedule_
  [root@jouet experimental]#

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/2016112404.7102-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 21 +
 tools/perf/util/symbol.h   |  1 +
 2 files changed, 22 insertions(+)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 43fcc13..06be809 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1966,7 +1966,28 @@ static bool is_idle_sample(struct perf_sched *sched,
 
return false;
}
+
callchain_cursor_commit(cursor);
+
+   while (true) {
+   struct callchain_cursor_node *node;
+   struct symbol *sym;
+
+   node = callchain_cursor_current(cursor);
+   if (node == NULL)
+   break;
+
+   sym = node->sym;
+   if (sym && sym->name) {
+   if (!strcmp(sym->name, "schedule") ||
+   !strcmp(sym->name, "__schedule") ||
+   !strcmp(sym->name, "preempt_schedule"))
+   sym->ignore = 1;
+   }
+
+   callchain_cursor_a

[tip:perf/core] perf callchain: Add option to skip ignore symbol when printing callchains

2016-11-25 Thread tip-bot for Namhyung Kim
Commit-ID:  2d9bbf6eb3825739efa9e91c256ce7ead60d8367
Gitweb: http://git.kernel.org/tip/2d9bbf6eb3825739efa9e91c256ce7ead60d8367
Author: Namhyung Kim 
AuthorDate: Thu, 24 Nov 2016 10:11:13 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 25 Nov 2016 10:49:38 -0300

perf callchain: Add option to skip ignore symbol when printing callchains

For tracepoint events, callchains always contain certain functions.
Sometimes it'd be better to skip those functions as they have no value.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/2016112404.7102-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c  | 3 ++-
 tools/perf/util/evsel.h | 1 +
 tools/perf/util/evsel_fprintf.c | 7 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 829468d..43fcc13 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1876,7 +1876,8 @@ static void timehist_print_sample(struct perf_sched 
*sched,
 
sample__fprintf_sym(sample, al, 0,
EVSEL__PRINT_SYM | EVSEL__PRINT_ONELINE |
-   EVSEL__PRINT_CALLCHAIN_ARROW,
+   EVSEL__PRINT_CALLCHAIN_ARROW |
+   EVSEL__PRINT_SKIP_IGNORED,
&callchain_cursor, stdout);
 
 out:
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 27fa3a3..6abb89c 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -392,6 +392,7 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,
 #define EVSEL__PRINT_SRCLINE   (1<<5)
 #define EVSEL__PRINT_UNKNOWN_AS_ADDR   (1<<6)
 #define EVSEL__PRINT_CALLCHAIN_ARROW   (1<<7)
+#define EVSEL__PRINT_SKIP_IGNORED  (1<<8)
 
 struct callchain_cursor;
 
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index 53bb614..5a6f522 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -109,6 +109,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
+   int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED;
char s = print_oneline ? ' ' : '\t';
bool first = true;
 
@@ -124,6 +125,9 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
if (!node)
break;
 
+   if (node->sym && node->sym->ignore && 
print_skip_ignored)
+   goto next;
+
printed += fprintf(fp, "%-*.*s", left_alignment, 
left_alignment, " ");
 
if (print_arrow && !first)
@@ -162,8 +166,9 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
if (!print_oneline)
printed += fprintf(fp, "\n");
 
-   callchain_cursor_advance(cursor);
first = false;
+next:
+   callchain_cursor_advance(cursor);
}
}
 


[tip:perf/core] perf evsel: Support printing callchains with arrows

2016-11-23 Thread tip-bot for Namhyung Kim
Commit-ID:  69b7e48070ca2ecee7498166259b5826b22e8b2e
Gitweb: http://git.kernel.org/tip/69b7e48070ca2ecee7498166259b5826b22e8b2e
Author: Namhyung Kim 
AuthorDate: Wed, 16 Nov 2016 15:06:28 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 23 Nov 2016 10:44:07 -0300

perf evsel: Support printing callchains with arrows

The EVSEL__PRINT_CALLCHAIN_ARROW options can be used to print callchains
with arrows for readability.  It will be used 'sched timehist' command
like below:

__schedule <- schedule <- schedule_timeout <- rcu_gp_kthread <- kthread <- 
ret_from_fork
__schedule <- schedule <- schedule_timeout <- rcu_gp_kthread <- kthread <- 
ret_from_fork
__schedule <- schedule <- worker_thread <- kthread <- ret_from_fork

Suggested-and-Acked-by: Ingo Molnar 
Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20161116060634.28477-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evsel.h | 1 +
 tools/perf/util/evsel_fprintf.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 8cd7cd2..27fa3a3 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -391,6 +391,7 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,
 #define EVSEL__PRINT_ONELINE   (1<<4)
 #define EVSEL__PRINT_SRCLINE   (1<<5)
 #define EVSEL__PRINT_UNKNOWN_AS_ADDR   (1<<6)
+#define EVSEL__PRINT_CALLCHAIN_ARROW   (1<<7)
 
 struct callchain_cursor;
 
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index ccb6023..53bb614 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -108,7 +108,9 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
+   int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
char s = print_oneline ? ' ' : '\t';
+   bool first = true;
 
if (sample->callchain) {
struct addr_location node_al;
@@ -124,6 +126,9 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
 
printed += fprintf(fp, "%-*.*s", left_alignment, 
left_alignment, " ");
 
+   if (print_arrow && !first)
+   printed += fprintf(fp, " <-");
+
if (print_ip)
printed += fprintf(fp, "%c%16" PRIx64, s, 
node->ip);
 
@@ -158,6 +163,7 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
printed += fprintf(fp, "\n");
 
callchain_cursor_advance(cursor);
+   first = false;
}
}
 


[tip:perf/core] perf symbols: Print symbol offsets conditionally

2016-11-23 Thread tip-bot for Namhyung Kim
Commit-ID:  a8763445f6c78628bd96d51649745065c0bb2c92
Gitweb: http://git.kernel.org/tip/a8763445f6c78628bd96d51649745065c0bb2c92
Author: Namhyung Kim 
AuthorDate: Wed, 16 Nov 2016 15:06:27 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 23 Nov 2016 10:44:06 -0300

perf symbols: Print symbol offsets conditionally

The __symbol__fprintf_symname_offs() always shows symbol offsets.  So
there's no difference between 'perf script -F ip,sym' and 'perf script
-F ip,sym,symoff'.  I don't think it's a desired behavior..

Signed-off-by: Namhyung Kim 
Acked-by: Ingo Molnar 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20161116060634.28477-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evsel_fprintf.c  |  6 --
 tools/perf/util/symbol.h |  3 ++-
 tools/perf/util/symbol_fprintf.c | 11 ++-
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index 662a0a6..ccb6023 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -137,7 +137,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, 
int left_alignment,
 
if (print_symoffset) {
printed += 
__symbol__fprintf_symname_offs(node->sym, &node_al,
-   
  print_unknown_as_addr, fp);
+   
  print_unknown_as_addr,
+   
  true, fp);
} else {
printed += 
__symbol__fprintf_symname(node->sym, &node_al,
 
print_unknown_as_addr, fp);
@@ -188,7 +189,8 @@ int sample__fprintf_sym(struct perf_sample *sample, struct 
addr_location *al,
printed += fprintf(fp, " ");
if (print_symoffset) {
printed += 
__symbol__fprintf_symname_offs(al->sym, al,
- 
print_unknown_as_addr, fp);
+ 
print_unknown_as_addr,
+ true, 
fp);
} else {
printed += __symbol__fprintf_symname(al->sym, 
al,
 
print_unknown_as_addr, fp);
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 2d0a905..dec7e2d4 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -282,7 +282,8 @@ int symbol__annotation_init(void);
 struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
 size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
  const struct addr_location *al,
- bool unknown_as_addr, FILE *fp);
+ bool unknown_as_addr,
+ bool print_offsets, FILE *fp);
 size_t symbol__fprintf_symname_offs(const struct symbol *sym,
const struct addr_location *al, FILE *fp);
 size_t __symbol__fprintf_symname(const struct symbol *sym,
diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fprintf.c
index a680bda..7c6b33e 100644
--- a/tools/perf/util/symbol_fprintf.c
+++ b/tools/perf/util/symbol_fprintf.c
@@ -15,14 +15,15 @@ size_t symbol__fprintf(struct symbol *sym, FILE *fp)
 
 size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
  const struct addr_location *al,
- bool unknown_as_addr, FILE *fp)
+ bool unknown_as_addr,
+ bool print_offsets, FILE *fp)
 {
unsigned long offset;
size_t length;
 
if (sym && sym->name) {
length = fprintf(fp, "%s", sym->name);
-   if (al) {
+   if (al && print_offsets) {
if (al->addr < sym->end)
offset = al->addr - sym->start;
else
@@ -40,19 +41,19 @@ size_t symbol__fprintf_symname_offs(const struct symbol 
*sym,
const struct addr_location *al,
FILE *fp)
 {
-   return __symbol__fprintf_symname_offs(sym, al, false, fp);
+   return __symbol__fprintf_symname_offs(sym, al, false, true, fp);
 }
 
 size_t __symbol__fprintf_symname(const struct symbol *sym,
  

[tip:perf/urgent] perf hists browser: Fix column indentation on --hierarchy

2016-11-12 Thread tip-bot for Namhyung Kim
Commit-ID:  b9bf911e990a189f89147ee6b0a153ed0125
Gitweb: http://git.kernel.org/tip/b9bf911e990a189f89147ee6b0a153ed0125
Author: Namhyung Kim 
AuthorDate: Tue, 8 Nov 2016 22:08:32 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 9 Nov 2016 11:45:58 -0300

perf hists browser: Fix column indentation on --hierarchy

When horizontall scrolling is used in hierarchy mode, the the right most
column has unnecessary indentation.  Actually it's needed only if some
of left (overhead) columns were shown.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Markus Trippelsdorf 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161108130833.9263-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e767fbd..a53fef0 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1361,8 +1361,10 @@ static int hist_browser__show_hierarchy_entry(struct 
hist_browser *browser,
width -= hpp.buf - s;
}
 
-   ui_browser__write_nstring(&browser->b, "", hierarchy_indent);
-   width -= hierarchy_indent;
+   if (!first) {
+   ui_browser__write_nstring(&browser->b, "", hierarchy_indent);
+   width -= hierarchy_indent;
+   }
 
if (column >= browser->b.horiz_scroll) {
char s[2048];
@@ -1565,6 +1567,7 @@ static int 
hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
if (advance_hpp_check(&dummy_hpp, ret))
return ret;
 
+   first_node = true;
/* the first hpp_list_node is for overhead columns */
fmt_node = list_first_entry(&hists->hpp_formats,
struct perf_hpp_list_node, list);
@@ -1579,12 +1582,16 @@ static int 
hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "  ");
if (advance_hpp_check(&dummy_hpp, ret))
break;
+
+   first_node = false;
}
 
-   ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "%*s",
-   indent * HIERARCHY_INDENT, "");
-   if (advance_hpp_check(&dummy_hpp, ret))
-   return ret;
+   if (!first_node) {
+   ret = scnprintf(dummy_hpp.buf, dummy_hpp.size, "%*s",
+   indent * HIERARCHY_INDENT, "");
+   if (advance_hpp_check(&dummy_hpp, ret))
+   return ret;
+   }
 
first_node = true;
list_for_each_entry_continue(fmt_node, &hists->hpp_formats, list) {


[tip:perf/urgent] perf hists browser: Show folded sign properly on --hierarchy

2016-11-12 Thread tip-bot for Namhyung Kim
Commit-ID:  131d51eb1d17aac3a604cf929fd99ff4dd34f495
Gitweb: http://git.kernel.org/tip/131d51eb1d17aac3a604cf929fd99ff4dd34f495
Author: Namhyung Kim 
AuthorDate: Tue, 8 Nov 2016 22:08:31 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 9 Nov 2016 11:30:47 -0300

perf hists browser: Show folded sign properly on --hierarchy

When horizontal scrolling is used in hierarchy mode, the folded signed
disappears at the right most column.

Committer note:

To test it, run 'perf top --hierarchy, see the '+' symbol at the first
column, then press the right arrow key, the '+' symbol will disappear,
this patch fixes that.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Markus Trippelsdorf 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161108130833.9263-3-namhy...@kernel.org
[ Move 'width -= 2' invariant to right after the if/else ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 225ef2a..e767fbd 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1381,7 +1381,13 @@ static int hist_browser__show_hierarchy_entry(struct 
hist_browser *browser,
}
 
perf_hpp_list__for_each_format(entry->hpp_list, fmt) {
-   ui_browser__write_nstring(&browser->b, "", 2);
+   if (first) {
+   ui_browser__printf(&browser->b, "%c ", 
folded_sign);
+   first = false;
+   } else {
+   ui_browser__write_nstring(&browser->b, "", 2);
+   }
+
width -= 2;
 
/*


[tip:perf/urgent] perf hist browser: Fix hierarchy column counts

2016-11-12 Thread tip-bot for Namhyung Kim
Commit-ID:  9cba9844547731d2f14d79485c43192ffaa37b76
Gitweb: http://git.kernel.org/tip/9cba9844547731d2f14d79485c43192ffaa37b76
Author: Namhyung Kim 
AuthorDate: Tue, 25 Oct 2016 01:21:10 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 9 Nov 2016 11:19:28 -0300

perf hist browser: Fix hierarchy column counts

The perf report/top on TUI supports horizontal scrolling using LEFT and
RIGHT keys.

But it calculate the number of columns incorrectly when hierarchy mode
is enabled so that keep pressing RIGHT key can make the output
disappeared.

In the hierarchy mode, all sort keys are collapsed into a single column,
so it needs to be applied when calculating column numbers.

Reported-and-Tested-by: Markus Trippelsdorf 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161024162110.17918-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 47b..5adedc1 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2076,8 +2076,21 @@ void hist_browser__init(struct hist_browser *browser,
browser->b.use_navkeypressed= true;
browser->show_headers   = symbol_conf.show_hist_headers;
 
-   hists__for_each_format(hists, fmt)
+   if (symbol_conf.report_hierarchy) {
+   struct perf_hpp_list_node *fmt_node;
+
+   /* count overhead columns (in the first node) */
+   fmt_node = list_first_entry(&hists->hpp_formats,
+   struct perf_hpp_list_node, list);
+   perf_hpp_list__for_each_format(&fmt_node->hpp, fmt)
+   ++browser->b.columns;
+
+   /* add a single column for whole hierarchy sort keys*/
++browser->b.columns;
+   } else {
+   hists__for_each_format(hists, fmt)
+   ++browser->b.columns;
+   }
 
hists__reset_column_width(hists);
 }


[tip:perf/urgent] perf hists browser: Fix indentation of folded sign on --hierarchy

2016-11-12 Thread tip-bot for Namhyung Kim
Commit-ID:  3d9f4683929a968dc9b9493f4e608b109ad292a2
Gitweb: http://git.kernel.org/tip/3d9f4683929a968dc9b9493f4e608b109ad292a2
Author: Namhyung Kim 
AuthorDate: Tue, 8 Nov 2016 22:08:30 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 9 Nov 2016 11:20:56 -0300

perf hists browser: Fix indentation of folded sign on --hierarchy

It should indent 2 spaces for folded sign and a whitespace.

Signed-off-by: Namhyung Kim 
Tested-by: Markus Trippelsdorf 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161108130833.9263-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 5adedc1..225ef2a 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1337,8 +1337,8 @@ static int hist_browser__show_hierarchy_entry(struct 
hist_browser *browser,
}
 
if (first) {
-   ui_browser__printf(&browser->b, "%c", folded_sign);
-   width--;
+   ui_browser__printf(&browser->b, "%c ", folded_sign);
+   width -= 2;
first = false;
} else {
ui_browser__printf(&browser->b, "  ");
@@ -1555,7 +1555,7 @@ static int 
hists_browser__scnprintf_hierarchy_headers(struct hist_browser *brows
int indent = hists->nr_hpp_node - 2;
bool first_node, first_col;
 
-   ret = scnprintf(buf, size, " ");
+   ret = scnprintf(buf, size, "  ");
if (advance_hpp_check(&dummy_hpp, ret))
return ret;
 


[tip:perf/urgent] perf hists: Fix column length on --hierarchy

2016-11-12 Thread tip-bot for Namhyung Kim
Commit-ID:  c72ab446cac1d6c9551fd26c4cfef1b2fc5041fd
Gitweb: http://git.kernel.org/tip/c72ab446cac1d6c9551fd26c4cfef1b2fc5041fd
Author: Namhyung Kim 
AuthorDate: Tue, 8 Nov 2016 22:08:33 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 9 Nov 2016 11:55:29 -0300

perf hists: Fix column length on --hierarchy

Markus reported that there's a weird behavior on perf top --hierarchy
regarding the column length.

Looking at the code, I found a dubious code which affects the symptoms.
When --hierarchy option is used, the last column length might be
inaccurate since it skips to update the length on leaf entries.

I cannot remember why it did and looks like a leftover from previous
version during the development.

Anyway, updating the column length often is not harmful.  So let's move
the code out.

Reported-and-Tested-by: Markus Trippelsdorf 
Signed-off-by: Namhyung Kim 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: 1a3906a7e6b9 ("perf hists: Resort hist entries with hierarchy")
Link: http://lkml.kernel.org/r/20161108130833.9263-5-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/hist.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index b02992e..a69f027 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1600,18 +1600,18 @@ static void hists__hierarchy_output_resort(struct hists 
*hists,
if (prog)
ui_progress__update(prog, 1);
 
+   hists->nr_entries++;
+   if (!he->filtered) {
+   hists->nr_non_filtered_entries++;
+   hists__calc_col_len(hists, he);
+   }
+
if (!he->leaf) {
hists__hierarchy_output_resort(hists, prog,
   &he->hroot_in,
   &he->hroot_out,
   min_callchain_hits,
   use_callchain);
-   hists->nr_entries++;
-   if (!he->filtered) {
-   hists->nr_non_filtered_entries++;
-   hists__calc_col_len(hists, he);
-   }
-
continue;
}
 


[tip:perf/core] perf tools: Introduce timestamp__scnprintf_usec()

2016-10-28 Thread tip-bot for Namhyung Kim
Commit-ID:  99620a5d0cc8e2dd9aedb629a6e81825f0db020e
Gitweb: http://git.kernel.org/tip/99620a5d0cc8e2dd9aedb629a6e81825f0db020e
Author: Namhyung Kim 
AuthorDate: Mon, 24 Oct 2016 11:02:45 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Fri, 28 Oct 2016 11:29:40 -0200

perf tools: Introduce timestamp__scnprintf_usec()

Joonwoo reported that there's a mismatch between timestamps in script
and sched commands.  This was because of difference in printing the
timestamp.  Factor out the code and share it so that they can be in
sync.  Also I found that sched map has similar problem, fix it too.

Committer notes:

Fixed the max_lat_at bug introduced by Namhyung's original patch, as
pointed out by Joonwoo, and made it a function following the scnprintf()
model, i.e. returning the number of bytes formatted, and receiving as
the first parameter the object from where the data to the formatting is
obtained, renaming it from:

   char *timestamp_in_usec(char *bf, size_t size, u64 timestamp)

to

   int timestamp__scnprintf_usec(u64 timestamp, char *bf, size_t size)

Reported-by: Joonwoo Park 
Signed-off-by: Namhyung Kim 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161024020246.14928-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c  | 10 +++---
 tools/perf/builtin-script.c | 10 ++
 tools/perf/util/util.c  |  8 
 tools/perf/util/util.h  |  3 +++
 4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 1f33d15..fb34412 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1191,6 +1191,7 @@ static void output_lat_thread(struct perf_sched *sched, 
struct work_atoms *work_
int i;
int ret;
u64 avg;
+   char max_lat_at[32];
 
if (!work_list->nb_atoms)
return;
@@ -1212,12 +1213,13 @@ static void output_lat_thread(struct perf_sched *sched, 
struct work_atoms *work_
printf(" ");
 
avg = work_list->total_lat / work_list->nb_atoms;
+   timestamp__scnprintf_usec(work_list->max_lat_at, max_lat_at, 
sizeof(max_lat_at));
 
-   printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max 
at: %13.6f s\n",
+   printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max 
at: %13s s\n",
  (double)work_list->total_runtime / NSEC_PER_MSEC,
 work_list->nb_atoms, (double)avg / NSEC_PER_MSEC,
 (double)work_list->max_lat / NSEC_PER_MSEC,
-(double)work_list->max_lat_at / NSEC_PER_SEC);
+max_lat_at);
 }
 
 static int pid_cmp(struct work_atoms *l, struct work_atoms *r)
@@ -1402,6 +1404,7 @@ static int map_switch_event(struct perf_sched *sched, 
struct perf_evsel *evsel,
int cpus_nr;
bool new_cpu = false;
const char *color = PERF_COLOR_NORMAL;
+   char stimestamp[32];
 
BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
 
@@ -1492,7 +1495,8 @@ static int map_switch_event(struct perf_sched *sched, 
struct perf_evsel *evsel,
if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu))
goto out;
 
-   color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp / 
NSEC_PER_SEC);
+   timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp));
+   color_fprintf(stdout, color, "  %12s secs ", stimestamp);
if (new_shortname || (verbose && sched_in->tid)) {
const char *pid_color = color;
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 412fb6e..e1daff3 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -441,7 +441,6 @@ static void print_sample_start(struct perf_sample *sample,
 {
struct perf_event_attr *attr = &evsel->attr;
unsigned long secs;
-   unsigned long usecs;
unsigned long long nsecs;
 
if (PRINT_FIELD(COMM)) {
@@ -471,11 +470,14 @@ static void print_sample_start(struct perf_sample *sample,
nsecs = sample->time;
secs = nsecs / NSEC_PER_SEC;
nsecs -= secs * NSEC_PER_SEC;
-   usecs = nsecs / NSEC_PER_USEC;
+
if (nanosecs)
printf("%5lu.%09llu: ", secs, nsecs);
-   else
-   printf("%5lu.%06lu: ", secs, usecs);
+   else {
+   char sample_time[32];
+   timestamp__scnprintf_usec(sample->time, sample_time, 
sizeof(sample_time));
+   printf("%12s: ", sample_time);
+   }
}
 }
 
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 85c5680..5bbd1f6 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -433,6 +433,14 @@ int parse_nsec_time(const char *str, u64 *ptime)
return 0;
 }
 
+int timestamp__scnprintf_usec

[tip:perf/core] perf sched map: Always show task comm with -v

2016-10-28 Thread tip-bot for Namhyung Kim
Commit-ID:  e107f129e2e0e75ddf1cd7995a9f52307766
Gitweb: http://git.kernel.org/tip/e107f129e2e0e75ddf1cd7995a9f52307766
Author: Namhyung Kim 
AuthorDate: Mon, 24 Oct 2016 11:02:44 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 25 Oct 2016 15:05:09 -0300

perf sched map: Always show task comm with -v

I'd like to see the name of tasks with perf sched map, but it only shows
name of new tasks and then use short names after all.  This is not good
for long running tasks since it's hard for users to track the short
names.  This patch makes it show the names (except the idle task) when
-v option is used.  Probably we may make it as default behavior.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: David Ahern 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161024020246.14928-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index a8ad859..1f33d15 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1493,7 +1493,7 @@ static int map_switch_event(struct perf_sched *sched, 
struct perf_evsel *evsel,
goto out;
 
color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp / 
NSEC_PER_SEC);
-   if (new_shortname) {
+   if (new_shortname || (verbose && sched_in->tid)) {
const char *pid_color = color;
 
if (thread__has_color(sched_in))


[tip:perf/core] perf sched map: Apply cpu color when there's an activity

2016-10-28 Thread tip-bot for Namhyung Kim
Commit-ID:  1208bb274ba547012579d5b68c693e0b36682b74
Gitweb: http://git.kernel.org/tip/1208bb274ba547012579d5b68c693e0b36682b74
Author: Namhyung Kim 
AuthorDate: Mon, 24 Oct 2016 11:02:43 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 25 Oct 2016 15:04:48 -0300

perf sched map: Apply cpu color when there's an activity

Applying cpu color always doesn't help readability IMHO.  Instead it
might be better to applying the color when there's an activity on those
CPUs.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: David Ahern 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161024020246.14928-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 8ca1b540..a8ad859 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1479,7 +1479,7 @@ static int map_switch_event(struct perf_sched *sched, 
struct perf_evsel *evsel,
cpu_color = COLOR_CPUS;
 
if (cpu != this_cpu)
-   color_fprintf(stdout, cpu_color, " ");
+   color_fprintf(stdout, color, " ");
else
color_fprintf(stdout, cpu_color, "*");
 


[tip:perf/core] perf sched: Make common options cascading

2016-10-28 Thread tip-bot for Namhyung Kim
Commit-ID:  77f02f44460ab1480af2ae6145a1a85b9fe0b8ac
Gitweb: http://git.kernel.org/tip/77f02f44460ab1480af2ae6145a1a85b9fe0b8ac
Author: Namhyung Kim 
AuthorDate: Mon, 24 Oct 2016 12:00:03 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 25 Oct 2016 10:24:48 -0300

perf sched: Make common options cascading

The -i and -v options can be used in subcommands so enable cascading the
sched_options.  This fixes the following inconvenience in 'perf sched':

  $ perf sched -i perf.data.sched  map
  ... (it works well) ...

  $ perf sched map  -i perf.data.sched
Error: unknown switch `i'

   Usage: perf sched map []

  --color-cpus 
highlight given CPUs in map
  --color-pids 
highlight given pids in map
  --compact map output in compact mode
  --cpus  display given CPUs in map

With this patch, the second command line works with the perf.data.sched
data file.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Josh Poimboeuf 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/20161024030003.28534-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index f5503ca..8ca1b540 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1954,6 +1954,15 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
.next_shortname2  = '0',
.skip_merge   = 0,
};
+   const struct option sched_options[] = {
+   OPT_STRING('i', "input", &input_name, "file",
+   "input file name"),
+   OPT_INCR('v', "verbose", &verbose,
+   "be more verbose (show symbol address, etc)"),
+   OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
+   "dump raw trace in ASCII"),
+   OPT_END()
+   };
const struct option latency_options[] = {
OPT_STRING('s', "sort", &sched.sort_order, "key[,key2...]",
   "sort by key(s): runtime, switch, avg, max"),
@@ -1965,7 +1974,7 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
"dump raw trace in ASCII"),
OPT_BOOLEAN('p', "pids", &sched.skip_merge,
"latency stats per pid instead of per comm"),
-   OPT_END()
+   OPT_PARENT(sched_options)
};
const struct option replay_options[] = {
OPT_UINTEGER('r', "repeat", &sched.replay_repeat,
@@ -1975,16 +1984,7 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
OPT_BOOLEAN('f', "force", &sched.force, "don't complain, do it"),
-   OPT_END()
-   };
-   const struct option sched_options[] = {
-   OPT_STRING('i', "input", &input_name, "file",
-   "input file name"),
-   OPT_INCR('v', "verbose", &verbose,
-   "be more verbose (show symbol address, etc)"),
-   OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
-   "dump raw trace in ASCII"),
-   OPT_END()
+   OPT_PARENT(sched_options)
};
const struct option map_options[] = {
OPT_BOOLEAN(0, "compact", &sched.map.comp,
@@ -1995,7 +1995,7 @@ int cmd_sched(int argc, const char **argv, const char 
*prefix __maybe_unused)
 "highlight given CPUs in map"),
OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
 "display given CPUs in map"),
-   OPT_END()
+   OPT_PARENT(sched_options)
};
const char * const latency_usage[] = {
"perf sched latency []",


[tip:perf/core] tools lib subcmd: Suppport cascading options

2016-10-28 Thread tip-bot for Namhyung Kim
Commit-ID:  369a2478973a416a2c42a37a8cf7031872a6d926
Gitweb: http://git.kernel.org/tip/369a2478973a416a2c42a37a8cf7031872a6d926
Author: Namhyung Kim 
AuthorDate: Mon, 24 Oct 2016 12:00:02 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 25 Oct 2016 10:12:16 -0300

tools lib subcmd: Suppport cascading options

Sometimes subcommand have common options and it can only handled in the
upper level command unless it duplicates the options.

This patch adds a parent field and fallback to the parent if the given
argument was not found in the current options.

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Josh Poimboeuf 
Cc: Peter Zijlstra 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/20161024030003.28534-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/subcmd/parse-options.c | 14 ++
 tools/lib/subcmd/parse-options.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 981bb44..3284bb1 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -314,12 +314,19 @@ static int get_value(struct parse_opt_ctx_t *p,
 
 static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option 
*options)
 {
+retry:
for (; options->type != OPTION_END; options++) {
if (options->short_name == *p->opt) {
p->opt = p->opt[1] ? p->opt + 1 : NULL;
return get_value(p, options, OPT_SHORT);
}
}
+
+   if (options->parent) {
+   options = options->parent;
+   goto retry;
+   }
+
return -2;
 }
 
@@ -333,6 +340,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const 
char *arg,
if (!arg_end)
arg_end = arg + strlen(arg);
 
+retry:
for (; options->type != OPTION_END; options++) {
const char *rest;
int flags = 0;
@@ -426,6 +434,12 @@ match:
}
if (abbrev_option)
return get_value(p, abbrev_option, abbrev_flags);
+
+   if (options->parent) {
+   options = options->parent;
+   goto retry;
+   }
+
return -2;
 }
 
diff --git a/tools/lib/subcmd/parse-options.h b/tools/lib/subcmd/parse-options.h
index d60cab2..8866ac4 100644
--- a/tools/lib/subcmd/parse-options.h
+++ b/tools/lib/subcmd/parse-options.h
@@ -109,11 +109,13 @@ struct option {
intptr_t defval;
bool *set;
void *data;
+   const struct option *parent;
 };
 
 #define check_vtype(v, type) ( 
BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v )
 
 #define OPT_END()   { .type = OPTION_END }
+#define OPT_PARENT(p)   { .type = OPTION_END, .parent = (p) }
 #define OPT_ARGUMENT(l, h)  { .type = OPTION_ARGUMENT, .long_name = 
(l), .help = (h) }
 #define OPT_GROUP(h){ .type = OPTION_GROUP, .help = (h) }
 #define OPT_BIT(s, l, v, h, b)  { .type = OPTION_BIT, .short_name = (s), 
.long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) }


[tip:perf/core] perf hist browser: Fix hierarchy column counts

2016-10-28 Thread tip-bot for Namhyung Kim
Commit-ID:  8a06b0be6507f97f3aa92ca814335b8b65fd3de2
Gitweb: http://git.kernel.org/tip/8a06b0be6507f97f3aa92ca814335b8b65fd3de2
Author: Namhyung Kim 
AuthorDate: Tue, 25 Oct 2016 01:21:10 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 25 Oct 2016 09:52:49 -0300

perf hist browser: Fix hierarchy column counts

The perf report/top on TUI supports horizontal scrolling using LEFT and
RIGHT keys.

But it calculate the number of columns incorrectly when hierarchy mode
is enabled so that keep pressing RIGHT key can make the output
disappeared.

In the hierarchy mode, all sort keys are collapsed into a single column,
so it needs to be applied when calculating column numbers.

Reported-and-Tested-by: Markus Trippelsdorf 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161024162110.17918-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index ddc4c3e..84f5dd2 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2076,8 +2076,21 @@ void hist_browser__init(struct hist_browser *browser,
browser->b.use_navkeypressed= true;
browser->show_headers   = symbol_conf.show_hist_headers;
 
-   hists__for_each_format(hists, fmt)
+   if (symbol_conf.report_hierarchy) {
+   struct perf_hpp_list_node *fmt_node;
+
+   /* count overhead columns (in the first node) */
+   fmt_node = list_first_entry(&hists->hpp_formats,
+   struct perf_hpp_list_node, list);
+   perf_hpp_list__for_each_format(&fmt_node->hpp, fmt)
+   ++browser->b.columns;
+
+   /* add a single column for whole hierarchy sort keys*/
++browser->b.columns;
+   } else {
+   hists__for_each_format(hists, fmt)
+   ++browser->b.columns;
+   }
 
hists__reset_column_width(hists);
 }


[tip:perf/urgent] perf top: Fix refreshing hierarchy entries on TUI

2016-10-17 Thread tip-bot for Namhyung Kim
Commit-ID:  c611152373e84a7677cd7d496e849de4debdab66
Gitweb: http://git.kernel.org/tip/c611152373e84a7677cd7d496e849de4debdab66
Author: Namhyung Kim 
AuthorDate: Fri, 7 Oct 2016 14:04:12 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 13 Oct 2016 11:10:14 -0300

perf top: Fix refreshing hierarchy entries on TUI

Markus reported that 'perf top --hierarchy' cannot scroll down after
refresh.  This was because the number of entries are not updated when
hierarchy is enabled.

Unlike normal report view, hierarchy mode needs to keep its own entry
count since it can have non-leaf entries which can expand/collapse.

Reported-and-Tested-by: Markus Trippelsdorf 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: f5b763feebe9 ("perf hists browser: Count number of hierarchy entries")
Link: http://lkml.kernel.org/r/20161007050412.3000-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fb8e42c..47b 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -601,7 +601,8 @@ int hist_browser__run(struct hist_browser *browser, const 
char *help)
u64 nr_entries;
hbt->timer(hbt->arg);
 
-   if (hist_browser__has_filter(browser))
+   if (hist_browser__has_filter(browser) ||
+   symbol_conf.report_hierarchy)
hist_browser__update_nr_entries(browser);
 
nr_entries = hist_browser__nr_entries(browser);


[tip:perf/urgent] tools lib traceevent: Fix kbuffer_read_at_offset()

2016-10-06 Thread tip-bot for Namhyung Kim
Commit-ID:  a130347973c408c0e0017a52c74cbc3226c1f0ef
Gitweb: http://git.kernel.org/tip/a130347973c408c0e0017a52c74cbc3226c1f0ef
Author: Namhyung Kim 
AuthorDate: Sat, 1 Oct 2016 19:17:00 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 5 Oct 2016 11:36:22 -0300

tools lib traceevent: Fix kbuffer_read_at_offset()

When it's called with an offset less than or equal to the first event,
it'll return a garbage value since the data is not initialized.

Signed-off-by: Namhyung Kim 
Acked-by: Steven Rostedt 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20161001101700.29146-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/traceevent/kbuffer-parse.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/lib/traceevent/kbuffer-parse.c 
b/tools/lib/traceevent/kbuffer-parse.c
index 3bcada3..65984f1 100644
--- a/tools/lib/traceevent/kbuffer-parse.c
+++ b/tools/lib/traceevent/kbuffer-parse.c
@@ -622,6 +622,7 @@ void *kbuffer_read_at_offset(struct kbuffer *kbuf, int 
offset,
 
/* Reset the buffer */
kbuffer_load_subbuffer(kbuf, kbuf->subbuffer);
+   data = kbuffer_read_event(kbuf, ts);
 
while (kbuf->curr < offset) {
data = kbuffer_next_event(kbuf, ts);


[tip:perf/core] perf hists: Factor out hists__reset_column_width()

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  e3b60bc93d81e0542ac433df226b8de8b963533e
Gitweb: http://git.kernel.org/tip/e3b60bc93d81e0542ac433df226b8de8b963533e
Author: Namhyung Kim 
AuthorDate: Tue, 20 Sep 2016 14:30:24 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 20 Sep 2016 16:13:37 -0300

perf hists: Factor out hists__reset_column_width()

The stdio and tui has same code to reset hpp format column width.
Factor it out as a new function.

Suggested-and-Acked-by: Jiri Olsa 
Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160920053025.13989-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 12 +++-
 tools/perf/ui/hist.c   | 15 +++
 tools/perf/ui/stdio/hist.c | 10 +-
 tools/perf/util/hist.h |  1 +
 4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 49db163..a6d5d24 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2067,7 +2067,6 @@ void hist_browser__init(struct hist_browser *browser,
struct hists *hists)
 {
struct perf_hpp_fmt *fmt;
-   struct perf_hpp_list_node *node;
 
browser->hists  = hists;
browser->b.refresh  = hist_browser__refresh;
@@ -2076,15 +2075,10 @@ void hist_browser__init(struct hist_browser *browser,
browser->b.use_navkeypressed= true;
browser->show_headers   = symbol_conf.show_hist_headers;
 
-   hists__for_each_format(hists, fmt) {
-   perf_hpp__reset_width(fmt, hists);
+   hists__for_each_format(hists, fmt)
++browser->b.columns;
-   }
-   /* hierarchy entries have their own hpp list */
-   list_for_each_entry(node, &hists->hpp_formats, list) {
-   perf_hpp_list__for_each_format(&node->hpp, fmt)
-   perf_hpp__reset_width(fmt, hists);
-   }
+
+   hists__reset_column_width(hists);
 }
 
 struct hist_browser *hist_browser__new(struct hists *hists)
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index b47fafc..60c4a4d 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -699,6 +699,21 @@ void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, 
struct hists *hists)
}
 }
 
+void hists__reset_column_width(struct hists *hists)
+{
+   struct perf_hpp_fmt *fmt;
+   struct perf_hpp_list_node *node;
+
+   hists__for_each_format(hists, fmt)
+   perf_hpp__reset_width(fmt, hists);
+
+   /* hierarchy entries have their own hpp list */
+   list_for_each_entry(node, &hists->hpp_formats, list) {
+   perf_hpp_list__for_each_format(&node->hpp, fmt)
+   perf_hpp__reset_width(fmt, hists);
+   }
+}
+
 void perf_hpp__set_user_width(const char *width_list_str)
 {
struct perf_hpp_fmt *fmt;
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index a57131e..8e1840b 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -717,8 +717,6 @@ size_t hists__fprintf(struct hists *hists, bool 
show_header, int max_rows,
  int max_cols, float min_pcnt, FILE *fp,
  bool use_callchain)
 {
-   struct perf_hpp_fmt *fmt;
-   struct perf_hpp_list_node *node;
struct rb_node *nd;
size_t ret = 0;
const char *sep = symbol_conf.field_sep;
@@ -729,13 +727,7 @@ size_t hists__fprintf(struct hists *hists, bool 
show_header, int max_rows,
 
init_rem_hits();
 
-   hists__for_each_format(hists, fmt)
-   perf_hpp__reset_width(fmt, hists);
-   /* hierarchy entries have their own hpp list */
-   list_for_each_entry(node, &hists->hpp_formats, list) {
-   perf_hpp_list__for_each_format(&node->hpp, fmt)
-   perf_hpp__reset_width(fmt, hists);
-   }
+   hists__reset_column_width(hists);
 
if (symbol_conf.col_width_list_str)
perf_hpp__set_user_width(symbol_conf.col_width_list_str);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index a002c93..defa957 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -368,6 +368,7 @@ static inline bool perf_hpp__should_skip(struct 
perf_hpp_fmt *format,
 void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
 void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
 void perf_hpp__set_user_width(const char *width_list_str);
+void hists__reset_column_width(struct hists *hists);
 
 typedef u64 (*hpp_field_fn)(struct hist_entry *he);
 typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);


[tip:perf/core] perf ui/tui: Reset output width for hierarchy

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  5ff3e7a224d40f9dd73625b91377787034a8b35e
Gitweb: http://git.kernel.org/tip/5ff3e7a224d40f9dd73625b91377787034a8b35e
Author: Namhyung Kim 
AuthorDate: Tue, 20 Sep 2016 14:30:23 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 20 Sep 2016 16:08:30 -0300

perf ui/tui: Reset output width for hierarchy

When --hierarchy option is used, each entry has its own hpp_list to show
the result.  But it missed to update width of each column.

Before:

  - 46.29% 48.12%netctl-auto
 + 31.44% 29.25%[kernel.vmlinux]
 + 8.52% 11.55%libc-2.22.so
 + 5.19% 6.91%bash
  + 10.75% 11.83%wpa_cli
  + 8.25% 2.23%swapper
  + 6.45% 5.40%tr
  + 4.81% 8.09%awk
  + 4.15% 2.85%firefox
  + 3.86% 2.53%sh

After:

  -  46.29%  48.12%netctl-auto
  +  31.44%  29.25%[kernel.vmlinux]
  +   8.52%  11.55%libc-2.22.so
  +   5.19%   6.91%bash
  +  10.75%  11.83%wpa_cli
  +   8.25%   2.23%swapper
  +   6.45%   5.40%tr
  +   4.81%   8.09%awk
  +   4.15%   2.85%firefox
  +   3.86%   2.53%sh

Committer note:

Full testing instructions:

1) Record with an event group:

  $ perf record -e '{cycles,instructions}' make -j4

2) Use report in hierarchy mode, to get a few expanded trees on
   the same screen, use --percent-limit:

  $ perf report --hierarchy --percent-limit 0.5

Samples: 103K of event 'anon group { cycles:u, instructions:u }',
Event count (approx.): 57317631725
 OverheadCommand / Shared Object / Symbol◆
-  58.89%  55.12%cc1 ▒
   -  50.26%  48.10%cc1  ▒
  3.61%   5.13%[.] _cpp_lex_token▒
  2.58%   0.78%[.] ht_lookup_with_hash   ▒
  1.31%   1.30%[.] ggc_internal_alloc▒
  1.08%   2.25%[.] get_combined_adhoc_loc▒
  1.01%   1.95%[.] ira_init  ▒
  0.96%   1.78%[.] linemap_position_for_column   ▒
  0.65%   1.01%[.] cpp_get_token_with_location   ▒
   -   7.52%   6.58%libc-2.23.so ▒
  1.70%   1.78%[.] _int_malloc   ▒
  0.69%   0.75%[.] _int_free ▒
  0.67%   0.42%[.] malloc_consolidate▒
   -   0.58%   0.42%ld-2.23.so   ▒
   no entry >= 0.50% ▒
   -   0.52%   0.03%[kernel.vmlinux] ▒
   no entry >= 0.50% ▒

Signed-off-by: Namhyung Kim 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: Peter Zijlstra 
Fixes: 1b2dbbf41a0f ("perf hists: Use own hpp_list for hierarchy mode")
Link: http://lkml.kernel.org/r/20160920053025.13989-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 35e44b1..49db163 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2067,6 +2067,7 @@ void hist_browser__init(struct hist_browser *browser,
struct hists *hists)
 {
struct perf_hpp_fmt *fmt;
+   struct perf_hpp_list_node *node;
 
browser->hists  = hists;
browser->b.refresh  = hist_browser__refresh;
@@ -2079,6 +2080,11 @@ void hist_browser__init(struct hist_browser *browser,
perf_hpp__reset_width(fmt, hists);
++browser->b.columns;
}
+   /* hierarchy entries have their own hpp list */
+   list_for_each_entry(node, &hists->hpp_formats, list) {
+   perf_hpp_list__for_each_format(&node->hpp, fmt)
+   perf_hpp__reset_width(fmt, hists);
+   }
 }
 
 struct hist_browser *hist_browser__new(struct hists *hists)


[tip:perf/core] perf report: Enable group view with hierarchy

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  30d476ae738d1ce33f170dd79398ecd211274df6
Gitweb: http://git.kernel.org/tip/30d476ae738d1ce33f170dd79398ecd211274df6
Author: Namhyung Kim 
AuthorDate: Tue, 13 Sep 2016 16:45:52 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 13 Sep 2016 16:43:41 -0300

perf report: Enable group view with hierarchy

Now that all the missing pieces are implemented, let's enable it.  An
example output below:

  $ perf record -e '{cycles,instructions}' make
  $ perf report --hierarchy --stdio
  ...
  #   Overhead  Command / Shared Object / Symbol
  # ..  ..
  #
  ...
  25.74%  27.18%sh
 19.96%  24.14%libc-2.24.so
9.55%  14.64%[.] __strcmp_sse2
1.54%   0.00%[.] __tfind
1.07%   1.13%[.] _int_malloc
0.95%   0.00%[.] __strchr_sse2
0.89%   1.39%[.] __tsearch
0.76%   0.00%[.] strlen
  ...

Signed-off-by: Namhyung Kim 
Requested-by: Andi Kleen 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160913074552.13284-8-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-report.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 1a07c4c..6e88460 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -935,7 +935,6 @@ repeat:
 
if (symbol_conf.report_hierarchy) {
/* disable incompatible options */
-   symbol_conf.event_group = false;
symbol_conf.cumulate_callchain = false;
 
if (field_order) {


[tip:perf/core] perf ui/stdio: Rename print_hierarchy_header()

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  195bc0f8443d8d564ae95d2e9c19ac0edfd647c3
Gitweb: http://git.kernel.org/tip/195bc0f8443d8d564ae95d2e9c19ac0edfd647c3
Author: Namhyung Kim 
AuthorDate: Tue, 13 Sep 2016 16:45:50 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 13 Sep 2016 16:41:36 -0300

perf ui/stdio: Rename print_hierarchy_header()

Now the hists__fprintf_hierarchy_headers() is a simple wrapper passing
field separator.  Let's do it directly.

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160913074552.13284-6-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/stdio/hist.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 18b4fd9..a57131e 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -528,8 +528,8 @@ static int print_hierarchy_indent(const char *sep, int 
indent,
return fprintf(fp, "%-.*s", (indent - 2) * HIERARCHY_INDENT, line);
 }
 
-static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
- const char *sep, FILE *fp)
+static int hists__fprintf_hierarchy_headers(struct hists *hists,
+   struct perf_hpp *hpp, FILE *fp)
 {
bool first_node, first_col;
int indent;
@@ -538,6 +538,7 @@ static int print_hierarchy_header(struct hists *hists, 
struct perf_hpp *hpp,
unsigned header_width = 0;
struct perf_hpp_fmt *fmt;
struct perf_hpp_list_node *fmt_node;
+   const char *sep = symbol_conf.field_sep;
 
indent = hists->nr_hpp_node;
 
@@ -623,14 +624,6 @@ static int print_hierarchy_header(struct hists *hists, 
struct perf_hpp *hpp,
return 2;
 }
 
-static int
-hists__fprintf_hierarchy_headers(struct hists *hists,
-struct perf_hpp *hpp,
-FILE *fp)
-{
-   return print_hierarchy_header(hists, hpp, symbol_conf.field_sep, fp);
-}
-
 static void fprintf_line(struct hists *hists, struct perf_hpp *hpp,
 int line, FILE *fp)
 {


[tip:perf/core] perf ui/stdio: Always reset output width for hierarchy

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  9a6ad25b5a2026ba1399abc879ec623957867e79
Gitweb: http://git.kernel.org/tip/9a6ad25b5a2026ba1399abc879ec623957867e79
Author: Namhyung Kim 
AuthorDate: Tue, 13 Sep 2016 16:45:49 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 13 Sep 2016 16:41:21 -0300

perf ui/stdio: Always reset output width for hierarchy

When the --hierarchy option is used, each entry has its own hpp_list to
show the result.  But it is not updating the width of each column for
perf-top.  The perf-report command has no problem since it resets it
during header display.

  $ sudo perf top --hierarchy --stdio

   PerfTop: 160 irqs/sec  kernel:38.8%  exact: 100.0%
 [4000Hz cycles:pp],  (all, 12 CPUs)
  --

   52.32% perf
  24.74% [.] __symbols__insert
  5.62% [.] rb_next
  5.14% [.] dso__load_sym

Move the code into hists__fprintf() so that it can be called always.
Also it'd be better to put similar code together.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: 1b2dbbf41a0f ("perf hists: Use own hpp_list for hierarchy mode")
Link: http://lkml.kernel.org/r/20160913074552.13284-5-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/stdio/hist.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 9b65f4a..18b4fd9 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -628,14 +628,6 @@ hists__fprintf_hierarchy_headers(struct hists *hists,
 struct perf_hpp *hpp,
 FILE *fp)
 {
-   struct perf_hpp_list_node *fmt_node;
-   struct perf_hpp_fmt *fmt;
-
-   list_for_each_entry(fmt_node, &hists->hpp_formats, list) {
-   perf_hpp_list__for_each_format(&fmt_node->hpp, fmt)
-   perf_hpp__reset_width(fmt, hists);
-   }
-
return print_hierarchy_header(hists, hpp, symbol_conf.field_sep, fp);
 }
 
@@ -733,6 +725,7 @@ size_t hists__fprintf(struct hists *hists, bool 
show_header, int max_rows,
  bool use_callchain)
 {
struct perf_hpp_fmt *fmt;
+   struct perf_hpp_list_node *node;
struct rb_node *nd;
size_t ret = 0;
const char *sep = symbol_conf.field_sep;
@@ -745,6 +738,11 @@ size_t hists__fprintf(struct hists *hists, bool 
show_header, int max_rows,
 
hists__for_each_format(hists, fmt)
perf_hpp__reset_width(fmt, hists);
+   /* hierarchy entries have their own hpp list */
+   list_for_each_entry(node, &hists->hpp_formats, list) {
+   perf_hpp_list__for_each_format(&node->hpp, fmt)
+   perf_hpp__reset_width(fmt, hists);
+   }
 
if (symbol_conf.col_width_list_str)
perf_hpp__set_user_width(symbol_conf.col_width_list_str);


[tip:perf/core] perf hists: Introduce hists__link_hierarchy()

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  9d97b8f512a0dd41819b8e3d9cdc7a59199e1b0c
Gitweb: http://git.kernel.org/tip/9d97b8f512a0dd41819b8e3d9cdc7a59199e1b0c
Author: Namhyung Kim 
AuthorDate: Tue, 13 Sep 2016 16:45:47 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 13 Sep 2016 16:35:46 -0300

perf hists: Introduce hists__link_hierarchy()

The hists__link_hierarchy() is to support hierarchy reports with an
event group.  When it matches the leader event and the other members
(using hists__match_hierarchy()), it also needs to link unmatched member
entries with a dummy leader event so that it can show up in the output.

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160913074552.13284-3-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/hist.c | 95 ++
 1 file changed, 95 insertions(+)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index be3f5ce..702ba3a 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -2149,6 +2149,50 @@ out:
return he;
 }
 
+static struct hist_entry *add_dummy_hierarchy_entry(struct hists *hists,
+   struct rb_root *root,
+   struct hist_entry *pair)
+{
+   struct rb_node **p;
+   struct rb_node *parent = NULL;
+   struct hist_entry *he;
+   struct perf_hpp_fmt *fmt;
+
+   p = &root->rb_node;
+   while (*p != NULL) {
+   int64_t cmp = 0;
+
+   parent = *p;
+   he = rb_entry(parent, struct hist_entry, rb_node_in);
+
+   perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) {
+   cmp = fmt->collapse(fmt, he, pair);
+   if (cmp)
+   break;
+   }
+   if (!cmp)
+   goto out;
+
+   if (cmp < 0)
+   p = &parent->rb_left;
+   else
+   p = &parent->rb_right;
+   }
+
+   he = hist_entry__new(pair, true);
+   if (he) {
+   rb_link_node(&he->rb_node_in, parent, p);
+   rb_insert_color(&he->rb_node_in, root);
+
+   he->dummy = true;
+   he->hists = hists;
+   memset(&he->stat, 0, sizeof(he->stat));
+   hists__inc_stats(hists, he);
+   }
+out:
+   return he;
+}
+
 static struct hist_entry *hists__find_entry(struct hists *hists,
struct hist_entry *he)
 {
@@ -2248,6 +2292,50 @@ void hists__match(struct hists *leader, struct hists 
*other)
}
 }
 
+static int hists__link_hierarchy(struct hists *leader_hists,
+struct hist_entry *parent,
+struct rb_root *leader_root,
+struct rb_root *other_root)
+{
+   struct rb_node *nd;
+   struct hist_entry *pos, *leader;
+
+   for (nd = rb_first(other_root); nd; nd = rb_next(nd)) {
+   pos = rb_entry(nd, struct hist_entry, rb_node_in);
+
+   if (hist_entry__has_pairs(pos)) {
+   bool found = false;
+
+   list_for_each_entry(leader, &pos->pairs.head, 
pairs.node) {
+   if (leader->hists == leader_hists) {
+   found = true;
+   break;
+   }
+   }
+   if (!found)
+   return -1;
+   } else {
+   leader = add_dummy_hierarchy_entry(leader_hists,
+  leader_root, pos);
+   if (leader == NULL)
+   return -1;
+
+   /* do not point parent in the pos */
+   leader->parent_he = parent;
+
+   hist_entry__add_pair(pos, leader);
+   }
+
+   if (!pos->leaf) {
+   if (hists__link_hierarchy(leader_hists, leader,
+ &leader->hroot_in,
+ &pos->hroot_in) < 0)
+   return -1;
+   }
+   }
+   return 0;
+}
+
 /*
  * Look for entries in the other hists that are not present in the leader, if
  * we find them, just add a dummy entry on the leader hists, with period=0,
@@ -2259,6 +2347,13 @@ int hists__link(struct hists *leader, struct hists 
*other)
struct rb_node *nd;
struct hist_entry *pos, *pair;
 
+   if (symbol_conf.report_hierarchy) {
+   /* hierarchy report always collapses entries */
+   return hists__link_hierarchy(leader, NULL,
+ 

[tip:perf/core] perf hist: Initialize hierarchy tree explicitly

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  d2580c7a5b4e78bffda1e53cfd583e7a2c7383a5
Gitweb: http://git.kernel.org/tip/d2580c7a5b4e78bffda1e53cfd583e7a2c7383a5
Author: Namhyung Kim 
AuthorDate: Tue, 13 Sep 2016 16:45:48 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 13 Sep 2016 16:36:46 -0300

perf hist: Initialize hierarchy tree explicitly

The hroot_in and hroot_out are roots of hierarchy trees of hist entries.

But when a hist entry is initialized by copying existing template entry,
it sometimes has non-empty tree and copies it incorrectly.  This is a
problem especially when an event group is used since it creates dummy
entries from already-processed entries in other event members.

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160913074552.13284-4-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/hist.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 702ba3a..37a08f2 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -417,6 +417,8 @@ static int hist_entry__init(struct hist_entry *he,
}
INIT_LIST_HEAD(&he->pairs.node);
thread__get(he->thread);
+   he->hroot_in  = RB_ROOT;
+   he->hroot_out = RB_ROOT;
 
if (!symbol_conf.report_hierarchy)
he->leaf = true;


[tip:perf/core] perf hists: Introduce hists__match_hierarchy()

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  09034de63e427a86ba96bedf39410eef7c9014a5
Gitweb: http://git.kernel.org/tip/09034de63e427a86ba96bedf39410eef7c9014a5
Author: Namhyung Kim 
AuthorDate: Tue, 13 Sep 2016 16:45:46 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 13 Sep 2016 16:31:24 -0300

perf hists: Introduce hists__match_hierarchy()

The hists__match_hierarchy() is to find matching hist entries in a
group.  A matching entry has the same values for all sort keys given.

With an event group (e.g.: -e "{cycles,instructions}"), a leader event
should show other members in a group.  So each entry in the leader
should be able to find its pair entries which have same values.

With hierarchy mode, it needs to search all matching children in a
hierarchy.

An example output looks like:

  #   Overhead  Command / Shared Object / Symbol
  # ..  ..
  #
  25.74%  27.18%sh
 19.96%  24.14%libc-2.24.so
9.55%  14.64%[.] __strcmp_sse2
1.54%   0.00%[.] __tfind
1.07%   1.13%[.] _int_malloc
  ...

In the above example, two overheads are shown - one for the leader and
another for the other group member.  They were matched since their
command, dso and symbol have the same values.

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160913074552.13284-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/hist.c | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index de15dbc..be3f5ce 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -2174,6 +2174,51 @@ static struct hist_entry *hists__find_entry(struct hists 
*hists,
return NULL;
 }
 
+static struct hist_entry *hists__find_hierarchy_entry(struct rb_root *root,
+ struct hist_entry *he)
+{
+   struct rb_node *n = root->rb_node;
+
+   while (n) {
+   struct hist_entry *iter;
+   struct perf_hpp_fmt *fmt;
+   int64_t cmp = 0;
+
+   iter = rb_entry(n, struct hist_entry, rb_node_in);
+   perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) {
+   cmp = fmt->collapse(fmt, iter, he);
+   if (cmp)
+   break;
+   }
+
+   if (cmp < 0)
+   n = n->rb_left;
+   else if (cmp > 0)
+   n = n->rb_right;
+   else
+   return iter;
+   }
+
+   return NULL;
+}
+
+static void hists__match_hierarchy(struct rb_root *leader_root,
+  struct rb_root *other_root)
+{
+   struct rb_node *nd;
+   struct hist_entry *pos, *pair;
+
+   for (nd = rb_first(leader_root); nd; nd = rb_next(nd)) {
+   pos  = rb_entry(nd, struct hist_entry, rb_node_in);
+   pair = hists__find_hierarchy_entry(other_root, pos);
+
+   if (pair) {
+   hist_entry__add_pair(pair, pos);
+   hists__match_hierarchy(&pos->hroot_in, &pair->hroot_in);
+   }
+   }
+}
+
 /*
  * Look for pairs to link to the leader buckets (hist_entries):
  */
@@ -2183,6 +2228,12 @@ void hists__match(struct hists *leader, struct hists 
*other)
struct rb_node *nd;
struct hist_entry *pos, *pair;
 
+   if (symbol_conf.report_hierarchy) {
+   /* hierarchy report always collapses entries */
+   return hists__match_hierarchy(&leader->entries_collapsed,
+ &other->entries_collapsed);
+   }
+
if (hists__has(leader, need_collapse))
root = &leader->entries_collapsed;
else


[tip:perf/core] perf hists browser: Fix event group display

2016-09-20 Thread tip-bot for Namhyung Kim
Commit-ID:  d9ea48bc4e7cc297ca1073fa3f90ed80d964b7b4
Gitweb: http://git.kernel.org/tip/d9ea48bc4e7cc297ca1073fa3f90ed80d964b7b4
Author: Namhyung Kim 
AuthorDate: Mon, 12 Sep 2016 15:19:52 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 12 Sep 2016 11:10:26 -0300

perf hists browser: Fix event group display

Milian reported that the event group on TUI shows duplicated overhead.
This was due to a bug on calculating hpp->buf position.  The
hpp_advance() was called from __hpp__slsmg_color_printf() on TUI but
it's already called from the hpp__call_print_fn macro in __hpp__fmt().
The end result is that the print function returns number of bytes it
printed but the buffer advanced twice of the length.

This is generally not a problem since it doesn't need to access the
buffer again.  But with event group, overhead needs to be printed
multiple times and hist_entry__snprintf_alignment() tries to fill the
space with buffer after it printed.  So it (brokenly) showed the last
overhead again.

The bug was there from the beginning, but I think it's only revealed
when the alignment function was added.

Reported-by: Milian Wolff 
Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Fixes: 89fee7094323 ("perf hists: Do column alignment on the format iterator")
Link: http://lkml.kernel.org/r/20160912061958.16656-2-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index f0611c9..35e44b1 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1097,7 +1097,6 @@ static int __hpp__slsmg_color_printf(struct perf_hpp 
*hpp, const char *fmt, ...)
ret = scnprintf(hpp->buf, hpp->size, fmt, len, percent);
ui_browser__printf(arg->b, "%s", hpp->buf);
 
-   advance_hpp(hpp, ret);
return ret;
 }
 


[tip:perf/urgent] tools lib traceevent: Ignore generated library files

2016-08-04 Thread tip-bot for Namhyung Kim
Commit-ID:  979a70a237efb68e15b1cee36f9f92037e71d1fd
Gitweb: http://git.kernel.org/tip/979a70a237efb68e15b1cee36f9f92037e71d1fd
Author: Namhyung Kim 
AuthorDate: Tue, 2 Aug 2016 14:01:47 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 2 Aug 2016 12:16:13 -0300

tools lib traceevent: Ignore generated library files

Signed-off-by: Namhyung Kim 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/r/20160802050148.3413-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/traceevent/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/lib/traceevent/.gitignore b/tools/lib/traceevent/.gitignore
index 3c60335..9e9f25f 100644
--- a/tools/lib/traceevent/.gitignore
+++ b/tools/lib/traceevent/.gitignore
@@ -1,2 +1,3 @@
 TRACEEVENT-CFLAGS
 libtraceevent-dynamic-list
+libtraceevent.so.*


[tip:perf/urgent] perf tools: Fix build failure on perl script context

2016-08-04 Thread tip-bot for Namhyung Kim
Commit-ID:  b581c01fff646b5075d65359c8667de9c667da9e
Gitweb: http://git.kernel.org/tip/b581c01fff646b5075d65359c8667de9c667da9e
Author: Namhyung Kim 
AuthorDate: Tue, 2 Aug 2016 11:43:17 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 2 Aug 2016 12:11:06 -0300

perf tools: Fix build failure on perl script context

On my Archlinux machine, perf faild to build like below:

CC   scripts/perl/Perf-Trace-Util/Context.o
  In file included from /usr/lib/perl5/core/perl/CORE/perl.h:3905:0,
   from Context.xs:23:
  /usr/lib/perl5/core/perl/CORE/inline.h: In function :
  /usr/lib/perl5/core/perl/CORE/cop.h:612:13: warning: declaration of 'av'
  shadows a previous local [-Werror-shadow]
 AV *av =3D GvAV(PL_defgv);
 ^
  /usr/lib/perl5/core/perl/CORE/inline.h:526:5: note: in expansion of
  macro 'CX_POP_SAVEARRAY'
 CX_POP_SAVEARRAY(cx);
 ^~~~
  In file included from /usr/lib/perl5/core/perl/CORE/perl.h:5853:0,
   from Context.xs:23:
  /usr/lib/perl5/core/perl/CORE/inline.h:518:9: note:
  shadowed declaration is here
 AV *av;
 ^~

What I did to fix is adding '-Wno-shadow' as the error message said it's
the cause of the failure.  Since it's from the perl (not perf) code
base, we don't have the control so I just wanted to ignore the warning
when compiling perl scripting code.

Committer note:

This also fixes the build on Fedora Rawhide.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20160802024317.31725-1-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/perl/Perf-Trace-Util/Build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Build 
b/tools/perf/scripts/perl/Perf-Trace-Util/Build
index 928e110..34faecf 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Build
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Build
@@ -1,3 +1,5 @@
 libperf-y += Context.o
 
-CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls 
-Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs -Wno-undef 
-Wno-switch-default
+CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls 
-Wno-strict-prototypes
+CFLAGS_Context.o += -Wno-unused-parameter -Wno-nested-externs -Wno-undef
+CFLAGS_Context.o += -Wno-switch-default -Wno-shadow


[tip:perf/urgent] perf stat: Use cpu-clock event for cpu targets

2016-05-19 Thread tip-bot for Namhyung Kim
Commit-ID:  a1f3d56761df31f0ffeb215b974e26d5613e92a4
Gitweb: http://git.kernel.org/tip/a1f3d56761df31f0ffeb215b974e26d5613e92a4
Author: Namhyung Kim 
AuthorDate: Fri, 13 May 2016 15:01:03 +0900
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 16 May 2016 23:11:47 -0300

perf stat: Use cpu-clock event for cpu targets

Currently 'perf stat' always counts task-clock event by default.  But
it's somewhat confusing for system-wide targets (especially with 'sleep
N' as the 'sleep' task just sleeps and doesn't use cputime).  Changing
to cpu-clock event instead for that case makes more sense IMHO.

Before:
  # perf stat -a sleep 0.1

   Performance counter stats for 'system wide':

403.038603  task-clock (msec) #4.001 CPUs utilized
   150  context-switches  #0.372 K/sec
 7  cpu-migrations#0.017 K/sec
71  page-faults   #0.176 K/sec
23,705,169  cycles#0.059 GHz
15,888,166  instructions  #0.67  insn per cycle
 3,326,078  branches  #8.253 M/sec
87,643  branch-misses #2.64% of all branches

   0.100737009 seconds time elapsed

  #

After:

  # perf stat -a sleep 0.1

   Performance counter stats for 'system wide':

404.271182  cpu-clock (msec)  #4.000 CPUs utilized
   143  context-switches  #0.354 K/sec
13  cpu-migrations#0.032 K/sec
73  page-faults   #0.181 K/sec
22,119,220  cycles#0.055 GHz
13,622,065  instructions  #0.62  insn per cycle
 2,918,769  branches  #7.220 M/sec
85,033  branch-misses #2.91% of all branches

   0.101073089 seconds time elapsed

  #

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1463119263-5569-3-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-stat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 16a923c..efdd232 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1905,6 +1905,9 @@ static int add_default_attributes(void)
}
 
if (!evsel_list->nr_entries) {
+   if (target__has_cpu(&target))
+   default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK;
+
if (perf_evlist__add_default_attrs(evsel_list, default_attrs0) 
< 0)
return -1;
if (pmu_have_event("cpu", "stalled-cycles-frontend")) {


  1   2   3   4   5   6   7   8   9   >