Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add pid/tid filtering to report and script commands

The 'record' and 'top' tools already allow a user to specify a CSV of
pids and/or tids of tasks to collect data.

Add those options to the 'report' and 'script' analysis commands to only
consider samples related to the given pids/tids.

This is also inline with the existing comm option.

Signed-off-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1427212361-7066-1-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

David Ahern and committed by
Arnaldo Carvalho de Melo
e03eaa40 6b1f3423

+67 -1
+5
tools/perf/Documentation/perf-report.txt
··· 40 40 Only consider symbols in these comms. CSV that understands 41 41 file://filename entries. This option will affect the percentage of 42 42 the overhead column. See --percentage for more info. 43 + --pid=:: 44 + Only show events for given process ID (comma separated list). 45 + 46 + --tid=:: 47 + Only show events for given thread ID (comma separated list). 43 48 -d:: 44 49 --dsos=:: 45 50 Only consider symbols in these dsos. CSV that understands
+6
tools/perf/Documentation/perf-script.txt
··· 193 193 Only display events for these comms. CSV that understands 194 194 file://filename entries. 195 195 196 + --pid=:: 197 + Only show events for given process ID (comma separated list). 198 + 199 + --tid=:: 200 + Only show events for given thread ID (comma separated list). 201 + 196 202 -I:: 197 203 --show-info:: 198 204 Display extended information about the perf.data file. This adds
+4
tools/perf/builtin-report.c
··· 669 669 "only consider symbols in these dsos"), 670 670 OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", 671 671 "only consider symbols in these comms"), 672 + OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]", 673 + "only consider symbols in these pids"), 674 + OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", 675 + "only consider symbols in these tids"), 672 676 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", 673 677 "only consider these symbols"), 674 678 OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
+4
tools/perf/builtin-script.c
··· 1562 1562 OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"), 1563 1563 OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", 1564 1564 "only display events for these comms"), 1565 + OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]", 1566 + "only consider symbols in these pids"), 1567 + OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", 1568 + "only consider symbols in these tids"), 1565 1569 OPT_BOOLEAN('I', "show-info", &show_full_info, 1566 1570 "display extended information from perf.data file"), 1567 1571 OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
+30 -1
tools/perf/util/symbol.c
··· 15 15 #include "machine.h" 16 16 #include "symbol.h" 17 17 #include "strlist.h" 18 + #include "intlist.h" 18 19 #include "header.h" 19 20 20 21 #include <elf.h> ··· 1860 1859 return 0; 1861 1860 } 1862 1861 1862 + int setup_intlist(struct intlist **list, const char *list_str, 1863 + const char *list_name) 1864 + { 1865 + if (list_str == NULL) 1866 + return 0; 1867 + 1868 + *list = intlist__new(list_str); 1869 + if (!*list) { 1870 + pr_err("problems parsing %s list\n", list_name); 1871 + return -1; 1872 + } 1873 + return 0; 1874 + } 1875 + 1863 1876 static bool symbol__read_kptr_restrict(void) 1864 1877 { 1865 1878 bool value = false; ··· 1924 1909 symbol_conf.comm_list_str, "comm") < 0) 1925 1910 goto out_free_dso_list; 1926 1911 1912 + if (setup_intlist(&symbol_conf.pid_list, 1913 + symbol_conf.pid_list_str, "pid") < 0) 1914 + goto out_free_comm_list; 1915 + 1916 + if (setup_intlist(&symbol_conf.tid_list, 1917 + symbol_conf.tid_list_str, "tid") < 0) 1918 + goto out_free_pid_list; 1919 + 1927 1920 if (setup_list(&symbol_conf.sym_list, 1928 1921 symbol_conf.sym_list_str, "symbol") < 0) 1929 - goto out_free_comm_list; 1922 + goto out_free_tid_list; 1930 1923 1931 1924 /* 1932 1925 * A path to symbols of "/" is identical to "" ··· 1953 1930 symbol_conf.initialized = true; 1954 1931 return 0; 1955 1932 1933 + out_free_tid_list: 1934 + intlist__delete(symbol_conf.tid_list); 1935 + out_free_pid_list: 1936 + intlist__delete(symbol_conf.pid_list); 1956 1937 out_free_comm_list: 1957 1938 strlist__delete(symbol_conf.comm_list); 1958 1939 out_free_dso_list: ··· 1971 1944 strlist__delete(symbol_conf.sym_list); 1972 1945 strlist__delete(symbol_conf.dso_list); 1973 1946 strlist__delete(symbol_conf.comm_list); 1947 + intlist__delete(symbol_conf.tid_list); 1948 + intlist__delete(symbol_conf.pid_list); 1974 1949 vmlinux_path__exit(); 1975 1950 symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL; 1976 1951 symbol_conf.initialized = false;
+7
tools/perf/util/symbol.h
··· 78 78 } 79 79 80 80 struct strlist; 81 + struct intlist; 81 82 82 83 struct symbol_conf { 83 84 unsigned short priv_size; ··· 116 115 const char *guestmount; 117 116 const char *dso_list_str, 118 117 *comm_list_str, 118 + *pid_list_str, 119 + *tid_list_str, 119 120 *sym_list_str, 120 121 *col_width_list_str; 121 122 struct strlist *dso_list, ··· 127 124 *dso_to_list, 128 125 *sym_from_list, 129 126 *sym_to_list; 127 + struct intlist *pid_list, 128 + *tid_list; 130 129 const char *symfs; 131 130 }; 132 131 ··· 300 295 301 296 int setup_list(struct strlist **list, const char *list_str, 302 297 const char *list_name); 298 + int setup_intlist(struct intlist **list, const char *list_str, 299 + const char *list_name); 303 300 304 301 #endif /* __PERF_SYMBOL */
+11
tools/perf/util/thread.h
··· 7 7 #include <sys/types.h> 8 8 #include "symbol.h" 9 9 #include <strlist.h> 10 + #include <intlist.h> 10 11 11 12 struct thread_stack; 12 13 ··· 98 97 { 99 98 if (symbol_conf.comm_list && 100 99 !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) { 100 + return true; 101 + } 102 + 103 + if (symbol_conf.pid_list && 104 + !intlist__has_entry(symbol_conf.pid_list, thread->pid_)) { 105 + return true; 106 + } 107 + 108 + if (symbol_conf.tid_list && 109 + !intlist__has_entry(symbol_conf.tid_list, thread->tid)) { 101 110 return true; 102 111 } 103 112