perf tools: Add sort__has_comm variable
Namhyung Kim
maintainerPATCH 1/3 perf tools: Add sort__has_comm variable
The sort__has_comm variable is to check whether the comm sort key is given. This is necessary to support thread filtering in the TUI hists browser later.
--- tools/perf/util/sort.c | 3 +++ tools/perf/util/sort.h | 1 + 2 files changed, 4 insertions(+)
tools/perf/util/sort.c +3 -0
@@ -27,6 +27,7 @@ int sort__has_sym = 0;int sort__has_dso =0 ;int sort__has_socket =0 ;int sort__has_thread =0 ; +int sort__has_comm =0 ;enum sort_mode sort__mode =SORT_MODE__NORMAL ;/*
@@ -2255,6 +2256,8 @@ static int sort_dimension__add(const char *tok, struct perf_evlist *evlist, sort__has_socket =1 ; }else if (sd->entry == &sort_thread) { sort__has_thread =1 ; + }else if (sd->entry == &sort_comm) { + sort__has_comm =1 ; }return __sort_dimension__add (sd, level);
tools/perf/util/sort.h +1 -0
@@ -37,6 +37,7 @@ extern int sort__has_parent;extern int sort__has_sym;extern int sort__has_socket;extern int sort__has_thread; +extern int sort__has_comm;extern enum sort_mode sort__mode;extern struct sort_entry sort_comm;extern struct sort_entry sort_dso;
Signature · 1 line
2.7.2
Namhyung Kim
maintainerPATCH 2/3 perf hists browser: Allow thread filtering for comm sort key
The commit 2eafd410e669 ("perf hists browser: Only 'Zoom into thread' only when sort order has 'pid'") disabled thread filtering in hist browser for the default sort key. However the he->thread is still valid even if 'pid' sort key is not given. Only thing it should not use is the pid (or tid) of the thread. So allow to filter by thread when 'comm' sort key is given and show pid only if 'pid' sort key is given.
--- tools/perf/ui/browsers/hists.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-)
tools/perf/ui/browsers/hists.c +29 -10
@@ -2136,11 +2136,17 @@ static int hists__browser_title(struct hists *hists,if (hists->uid_filter_str) printed +=snprintf (bf + printed, size - printed,", UID: %s" , hists->uid_filter_str); -if (thread) - printed +=scnprintf (bf + printed, size - printed, +if (thread) { +if (sort__has_thread) + printed +=scnprintf (bf + printed, size - printed,", Thread: %s(%d)" , (thread->comm_set ?thread__comm_str (thread) :"" ), thread->tid); +else + printed +=scnprintf (bf + printed, size - printed, +", Thread: %s" , + (thread->comm_set ?thread__comm_str (thread) :"" )); + }if (dso) printed +=scnprintf (bf + printed, size - printed,", DSO: %s" , dso->short_name);
@@ -2321,9 +2327,14 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act)thread__zput (browser->hists->thread_filter);ui_helpline__pop (); }else { -ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , - thread->comm_set ?thread__comm_str (thread) :"" , - thread->tid); +if (sort__has_thread) +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); +else +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" ); + browser->hists->thread_filter =thread__get (thread);perf_hpp__set_elide (HISTC_THREAD , false);pstack__push (browser->pstack, &browser->hists->thread_filter);
@@ -2338,13 +2349,21 @@ static int add_thread_opt(struct hist_browser *browser, struct popup_action *act, char **optstr, struct thread *thread) { - if (!sort__has_thread || thread == NULL) + int ret; + +if ((!sort__has_thread && !sort__has_comm) || thread ==NULL )return 0 ; - if (asprintf(optstr, "Zoom %s %s(%d) thread", - browser->hists->thread_filter ? "out of" : "into", - thread->comm_set ? thread__comm_str(thread) : "", - thread->tid) < 0) +if (sort__has_thread) + ret =asprintf (optstr,"Zoom %s %s(%d) thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); +else + ret =asprintf (optstr,"Zoom %s %s thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" ); +if (ret <0 )return 0 ; act->thread = thread;
Signature · 1 line
2.7.2
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/3] perf hists browser: Allow thread filtering for comm sort key
Em Wed, Mar 09, 2016 at 11:20:52PM +0900, Namhyung Kim escreveu:
Quoted 17 lines
The commit
2eafd410e669("perf hists browser: Only 'Zoom into thread' only when sort order has 'pid'") disabled thread filtering in hist browser for the default sort key. However thehe->threadis still valid even if 'pid' sort key is not given. Only thing it should not use is the pid (or tid) of the thread. So allow to filter by thread when 'comm' sort key is given and show pid only if 'pid' sort key is given.Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/ui/browsers/hists.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-)tools/perf/ui/browsers/hists.c +0
-0
tools/perf/ui/browsers/hists.c static int hists__browser_title(struct hists *hists, · line 2140
Quoted 7 lines
tools/perf/ui/browsers/hists.c +2
-2@@ -2136,11 +2136,17 @@ static int hists__browser_title(struct hists *hists,if (hists->uid_filter_str) printed +=snprintf (bf + printed, size - printed,", UID: %s" , hists->uid_filter_str); -if (thread) - printed += scnprintf(bf + printed, size - printed, +if (thread) { +if (sort__has_thread)
Please use { } for multi-line if blocks.
Quoted 35 lines
tools/perf/ui/browsers/hists.c +14
-4+ printed +=scnprintf (bf + printed, size - printed,", Thread: %s(%d)" , (thread->comm_set ?thread__comm_str (thread) :"" ), thread->tid); + else + printed += scnprintf(bf + printed, size - printed, +", Thread: %s" , + (thread->comm_set ? thread__comm_str(thread) : "")); + }if (dso) printed +=scnprintf (bf + printed, size - printed,", DSO: %s" , dso->short_name);@@ -2321,9 +2327,14 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act)thread__zput (browser->hists->thread_filter);ui_helpline__pop (); }else { -ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , - thread->comm_set ?thread__comm_str (thread) :"" , - thread->tid); +if (sort__has_thread) +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); +else +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" ); + browser->hists->thread_filter =thread__get (thread);perf_hpp__set_elide (HISTC_THREAD , false);pstack__push (browser->pstack, &browser->hists->thread_filter);@@ -2338,13 +2349,21 @@ static int add_thread_opt(struct hist_browser *browser, struct popup_action *act, char **optstr, struct thread *thread) { - if (!sort__has_thread || thread == NULL)
tools/perf/ui/browsers/hists.c static int · line 2357
Quoted 10 lines
tools/perf/ui/browsers/hists.c +4
-4+int ret; + +if ((!sort__has_thread && !sort__has_comm) || thread ==NULL )return 0 ; -if (asprintf (optstr,"Zoom %s %s(%d) thread" , - browser->hists->thread_filter ?"out of" :"into" , - thread->comm_set ?thread__comm_str (thread) :"" , - thread->tid) <0 ) +if (sort__has_thread)
Ditto
tools/perf/ui/browsers/hists.c static int · line 2362
Quoted 5 lines
tools/perf/ui/browsers/hists.c +5
-0+ ret =asprintf (optstr,"Zoom %s %s(%d) thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); + else
ditto
Quoted 9 lines
tools/perf/ui/browsers/hists.c +4
-0+ ret =asprintf (optstr,"Zoom %s %s thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" ); +if (ret <0 )return 0 ; act->thread = thread;Signature · 1 line
2.7.2
Namhyung Kim
maintainerPATCH v2 2/3 perf hists browser: Allow thread filtering for comm sort key
The commit 2eafd410e669 ("perf hists browser: Only 'Zoom into thread' only when sort order has 'pid'") disabled thread filtering in hist browser for the default sort key. However the he->thread is still valid even if 'pid' sort key is not given. Only thing it should not use is the pid (or tid) of the thread. So allow to filter by thread when 'comm' sort key is given and show pid only if 'pid' sort key is given.
--- tools/perf/ui/browsers/hists.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-)
tools/perf/ui/browsers/hists.c +32 -10
@@ -2136,11 +2136,18 @@ static int hists__browser_title(struct hists *hists,if (hists->uid_filter_str) printed +=snprintf (bf + printed, size - printed,", UID: %s" , hists->uid_filter_str); -if (thread) - printed +=scnprintf (bf + printed, size - printed, +if (thread) { +if (sort__has_thread) { + printed +=scnprintf (bf + printed, size - printed,", Thread: %s(%d)" , (thread->comm_set ?thread__comm_str (thread) :"" ), thread->tid); + }else { + printed +=scnprintf (bf + printed, size - printed, +", Thread: %s" , + (thread->comm_set ?thread__comm_str (thread) :"" )); + } + }if (dso) printed +=scnprintf (bf + printed, size - printed,", DSO: %s" , dso->short_name);
@@ -2321,9 +2328,15 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act)thread__zput (browser->hists->thread_filter);ui_helpline__pop (); }else { -ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , - thread->comm_set ?thread__comm_str (thread) :"" , - thread->tid); +if (sort__has_thread) { +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); + }else { +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" ); + } + browser->hists->thread_filter =thread__get (thread);perf_hpp__set_elide (HISTC_THREAD , false);pstack__push (browser->pstack, &browser->hists->thread_filter);
@@ -2338,13 +2351,22 @@ static int add_thread_opt(struct hist_browser *browser, struct popup_action *act, char **optstr, struct thread *thread) { - if (!sort__has_thread || thread == NULL) + int ret; + +if ((!sort__has_thread && !sort__has_comm) || thread ==NULL )return 0 ; - if (asprintf(optstr, "Zoom %s %s(%d) thread", - browser->hists->thread_filter ? "out of" : "into", - thread->comm_set ? thread__comm_str(thread) : "", - thread->tid) < 0) +if (sort__has_thread) { + ret =asprintf (optstr,"Zoom %s %s(%d) thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); + }else { + ret =asprintf (optstr,"Zoom %s %s thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" ); + } +if (ret <0 )return 0 ; act->thread = thread;
Signature · 1 line
2.7.2
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf hists browser: Allow thread filtering for comm sort key
perf hists browser: Allow thread filtering for comm sort key
Commit-ID: 6962ccb37b50366014074aec6fd14497cf719642 Gitweb: http://git.kernel.org/tip/6962ccb37b50366014074aec6fd14497cf719642 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 10 Mar 2016 00:14:50 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 10 Mar 2016 16:47:37 -0300
perf hists browser: Allow thread filtering for comm sort key
The commit 2eafd410e669 ("perf hists browser: Only 'Zoom into thread' only when sort order has 'pid'") disabled thread filtering in hist browser for the default sort key. However the he->thread is still valid even if 'pid' sort key is not given. Only thing it should not use is the pid (or tid) of the thread. So allow to filter by thread when 'comm' sort key is given and show pid only if 'pid' sort key is given.
--- tools/perf/ui/browsers/hists.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-)
tools/perf/ui/browsers/hists.c +32 -10
@@ -2136,11 +2136,18 @@ static int hists__browser_title(struct hists *hists,if (hists->uid_filter_str) printed +=snprintf (bf + printed, size - printed,", UID: %s" , hists->uid_filter_str); -if (thread) - printed +=scnprintf (bf + printed, size - printed, +if (thread) { +if (sort__has_thread) { + printed +=scnprintf (bf + printed, size - printed,", Thread: %s(%d)" , (thread->comm_set ?thread__comm_str (thread) :"" ), thread->tid); + }else { + printed +=scnprintf (bf + printed, size - printed, +", Thread: %s" , + (thread->comm_set ?thread__comm_str (thread) :"" )); + } + }if (dso) printed +=scnprintf (bf + printed, size - printed,", DSO: %s" , dso->short_name);
@@ -2321,9 +2328,15 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act)thread__zput (browser->hists->thread_filter);ui_helpline__pop (); }else { -ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , - thread->comm_set ?thread__comm_str (thread) :"" , - thread->tid); +if (sort__has_thread) { +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); + }else { +ui_helpline__fpush ("To zoom out press ESC or ENTER + \"Zoom out of %s thread\"" , + thread->comm_set ?thread__comm_str (thread) :"" ); + } + browser->hists->thread_filter =thread__get (thread);perf_hpp__set_elide (HISTC_THREAD , false);pstack__push (browser->pstack, &browser->hists->thread_filter);
@@ -2338,13 +2351,22 @@ static int add_thread_opt(struct hist_browser *browser, struct popup_action *act, char **optstr, struct thread *thread) { - if (!sort__has_thread || thread == NULL) + int ret; + +if ((!sort__has_thread && !sort__has_comm) || thread ==NULL )return 0 ; - if (asprintf(optstr, "Zoom %s %s(%d) thread", - browser->hists->thread_filter ? "out of" : "into", - thread->comm_set ? thread__comm_str(thread) : "", - thread->tid) < 0) +if (sort__has_thread) { + ret =asprintf (optstr,"Zoom %s %s(%d) thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" , + thread->tid); + }else { + ret =asprintf (optstr,"Zoom %s %s thread" , + browser->hists->thread_filter ?"out of" :"into" , + thread->comm_set ?thread__comm_str (thread) :"" ); + } +if (ret <0 )return 0 ; act->thread = thread;
Namhyung Kim
maintainerPATCH 3/3 perf hists browser: Check sort keys before hot key actions
In reply to Namhyung KimThe context menu in TUI hists browser checks corresponding sort keys when creating the menu item. But hotkey actions lacks these checks so it can filter using incorrect info.
For example, default sort key of 'perf top' doesn't contain 'comm' or 'pid' sort key so each hist entry's thread info is not reliable. Thus it should prohibit using thread filter on 't' key.
--- tools/perf/ui/browsers/hists.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/ui/browsers/hists.c +9 -0
@@ -2321,6 +2321,9 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act) {struct thread *thread = act->thread; +if ((!sort__has_thread && !sort__has_comm) || thread ==NULL ) +return 0 ; +if (browser->hists->thread_filter) {pstack__remove (browser->pstack, &browser->hists->thread_filter);perf_hpp__set_elide (HISTC_THREAD , false);
@@ -2376,6 +2379,9 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act) {struct map *map = act->ms.map; +if (!sort__has_dso || map ==NULL ) +return 0 ; +if (browser->hists->dso_filter) {pstack__remove (browser->pstack, &browser->hists->dso_filter);perf_hpp__set_elide (HISTC_DSO , false);
@@ -2527,6 +2533,9 @@ add_exit_opt(struct hist_browser *browser __maybe_unused,static int do_zoom_socket (struct hist_browser *browser,struct popup_action *act) { +if (!sort__has_socket || act->socket <0 ) +return 0 ; +if (browser->hists->socket_filter >-1 ) {pstack__remove (browser->pstack, &browser->hists->socket_filter); browser->hists->socket_filter =-1 ;
Signature · 1 line
2.7.2
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf hists browser: Check sort keys before hot key actions
perf hists browser: Check sort keys before hot key actions
Commit-ID: 599a2f38a989a79df99838f22cb607f5e2b5b56c Gitweb: http://git.kernel.org/tip/599a2f38a989a79df99838f22cb607f5e2b5b56c Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 9 Mar 2016 23:20:53 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 10 Mar 2016 16:48:02 -0300
perf hists browser: Check sort keys before hot key actions
The context menu in TUI hists browser checks corresponding sort keys when creating the menu item. But hotkey actions lacks these checks so it can filter using incorrect info.
For example, default sort key of 'perf top' doesn't contain 'comm' or 'pid' sort key so each hist entry's thread info is not reliable. Thus it should prohibit using thread filter on 't' key.
--- tools/perf/ui/browsers/hists.c | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/ui/browsers/hists.c +9 -0
@@ -2322,6 +2322,9 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act) {struct thread *thread = act->thread; +if ((!sort__has_thread && !sort__has_comm) || thread ==NULL ) +return 0 ; +if (browser->hists->thread_filter) {pstack__remove (browser->pstack, &browser->hists->thread_filter);perf_hpp__set_elide (HISTC_THREAD , false);
@@ -2379,6 +2382,9 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act) {struct map *map = act->ms.map; +if (!sort__has_dso || map ==NULL ) +return 0 ; +if (browser->hists->dso_filter) {pstack__remove (browser->pstack, &browser->hists->dso_filter);perf_hpp__set_elide (HISTC_DSO , false);
@@ -2530,6 +2536,9 @@ add_exit_opt(struct hist_browser *browser __maybe_unused,static int do_zoom_socket (struct hist_browser *browser,struct popup_action *act) { +if (!sort__has_socket || act->socket <0 ) +return 0 ; +if (browser->hists->socket_filter >-1 ) {pstack__remove (browser->pstack, &browser->hists->socket_filter); browser->hists->socket_filter =-1 ;
tip-bot for Namhyung Kim
merge botperf tools: Add sort__has_comm variable
Commit-ID: 078b8d4a406fa8ce4a3c9d5145c27be1ed2b1dfd Gitweb: http://git.kernel.org/tip/078b8d4a406fa8ce4a3c9d5145c27be1ed2b1dfd Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 9 Mar 2016 23:20:51 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 10 Mar 2016 16:47:19 -0300
perf tools: Add sort__has_comm variable
The sort__has_comm variable is to check whether the comm sort key is given. This is necessary to support thread filtering in the TUI hists browser later.
--- tools/perf/util/sort.c | 3 +++ tools/perf/util/sort.h | 1 + 2 files changed, 4 insertions(+)
tools/perf/util/sort.c +3 -0
@@ -27,6 +27,7 @@ int sort__has_sym = 0;int sort__has_dso =0 ;int sort__has_socket =0 ;int sort__has_thread =0 ; +int sort__has_comm =0 ;enum sort_mode sort__mode =SORT_MODE__NORMAL ;/*
@@ -2262,6 +2263,8 @@ static int sort_dimension__add(struct perf_hpp_list *list, const char *tok, sort__has_socket =1 ; }else if (sd->entry == &sort_thread) { sort__has_thread =1 ; + }else if (sd->entry == &sort_comm) { + sort__has_comm =1 ; }return __sort_dimension__add (sd, list, level);
tools/perf/util/sort.h +1 -0
@@ -37,6 +37,7 @@ extern int sort__has_parent;extern int sort__has_sym;extern int sort__has_socket;extern int sort__has_thread; +extern int sort__has_comm;extern enum sort_mode sort__mode;extern struct sort_entry sort_comm;extern struct sort_entry sort_dso;