diff options
| author | Mark Brown <broonie@kernel.org> | 2016-02-09 13:20:39 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2016-02-09 13:20:39 -0500 |
| commit | fcdcc79628a1919bde9acf239e364f65bab6327c (patch) | |
| tree | 5499be387cf3028c90ac083b1cf866ebed7bf7e0 /tools/perf | |
| parent | 7a8d44bc89e5cddcd5c0704a11a90484d36ba6ba (diff) | |
| parent | a0a90718f18264dc904d34a580f332006f5561e9 (diff) | |
Merge branch 'topic/acpi' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi into spi-pxa2xx
Diffstat (limited to 'tools/perf')
195 files changed, 6556 insertions, 3160 deletions
diff --git a/tools/perf/Build b/tools/perf/Build index 72237455b400..a43fae7f439a 100644 --- a/tools/perf/Build +++ b/tools/perf/Build | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | perf-y += builtin-bench.o | 1 | perf-y += builtin-bench.o |
| 2 | perf-y += builtin-annotate.o | 2 | perf-y += builtin-annotate.o |
| 3 | perf-y += builtin-config.o | ||
| 3 | perf-y += builtin-diff.o | 4 | perf-y += builtin-diff.o |
| 4 | perf-y += builtin-evlist.o | 5 | perf-y += builtin-evlist.o |
| 5 | perf-y += builtin-help.o | 6 | perf-y += builtin-help.o |
| @@ -19,6 +20,7 @@ perf-y += builtin-kvm.o | |||
| 19 | perf-y += builtin-inject.o | 20 | perf-y += builtin-inject.o |
| 20 | perf-y += builtin-mem.o | 21 | perf-y += builtin-mem.o |
| 21 | perf-y += builtin-data.o | 22 | perf-y += builtin-data.o |
| 23 | perf-y += builtin-version.o | ||
| 22 | 24 | ||
| 23 | perf-$(CONFIG_AUDIT) += builtin-trace.o | 25 | perf-$(CONFIG_AUDIT) += builtin-trace.o |
| 24 | perf-$(CONFIG_LIBELF) += builtin-probe.o | 26 | perf-$(CONFIG_LIBELF) += builtin-probe.o |
| @@ -34,8 +36,13 @@ paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))" | |||
| 34 | 36 | ||
| 35 | CFLAGS_builtin-help.o += $(paths) | 37 | CFLAGS_builtin-help.o += $(paths) |
| 36 | CFLAGS_builtin-timechart.o += $(paths) | 38 | CFLAGS_builtin-timechart.o += $(paths) |
| 37 | CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE | 39 | CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" \ |
| 40 | -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" \ | ||
| 41 | -DPREFIX="BUILD_STR($(prefix_SQ))" \ | ||
| 42 | -include $(OUTPUT)PERF-VERSION-FILE | ||
| 38 | CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" | 43 | CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" |
| 44 | CFLAGS_builtin-report.o += -DTIPDIR="BUILD_STR($(tipdir_SQ))" | ||
| 45 | CFLAGS_builtin-report.o += -DDOCDIR="BUILD_STR($(srcdir_SQ)/Documentation)" | ||
| 39 | 46 | ||
| 40 | libperf-y += util/ | 47 | libperf-y += util/ |
| 41 | libperf-y += arch/ | 48 | libperf-y += arch/ |
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt new file mode 100644 index 000000000000..b9ca1e304158 --- /dev/null +++ b/tools/perf/Documentation/perf-config.txt | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | perf-config(1) | ||
| 2 | ============== | ||
| 3 | |||
| 4 | NAME | ||
| 5 | ---- | ||
| 6 | perf-config - Get and set variables in a configuration file. | ||
| 7 | |||
| 8 | SYNOPSIS | ||
| 9 | -------- | ||
| 10 | [verse] | ||
| 11 | 'perf config' -l | --list | ||
| 12 | |||
| 13 | DESCRIPTION | ||
| 14 | ----------- | ||
| 15 | You can manage variables in a configuration file with this command. | ||
| 16 | |||
| 17 | OPTIONS | ||
| 18 | ------- | ||
| 19 | |||
| 20 | -l:: | ||
| 21 | --list:: | ||
| 22 | Show current config variables, name and value, for all sections. | ||
| 23 | |||
| 24 | CONFIGURATION FILE | ||
| 25 | ------------------ | ||
| 26 | |||
| 27 | The perf configuration file contains many variables to change various | ||
| 28 | aspects of each of its tools, including output, disk usage, etc. | ||
| 29 | The '$HOME/.perfconfig' file is used to store a per-user configuration. | ||
| 30 | The file '$(sysconfdir)/perfconfig' can be used to | ||
| 31 | store a system-wide default configuration. | ||
| 32 | |||
| 33 | Syntax | ||
| 34 | ~~~~~~ | ||
| 35 | |||
| 36 | The file consist of sections. A section starts with its name | ||
| 37 | surrounded by square brackets and continues till the next section | ||
| 38 | begins. Each variable must be in a section, and have the form | ||
| 39 | 'name = value', for example: | ||
| 40 | |||
| 41 | [section] | ||
| 42 | name1 = value1 | ||
| 43 | name2 = value2 | ||
| 44 | |||
| 45 | Section names are case sensitive and can contain any characters except | ||
| 46 | newline (double quote `"` and backslash have to be escaped as `\"` and `\\`, | ||
| 47 | respectively). Section headers can't span multiple lines. | ||
| 48 | |||
| 49 | Example | ||
| 50 | ~~~~~~~ | ||
| 51 | |||
| 52 | Given a $HOME/.perfconfig like this: | ||
| 53 | |||
| 54 | # | ||
| 55 | # This is the config file, and | ||
| 56 | # a '#' and ';' character indicates a comment | ||
| 57 | # | ||
| 58 | |||
| 59 | [colors] | ||
| 60 | # Color variables | ||
| 61 | top = red, default | ||
| 62 | medium = green, default | ||
| 63 | normal = lightgray, default | ||
| 64 | selected = white, lightgray | ||
| 65 | code = blue, default | ||
| 66 | addr = magenta, default | ||
| 67 | root = white, blue | ||
| 68 | |||
| 69 | [tui] | ||
| 70 | # Defaults if linked with libslang | ||
| 71 | report = on | ||
| 72 | annotate = on | ||
| 73 | top = on | ||
| 74 | |||
| 75 | [buildid] | ||
| 76 | # Default, disable using /dev/null | ||
| 77 | dir = ~/.debug | ||
| 78 | |||
| 79 | [annotate] | ||
| 80 | # Defaults | ||
| 81 | hide_src_code = false | ||
| 82 | use_offset = true | ||
| 83 | jump_arrows = true | ||
| 84 | show_nr_jumps = false | ||
| 85 | |||
| 86 | [help] | ||
| 87 | # Format can be man, info, web or html | ||
| 88 | format = man | ||
| 89 | autocorrect = 0 | ||
| 90 | |||
| 91 | [ui] | ||
| 92 | show-headers = true | ||
| 93 | |||
| 94 | [call-graph] | ||
| 95 | # fp (framepointer), dwarf | ||
| 96 | record-mode = fp | ||
| 97 | print-type = graph | ||
| 98 | order = caller | ||
| 99 | sort-key = function | ||
| 100 | |||
| 101 | SEE ALSO | ||
| 102 | -------- | ||
| 103 | linkperf:perf[1] | ||
diff --git a/tools/perf/Documentation/perf-evlist.txt b/tools/perf/Documentation/perf-evlist.txt index 1ceb3700ffbb..6f7200fb85cf 100644 --- a/tools/perf/Documentation/perf-evlist.txt +++ b/tools/perf/Documentation/perf-evlist.txt | |||
| @@ -32,6 +32,9 @@ OPTIONS | |||
| 32 | --group:: | 32 | --group:: |
| 33 | Show event group information. | 33 | Show event group information. |
| 34 | 34 | ||
| 35 | --trace-fields:: | ||
| 36 | Show tracepoint field names. | ||
| 37 | |||
| 35 | SEE ALSO | 38 | SEE ALSO |
| 36 | -------- | 39 | -------- |
| 37 | linkperf:perf-record[1], linkperf:perf-list[1], | 40 | linkperf:perf-record[1], linkperf:perf-list[1], |
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index e630a7d2c348..fbceb631387c 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
| @@ -207,11 +207,23 @@ comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0- | |||
| 207 | In per-thread mode with inheritance mode on (default), samples are captured only when | 207 | In per-thread mode with inheritance mode on (default), samples are captured only when |
| 208 | the thread executes on the designated CPUs. Default is to monitor all CPUs. | 208 | the thread executes on the designated CPUs. Default is to monitor all CPUs. |
| 209 | 209 | ||
| 210 | -B:: | ||
| 211 | --no-buildid:: | ||
| 212 | Do not save the build ids of binaries in the perf.data files. This skips | ||
| 213 | post processing after recording, which sometimes makes the final step in | ||
| 214 | the recording process to take a long time, as it needs to process all | ||
| 215 | events looking for mmap records. The downside is that it can misresolve | ||
| 216 | symbols if the workload binaries used when recording get locally rebuilt | ||
| 217 | or upgraded, because the only key available in this case is the | ||
| 218 | pathname. You can also set the "record.build-id" config variable to | ||
| 219 | 'skip to have this behaviour permanently. | ||
| 220 | |||
| 210 | -N:: | 221 | -N:: |
| 211 | --no-buildid-cache:: | 222 | --no-buildid-cache:: |
| 212 | Do not update the buildid cache. This saves some overhead in situations | 223 | Do not update the buildid cache. This saves some overhead in situations |
| 213 | where the information in the perf.data file (which includes buildids) | 224 | where the information in the perf.data file (which includes buildids) |
| 214 | is sufficient. | 225 | is sufficient. You can also set the "record.build-id" config variable to |
| 226 | 'no-cache' to have the same effect. | ||
| 215 | 227 | ||
| 216 | -G name,...:: | 228 | -G name,...:: |
| 217 | --cgroup name,...:: | 229 | --cgroup name,...:: |
| @@ -314,11 +326,20 @@ This option sets the time out limit. The default value is 500 ms. | |||
| 314 | Record context switch events i.e. events of type PERF_RECORD_SWITCH or | 326 | Record context switch events i.e. events of type PERF_RECORD_SWITCH or |
| 315 | PERF_RECORD_SWITCH_CPU_WIDE. | 327 | PERF_RECORD_SWITCH_CPU_WIDE. |
| 316 | 328 | ||
| 317 | --clang-path:: | 329 | --clang-path=PATH:: |
| 318 | Path to clang binary to use for compiling BPF scriptlets. | 330 | Path to clang binary to use for compiling BPF scriptlets. |
| 331 | (enabled when BPF support is on) | ||
| 319 | 332 | ||
| 320 | --clang-opt:: | 333 | --clang-opt=OPTIONS:: |
| 321 | Options passed to clang when compiling BPF scriptlets. | 334 | Options passed to clang when compiling BPF scriptlets. |
| 335 | (enabled when BPF support is on) | ||
| 336 | |||
| 337 | --vmlinux=PATH:: | ||
| 338 | Specify vmlinux path which has debuginfo. | ||
| 339 | (enabled when BPF prologue is on) | ||
| 340 | |||
| 341 | --buildid-all:: | ||
| 342 | Record build-id of all DSOs regardless whether it's actually hit or not. | ||
| 322 | 343 | ||
| 323 | SEE ALSO | 344 | SEE ALSO |
| 324 | -------- | 345 | -------- |
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt index 5ce8da1e1256..8a301f6afb37 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt | |||
| @@ -117,6 +117,30 @@ OPTIONS | |||
| 117 | And default sort keys are changed to comm, dso_from, symbol_from, dso_to | 117 | And default sort keys are changed to comm, dso_from, symbol_from, dso_to |
| 118 | and symbol_to, see '--branch-stack'. | 118 | and symbol_to, see '--branch-stack'. |
| 119 | 119 | ||
| 120 | If the data file has tracepoint event(s), following (dynamic) sort keys | ||
| 121 | are also available: | ||
| 122 | trace, trace_fields, [<event>.]<field>[/raw] | ||
| 123 | |||
| 124 | - trace: pretty printed trace output in a single column | ||
| 125 | - trace_fields: fields in tracepoints in separate columns | ||
| 126 | - <field name>: optional event and field name for a specific field | ||
| 127 | |||
| 128 | The last form consists of event and field names. If event name is | ||
| 129 | omitted, it searches all events for matching field name. The matched | ||
| 130 | field will be shown only for the event has the field. The event name | ||
| 131 | supports substring match so user doesn't need to specify full subsystem | ||
| 132 | and event name everytime. For example, 'sched:sched_switch' event can | ||
| 133 | be shortened to 'switch' as long as it's not ambiguous. Also event can | ||
| 134 | be specified by its index (starting from 1) preceded by the '%'. | ||
| 135 | So '%1' is the first event, '%2' is the second, and so on. | ||
| 136 | |||
| 137 | The field name can have '/raw' suffix which disables pretty printing | ||
| 138 | and shows raw field value like hex numbers. The --raw-trace option | ||
| 139 | has the same effect for all dynamic sort keys. | ||
| 140 | |||
| 141 | The default sort keys are changed to 'trace' if all events in the data | ||
| 142 | file are tracepoint. | ||
| 143 | |||
| 120 | -F:: | 144 | -F:: |
| 121 | --fields=:: | 145 | --fields=:: |
| 122 | Specify output field - multiple keys can be specified in CSV format. | 146 | Specify output field - multiple keys can be specified in CSV format. |
| @@ -170,17 +194,18 @@ OPTIONS | |||
| 170 | Dump raw trace in ASCII. | 194 | Dump raw trace in ASCII. |
| 171 | 195 | ||
| 172 | -g:: | 196 | -g:: |
| 173 | --call-graph=<print_type,threshold[,print_limit],order,sort_key,branch>:: | 197 | --call-graph=<print_type,threshold[,print_limit],order,sort_key[,branch],value>:: |
| 174 | Display call chains using type, min percent threshold, print limit, | 198 | Display call chains using type, min percent threshold, print limit, |
| 175 | call order, sort key and branch. Note that ordering of parameters is not | 199 | call order, sort key, optional branch and value. Note that ordering of |
| 176 | fixed so any parement can be given in an arbitraty order. One exception | 200 | parameters is not fixed so any parement can be given in an arbitraty order. |
| 177 | is the print_limit which should be preceded by threshold. | 201 | One exception is the print_limit which should be preceded by threshold. |
| 178 | 202 | ||
| 179 | print_type can be either: | 203 | print_type can be either: |
| 180 | - flat: single column, linear exposure of call chains. | 204 | - flat: single column, linear exposure of call chains. |
| 181 | - graph: use a graph tree, displaying absolute overhead rates. (default) | 205 | - graph: use a graph tree, displaying absolute overhead rates. (default) |
| 182 | - fractal: like graph, but displays relative rates. Each branch of | 206 | - fractal: like graph, but displays relative rates. Each branch of |
| 183 | the tree is considered as a new profiled object. | 207 | the tree is considered as a new profiled object. |
| 208 | - folded: call chains are displayed in a line, separated by semicolons | ||
| 184 | - none: disable call chain display. | 209 | - none: disable call chain display. |
| 185 | 210 | ||
| 186 | threshold is a percentage value which specifies a minimum percent to be | 211 | threshold is a percentage value which specifies a minimum percent to be |
| @@ -204,6 +229,11 @@ OPTIONS | |||
| 204 | - branch: include last branch information in callgraph when available. | 229 | - branch: include last branch information in callgraph when available. |
| 205 | Usually more convenient to use --branch-history for this. | 230 | Usually more convenient to use --branch-history for this. |
| 206 | 231 | ||
| 232 | value can be: | ||
| 233 | - percent: diplay overhead percent (default) | ||
| 234 | - period: display event period | ||
| 235 | - count: display event count | ||
| 236 | |||
| 207 | --children:: | 237 | --children:: |
| 208 | Accumulate callchain of children to parent entry so that then can | 238 | Accumulate callchain of children to parent entry so that then can |
| 209 | show up in the output. The output will have a new "Children" column | 239 | show up in the output. The output will have a new "Children" column |
| @@ -365,6 +395,9 @@ include::itrace.txt[] | |||
| 365 | --socket-filter:: | 395 | --socket-filter:: |
| 366 | Only report the samples on the processor socket that match with this filter | 396 | Only report the samples on the processor socket that match with this filter |
| 367 | 397 | ||
| 398 | --raw-trace:: | ||
| 399 | When displaying traceevent output, do not use print fmt or plugins. | ||
| 400 | |||
| 368 | include::callchain-overhead-calculation.txt[] | 401 | include::callchain-overhead-calculation.txt[] |
| 369 | 402 | ||
| 370 | SEE ALSO | 403 | SEE ALSO |
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 4e074a660826..52ef7a9d50aa 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt | |||
| @@ -10,6 +10,8 @@ SYNOPSIS | |||
| 10 | [verse] | 10 | [verse] |
| 11 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command> | 11 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] <command> |
| 12 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>] | 12 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] -- <command> [<options>] |
| 13 | 'perf stat' [-e <EVENT> | --event=EVENT] [-a] record [-o file] -- <command> [<options>] | ||
| 14 | 'perf stat' report [-i file] | ||
| 13 | 15 | ||
| 14 | DESCRIPTION | 16 | DESCRIPTION |
| 15 | ----------- | 17 | ----------- |
| @@ -22,6 +24,11 @@ OPTIONS | |||
| 22 | <command>...:: | 24 | <command>...:: |
| 23 | Any command you can specify in a shell. | 25 | Any command you can specify in a shell. |
| 24 | 26 | ||
| 27 | record:: | ||
| 28 | See STAT RECORD. | ||
| 29 | |||
| 30 | report:: | ||
| 31 | See STAT REPORT. | ||
| 25 | 32 | ||
| 26 | -e:: | 33 | -e:: |
| 27 | --event=:: | 34 | --event=:: |
| @@ -159,6 +166,33 @@ filter out the startup phase of the program, which is often very different. | |||
| 159 | 166 | ||
| 160 | Print statistics of transactional execution if supported. | 167 | Print statistics of transactional execution if supported. |
| 161 | 168 | ||
| 169 | STAT RECORD | ||
| 170 | ----------- | ||
| 171 | Stores stat data into perf data file. | ||
| 172 | |||
| 173 | -o file:: | ||
| 174 | --output file:: | ||
| 175 | Output file name. | ||
| 176 | |||
| 177 | STAT REPORT | ||
| 178 | ----------- | ||
| 179 | Reads and reports stat data from perf data file. | ||
| 180 | |||
| 181 | -i file:: | ||
| 182 | --input file:: | ||
| 183 | Input file name. | ||
| 184 | |||
| 185 | --per-socket:: | ||
| 186 | Aggregate counts per processor socket for system-wide mode measurements. | ||
| 187 | |||
| 188 | --per-core:: | ||
| 189 | Aggregate counts per physical processor for system-wide mode measurements. | ||
| 190 | |||
| 191 | -A:: | ||
| 192 | --no-aggr:: | ||
| 193 | Do not aggregate counts across all monitored CPUs. | ||
| 194 | |||
| 195 | |||
| 162 | EXAMPLES | 196 | EXAMPLES |
| 163 | -------- | 197 | -------- |
| 164 | 198 | ||
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt index 556cec09bf50..b0e60e17db38 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt | |||
| @@ -230,6 +230,9 @@ Default is to monitor all CPUS. | |||
| 230 | The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k | 230 | The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k |
| 231 | Note that this feature may not be available on all processors. | 231 | Note that this feature may not be available on all processors. |
| 232 | 232 | ||
| 233 | --raw-trace:: | ||
| 234 | When displaying traceevent output, do not use print fmt or plugins. | ||
| 235 | |||
| 233 | INTERACTIVE PROMPTING KEYS | 236 | INTERACTIVE PROMPTING KEYS |
| 234 | -------------------------- | 237 | -------------------------- |
| 235 | 238 | ||
diff --git a/tools/perf/Documentation/tips.txt b/tools/perf/Documentation/tips.txt new file mode 100644 index 000000000000..e0ce9573b79b --- /dev/null +++ b/tools/perf/Documentation/tips.txt | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | For a higher level overview, try: perf report --sort comm,dso | ||
| 2 | Sample related events with: perf record -e '{cycles,instructions}:S' | ||
| 3 | Compare performance results with: perf diff [<old file> <new file>] | ||
| 4 | Boolean options have negative forms, e.g.: perf report --no-children | ||
| 5 | Customize output of perf script with: perf script -F event,ip,sym | ||
| 6 | Generate a script for your data: perf script -g <lang> | ||
| 7 | Save output of perf stat using: perf stat record <target workload> | ||
| 8 | Create an archive with symtabs to analyse on other machine: perf archive | ||
| 9 | Search options using a keyword: perf report -h <keyword> | ||
| 10 | Use parent filter to see specific call path: perf report -p <regex> | ||
| 11 | List events using substring match: perf list <keyword> | ||
| 12 | To see list of saved events and attributes: perf evlist -v | ||
| 13 | Use --symfs <dir> if your symbol files are in non-standard locations | ||
| 14 | To see callchains in a more compact form: perf report -g folded | ||
| 15 | Show individual samples with: perf script | ||
| 16 | Limit to show entries above 5% only: perf report --percent-limit 5 | ||
| 17 | Profiling branch (mis)predictions with: perf record -b / perf report | ||
| 18 | Treat branches as callchains: perf report --branch-history | ||
| 19 | To count events in every 1000 msec: perf stat -I 1000 | ||
| 20 | Print event counts in CSV format with: perf stat -x, | ||
| 21 | If you have debuginfo enabled, try: perf report -s sym,srcline | ||
| 22 | For memory address profiling, try: perf mem record / perf mem report | ||
| 23 | For tracepoint events, try: perf report -s trace_fields | ||
| 24 | To record callchains for each sample: perf record -g | ||
| 25 | To record every process run by an user: perf record -u <user> | ||
| 26 | Skip collecing build-id when recording: perf record -B | ||
| 27 | To change sampling frequency to 100 Hz: perf record -F 100 | ||
| 28 | See assembly instructions with percentage: perf annotate <symbol> | ||
| 29 | If you prefer Intel style assembly, try: perf annotate -M intel | ||
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index 39c38cb45b00..2e1fa2357528 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | tools/perf | 1 | tools/perf |
| 2 | tools/arch/alpha/include/asm/barrier.h | 2 | tools/arch/alpha/include/asm/barrier.h |
| 3 | tools/arch/arm/include/asm/barrier.h | 3 | tools/arch/arm/include/asm/barrier.h |
| 4 | tools/arch/arm64/include/asm/barrier.h | ||
| 4 | tools/arch/ia64/include/asm/barrier.h | 5 | tools/arch/ia64/include/asm/barrier.h |
| 5 | tools/arch/mips/include/asm/barrier.h | 6 | tools/arch/mips/include/asm/barrier.h |
| 6 | tools/arch/powerpc/include/asm/barrier.h | 7 | tools/arch/powerpc/include/asm/barrier.h |
| @@ -20,14 +21,18 @@ tools/lib/traceevent | |||
| 20 | tools/lib/bpf | 21 | tools/lib/bpf |
| 21 | tools/lib/api | 22 | tools/lib/api |
| 22 | tools/lib/bpf | 23 | tools/lib/bpf |
| 24 | tools/lib/subcmd | ||
| 23 | tools/lib/hweight.c | 25 | tools/lib/hweight.c |
| 24 | tools/lib/rbtree.c | 26 | tools/lib/rbtree.c |
| 27 | tools/lib/string.c | ||
| 25 | tools/lib/symbol/kallsyms.c | 28 | tools/lib/symbol/kallsyms.c |
| 26 | tools/lib/symbol/kallsyms.h | 29 | tools/lib/symbol/kallsyms.h |
| 27 | tools/lib/util/find_next_bit.c | 30 | tools/lib/find_bit.c |
| 31 | tools/lib/bitmap.c | ||
| 28 | tools/include/asm/atomic.h | 32 | tools/include/asm/atomic.h |
| 29 | tools/include/asm/barrier.h | 33 | tools/include/asm/barrier.h |
| 30 | tools/include/asm/bug.h | 34 | tools/include/asm/bug.h |
| 35 | tools/include/asm-generic/atomic-gcc.h | ||
| 31 | tools/include/asm-generic/barrier.h | 36 | tools/include/asm-generic/barrier.h |
| 32 | tools/include/asm-generic/bitops/arch_hweight.h | 37 | tools/include/asm-generic/bitops/arch_hweight.h |
| 33 | tools/include/asm-generic/bitops/atomic.h | 38 | tools/include/asm-generic/bitops/atomic.h |
| @@ -50,8 +55,10 @@ tools/include/linux/log2.h | |||
| 50 | tools/include/linux/poison.h | 55 | tools/include/linux/poison.h |
| 51 | tools/include/linux/rbtree.h | 56 | tools/include/linux/rbtree.h |
| 52 | tools/include/linux/rbtree_augmented.h | 57 | tools/include/linux/rbtree_augmented.h |
| 58 | tools/include/linux/string.h | ||
| 53 | tools/include/linux/types.h | 59 | tools/include/linux/types.h |
| 54 | tools/include/linux/err.h | 60 | tools/include/linux/err.h |
| 61 | tools/include/linux/bitmap.h | ||
| 55 | include/asm-generic/bitops/arch_hweight.h | 62 | include/asm-generic/bitops/arch_hweight.h |
| 56 | include/asm-generic/bitops/const_hweight.h | 63 | include/asm-generic/bitops/const_hweight.h |
| 57 | include/asm-generic/bitops/fls64.h | 64 | include/asm-generic/bitops/fls64.h |
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 0d19d5447d6c..0a22407e1d7d 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
| @@ -145,9 +145,10 @@ BISON = bison | |||
| 145 | STRIP = strip | 145 | STRIP = strip |
| 146 | AWK = awk | 146 | AWK = awk |
| 147 | 147 | ||
| 148 | LIB_DIR = $(srctree)/tools/lib/api/ | 148 | LIB_DIR = $(srctree)/tools/lib/api/ |
| 149 | TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/ | 149 | TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/ |
| 150 | BPF_DIR = $(srctree)/tools/lib/bpf/ | 150 | BPF_DIR = $(srctree)/tools/lib/bpf/ |
| 151 | SUBCMD_DIR = $(srctree)/tools/lib/subcmd/ | ||
| 151 | 152 | ||
| 152 | # include config/Makefile by default and rule out | 153 | # include config/Makefile by default and rule out |
| 153 | # non-config cases | 154 | # non-config cases |
| @@ -184,15 +185,17 @@ strip-libs = $(filter-out -l%,$(1)) | |||
| 184 | ifneq ($(OUTPUT),) | 185 | ifneq ($(OUTPUT),) |
| 185 | TE_PATH=$(OUTPUT) | 186 | TE_PATH=$(OUTPUT) |
| 186 | BPF_PATH=$(OUTPUT) | 187 | BPF_PATH=$(OUTPUT) |
| 188 | SUBCMD_PATH=$(OUTPUT) | ||
| 187 | ifneq ($(subdir),) | 189 | ifneq ($(subdir),) |
| 188 | LIB_PATH=$(OUTPUT)/../lib/api/ | 190 | API_PATH=$(OUTPUT)/../lib/api/ |
| 189 | else | 191 | else |
| 190 | LIB_PATH=$(OUTPUT) | 192 | API_PATH=$(OUTPUT) |
| 191 | endif | 193 | endif |
| 192 | else | 194 | else |
| 193 | TE_PATH=$(TRACE_EVENT_DIR) | 195 | TE_PATH=$(TRACE_EVENT_DIR) |
| 194 | LIB_PATH=$(LIB_DIR) | 196 | API_PATH=$(LIB_DIR) |
| 195 | BPF_PATH=$(BPF_DIR) | 197 | BPF_PATH=$(BPF_DIR) |
| 198 | SUBCMD_PATH=$(SUBCMD_DIR) | ||
| 196 | endif | 199 | endif |
| 197 | 200 | ||
| 198 | LIBTRACEEVENT = $(TE_PATH)libtraceevent.a | 201 | LIBTRACEEVENT = $(TE_PATH)libtraceevent.a |
| @@ -201,11 +204,13 @@ export LIBTRACEEVENT | |||
| 201 | LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list | 204 | LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list |
| 202 | LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST) | 205 | LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST) |
| 203 | 206 | ||
| 204 | LIBAPI = $(LIB_PATH)libapi.a | 207 | LIBAPI = $(API_PATH)libapi.a |
| 205 | export LIBAPI | 208 | export LIBAPI |
| 206 | 209 | ||
| 207 | LIBBPF = $(BPF_PATH)libbpf.a | 210 | LIBBPF = $(BPF_PATH)libbpf.a |
| 208 | 211 | ||
| 212 | LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a | ||
| 213 | |||
| 209 | # python extension build directories | 214 | # python extension build directories |
| 210 | PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ | 215 | PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ |
| 211 | PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ | 216 | PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ |
| @@ -257,7 +262,7 @@ export PERL_PATH | |||
| 257 | 262 | ||
| 258 | LIB_FILE=$(OUTPUT)libperf.a | 263 | LIB_FILE=$(OUTPUT)libperf.a |
| 259 | 264 | ||
| 260 | PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) | 265 | PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) |
| 261 | ifndef NO_LIBBPF | 266 | ifndef NO_LIBBPF |
| 262 | PERFLIBS += $(LIBBPF) | 267 | PERFLIBS += $(LIBBPF) |
| 263 | endif | 268 | endif |
| @@ -420,7 +425,7 @@ $(LIBTRACEEVENT)-clean: | |||
| 420 | $(call QUIET_CLEAN, libtraceevent) | 425 | $(call QUIET_CLEAN, libtraceevent) |
| 421 | $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) O=$(OUTPUT) clean >/dev/null | 426 | $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) O=$(OUTPUT) clean >/dev/null |
| 422 | 427 | ||
| 423 | install-traceevent-plugins: $(LIBTRACEEVENT) | 428 | install-traceevent-plugins: libtraceevent_plugins |
| 424 | $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins | 429 | $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins |
| 425 | 430 | ||
| 426 | $(LIBAPI): fixdep FORCE | 431 | $(LIBAPI): fixdep FORCE |
| @@ -431,12 +436,19 @@ $(LIBAPI)-clean: | |||
| 431 | $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null | 436 | $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null |
| 432 | 437 | ||
| 433 | $(LIBBPF): fixdep FORCE | 438 | $(LIBBPF): fixdep FORCE |
| 434 | $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a | 439 | $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(realpath $(OUTPUT)FEATURE-DUMP) |
| 435 | 440 | ||
| 436 | $(LIBBPF)-clean: | 441 | $(LIBBPF)-clean: |
| 437 | $(call QUIET_CLEAN, libbpf) | 442 | $(call QUIET_CLEAN, libbpf) |
| 438 | $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null | 443 | $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null |
| 439 | 444 | ||
| 445 | $(LIBSUBCMD): fixdep FORCE | ||
| 446 | $(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a | ||
| 447 | |||
| 448 | $(LIBSUBCMD)-clean: | ||
| 449 | $(call QUIET_CLEAN, libsubcmd) | ||
| 450 | $(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) clean | ||
| 451 | |||
| 440 | help: | 452 | help: |
| 441 | @echo 'Perf make targets:' | 453 | @echo 'Perf make targets:' |
| 442 | @echo ' doc - make *all* documentation (see below)' | 454 | @echo ' doc - make *all* documentation (see below)' |
| @@ -476,7 +488,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html | |||
| 476 | $(DOC_TARGETS): | 488 | $(DOC_TARGETS): |
| 477 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all) | 489 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all) |
| 478 | 490 | ||
| 479 | TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include ../lib/bpf | 491 | TAG_FOLDERS= . ../lib ../include |
| 480 | TAG_FILES= ../../include/uapi/linux/perf_event.h | 492 | TAG_FILES= ../../include/uapi/linux/perf_event.h |
| 481 | 493 | ||
| 482 | TAGS: | 494 | TAGS: |
| @@ -555,6 +567,9 @@ endif | |||
| 555 | $(call QUIET_INSTALL, perf_completion-script) \ | 567 | $(call QUIET_INSTALL, perf_completion-script) \ |
| 556 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \ | 568 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \ |
| 557 | $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' | 569 | $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' |
| 570 | $(call QUIET_INSTALL, perf-tip) \ | ||
| 571 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(tip_instdir_SQ)'; \ | ||
| 572 | $(INSTALL) Documentation/tips.txt -t '$(DESTDIR_SQ)$(tip_instdir_SQ)' | ||
| 558 | 573 | ||
| 559 | install-tests: all install-gtk | 574 | install-tests: all install-gtk |
| 560 | $(call QUIET_INSTALL, tests) \ | 575 | $(call QUIET_INSTALL, tests) \ |
| @@ -582,15 +597,16 @@ $(INSTALL_DOC_TARGETS): | |||
| 582 | # | 597 | # |
| 583 | config-clean: | 598 | config-clean: |
| 584 | $(call QUIET_CLEAN, config) | 599 | $(call QUIET_CLEAN, config) |
| 585 | $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null | 600 | $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ $(if $(OUTPUT),OUTPUT=$(OUTPUT)feature/,) clean >/dev/null |
| 586 | 601 | ||
| 587 | clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean | 602 | clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean config-clean |
| 588 | $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) | 603 | $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) |
| 589 | $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete | 604 | $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete |
| 590 | $(Q)$(RM) $(OUTPUT).config-detected | 605 | $(Q)$(RM) $(OUTPUT).config-detected |
| 591 | $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 | 606 | $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 |
| 592 | $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \ | 607 | $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \ |
| 593 | $(OUTPUT)util/intel-pt-decoder/inat-tables.c | 608 | $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \ |
| 609 | $(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c | ||
| 594 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean | 610 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean |
| 595 | $(python-clean) | 611 | $(python-clean) |
| 596 | 612 | ||
diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86/include/arch-tests.h index 7ed00f4b0908..b48de2f5813c 100644 --- a/tools/perf/arch/x86/include/arch-tests.h +++ b/tools/perf/arch/x86/include/arch-tests.h | |||
| @@ -2,10 +2,10 @@ | |||
| 2 | #define ARCH_TESTS_H | 2 | #define ARCH_TESTS_H |
| 3 | 3 | ||
| 4 | /* Tests */ | 4 | /* Tests */ |
| 5 | int test__rdpmc(void); | 5 | int test__rdpmc(int subtest); |
| 6 | int test__perf_time_to_tsc(void); | 6 | int test__perf_time_to_tsc(int subtest); |
| 7 | int test__insn_x86(void); | 7 | int test__insn_x86(int subtest); |
| 8 | int test__intel_cqm_count_nmi_context(void); | 8 | int test__intel_cqm_count_nmi_context(int subtest); |
| 9 | 9 | ||
| 10 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | 10 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
| 11 | struct thread; | 11 | struct thread; |
diff --git a/tools/perf/arch/x86/tests/insn-x86.c b/tools/perf/arch/x86/tests/insn-x86.c index b6115dfd28f0..08d9b2bc185c 100644 --- a/tools/perf/arch/x86/tests/insn-x86.c +++ b/tools/perf/arch/x86/tests/insn-x86.c | |||
| @@ -171,7 +171,7 @@ static int test_data_set(struct test_data *dat_set, int x86_64) | |||
| 171 | * verbose (-v) option to see all the instructions and whether or not they | 171 | * verbose (-v) option to see all the instructions and whether or not they |
| 172 | * decoded successfuly. | 172 | * decoded successfuly. |
| 173 | */ | 173 | */ |
| 174 | int test__insn_x86(void) | 174 | int test__insn_x86(int subtest __maybe_unused) |
| 175 | { | 175 | { |
| 176 | int ret = 0; | 176 | int ret = 0; |
| 177 | 177 | ||
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c b/tools/perf/arch/x86/tests/intel-cqm.c index d28c1b6a3b54..3e89ba825f6b 100644 --- a/tools/perf/arch/x86/tests/intel-cqm.c +++ b/tools/perf/arch/x86/tests/intel-cqm.c | |||
| @@ -33,7 +33,7 @@ static pid_t spawn(void) | |||
| 33 | * the last read counter value to avoid triggering a WARN_ON_ONCE() in | 33 | * the last read counter value to avoid triggering a WARN_ON_ONCE() in |
| 34 | * smp_call_function_many() caused by sending IPIs from NMI context. | 34 | * smp_call_function_many() caused by sending IPIs from NMI context. |
| 35 | */ | 35 | */ |
| 36 | int test__intel_cqm_count_nmi_context(void) | 36 | int test__intel_cqm_count_nmi_context(int subtest __maybe_unused) |
| 37 | { | 37 | { |
| 38 | struct perf_evlist *evlist = NULL; | 38 | struct perf_evlist *evlist = NULL; |
| 39 | struct perf_evsel *evsel = NULL; | 39 | struct perf_evsel *evsel = NULL; |
| @@ -54,7 +54,7 @@ int test__intel_cqm_count_nmi_context(void) | |||
| 54 | 54 | ||
| 55 | ret = parse_events(evlist, "intel_cqm/llc_occupancy/", NULL); | 55 | ret = parse_events(evlist, "intel_cqm/llc_occupancy/", NULL); |
| 56 | if (ret) { | 56 | if (ret) { |
| 57 | pr_debug("parse_events failed\n"); | 57 | pr_debug("parse_events failed, is \"intel_cqm/llc_occupancy/\" available?\n"); |
| 58 | err = TEST_SKIP; | 58 | err = TEST_SKIP; |
| 59 | goto out; | 59 | goto out; |
| 60 | } | 60 | } |
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c index 658cd200af74..9d29ee283ac5 100644 --- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c +++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c | |||
| @@ -35,13 +35,12 @@ | |||
| 35 | * %0 is returned, otherwise %-1 is returned. If TSC conversion is not | 35 | * %0 is returned, otherwise %-1 is returned. If TSC conversion is not |
| 36 | * supported then then the test passes but " (not supported)" is printed. | 36 | * supported then then the test passes but " (not supported)" is printed. |
| 37 | */ | 37 | */ |
| 38 | int test__perf_time_to_tsc(void) | 38 | int test__perf_time_to_tsc(int subtest __maybe_unused) |
| 39 | { | 39 | { |
| 40 | struct record_opts opts = { | 40 | struct record_opts opts = { |
| 41 | .mmap_pages = UINT_MAX, | 41 | .mmap_pages = UINT_MAX, |
| 42 | .user_freq = UINT_MAX, | 42 | .user_freq = UINT_MAX, |
| 43 | .user_interval = ULLONG_MAX, | 43 | .user_interval = ULLONG_MAX, |
| 44 | .freq = 4000, | ||
| 45 | .target = { | 44 | .target = { |
| 46 | .uses_mmap = true, | 45 | .uses_mmap = true, |
| 47 | }, | 46 | }, |
diff --git a/tools/perf/arch/x86/tests/rdpmc.c b/tools/perf/arch/x86/tests/rdpmc.c index e7688214c7cf..7bb0d13c235f 100644 --- a/tools/perf/arch/x86/tests/rdpmc.c +++ b/tools/perf/arch/x86/tests/rdpmc.c | |||
| @@ -149,7 +149,7 @@ out_close: | |||
| 149 | return 0; | 149 | return 0; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | int test__rdpmc(void) | 152 | int test__rdpmc(int subtest __maybe_unused) |
| 153 | { | 153 | { |
| 154 | int status = 0; | 154 | int status = 0; |
| 155 | int wret = 0; | 155 | int wret = 0; |
diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index ff63649fa9ac..465970370f3e 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build | |||
| @@ -5,6 +5,7 @@ libperf-y += kvm-stat.o | |||
| 5 | libperf-y += perf_regs.o | 5 | libperf-y += perf_regs.o |
| 6 | 6 | ||
| 7 | libperf-$(CONFIG_DWARF) += dwarf-regs.o | 7 | libperf-$(CONFIG_DWARF) += dwarf-regs.o |
| 8 | libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o | ||
| 8 | 9 | ||
| 9 | libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o | 10 | libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o |
| 10 | libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o | 11 | libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o |
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c index 9b94ce520917..8d8150f1cf9b 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c | |||
| @@ -327,7 +327,7 @@ static int intel_bts_snapshot_start(struct auxtrace_record *itr) | |||
| 327 | 327 | ||
| 328 | evlist__for_each(btsr->evlist, evsel) { | 328 | evlist__for_each(btsr->evlist, evsel) { |
| 329 | if (evsel->attr.type == btsr->intel_bts_pmu->type) | 329 | if (evsel->attr.type == btsr->intel_bts_pmu->type) |
| 330 | return perf_evlist__disable_event(btsr->evlist, evsel); | 330 | return perf_evsel__disable(evsel); |
| 331 | } | 331 | } |
| 332 | return -EINVAL; | 332 | return -EINVAL; |
| 333 | } | 333 | } |
| @@ -340,7 +340,7 @@ static int intel_bts_snapshot_finish(struct auxtrace_record *itr) | |||
| 340 | 340 | ||
| 341 | evlist__for_each(btsr->evlist, evsel) { | 341 | evlist__for_each(btsr->evlist, evsel) { |
| 342 | if (evsel->attr.type == btsr->intel_bts_pmu->type) | 342 | if (evsel->attr.type == btsr->intel_bts_pmu->type) |
| 343 | return perf_evlist__enable_event(btsr->evlist, evsel); | 343 | return perf_evsel__enable(evsel); |
| 344 | } | 344 | } |
| 345 | return -EINVAL; | 345 | return -EINVAL; |
| 346 | } | 346 | } |
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index b02af064f0f9..f05daacc9e78 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c | |||
| @@ -26,7 +26,7 @@ | |||
| 26 | #include "../../util/evlist.h" | 26 | #include "../../util/evlist.h" |
| 27 | #include "../../util/evsel.h" | 27 | #include "../../util/evsel.h" |
| 28 | #include "../../util/cpumap.h" | 28 | #include "../../util/cpumap.h" |
| 29 | #include "../../util/parse-options.h" | 29 | #include <subcmd/parse-options.h> |
| 30 | #include "../../util/parse-events.h" | 30 | #include "../../util/parse-events.h" |
| 31 | #include "../../util/pmu.h" | 31 | #include "../../util/pmu.h" |
| 32 | #include "../../util/debug.h" | 32 | #include "../../util/debug.h" |
| @@ -725,7 +725,7 @@ static int intel_pt_snapshot_start(struct auxtrace_record *itr) | |||
| 725 | 725 | ||
| 726 | evlist__for_each(ptr->evlist, evsel) { | 726 | evlist__for_each(ptr->evlist, evsel) { |
| 727 | if (evsel->attr.type == ptr->intel_pt_pmu->type) | 727 | if (evsel->attr.type == ptr->intel_pt_pmu->type) |
| 728 | return perf_evlist__disable_event(ptr->evlist, evsel); | 728 | return perf_evsel__disable(evsel); |
| 729 | } | 729 | } |
| 730 | return -EINVAL; | 730 | return -EINVAL; |
| 731 | } | 731 | } |
| @@ -738,7 +738,7 @@ static int intel_pt_snapshot_finish(struct auxtrace_record *itr) | |||
| 738 | 738 | ||
| 739 | evlist__for_each(ptr->evlist, evsel) { | 739 | evlist__for_each(ptr->evlist, evsel) { |
| 740 | if (evsel->attr.type == ptr->intel_pt_pmu->type) | 740 | if (evsel->attr.type == ptr->intel_pt_pmu->type) |
| 741 | return perf_evlist__enable_event(ptr->evlist, evsel); | 741 | return perf_evsel__enable(evsel); |
| 742 | } | 742 | } |
| 743 | return -EINVAL; | 743 | return -EINVAL; |
| 744 | } | 744 | } |
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index fc9bebd2cca0..0999ac536d86 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "../perf.h" | 11 | #include "../perf.h" |
| 12 | #include "../util/util.h" | 12 | #include "../util/util.h" |
| 13 | #include "../util/stat.h" | 13 | #include "../util/stat.h" |
| 14 | #include "../util/parse-options.h" | 14 | #include <subcmd/parse-options.h> |
| 15 | #include "../util/header.h" | 15 | #include "../util/header.h" |
| 16 | #include "bench.h" | 16 | #include "bench.h" |
| 17 | #include "futex.h" | 17 | #include "futex.h" |
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c index bc6a16adbca8..6a18ce21f865 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include "../perf.h" | 5 | #include "../perf.h" |
| 6 | #include "../util/util.h" | 6 | #include "../util/util.h" |
| 7 | #include "../util/stat.h" | 7 | #include "../util/stat.h" |
| 8 | #include "../util/parse-options.h" | 8 | #include <subcmd/parse-options.h> |
| 9 | #include "../util/header.h" | 9 | #include "../util/header.h" |
| 10 | #include "bench.h" | 10 | #include "bench.h" |
| 11 | #include "futex.h" | 11 | #include "futex.h" |
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index ad0d9b5342fb..718238683013 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "../perf.h" | 11 | #include "../perf.h" |
| 12 | #include "../util/util.h" | 12 | #include "../util/util.h" |
| 13 | #include "../util/stat.h" | 13 | #include "../util/stat.h" |
| 14 | #include "../util/parse-options.h" | 14 | #include <subcmd/parse-options.h> |
| 15 | #include "../util/header.h" | 15 | #include "../util/header.h" |
| 16 | #include "bench.h" | 16 | #include "bench.h" |
| 17 | #include "futex.h" | 17 | #include "futex.h" |
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index 6d8c9fa2a16c..91aaf2a1fa90 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | #include "../perf.h" | 10 | #include "../perf.h" |
| 11 | #include "../util/util.h" | 11 | #include "../util/util.h" |
| 12 | #include "../util/stat.h" | 12 | #include "../util/stat.h" |
| 13 | #include "../util/parse-options.h" | 13 | #include <subcmd/parse-options.h> |
| 14 | #include "../util/header.h" | 14 | #include "../util/header.h" |
| 15 | #include "bench.h" | 15 | #include "bench.h" |
| 16 | #include "futex.h" | 16 | #include "futex.h" |
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index e5e41d3bdce7..f416bd705f66 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "../perf.h" | 11 | #include "../perf.h" |
| 12 | #include "../util/util.h" | 12 | #include "../util/util.h" |
| 13 | #include "../util/stat.h" | 13 | #include "../util/stat.h" |
| 14 | #include "../util/parse-options.h" | 14 | #include <subcmd/parse-options.h> |
| 15 | #include "../util/header.h" | 15 | #include "../util/header.h" |
| 16 | #include "bench.h" | 16 | #include "bench.h" |
| 17 | #include "futex.h" | 17 | #include "futex.h" |
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c index 9419b944220f..a91aa85d80ff 100644 --- a/tools/perf/bench/mem-functions.c +++ b/tools/perf/bench/mem-functions.c | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | #include "../perf.h" | 9 | #include "../perf.h" |
| 10 | #include "../util/util.h" | 10 | #include "../util/util.h" |
| 11 | #include "../util/parse-options.h" | 11 | #include <subcmd/parse-options.h> |
| 12 | #include "../util/header.h" | 12 | #include "../util/header.h" |
| 13 | #include "../util/cloexec.h" | 13 | #include "../util/cloexec.h" |
| 14 | #include "bench.h" | 14 | #include "bench.h" |
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 492df2752a2d..5049d6357a46 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "../perf.h" | 7 | #include "../perf.h" |
| 8 | #include "../builtin.h" | 8 | #include "../builtin.h" |
| 9 | #include "../util/util.h" | 9 | #include "../util/util.h" |
| 10 | #include "../util/parse-options.h" | 10 | #include <subcmd/parse-options.h> |
| 11 | #include "../util/cloexec.h" | 11 | #include "../util/cloexec.h" |
| 12 | 12 | ||
| 13 | #include "bench.h" | 13 | #include "bench.h" |
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c index d4ff1b539cfd..bfaf9503de8e 100644 --- a/tools/perf/bench/sched-messaging.c +++ b/tools/perf/bench/sched-messaging.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | #include "../perf.h" | 12 | #include "../perf.h" |
| 13 | #include "../util/util.h" | 13 | #include "../util/util.h" |
| 14 | #include "../util/parse-options.h" | 14 | #include <subcmd/parse-options.h> |
| 15 | #include "../builtin.h" | 15 | #include "../builtin.h" |
| 16 | #include "bench.h" | 16 | #include "bench.h" |
| 17 | 17 | ||
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c index 005cc283790c..1dc2d13cc272 100644 --- a/tools/perf/bench/sched-pipe.c +++ b/tools/perf/bench/sched-pipe.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | */ | 10 | */ |
| 11 | #include "../perf.h" | 11 | #include "../perf.h" |
| 12 | #include "../util/util.h" | 12 | #include "../util/util.h" |
| 13 | #include "../util/parse-options.h" | 13 | #include <subcmd/parse-options.h> |
| 14 | #include "../builtin.h" | 14 | #include "../builtin.h" |
| 15 | #include "bench.h" | 15 | #include "bench.h" |
| 16 | 16 | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 2bf9b3fd9e61..cc5c1267c738 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | #include "util/evsel.h" | 21 | #include "util/evsel.h" |
| 22 | #include "util/annotate.h" | 22 | #include "util/annotate.h" |
| 23 | #include "util/event.h" | 23 | #include "util/event.h" |
| 24 | #include "util/parse-options.h" | 24 | #include <subcmd/parse-options.h> |
| 25 | #include "util/parse-events.h" | 25 | #include "util/parse-events.h" |
| 26 | #include "util/thread.h" | 26 | #include "util/thread.h" |
| 27 | #include "util/sort.h" | 27 | #include "util/sort.h" |
| @@ -47,7 +47,7 @@ struct perf_annotate { | |||
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | static int perf_evsel__add_sample(struct perf_evsel *evsel, | 49 | static int perf_evsel__add_sample(struct perf_evsel *evsel, |
| 50 | struct perf_sample *sample __maybe_unused, | 50 | struct perf_sample *sample, |
| 51 | struct addr_location *al, | 51 | struct addr_location *al, |
| 52 | struct perf_annotate *ann) | 52 | struct perf_annotate *ann) |
| 53 | { | 53 | { |
| @@ -72,7 +72,10 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel, | |||
| 72 | return 0; | 72 | return 0; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | he = __hists__add_entry(hists, al, NULL, NULL, NULL, 1, 1, 0, true); | 75 | sample->period = 1; |
| 76 | sample->weight = 1; | ||
| 77 | |||
| 78 | he = __hists__add_entry(hists, al, NULL, NULL, NULL, sample, true); | ||
| 76 | if (he == NULL) | 79 | if (he == NULL) |
| 77 | return -ENOMEM; | 80 | return -ENOMEM; |
| 78 | 81 | ||
| @@ -343,18 +346,19 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 343 | return ret; | 346 | return ret; |
| 344 | 347 | ||
| 345 | argc = parse_options(argc, argv, options, annotate_usage, 0); | 348 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
| 349 | if (argc) { | ||
| 350 | /* | ||
| 351 | * Special case: if there's an argument left then assume that | ||
| 352 | * it's a symbol filter: | ||
| 353 | */ | ||
| 354 | if (argc > 1) | ||
| 355 | usage_with_options(annotate_usage, options); | ||
| 346 | 356 | ||
| 347 | if (annotate.use_stdio) | 357 | annotate.sym_hist_filter = argv[0]; |
| 348 | use_browser = 0; | 358 | } |
| 349 | else if (annotate.use_tui) | ||
| 350 | use_browser = 1; | ||
| 351 | else if (annotate.use_gtk) | ||
| 352 | use_browser = 2; | ||
| 353 | 359 | ||
| 354 | file.path = input_name; | 360 | file.path = input_name; |
| 355 | 361 | ||
| 356 | setup_browser(true); | ||
| 357 | |||
| 358 | annotate.session = perf_session__new(&file, false, &annotate.tool); | 362 | annotate.session = perf_session__new(&file, false, &annotate.tool); |
| 359 | if (annotate.session == NULL) | 363 | if (annotate.session == NULL) |
| 360 | return -1; | 364 | return -1; |
| @@ -366,19 +370,17 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 366 | if (ret < 0) | 370 | if (ret < 0) |
| 367 | goto out_delete; | 371 | goto out_delete; |
| 368 | 372 | ||
| 369 | if (setup_sorting() < 0) | 373 | if (setup_sorting(NULL) < 0) |
| 370 | usage_with_options(annotate_usage, options); | 374 | usage_with_options(annotate_usage, options); |
| 371 | 375 | ||
| 372 | if (argc) { | 376 | if (annotate.use_stdio) |
| 373 | /* | 377 | use_browser = 0; |
| 374 | * Special case: if there's an argument left then assume that | 378 | else if (annotate.use_tui) |
| 375 | * it's a symbol filter: | 379 | use_browser = 1; |
| 376 | */ | 380 | else if (annotate.use_gtk) |
| 377 | if (argc > 1) | 381 | use_browser = 2; |
| 378 | usage_with_options(annotate_usage, options); | ||
| 379 | 382 | ||
| 380 | annotate.sym_hist_filter = argv[0]; | 383 | setup_browser(true); |
| 381 | } | ||
| 382 | 384 | ||
| 383 | ret = __cmd_annotate(&annotate); | 385 | ret = __cmd_annotate(&annotate); |
| 384 | 386 | ||
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c index b17aed36ca16..a1cddc6bbf0f 100644 --- a/tools/perf/builtin-bench.c +++ b/tools/perf/builtin-bench.c | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | */ | 16 | */ |
| 17 | #include "perf.h" | 17 | #include "perf.h" |
| 18 | #include "util/util.h" | 18 | #include "util/util.h" |
| 19 | #include "util/parse-options.h" | 19 | #include <subcmd/parse-options.h> |
| 20 | #include "builtin.h" | 20 | #include "builtin.h" |
| 21 | #include "bench/bench.h" | 21 | #include "bench/bench.h" |
| 22 | 22 | ||
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 7b8450cd33c2..d93bff7fc0e4 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | #include "util/cache.h" | 16 | #include "util/cache.h" |
| 17 | #include "util/debug.h" | 17 | #include "util/debug.h" |
| 18 | #include "util/header.h" | 18 | #include "util/header.h" |
| 19 | #include "util/parse-options.h" | 19 | #include <subcmd/parse-options.h> |
| 20 | #include "util/strlist.h" | 20 | #include "util/strlist.h" |
| 21 | #include "util/build-id.h" | 21 | #include "util/build-id.h" |
| 22 | #include "util/session.h" | 22 | #include "util/session.h" |
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index 918b4de29de4..5e914ee79eb3 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "util/build-id.h" | 12 | #include "util/build-id.h" |
| 13 | #include "util/cache.h" | 13 | #include "util/cache.h" |
| 14 | #include "util/debug.h" | 14 | #include "util/debug.h" |
| 15 | #include "util/parse-options.h" | 15 | #include <subcmd/parse-options.h> |
| 16 | #include "util/session.h" | 16 | #include "util/session.h" |
| 17 | #include "util/symbol.h" | 17 | #include "util/symbol.h" |
| 18 | #include "util/data.h" | 18 | #include "util/data.h" |
| @@ -110,7 +110,7 @@ int cmd_buildid_list(int argc, const char **argv, | |||
| 110 | setup_pager(); | 110 | setup_pager(); |
| 111 | 111 | ||
| 112 | if (show_kernel) | 112 | if (show_kernel) |
| 113 | return sysfs__fprintf_build_id(stdout); | 113 | return !(sysfs__fprintf_build_id(stdout) > 0); |
| 114 | 114 | ||
| 115 | return perf_session__list_build_ids(force, with_hits); | 115 | return perf_session__list_build_ids(force, with_hits); |
| 116 | } | 116 | } |
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c new file mode 100644 index 000000000000..f04e804a9fad --- /dev/null +++ b/tools/perf/builtin-config.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * builtin-config.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015, Taeung Song <treeze.taeung@gmail.com> | ||
| 5 | * | ||
| 6 | */ | ||
| 7 | #include "builtin.h" | ||
| 8 | |||
| 9 | #include "perf.h" | ||
| 10 | |||
| 11 | #include "util/cache.h" | ||
| 12 | #include <subcmd/parse-options.h> | ||
| 13 | #include "util/util.h" | ||
| 14 | #include "util/debug.h" | ||
| 15 | |||
| 16 | static const char * const config_usage[] = { | ||
| 17 | "perf config [options]", | ||
| 18 | NULL | ||
| 19 | }; | ||
| 20 | |||
| 21 | enum actions { | ||
| 22 | ACTION_LIST = 1 | ||
| 23 | } actions; | ||
| 24 | |||
| 25 | static struct option config_options[] = { | ||
| 26 | OPT_SET_UINT('l', "list", &actions, | ||
| 27 | "show current config variables", ACTION_LIST), | ||
| 28 | OPT_END() | ||
| 29 | }; | ||
| 30 | |||
| 31 | static int show_config(const char *key, const char *value, | ||
| 32 | void *cb __maybe_unused) | ||
| 33 | { | ||
| 34 | if (value) | ||
| 35 | printf("%s=%s\n", key, value); | ||
| 36 | else | ||
| 37 | printf("%s\n", key); | ||
| 38 | |||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) | ||
| 43 | { | ||
| 44 | int ret = 0; | ||
| 45 | |||
| 46 | argc = parse_options(argc, argv, config_options, config_usage, | ||
| 47 | PARSE_OPT_STOP_AT_NON_OPTION); | ||
| 48 | |||
| 49 | switch (actions) { | ||
| 50 | case ACTION_LIST: | ||
| 51 | if (argc) { | ||
| 52 | pr_err("Error: takes no arguments\n"); | ||
| 53 | parse_options_usage(config_usage, config_options, "l", 1); | ||
| 54 | } else { | ||
| 55 | ret = perf_config(show_config, NULL); | ||
| 56 | if (ret < 0) | ||
| 57 | pr_err("Nothing configured, " | ||
| 58 | "please check your ~/.perfconfig file\n"); | ||
| 59 | } | ||
| 60 | break; | ||
| 61 | default: | ||
| 62 | usage_with_options(config_usage, config_options); | ||
| 63 | } | ||
| 64 | |||
| 65 | return ret; | ||
| 66 | } | ||
diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c index d6525bc54d13..b97bc1518b44 100644 --- a/tools/perf/builtin-data.c +++ b/tools/perf/builtin-data.c | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | #include "builtin.h" | 2 | #include "builtin.h" |
| 3 | #include "perf.h" | 3 | #include "perf.h" |
| 4 | #include "debug.h" | 4 | #include "debug.h" |
| 5 | #include "parse-options.h" | 5 | #include <subcmd/parse-options.h> |
| 6 | #include "data-convert-bt.h" | 6 | #include "data-convert-bt.h" |
| 7 | 7 | ||
| 8 | typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix); | 8 | typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix); |
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 0b180a885ba3..36ccc2b8827f 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
| @@ -311,11 +311,11 @@ static int formula_fprintf(struct hist_entry *he, struct hist_entry *pair, | |||
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | static int hists__add_entry(struct hists *hists, | 313 | static int hists__add_entry(struct hists *hists, |
| 314 | struct addr_location *al, u64 period, | 314 | struct addr_location *al, |
| 315 | u64 weight, u64 transaction) | 315 | struct perf_sample *sample) |
| 316 | { | 316 | { |
| 317 | if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight, | 317 | if (__hists__add_entry(hists, al, NULL, NULL, NULL, |
| 318 | transaction, true) != NULL) | 318 | sample, true) != NULL) |
| 319 | return 0; | 319 | return 0; |
| 320 | return -ENOMEM; | 320 | return -ENOMEM; |
| 321 | } | 321 | } |
| @@ -336,8 +336,7 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused, | |||
| 336 | return -1; | 336 | return -1; |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | if (hists__add_entry(hists, &al, sample->period, | 339 | if (hists__add_entry(hists, &al, sample)) { |
| 340 | sample->weight, sample->transaction)) { | ||
| 341 | pr_warning("problem incrementing symbol period, skipping event\n"); | 340 | pr_warning("problem incrementing symbol period, skipping event\n"); |
| 342 | goto out_put; | 341 | goto out_put; |
| 343 | } | 342 | } |
| @@ -1208,7 +1207,7 @@ static int ui_init(void) | |||
| 1208 | BUG_ON(1); | 1207 | BUG_ON(1); |
| 1209 | } | 1208 | } |
| 1210 | 1209 | ||
| 1211 | list_add(&fmt->sort_list, &perf_hpp__sort_list); | 1210 | perf_hpp__register_sort_field(fmt); |
| 1212 | return 0; | 1211 | return 0; |
| 1213 | } | 1212 | } |
| 1214 | 1213 | ||
| @@ -1280,7 +1279,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1280 | 1279 | ||
| 1281 | sort__mode = SORT_MODE__DIFF; | 1280 | sort__mode = SORT_MODE__DIFF; |
| 1282 | 1281 | ||
| 1283 | if (setup_sorting() < 0) | 1282 | if (setup_sorting(NULL) < 0) |
| 1284 | usage_with_options(diff_usage, options); | 1283 | usage_with_options(diff_usage, options); |
| 1285 | 1284 | ||
| 1286 | setup_pager(); | 1285 | setup_pager(); |
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c index f4d62510acbb..8a31f511e1a0 100644 --- a/tools/perf/builtin-evlist.c +++ b/tools/perf/builtin-evlist.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "util/evlist.h" | 12 | #include "util/evlist.h" |
| 13 | #include "util/evsel.h" | 13 | #include "util/evsel.h" |
| 14 | #include "util/parse-events.h" | 14 | #include "util/parse-events.h" |
| 15 | #include "util/parse-options.h" | 15 | #include <subcmd/parse-options.h> |
| 16 | #include "util/session.h" | 16 | #include "util/session.h" |
| 17 | #include "util/data.h" | 17 | #include "util/data.h" |
| 18 | #include "util/debug.h" | 18 | #include "util/debug.h" |
| @@ -26,14 +26,22 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details | |||
| 26 | .mode = PERF_DATA_MODE_READ, | 26 | .mode = PERF_DATA_MODE_READ, |
| 27 | .force = details->force, | 27 | .force = details->force, |
| 28 | }; | 28 | }; |
| 29 | bool has_tracepoint = false; | ||
| 29 | 30 | ||
| 30 | session = perf_session__new(&file, 0, NULL); | 31 | session = perf_session__new(&file, 0, NULL); |
| 31 | if (session == NULL) | 32 | if (session == NULL) |
| 32 | return -1; | 33 | return -1; |
| 33 | 34 | ||
| 34 | evlist__for_each(session->evlist, pos) | 35 | evlist__for_each(session->evlist, pos) { |
| 35 | perf_evsel__fprintf(pos, details, stdout); | 36 | perf_evsel__fprintf(pos, details, stdout); |
| 36 | 37 | ||
| 38 | if (pos->attr.type == PERF_TYPE_TRACEPOINT) | ||
| 39 | has_tracepoint = true; | ||
| 40 | } | ||
| 41 | |||
| 42 | if (has_tracepoint && !details->trace_fields) | ||
| 43 | printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n"); | ||
| 44 | |||
| 37 | perf_session__delete(session); | 45 | perf_session__delete(session); |
| 38 | return 0; | 46 | return 0; |
| 39 | } | 47 | } |
| @@ -49,6 +57,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 49 | OPT_BOOLEAN('g', "group", &details.event_group, | 57 | OPT_BOOLEAN('g', "group", &details.event_group, |
| 50 | "Show event group information"), | 58 | "Show event group information"), |
| 51 | OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"), | 59 | OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"), |
| 60 | OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"), | ||
| 52 | OPT_END() | 61 | OPT_END() |
| 53 | }; | 62 | }; |
| 54 | const char * const evlist_usage[] = { | 63 | const char * const evlist_usage[] = { |
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index a7d588bf3cdd..96c1a4cfbbbf 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c | |||
| @@ -6,11 +6,11 @@ | |||
| 6 | #include "perf.h" | 6 | #include "perf.h" |
| 7 | #include "util/cache.h" | 7 | #include "util/cache.h" |
| 8 | #include "builtin.h" | 8 | #include "builtin.h" |
| 9 | #include "util/exec_cmd.h" | 9 | #include <subcmd/exec-cmd.h> |
| 10 | #include "common-cmds.h" | 10 | #include "common-cmds.h" |
| 11 | #include "util/parse-options.h" | 11 | #include <subcmd/parse-options.h> |
| 12 | #include "util/run-command.h" | 12 | #include <subcmd/run-command.h> |
| 13 | #include "util/help.h" | 13 | #include <subcmd/help.h> |
| 14 | #include "util/debug.h" | 14 | #include "util/debug.h" |
| 15 | 15 | ||
| 16 | static struct man_viewer_list { | 16 | static struct man_viewer_list { |
| @@ -407,7 +407,7 @@ static int get_html_page_path(struct strbuf *page_path, const char *page) | |||
| 407 | #ifndef open_html | 407 | #ifndef open_html |
| 408 | static void open_html(const char *path) | 408 | static void open_html(const char *path) |
| 409 | { | 409 | { |
| 410 | execl_perf_cmd("web--browse", "-c", "help.browser", path, NULL); | 410 | execl_cmd("web--browse", "-c", "help.browser", path, NULL); |
| 411 | } | 411 | } |
| 412 | #endif | 412 | #endif |
| 413 | 413 | ||
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 0a945d2e8ca5..0022e02ed31a 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
| @@ -18,7 +18,7 @@ | |||
| 18 | #include "util/data.h" | 18 | #include "util/data.h" |
| 19 | #include "util/auxtrace.h" | 19 | #include "util/auxtrace.h" |
| 20 | 20 | ||
| 21 | #include "util/parse-options.h" | 21 | #include <subcmd/parse-options.h> |
| 22 | 22 | ||
| 23 | #include <linux/list.h> | 23 | #include <linux/list.h> |
| 24 | 24 | ||
| @@ -675,6 +675,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 675 | .fork = perf_event__repipe, | 675 | .fork = perf_event__repipe, |
| 676 | .exit = perf_event__repipe, | 676 | .exit = perf_event__repipe, |
| 677 | .lost = perf_event__repipe, | 677 | .lost = perf_event__repipe, |
| 678 | .lost_samples = perf_event__repipe, | ||
| 678 | .aux = perf_event__repipe, | 679 | .aux = perf_event__repipe, |
| 679 | .itrace_start = perf_event__repipe, | 680 | .itrace_start = perf_event__repipe, |
| 680 | .context_switch = perf_event__repipe, | 681 | .context_switch = perf_event__repipe, |
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 93ce665f976f..118010553d0c 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "util/tool.h" | 12 | #include "util/tool.h" |
| 13 | #include "util/callchain.h" | 13 | #include "util/callchain.h" |
| 14 | 14 | ||
| 15 | #include "util/parse-options.h" | 15 | #include <subcmd/parse-options.h> |
| 16 | #include "util/trace-event.h" | 16 | #include "util/trace-event.h" |
| 17 | #include "util/data.h" | 17 | #include "util/data.h" |
| 18 | #include "util/cpumap.h" | 18 | #include "util/cpumap.h" |
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index dd94b4ca2213..4418d9214872 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | #include "util/header.h" | 10 | #include "util/header.h" |
| 11 | #include "util/session.h" | 11 | #include "util/session.h" |
| 12 | #include "util/intlist.h" | 12 | #include "util/intlist.h" |
| 13 | #include "util/parse-options.h" | 13 | #include <subcmd/parse-options.h> |
| 14 | #include "util/trace-event.h" | 14 | #include "util/trace-event.h" |
| 15 | #include "util/debug.h" | 15 | #include "util/debug.h" |
| 16 | #include "util/tool.h" | 16 | #include "util/tool.h" |
| @@ -1351,7 +1351,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, | |||
| 1351 | disable_buildid_cache(); | 1351 | disable_buildid_cache(); |
| 1352 | 1352 | ||
| 1353 | use_browser = 0; | 1353 | use_browser = 0; |
| 1354 | setup_browser(false); | ||
| 1355 | 1354 | ||
| 1356 | if (argc) { | 1355 | if (argc) { |
| 1357 | argc = parse_options(argc, argv, live_options, | 1356 | argc = parse_options(argc, argv, live_options, |
| @@ -1409,8 +1408,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, | |||
| 1409 | err = kvm_events_live_report(kvm); | 1408 | err = kvm_events_live_report(kvm); |
| 1410 | 1409 | ||
| 1411 | out: | 1410 | out: |
| 1412 | exit_browser(0); | ||
| 1413 | |||
| 1414 | if (kvm->session) | 1411 | if (kvm->session) |
| 1415 | perf_session__delete(kvm->session); | 1412 | perf_session__delete(kvm->session); |
| 1416 | kvm->session = NULL; | 1413 | kvm->session = NULL; |
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index bf679e2c978b..5e22db4684b8 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | #include "util/parse-events.h" | 14 | #include "util/parse-events.h" |
| 15 | #include "util/cache.h" | 15 | #include "util/cache.h" |
| 16 | #include "util/pmu.h" | 16 | #include "util/pmu.h" |
| 17 | #include "util/parse-options.h" | 17 | #include <subcmd/parse-options.h> |
| 18 | 18 | ||
| 19 | int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) | 19 | int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) |
| 20 | { | 20 | { |
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index de16aaed516e..ce3bfb48b26f 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include "util/thread.h" | 9 | #include "util/thread.h" |
| 10 | #include "util/header.h" | 10 | #include "util/header.h" |
| 11 | 11 | ||
| 12 | #include "util/parse-options.h" | 12 | #include <subcmd/parse-options.h> |
| 13 | #include "util/trace-event.h" | 13 | #include "util/trace-event.h" |
| 14 | 14 | ||
| 15 | #include "util/debug.h" | 15 | #include "util/debug.h" |
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 80170aace5d4..390170041696 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "builtin.h" | 1 | #include "builtin.h" |
| 2 | #include "perf.h" | 2 | #include "perf.h" |
| 3 | 3 | ||
| 4 | #include "util/parse-options.h" | 4 | #include <subcmd/parse-options.h> |
| 5 | #include "util/trace-event.h" | 5 | #include "util/trace-event.h" |
| 6 | #include "util/tool.h" | 6 | #include "util/tool.h" |
| 7 | #include "util/session.h" | 7 | #include "util/session.h" |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 132afc97676c..9af859b28b15 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
| @@ -37,7 +37,7 @@ | |||
| 37 | #include "util/strfilter.h" | 37 | #include "util/strfilter.h" |
| 38 | #include "util/symbol.h" | 38 | #include "util/symbol.h" |
| 39 | #include "util/debug.h" | 39 | #include "util/debug.h" |
| 40 | #include "util/parse-options.h" | 40 | #include <subcmd/parse-options.h> |
| 41 | #include "util/probe-finder.h" | 41 | #include "util/probe-finder.h" |
| 42 | #include "util/probe-event.h" | 42 | #include "util/probe-event.h" |
| 43 | #include "util/probe-file.h" | 43 | #include "util/probe-file.h" |
| @@ -249,6 +249,9 @@ static int opt_show_vars(const struct option *opt, | |||
| 249 | 249 | ||
| 250 | return ret; | 250 | return ret; |
| 251 | } | 251 | } |
| 252 | #else | ||
| 253 | # define opt_show_lines NULL | ||
| 254 | # define opt_show_vars NULL | ||
| 252 | #endif | 255 | #endif |
| 253 | static int opt_add_probe_event(const struct option *opt, | 256 | static int opt_add_probe_event(const struct option *opt, |
| 254 | const char *str, int unset __maybe_unused) | 257 | const char *str, int unset __maybe_unused) |
| @@ -473,7 +476,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 473 | opt_add_probe_event), | 476 | opt_add_probe_event), |
| 474 | OPT_BOOLEAN('f', "force", &probe_conf.force_add, "forcibly add events" | 477 | OPT_BOOLEAN('f', "force", &probe_conf.force_add, "forcibly add events" |
| 475 | " with existing name"), | 478 | " with existing name"), |
| 476 | #ifdef HAVE_DWARF_SUPPORT | ||
| 477 | OPT_CALLBACK('L', "line", NULL, | 479 | OPT_CALLBACK('L', "line", NULL, |
| 478 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", | 480 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", |
| 479 | "Show source code lines.", opt_show_lines), | 481 | "Show source code lines.", opt_show_lines), |
| @@ -490,7 +492,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 490 | "directory", "path to kernel source"), | 492 | "directory", "path to kernel source"), |
| 491 | OPT_BOOLEAN('\0', "no-inlines", &probe_conf.no_inlines, | 493 | OPT_BOOLEAN('\0', "no-inlines", &probe_conf.no_inlines, |
| 492 | "Don't search inlined functions"), | 494 | "Don't search inlined functions"), |
| 493 | #endif | ||
| 494 | OPT__DRY_RUN(&probe_event_dry_run), | 495 | OPT__DRY_RUN(&probe_event_dry_run), |
| 495 | OPT_INTEGER('\0', "max-probes", &probe_conf.max_probes, | 496 | OPT_INTEGER('\0', "max-probes", &probe_conf.max_probes, |
| 496 | "Set how many probe points can be found for a probe."), | 497 | "Set how many probe points can be found for a probe."), |
| @@ -521,6 +522,16 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 521 | #ifdef HAVE_DWARF_SUPPORT | 522 | #ifdef HAVE_DWARF_SUPPORT |
| 522 | set_option_flag(options, 'L', "line", PARSE_OPT_EXCLUSIVE); | 523 | set_option_flag(options, 'L', "line", PARSE_OPT_EXCLUSIVE); |
| 523 | set_option_flag(options, 'V', "vars", PARSE_OPT_EXCLUSIVE); | 524 | set_option_flag(options, 'V', "vars", PARSE_OPT_EXCLUSIVE); |
| 525 | #else | ||
| 526 | # define set_nobuild(s, l, c) set_option_nobuild(options, s, l, "NO_DWARF=1", c) | ||
| 527 | set_nobuild('L', "line", false); | ||
| 528 | set_nobuild('V', "vars", false); | ||
| 529 | set_nobuild('\0', "externs", false); | ||
| 530 | set_nobuild('\0', "range", false); | ||
| 531 | set_nobuild('k', "vmlinux", true); | ||
| 532 | set_nobuild('s', "source", true); | ||
| 533 | set_nobuild('\0', "no-inlines", true); | ||
| 534 | # undef set_nobuild | ||
| 524 | #endif | 535 | #endif |
| 525 | set_option_flag(options, 'F', "funcs", PARSE_OPT_EXCLUSIVE); | 536 | set_option_flag(options, 'F', "funcs", PARSE_OPT_EXCLUSIVE); |
| 526 | 537 | ||
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 199fc31e3919..319712a4e02b 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | #include "util/build-id.h" | 12 | #include "util/build-id.h" |
| 13 | #include "util/util.h" | 13 | #include "util/util.h" |
| 14 | #include "util/parse-options.h" | 14 | #include <subcmd/parse-options.h> |
| 15 | #include "util/parse-events.h" | 15 | #include "util/parse-events.h" |
| 16 | 16 | ||
| 17 | #include "util/callchain.h" | 17 | #include "util/callchain.h" |
| @@ -50,6 +50,7 @@ struct record { | |||
| 50 | int realtime_prio; | 50 | int realtime_prio; |
| 51 | bool no_buildid; | 51 | bool no_buildid; |
| 52 | bool no_buildid_cache; | 52 | bool no_buildid_cache; |
| 53 | bool buildid_all; | ||
| 53 | unsigned long long samples; | 54 | unsigned long long samples; |
| 54 | }; | 55 | }; |
| 55 | 56 | ||
| @@ -362,6 +363,13 @@ static int process_buildids(struct record *rec) | |||
| 362 | */ | 363 | */ |
| 363 | symbol_conf.ignore_vmlinux_buildid = true; | 364 | symbol_conf.ignore_vmlinux_buildid = true; |
| 364 | 365 | ||
| 366 | /* | ||
| 367 | * If --buildid-all is given, it marks all DSO regardless of hits, | ||
| 368 | * so no need to process samples. | ||
| 369 | */ | ||
| 370 | if (rec->buildid_all) | ||
| 371 | rec->tool.sample = NULL; | ||
| 372 | |||
| 365 | return perf_session__process_events(session); | 373 | return perf_session__process_events(session); |
| 366 | } | 374 | } |
| 367 | 375 | ||
| @@ -452,6 +460,8 @@ static void record__init_features(struct record *rec) | |||
| 452 | 460 | ||
| 453 | if (!rec->opts.full_auxtrace) | 461 | if (!rec->opts.full_auxtrace) |
| 454 | perf_header__clear_feat(&session->header, HEADER_AUXTRACE); | 462 | perf_header__clear_feat(&session->header, HEADER_AUXTRACE); |
| 463 | |||
| 464 | perf_header__clear_feat(&session->header, HEADER_STAT); | ||
| 455 | } | 465 | } |
| 456 | 466 | ||
| 457 | static volatile int workload_exec_errno; | 467 | static volatile int workload_exec_errno; |
| @@ -754,12 +764,8 @@ out_child: | |||
| 754 | 764 | ||
| 755 | if (!rec->no_buildid) { | 765 | if (!rec->no_buildid) { |
| 756 | process_buildids(rec); | 766 | process_buildids(rec); |
| 757 | /* | 767 | |
| 758 | * We take all buildids when the file contains | 768 | if (rec->buildid_all) |
| 759 | * AUX area tracing data because we do not decode the | ||
| 760 | * trace because it would take too long. | ||
| 761 | */ | ||
| 762 | if (rec->opts.full_auxtrace) | ||
| 763 | dsos__hit_all(rec->session); | 769 | dsos__hit_all(rec->session); |
| 764 | } | 770 | } |
| 765 | perf_session__write_header(rec->session, rec->evlist, fd, true); | 771 | perf_session__write_header(rec->session, rec->evlist, fd, true); |
| @@ -813,8 +819,12 @@ int record_parse_callchain_opt(const struct option *opt, | |||
| 813 | } | 819 | } |
| 814 | 820 | ||
| 815 | ret = parse_callchain_record_opt(arg, &callchain_param); | 821 | ret = parse_callchain_record_opt(arg, &callchain_param); |
| 816 | if (!ret) | 822 | if (!ret) { |
| 823 | /* Enable data address sampling for DWARF unwind. */ | ||
| 824 | if (callchain_param.record_mode == CALLCHAIN_DWARF) | ||
| 825 | record->sample_address = true; | ||
| 817 | callchain_debug(); | 826 | callchain_debug(); |
| 827 | } | ||
| 818 | 828 | ||
| 819 | return ret; | 829 | return ret; |
| 820 | } | 830 | } |
| @@ -837,6 +847,19 @@ int record_callchain_opt(const struct option *opt, | |||
| 837 | 847 | ||
| 838 | static int perf_record_config(const char *var, const char *value, void *cb) | 848 | static int perf_record_config(const char *var, const char *value, void *cb) |
| 839 | { | 849 | { |
| 850 | struct record *rec = cb; | ||
| 851 | |||
| 852 | if (!strcmp(var, "record.build-id")) { | ||
| 853 | if (!strcmp(value, "cache")) | ||
| 854 | rec->no_buildid_cache = false; | ||
| 855 | else if (!strcmp(value, "no-cache")) | ||
| 856 | rec->no_buildid_cache = true; | ||
| 857 | else if (!strcmp(value, "skip")) | ||
| 858 | rec->no_buildid = true; | ||
| 859 | else | ||
| 860 | return -1; | ||
| 861 | return 0; | ||
| 862 | } | ||
| 840 | if (!strcmp(var, "record.call-graph")) | 863 | if (!strcmp(var, "record.call-graph")) |
| 841 | var = "call-graph.record-mode"; /* fall-through */ | 864 | var = "call-graph.record-mode"; /* fall-through */ |
| 842 | 865 | ||
| @@ -1113,12 +1136,14 @@ struct option __record_options[] = { | |||
| 1113 | "per thread proc mmap processing timeout in ms"), | 1136 | "per thread proc mmap processing timeout in ms"), |
| 1114 | OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events, | 1137 | OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events, |
| 1115 | "Record context switch events"), | 1138 | "Record context switch events"), |
| 1116 | #ifdef HAVE_LIBBPF_SUPPORT | ||
| 1117 | OPT_STRING(0, "clang-path", &llvm_param.clang_path, "clang path", | 1139 | OPT_STRING(0, "clang-path", &llvm_param.clang_path, "clang path", |
| 1118 | "clang binary to use for compiling BPF scriptlets"), | 1140 | "clang binary to use for compiling BPF scriptlets"), |
| 1119 | OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options", | 1141 | OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options", |
| 1120 | "options passed to clang when compiling BPF scriptlets"), | 1142 | "options passed to clang when compiling BPF scriptlets"), |
| 1121 | #endif | 1143 | OPT_STRING(0, "vmlinux", &symbol_conf.vmlinux_name, |
| 1144 | "file", "vmlinux pathname"), | ||
| 1145 | OPT_BOOLEAN(0, "buildid-all", &record.buildid_all, | ||
| 1146 | "Record build-id of all DSOs regardless of hits"), | ||
| 1122 | OPT_END() | 1147 | OPT_END() |
| 1123 | }; | 1148 | }; |
| 1124 | 1149 | ||
| @@ -1130,6 +1155,27 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1130 | struct record *rec = &record; | 1155 | struct record *rec = &record; |
| 1131 | char errbuf[BUFSIZ]; | 1156 | char errbuf[BUFSIZ]; |
| 1132 | 1157 | ||
| 1158 | #ifndef HAVE_LIBBPF_SUPPORT | ||
| 1159 | # define set_nobuild(s, l, c) set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c) | ||
| 1160 | set_nobuild('\0', "clang-path", true); | ||
| 1161 | set_nobuild('\0', "clang-opt", true); | ||
| 1162 | # undef set_nobuild | ||
| 1163 | #endif | ||
| 1164 | |||
| 1165 | #ifndef HAVE_BPF_PROLOGUE | ||
| 1166 | # if !defined (HAVE_DWARF_SUPPORT) | ||
| 1167 | # define REASON "NO_DWARF=1" | ||
| 1168 | # elif !defined (HAVE_LIBBPF_SUPPORT) | ||
| 1169 | # define REASON "NO_LIBBPF=1" | ||
| 1170 | # else | ||
| 1171 | # define REASON "this architecture doesn't support BPF prologue" | ||
| 1172 | # endif | ||
| 1173 | # define set_nobuild(s, l, c) set_option_nobuild(record_options, s, l, REASON, c) | ||
| 1174 | set_nobuild('\0', "vmlinux", true); | ||
| 1175 | # undef set_nobuild | ||
| 1176 | # undef REASON | ||
| 1177 | #endif | ||
| 1178 | |||
| 1133 | rec->evlist = perf_evlist__new(); | 1179 | rec->evlist = perf_evlist__new(); |
| 1134 | if (rec->evlist == NULL) | 1180 | if (rec->evlist == NULL) |
| 1135 | return -ENOMEM; | 1181 | return -ENOMEM; |
| @@ -1215,6 +1261,14 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1215 | if (err) | 1261 | if (err) |
| 1216 | goto out_symbol_exit; | 1262 | goto out_symbol_exit; |
| 1217 | 1263 | ||
| 1264 | /* | ||
| 1265 | * We take all buildids when the file contains | ||
| 1266 | * AUX area tracing data because we do not decode the | ||
| 1267 | * trace because it would take too long. | ||
| 1268 | */ | ||
| 1269 | if (rec->opts.full_auxtrace) | ||
| 1270 | rec->buildid_all = true; | ||
| 1271 | |||
| 1218 | if (record_opts__config(&rec->opts)) { | 1272 | if (record_opts__config(&rec->opts)) { |
| 1219 | err = -EINVAL; | 1273 | err = -EINVAL; |
| 1220 | goto out_symbol_exit; | 1274 | goto out_symbol_exit; |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 2853ad2bd435..2bf537f190a0 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
| @@ -27,7 +27,8 @@ | |||
| 27 | #include "util/session.h" | 27 | #include "util/session.h" |
| 28 | #include "util/tool.h" | 28 | #include "util/tool.h" |
| 29 | 29 | ||
| 30 | #include "util/parse-options.h" | 30 | #include <subcmd/parse-options.h> |
| 31 | #include <subcmd/exec-cmd.h> | ||
| 31 | #include "util/parse-events.h" | 32 | #include "util/parse-events.h" |
| 32 | 33 | ||
| 33 | #include "util/thread.h" | 34 | #include "util/thread.h" |
| @@ -44,8 +45,7 @@ | |||
| 44 | struct report { | 45 | struct report { |
| 45 | struct perf_tool tool; | 46 | struct perf_tool tool; |
| 46 | struct perf_session *session; | 47 | struct perf_session *session; |
| 47 | bool force, use_tui, use_gtk, use_stdio; | 48 | bool use_tui, use_gtk, use_stdio; |
| 48 | bool hide_unresolved; | ||
| 49 | bool dont_use_callchains; | 49 | bool dont_use_callchains; |
| 50 | bool show_full_info; | 50 | bool show_full_info; |
| 51 | bool show_threads; | 51 | bool show_threads; |
| @@ -146,7 +146,7 @@ static int process_sample_event(struct perf_tool *tool, | |||
| 146 | struct hist_entry_iter iter = { | 146 | struct hist_entry_iter iter = { |
| 147 | .evsel = evsel, | 147 | .evsel = evsel, |
| 148 | .sample = sample, | 148 | .sample = sample, |
| 149 | .hide_unresolved = rep->hide_unresolved, | 149 | .hide_unresolved = symbol_conf.hide_unresolved, |
| 150 | .add_entry_cb = hist_iter__report_callback, | 150 | .add_entry_cb = hist_iter__report_callback, |
| 151 | }; | 151 | }; |
| 152 | int ret = 0; | 152 | int ret = 0; |
| @@ -157,7 +157,7 @@ static int process_sample_event(struct perf_tool *tool, | |||
| 157 | return -1; | 157 | return -1; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | if (rep->hide_unresolved && al.sym == NULL) | 160 | if (symbol_conf.hide_unresolved && al.sym == NULL) |
| 161 | goto out_put; | 161 | goto out_put; |
| 162 | 162 | ||
| 163 | if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) | 163 | if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) |
| @@ -434,7 +434,14 @@ static int report__browse_hists(struct report *rep) | |||
| 434 | int ret; | 434 | int ret; |
| 435 | struct perf_session *session = rep->session; | 435 | struct perf_session *session = rep->session; |
| 436 | struct perf_evlist *evlist = session->evlist; | 436 | struct perf_evlist *evlist = session->evlist; |
| 437 | const char *help = "For a higher level overview, try: perf report --sort comm,dso"; | 437 | const char *help = perf_tip(system_path(TIPDIR)); |
| 438 | |||
| 439 | if (help == NULL) { | ||
| 440 | /* fallback for people who don't install perf ;-) */ | ||
| 441 | help = perf_tip(DOCDIR); | ||
| 442 | if (help == NULL) | ||
| 443 | help = "Cannot load tips.txt file, please install perf!"; | ||
| 444 | } | ||
| 438 | 445 | ||
| 439 | switch (use_browser) { | 446 | switch (use_browser) { |
| 440 | case 1: | 447 | case 1: |
| @@ -514,20 +521,26 @@ static int __cmd_report(struct report *rep) | |||
| 514 | if (rep->cpu_list) { | 521 | if (rep->cpu_list) { |
| 515 | ret = perf_session__cpu_bitmap(session, rep->cpu_list, | 522 | ret = perf_session__cpu_bitmap(session, rep->cpu_list, |
| 516 | rep->cpu_bitmap); | 523 | rep->cpu_bitmap); |
| 517 | if (ret) | 524 | if (ret) { |
| 525 | ui__error("failed to set cpu bitmap\n"); | ||
| 518 | return ret; | 526 | return ret; |
| 527 | } | ||
| 519 | } | 528 | } |
| 520 | 529 | ||
| 521 | if (rep->show_threads) | 530 | if (rep->show_threads) |
| 522 | perf_read_values_init(&rep->show_threads_values); | 531 | perf_read_values_init(&rep->show_threads_values); |
| 523 | 532 | ||
| 524 | ret = report__setup_sample_type(rep); | 533 | ret = report__setup_sample_type(rep); |
| 525 | if (ret) | 534 | if (ret) { |
| 535 | /* report__setup_sample_type() already showed error message */ | ||
| 526 | return ret; | 536 | return ret; |
| 537 | } | ||
| 527 | 538 | ||
| 528 | ret = perf_session__process_events(session); | 539 | ret = perf_session__process_events(session); |
| 529 | if (ret) | 540 | if (ret) { |
| 541 | ui__error("failed to process sample\n"); | ||
| 530 | return ret; | 542 | return ret; |
| 543 | } | ||
| 531 | 544 | ||
| 532 | report__warn_kptr_restrict(rep); | 545 | report__warn_kptr_restrict(rep); |
| 533 | 546 | ||
| @@ -625,7 +638,7 @@ parse_percent_limit(const struct option *opt, const char *str, | |||
| 625 | return 0; | 638 | return 0; |
| 626 | } | 639 | } |
| 627 | 640 | ||
| 628 | #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function" | 641 | #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent" |
| 629 | 642 | ||
| 630 | const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n" | 643 | const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n" |
| 631 | CALLCHAIN_REPORT_HELP | 644 | CALLCHAIN_REPORT_HELP |
| @@ -678,7 +691,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 678 | "file", "vmlinux pathname"), | 691 | "file", "vmlinux pathname"), |
| 679 | OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, | 692 | OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, |
| 680 | "file", "kallsyms pathname"), | 693 | "file", "kallsyms pathname"), |
| 681 | OPT_BOOLEAN('f', "force", &report.force, "don't complain, do it"), | 694 | OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), |
| 682 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, | 695 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
| 683 | "load module symbols - WARNING: use only with -k and LIVE kernel"), | 696 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
| 684 | OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, | 697 | OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, |
| @@ -708,7 +721,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 708 | OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other, | 721 | OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other, |
| 709 | "Only display entries with parent-match"), | 722 | "Only display entries with parent-match"), |
| 710 | OPT_CALLBACK_DEFAULT('g', "call-graph", &report, | 723 | OPT_CALLBACK_DEFAULT('g', "call-graph", &report, |
| 711 | "print_type,threshold[,print_limit],order,sort_key[,branch]", | 724 | "print_type,threshold[,print_limit],order,sort_key[,branch],value", |
| 712 | report_callchain_help, &report_parse_callchain_opt, | 725 | report_callchain_help, &report_parse_callchain_opt, |
| 713 | callchain_default_opt), | 726 | callchain_default_opt), |
| 714 | OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain, | 727 | OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain, |
| @@ -740,7 +753,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 740 | OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator", | 753 | OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator", |
| 741 | "separator for columns, no spaces will be added between " | 754 | "separator for columns, no spaces will be added between " |
| 742 | "columns '.' is reserved."), | 755 | "columns '.' is reserved."), |
| 743 | OPT_BOOLEAN('U', "hide-unresolved", &report.hide_unresolved, | 756 | OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved, |
| 744 | "Only display entries resolved to a symbol"), | 757 | "Only display entries resolved to a symbol"), |
| 745 | OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory", | 758 | OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory", |
| 746 | "Look for files with symbols relative to this directory"), | 759 | "Look for files with symbols relative to this directory"), |
| @@ -783,6 +796,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 783 | "Show callgraph from reference event"), | 796 | "Show callgraph from reference event"), |
| 784 | OPT_INTEGER(0, "socket-filter", &report.socket_filter, | 797 | OPT_INTEGER(0, "socket-filter", &report.socket_filter, |
| 785 | "only show processor socket that match with this filter"), | 798 | "only show processor socket that match with this filter"), |
| 799 | OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace, | ||
| 800 | "Show raw trace event output (do not use print fmt or plugins)"), | ||
| 786 | OPT_END() | 801 | OPT_END() |
| 787 | }; | 802 | }; |
| 788 | struct perf_data_file file = { | 803 | struct perf_data_file file = { |
| @@ -796,6 +811,16 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 796 | perf_config(report__config, &report); | 811 | perf_config(report__config, &report); |
| 797 | 812 | ||
| 798 | argc = parse_options(argc, argv, options, report_usage, 0); | 813 | argc = parse_options(argc, argv, options, report_usage, 0); |
| 814 | if (argc) { | ||
| 815 | /* | ||
| 816 | * Special case: if there's an argument left then assume that | ||
| 817 | * it's a symbol filter: | ||
| 818 | */ | ||
| 819 | if (argc > 1) | ||
| 820 | usage_with_options(report_usage, options); | ||
| 821 | |||
| 822 | report.symbol_filter_str = argv[0]; | ||
| 823 | } | ||
| 799 | 824 | ||
| 800 | if (symbol_conf.vmlinux_name && | 825 | if (symbol_conf.vmlinux_name && |
| 801 | access(symbol_conf.vmlinux_name, R_OK)) { | 826 | access(symbol_conf.vmlinux_name, R_OK)) { |
| @@ -832,7 +857,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 832 | } | 857 | } |
| 833 | 858 | ||
| 834 | file.path = input_name; | 859 | file.path = input_name; |
| 835 | file.force = report.force; | 860 | file.force = symbol_conf.force; |
| 836 | 861 | ||
| 837 | repeat: | 862 | repeat: |
| 838 | session = perf_session__new(&file, false, &report.tool); | 863 | session = perf_session__new(&file, false, &report.tool); |
| @@ -882,7 +907,7 @@ repeat: | |||
| 882 | symbol_conf.cumulate_callchain = false; | 907 | symbol_conf.cumulate_callchain = false; |
| 883 | } | 908 | } |
| 884 | 909 | ||
| 885 | if (setup_sorting() < 0) { | 910 | if (setup_sorting(session->evlist) < 0) { |
| 886 | if (sort_order) | 911 | if (sort_order) |
| 887 | parse_options_usage(report_usage, options, "s", 1); | 912 | parse_options_usage(report_usage, options, "s", 1); |
| 888 | if (field_order) | 913 | if (field_order) |
| @@ -941,17 +966,6 @@ repeat: | |||
| 941 | if (symbol__init(&session->header.env) < 0) | 966 | if (symbol__init(&session->header.env) < 0) |
| 942 | goto error; | 967 | goto error; |
| 943 | 968 | ||
| 944 | if (argc) { | ||
| 945 | /* | ||
| 946 | * Special case: if there's an argument left then assume that | ||
| 947 | * it's a symbol filter: | ||
| 948 | */ | ||
| 949 | if (argc > 1) | ||
| 950 | usage_with_options(report_usage, options); | ||
| 951 | |||
| 952 | report.symbol_filter_str = argv[0]; | ||
| 953 | } | ||
| 954 | |||
| 955 | sort__setup_elide(stdout); | 969 | sort__setup_elide(stdout); |
| 956 | 970 | ||
| 957 | ret = __cmd_report(&report); | 971 | ret = __cmd_report(&report); |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index e3d3e32c0a93..871b55ae22a4 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | #include "util/tool.h" | 12 | #include "util/tool.h" |
| 13 | #include "util/cloexec.h" | 13 | #include "util/cloexec.h" |
| 14 | 14 | ||
| 15 | #include "util/parse-options.h" | 15 | #include <subcmd/parse-options.h> |
| 16 | #include "util/trace-event.h" | 16 | #include "util/trace-event.h" |
| 17 | 17 | ||
| 18 | #include "util/debug.h" | 18 | #include "util/debug.h" |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 72b5deb4bd79..c691214d820f 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
| @@ -3,9 +3,9 @@ | |||
| 3 | #include "perf.h" | 3 | #include "perf.h" |
| 4 | #include "util/cache.h" | 4 | #include "util/cache.h" |
| 5 | #include "util/debug.h" | 5 | #include "util/debug.h" |
| 6 | #include "util/exec_cmd.h" | 6 | #include <subcmd/exec-cmd.h> |
| 7 | #include "util/header.h" | 7 | #include "util/header.h" |
| 8 | #include "util/parse-options.h" | 8 | #include <subcmd/parse-options.h> |
| 9 | #include "util/perf_regs.h" | 9 | #include "util/perf_regs.h" |
| 10 | #include "util/session.h" | 10 | #include "util/session.h" |
| 11 | #include "util/tool.h" | 11 | #include "util/tool.h" |
| @@ -18,7 +18,11 @@ | |||
| 18 | #include "util/sort.h" | 18 | #include "util/sort.h" |
| 19 | #include "util/data.h" | 19 | #include "util/data.h" |
| 20 | #include "util/auxtrace.h" | 20 | #include "util/auxtrace.h" |
| 21 | #include "util/cpumap.h" | ||
| 22 | #include "util/thread_map.h" | ||
| 23 | #include "util/stat.h" | ||
| 21 | #include <linux/bitmap.h> | 24 | #include <linux/bitmap.h> |
| 25 | #include "asm/bug.h" | ||
| 22 | 26 | ||
| 23 | static char const *script_name; | 27 | static char const *script_name; |
| 24 | static char const *generate_script_lang; | 28 | static char const *generate_script_lang; |
| @@ -32,6 +36,7 @@ static bool print_flags; | |||
| 32 | static bool nanosecs; | 36 | static bool nanosecs; |
| 33 | static const char *cpu_list; | 37 | static const char *cpu_list; |
| 34 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); | 38 | static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); |
| 39 | static struct perf_stat_config stat_config; | ||
| 35 | 40 | ||
| 36 | unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH; | 41 | unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH; |
| 37 | 42 | ||
| @@ -130,6 +135,18 @@ static struct { | |||
| 130 | 135 | ||
| 131 | .invalid_fields = PERF_OUTPUT_TRACE, | 136 | .invalid_fields = PERF_OUTPUT_TRACE, |
| 132 | }, | 137 | }, |
| 138 | |||
| 139 | [PERF_TYPE_BREAKPOINT] = { | ||
| 140 | .user_set = false, | ||
| 141 | |||
| 142 | .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID | | ||
| 143 | PERF_OUTPUT_CPU | PERF_OUTPUT_TIME | | ||
| 144 | PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP | | ||
| 145 | PERF_OUTPUT_SYM | PERF_OUTPUT_DSO | | ||
| 146 | PERF_OUTPUT_PERIOD, | ||
| 147 | |||
| 148 | .invalid_fields = PERF_OUTPUT_TRACE, | ||
| 149 | }, | ||
| 133 | }; | 150 | }; |
| 134 | 151 | ||
| 135 | static bool output_set_by_user(void) | 152 | static bool output_set_by_user(void) |
| @@ -204,6 +221,9 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, | |||
| 204 | struct perf_event_attr *attr = &evsel->attr; | 221 | struct perf_event_attr *attr = &evsel->attr; |
| 205 | bool allow_user_set; | 222 | bool allow_user_set; |
| 206 | 223 | ||
| 224 | if (perf_header__has_feat(&session->header, HEADER_STAT)) | ||
| 225 | return 0; | ||
| 226 | |||
| 207 | allow_user_set = perf_header__has_feat(&session->header, | 227 | allow_user_set = perf_header__has_feat(&session->header, |
| 208 | HEADER_AUXTRACE); | 228 | HEADER_AUXTRACE); |
| 209 | 229 | ||
| @@ -588,8 +608,35 @@ static void print_sample_flags(u32 flags) | |||
| 588 | printf(" %-4s ", str); | 608 | printf(" %-4s ", str); |
| 589 | } | 609 | } |
| 590 | 610 | ||
| 591 | static void process_event(union perf_event *event, struct perf_sample *sample, | 611 | struct perf_script { |
| 592 | struct perf_evsel *evsel, struct addr_location *al) | 612 | struct perf_tool tool; |
| 613 | struct perf_session *session; | ||
| 614 | bool show_task_events; | ||
| 615 | bool show_mmap_events; | ||
| 616 | bool show_switch_events; | ||
| 617 | bool allocated; | ||
| 618 | struct cpu_map *cpus; | ||
| 619 | struct thread_map *threads; | ||
| 620 | int name_width; | ||
| 621 | }; | ||
| 622 | |||
| 623 | static int perf_evlist__max_name_len(struct perf_evlist *evlist) | ||
| 624 | { | ||
| 625 | struct perf_evsel *evsel; | ||
| 626 | int max = 0; | ||
| 627 | |||
| 628 | evlist__for_each(evlist, evsel) { | ||
| 629 | int len = strlen(perf_evsel__name(evsel)); | ||
| 630 | |||
| 631 | max = MAX(len, max); | ||
| 632 | } | ||
| 633 | |||
| 634 | return max; | ||
| 635 | } | ||
| 636 | |||
| 637 | static void process_event(struct perf_script *script, union perf_event *event, | ||
| 638 | struct perf_sample *sample, struct perf_evsel *evsel, | ||
| 639 | struct addr_location *al) | ||
| 593 | { | 640 | { |
| 594 | struct thread *thread = al->thread; | 641 | struct thread *thread = al->thread; |
| 595 | struct perf_event_attr *attr = &evsel->attr; | 642 | struct perf_event_attr *attr = &evsel->attr; |
| @@ -604,7 +651,12 @@ static void process_event(union perf_event *event, struct perf_sample *sample, | |||
| 604 | 651 | ||
| 605 | if (PRINT_FIELD(EVNAME)) { | 652 | if (PRINT_FIELD(EVNAME)) { |
| 606 | const char *evname = perf_evsel__name(evsel); | 653 | const char *evname = perf_evsel__name(evsel); |
| 607 | printf("%s: ", evname ? evname : "[unknown]"); | 654 | |
| 655 | if (!script->name_width) | ||
| 656 | script->name_width = perf_evlist__max_name_len(script->session->evlist); | ||
| 657 | |||
| 658 | printf("%*s: ", script->name_width, | ||
| 659 | evname ? evname : "[unknown]"); | ||
| 608 | } | 660 | } |
| 609 | 661 | ||
| 610 | if (print_flags) | 662 | if (print_flags) |
| @@ -643,65 +695,81 @@ static void process_event(union perf_event *event, struct perf_sample *sample, | |||
| 643 | printf("\n"); | 695 | printf("\n"); |
| 644 | } | 696 | } |
| 645 | 697 | ||
| 646 | static int default_start_script(const char *script __maybe_unused, | 698 | static struct scripting_ops *scripting_ops; |
| 647 | int argc __maybe_unused, | ||
| 648 | const char **argv __maybe_unused) | ||
| 649 | { | ||
| 650 | return 0; | ||
| 651 | } | ||
| 652 | 699 | ||
| 653 | static int default_flush_script(void) | 700 | static void __process_stat(struct perf_evsel *counter, u64 tstamp) |
| 654 | { | 701 | { |
| 655 | return 0; | 702 | int nthreads = thread_map__nr(counter->threads); |
| 703 | int ncpus = perf_evsel__nr_cpus(counter); | ||
| 704 | int cpu, thread; | ||
| 705 | static int header_printed; | ||
| 706 | |||
| 707 | if (counter->system_wide) | ||
| 708 | nthreads = 1; | ||
| 709 | |||
| 710 | if (!header_printed) { | ||
| 711 | printf("%3s %8s %15s %15s %15s %15s %s\n", | ||
| 712 | "CPU", "THREAD", "VAL", "ENA", "RUN", "TIME", "EVENT"); | ||
| 713 | header_printed = 1; | ||
| 714 | } | ||
| 715 | |||
| 716 | for (thread = 0; thread < nthreads; thread++) { | ||
| 717 | for (cpu = 0; cpu < ncpus; cpu++) { | ||
| 718 | struct perf_counts_values *counts; | ||
| 719 | |||
| 720 | counts = perf_counts(counter->counts, cpu, thread); | ||
| 721 | |||
| 722 | printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n", | ||
| 723 | counter->cpus->map[cpu], | ||
| 724 | thread_map__pid(counter->threads, thread), | ||
| 725 | counts->val, | ||
| 726 | counts->ena, | ||
| 727 | counts->run, | ||
| 728 | tstamp, | ||
| 729 | perf_evsel__name(counter)); | ||
| 730 | } | ||
| 731 | } | ||
| 656 | } | 732 | } |
| 657 | 733 | ||
| 658 | static int default_stop_script(void) | 734 | static void process_stat(struct perf_evsel *counter, u64 tstamp) |
| 659 | { | 735 | { |
| 660 | return 0; | 736 | if (scripting_ops && scripting_ops->process_stat) |
| 737 | scripting_ops->process_stat(&stat_config, counter, tstamp); | ||
| 738 | else | ||
| 739 | __process_stat(counter, tstamp); | ||
| 661 | } | 740 | } |
| 662 | 741 | ||
| 663 | static int default_generate_script(struct pevent *pevent __maybe_unused, | 742 | static void process_stat_interval(u64 tstamp) |
| 664 | const char *outfile __maybe_unused) | ||
| 665 | { | 743 | { |
| 666 | return 0; | 744 | if (scripting_ops && scripting_ops->process_stat_interval) |
| 745 | scripting_ops->process_stat_interval(tstamp); | ||
| 667 | } | 746 | } |
| 668 | 747 | ||
| 669 | static struct scripting_ops default_scripting_ops = { | ||
| 670 | .start_script = default_start_script, | ||
| 671 | .flush_script = default_flush_script, | ||
| 672 | .stop_script = default_stop_script, | ||
| 673 | .process_event = process_event, | ||
| 674 | .generate_script = default_generate_script, | ||
| 675 | }; | ||
| 676 | |||
| 677 | static struct scripting_ops *scripting_ops; | ||
| 678 | |||
| 679 | static void setup_scripting(void) | 748 | static void setup_scripting(void) |
| 680 | { | 749 | { |
| 681 | setup_perl_scripting(); | 750 | setup_perl_scripting(); |
| 682 | setup_python_scripting(); | 751 | setup_python_scripting(); |
| 683 | |||
| 684 | scripting_ops = &default_scripting_ops; | ||
| 685 | } | 752 | } |
| 686 | 753 | ||
| 687 | static int flush_scripting(void) | 754 | static int flush_scripting(void) |
| 688 | { | 755 | { |
| 689 | return scripting_ops->flush_script(); | 756 | return scripting_ops ? scripting_ops->flush_script() : 0; |
| 690 | } | 757 | } |
| 691 | 758 | ||
| 692 | static int cleanup_scripting(void) | 759 | static int cleanup_scripting(void) |
| 693 | { | 760 | { |
| 694 | pr_debug("\nperf script stopped\n"); | 761 | pr_debug("\nperf script stopped\n"); |
| 695 | 762 | ||
| 696 | return scripting_ops->stop_script(); | 763 | return scripting_ops ? scripting_ops->stop_script() : 0; |
| 697 | } | 764 | } |
| 698 | 765 | ||
| 699 | static int process_sample_event(struct perf_tool *tool __maybe_unused, | 766 | static int process_sample_event(struct perf_tool *tool, |
| 700 | union perf_event *event, | 767 | union perf_event *event, |
| 701 | struct perf_sample *sample, | 768 | struct perf_sample *sample, |
| 702 | struct perf_evsel *evsel, | 769 | struct perf_evsel *evsel, |
| 703 | struct machine *machine) | 770 | struct machine *machine) |
| 704 | { | 771 | { |
| 772 | struct perf_script *scr = container_of(tool, struct perf_script, tool); | ||
| 705 | struct addr_location al; | 773 | struct addr_location al; |
| 706 | 774 | ||
| 707 | if (debug_mode) { | 775 | if (debug_mode) { |
| @@ -727,20 +795,16 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, | |||
| 727 | if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) | 795 | if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) |
| 728 | goto out_put; | 796 | goto out_put; |
| 729 | 797 | ||
| 730 | scripting_ops->process_event(event, sample, evsel, &al); | 798 | if (scripting_ops) |
| 799 | scripting_ops->process_event(event, sample, evsel, &al); | ||
| 800 | else | ||
| 801 | process_event(scr, event, sample, evsel, &al); | ||
| 802 | |||
| 731 | out_put: | 803 | out_put: |
| 732 | addr_location__put(&al); | 804 | addr_location__put(&al); |
| 733 | return 0; | 805 | return 0; |
| 734 | } | 806 | } |
| 735 | 807 | ||
| 736 | struct perf_script { | ||
| 737 | struct perf_tool tool; | ||
| 738 | struct perf_session *session; | ||
| 739 | bool show_task_events; | ||
| 740 | bool show_mmap_events; | ||
| 741 | bool show_switch_events; | ||
| 742 | }; | ||
| 743 | |||
| 744 | static int process_attr(struct perf_tool *tool, union perf_event *event, | 808 | static int process_attr(struct perf_tool *tool, union perf_event *event, |
| 745 | struct perf_evlist **pevlist) | 809 | struct perf_evlist **pevlist) |
| 746 | { | 810 | { |
| @@ -1156,6 +1220,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused, | |||
| 1156 | type = PERF_TYPE_TRACEPOINT; | 1220 | type = PERF_TYPE_TRACEPOINT; |
| 1157 | else if (!strcmp(str, "raw")) | 1221 | else if (!strcmp(str, "raw")) |
| 1158 | type = PERF_TYPE_RAW; | 1222 | type = PERF_TYPE_RAW; |
| 1223 | else if (!strcmp(str, "break")) | ||
| 1224 | type = PERF_TYPE_BREAKPOINT; | ||
| 1159 | else { | 1225 | else { |
| 1160 | fprintf(stderr, "Invalid event type in field string.\n"); | 1226 | fprintf(stderr, "Invalid event type in field string.\n"); |
| 1161 | rc = -EINVAL; | 1227 | rc = -EINVAL; |
| @@ -1421,7 +1487,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused, | |||
| 1421 | char first_half[BUFSIZ]; | 1487 | char first_half[BUFSIZ]; |
| 1422 | char *script_root; | 1488 | char *script_root; |
| 1423 | 1489 | ||
| 1424 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path()); | 1490 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
| 1425 | 1491 | ||
| 1426 | scripts_dir = opendir(scripts_path); | 1492 | scripts_dir = opendir(scripts_path); |
| 1427 | if (!scripts_dir) | 1493 | if (!scripts_dir) |
| @@ -1542,7 +1608,7 @@ int find_scripts(char **scripts_array, char **scripts_path_array) | |||
| 1542 | if (!session) | 1608 | if (!session) |
| 1543 | return -1; | 1609 | return -1; |
| 1544 | 1610 | ||
| 1545 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path()); | 1611 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
| 1546 | 1612 | ||
| 1547 | scripts_dir = opendir(scripts_path); | 1613 | scripts_dir = opendir(scripts_path); |
| 1548 | if (!scripts_dir) { | 1614 | if (!scripts_dir) { |
| @@ -1600,7 +1666,7 @@ static char *get_script_path(const char *script_root, const char *suffix) | |||
| 1600 | char lang_path[MAXPATHLEN]; | 1666 | char lang_path[MAXPATHLEN]; |
| 1601 | char *__script_root; | 1667 | char *__script_root; |
| 1602 | 1668 | ||
| 1603 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path()); | 1669 | snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path()); |
| 1604 | 1670 | ||
| 1605 | scripts_dir = opendir(scripts_path); | 1671 | scripts_dir = opendir(scripts_path); |
| 1606 | if (!scripts_dir) | 1672 | if (!scripts_dir) |
| @@ -1695,6 +1761,87 @@ static void script__setup_sample_type(struct perf_script *script) | |||
| 1695 | } | 1761 | } |
| 1696 | } | 1762 | } |
| 1697 | 1763 | ||
| 1764 | static int process_stat_round_event(struct perf_tool *tool __maybe_unused, | ||
| 1765 | union perf_event *event, | ||
| 1766 | struct perf_session *session) | ||
| 1767 | { | ||
| 1768 | struct stat_round_event *round = &event->stat_round; | ||
| 1769 | struct perf_evsel *counter; | ||
| 1770 | |||
| 1771 | evlist__for_each(session->evlist, counter) { | ||
| 1772 | perf_stat_process_counter(&stat_config, counter); | ||
| 1773 | process_stat(counter, round->time); | ||
| 1774 | } | ||
| 1775 | |||
| 1776 | process_stat_interval(round->time); | ||
| 1777 | return 0; | ||
| 1778 | } | ||
| 1779 | |||
| 1780 | static int process_stat_config_event(struct perf_tool *tool __maybe_unused, | ||
| 1781 | union perf_event *event, | ||
| 1782 | struct perf_session *session __maybe_unused) | ||
| 1783 | { | ||
| 1784 | perf_event__read_stat_config(&stat_config, &event->stat_config); | ||
| 1785 | return 0; | ||
| 1786 | } | ||
| 1787 | |||
| 1788 | static int set_maps(struct perf_script *script) | ||
| 1789 | { | ||
| 1790 | struct perf_evlist *evlist = script->session->evlist; | ||
| 1791 | |||
| 1792 | if (!script->cpus || !script->threads) | ||
| 1793 | return 0; | ||
| 1794 | |||
| 1795 | if (WARN_ONCE(script->allocated, "stats double allocation\n")) | ||
| 1796 | return -EINVAL; | ||
| 1797 | |||
| 1798 | perf_evlist__set_maps(evlist, script->cpus, script->threads); | ||
| 1799 | |||
| 1800 | if (perf_evlist__alloc_stats(evlist, true)) | ||
| 1801 | return -ENOMEM; | ||
| 1802 | |||
| 1803 | script->allocated = true; | ||
| 1804 | return 0; | ||
| 1805 | } | ||
| 1806 | |||
| 1807 | static | ||
| 1808 | int process_thread_map_event(struct perf_tool *tool, | ||
| 1809 | union perf_event *event, | ||
| 1810 | struct perf_session *session __maybe_unused) | ||
| 1811 | { | ||
| 1812 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
| 1813 | |||
| 1814 | if (script->threads) { | ||
| 1815 | pr_warning("Extra thread map event, ignoring.\n"); | ||
| 1816 | return 0; | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | script->threads = thread_map__new_event(&event->thread_map); | ||
| 1820 | if (!script->threads) | ||
| 1821 | return -ENOMEM; | ||
| 1822 | |||
| 1823 | return set_maps(script); | ||
| 1824 | } | ||
| 1825 | |||
| 1826 | static | ||
| 1827 | int process_cpu_map_event(struct perf_tool *tool __maybe_unused, | ||
| 1828 | union perf_event *event, | ||
| 1829 | struct perf_session *session __maybe_unused) | ||
| 1830 | { | ||
| 1831 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
| 1832 | |||
| 1833 | if (script->cpus) { | ||
| 1834 | pr_warning("Extra cpu map event, ignoring.\n"); | ||
| 1835 | return 0; | ||
| 1836 | } | ||
| 1837 | |||
| 1838 | script->cpus = cpu_map__new_data(&event->cpu_map.data); | ||
| 1839 | if (!script->cpus) | ||
| 1840 | return -ENOMEM; | ||
| 1841 | |||
| 1842 | return set_maps(script); | ||
| 1843 | } | ||
| 1844 | |||
| 1698 | int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | 1845 | int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) |
| 1699 | { | 1846 | { |
| 1700 | bool show_full_info = false; | 1847 | bool show_full_info = false; |
| @@ -1723,6 +1870,11 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1723 | .auxtrace_info = perf_event__process_auxtrace_info, | 1870 | .auxtrace_info = perf_event__process_auxtrace_info, |
| 1724 | .auxtrace = perf_event__process_auxtrace, | 1871 | .auxtrace = perf_event__process_auxtrace, |
| 1725 | .auxtrace_error = perf_event__process_auxtrace_error, | 1872 | .auxtrace_error = perf_event__process_auxtrace_error, |
| 1873 | .stat = perf_event__process_stat_event, | ||
| 1874 | .stat_round = process_stat_round_event, | ||
| 1875 | .stat_config = process_stat_config_event, | ||
| 1876 | .thread_map = process_thread_map_event, | ||
| 1877 | .cpu_map = process_cpu_map_event, | ||
| 1726 | .ordered_events = true, | 1878 | .ordered_events = true, |
| 1727 | .ordering_requires_timestamps = true, | 1879 | .ordering_requires_timestamps = true, |
| 1728 | }, | 1880 | }, |
| @@ -1836,7 +1988,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1836 | scripting_max_stack = itrace_synth_opts.callchain_sz; | 1988 | scripting_max_stack = itrace_synth_opts.callchain_sz; |
| 1837 | 1989 | ||
| 1838 | /* make sure PERF_EXEC_PATH is set for scripts */ | 1990 | /* make sure PERF_EXEC_PATH is set for scripts */ |
| 1839 | perf_set_argv_exec_path(perf_exec_path()); | 1991 | set_argv_exec_path(get_argv_exec_path()); |
| 1840 | 1992 | ||
| 1841 | if (argc && !script_name && !rec_script_path && !rep_script_path) { | 1993 | if (argc && !script_name && !rec_script_path && !rep_script_path) { |
| 1842 | int live_pipe[2]; | 1994 | int live_pipe[2]; |
| @@ -2076,6 +2228,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 2076 | flush_scripting(); | 2228 | flush_scripting(); |
| 2077 | 2229 | ||
| 2078 | out_delete: | 2230 | out_delete: |
| 2231 | perf_evlist__free_stats(session->evlist); | ||
| 2079 | perf_session__delete(session); | 2232 | perf_session__delete(session); |
| 2080 | 2233 | ||
| 2081 | if (script_started) | 2234 | if (script_started) |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index e77880b5094d..038e877081b6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
| @@ -45,7 +45,7 @@ | |||
| 45 | #include "builtin.h" | 45 | #include "builtin.h" |
| 46 | #include "util/cgroup.h" | 46 | #include "util/cgroup.h" |
| 47 | #include "util/util.h" | 47 | #include "util/util.h" |
| 48 | #include "util/parse-options.h" | 48 | #include <subcmd/parse-options.h> |
| 49 | #include "util/parse-events.h" | 49 | #include "util/parse-events.h" |
| 50 | #include "util/pmu.h" | 50 | #include "util/pmu.h" |
| 51 | #include "util/event.h" | 51 | #include "util/event.h" |
| @@ -59,6 +59,9 @@ | |||
| 59 | #include "util/thread.h" | 59 | #include "util/thread.h" |
| 60 | #include "util/thread_map.h" | 60 | #include "util/thread_map.h" |
| 61 | #include "util/counts.h" | 61 | #include "util/counts.h" |
| 62 | #include "util/session.h" | ||
| 63 | #include "util/tool.h" | ||
| 64 | #include "asm/bug.h" | ||
| 62 | 65 | ||
| 63 | #include <stdlib.h> | 66 | #include <stdlib.h> |
| 64 | #include <sys/prctl.h> | 67 | #include <sys/prctl.h> |
| @@ -126,6 +129,21 @@ static bool append_file; | |||
| 126 | static const char *output_name; | 129 | static const char *output_name; |
| 127 | static int output_fd; | 130 | static int output_fd; |
| 128 | 131 | ||
| 132 | struct perf_stat { | ||
| 133 | bool record; | ||
| 134 | struct perf_data_file file; | ||
| 135 | struct perf_session *session; | ||
| 136 | u64 bytes_written; | ||
| 137 | struct perf_tool tool; | ||
| 138 | bool maps_allocated; | ||
| 139 | struct cpu_map *cpus; | ||
| 140 | struct thread_map *threads; | ||
| 141 | enum aggr_mode aggr_mode; | ||
| 142 | }; | ||
| 143 | |||
| 144 | static struct perf_stat perf_stat; | ||
| 145 | #define STAT_RECORD perf_stat.record | ||
| 146 | |||
| 129 | static volatile int done = 0; | 147 | static volatile int done = 0; |
| 130 | 148 | ||
| 131 | static struct perf_stat_config stat_config = { | 149 | static struct perf_stat_config stat_config = { |
| @@ -161,15 +179,43 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) | |||
| 161 | 179 | ||
| 162 | attr->inherit = !no_inherit; | 180 | attr->inherit = !no_inherit; |
| 163 | 181 | ||
| 164 | if (target__has_cpu(&target)) | 182 | /* |
| 165 | return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); | 183 | * Some events get initialized with sample_(period/type) set, |
| 184 | * like tracepoints. Clear it up for counting. | ||
| 185 | */ | ||
| 186 | attr->sample_period = 0; | ||
| 187 | |||
| 188 | /* | ||
| 189 | * But set sample_type to PERF_SAMPLE_IDENTIFIER, which should be harmless | ||
| 190 | * while avoiding that older tools show confusing messages. | ||
| 191 | * | ||
| 192 | * However for pipe sessions we need to keep it zero, | ||
| 193 | * because script's perf_evsel__check_attr is triggered | ||
| 194 | * by attr->sample_type != 0, and we can't run it on | ||
| 195 | * stat sessions. | ||
| 196 | */ | ||
| 197 | if (!(STAT_RECORD && perf_stat.file.is_pipe)) | ||
| 198 | attr->sample_type = PERF_SAMPLE_IDENTIFIER; | ||
| 166 | 199 | ||
| 167 | if (!target__has_task(&target) && perf_evsel__is_group_leader(evsel)) { | 200 | /* |
| 201 | * Disabling all counters initially, they will be enabled | ||
| 202 | * either manually by us or by kernel via enable_on_exec | ||
| 203 | * set later. | ||
| 204 | */ | ||
| 205 | if (perf_evsel__is_group_leader(evsel)) { | ||
| 168 | attr->disabled = 1; | 206 | attr->disabled = 1; |
| 169 | if (!initial_delay) | 207 | |
| 208 | /* | ||
| 209 | * In case of initial_delay we enable tracee | ||
| 210 | * events manually. | ||
| 211 | */ | ||
| 212 | if (target__none(&target) && !initial_delay) | ||
| 170 | attr->enable_on_exec = 1; | 213 | attr->enable_on_exec = 1; |
| 171 | } | 214 | } |
| 172 | 215 | ||
| 216 | if (target__has_cpu(&target)) | ||
| 217 | return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); | ||
| 218 | |||
| 173 | return perf_evsel__open_per_thread(evsel, evsel_list->threads); | 219 | return perf_evsel__open_per_thread(evsel, evsel_list->threads); |
| 174 | } | 220 | } |
| 175 | 221 | ||
| @@ -185,6 +231,42 @@ static inline int nsec_counter(struct perf_evsel *evsel) | |||
| 185 | return 0; | 231 | return 0; |
| 186 | } | 232 | } |
| 187 | 233 | ||
| 234 | static int process_synthesized_event(struct perf_tool *tool __maybe_unused, | ||
| 235 | union perf_event *event, | ||
| 236 | struct perf_sample *sample __maybe_unused, | ||
| 237 | struct machine *machine __maybe_unused) | ||
| 238 | { | ||
| 239 | if (perf_data_file__write(&perf_stat.file, event, event->header.size) < 0) { | ||
| 240 | pr_err("failed to write perf data, error: %m\n"); | ||
| 241 | return -1; | ||
| 242 | } | ||
| 243 | |||
| 244 | perf_stat.bytes_written += event->header.size; | ||
| 245 | return 0; | ||
| 246 | } | ||
| 247 | |||
| 248 | static int write_stat_round_event(u64 tm, u64 type) | ||
| 249 | { | ||
| 250 | return perf_event__synthesize_stat_round(NULL, tm, type, | ||
| 251 | process_synthesized_event, | ||
| 252 | NULL); | ||
| 253 | } | ||
| 254 | |||
| 255 | #define WRITE_STAT_ROUND_EVENT(time, interval) \ | ||
| 256 | write_stat_round_event(time, PERF_STAT_ROUND_TYPE__ ## interval) | ||
| 257 | |||
| 258 | #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) | ||
| 259 | |||
| 260 | static int | ||
| 261 | perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread, | ||
| 262 | struct perf_counts_values *count) | ||
| 263 | { | ||
| 264 | struct perf_sample_id *sid = SID(counter, cpu, thread); | ||
| 265 | |||
| 266 | return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, | ||
| 267 | process_synthesized_event, NULL); | ||
| 268 | } | ||
| 269 | |||
| 188 | /* | 270 | /* |
| 189 | * Read out the results of a single counter: | 271 | * Read out the results of a single counter: |
| 190 | * do not aggregate counts across CPUs in system-wide mode | 272 | * do not aggregate counts across CPUs in system-wide mode |
| @@ -208,6 +290,13 @@ static int read_counter(struct perf_evsel *counter) | |||
| 208 | count = perf_counts(counter->counts, cpu, thread); | 290 | count = perf_counts(counter->counts, cpu, thread); |
| 209 | if (perf_evsel__read(counter, cpu, thread, count)) | 291 | if (perf_evsel__read(counter, cpu, thread, count)) |
| 210 | return -1; | 292 | return -1; |
| 293 | |||
| 294 | if (STAT_RECORD) { | ||
| 295 | if (perf_evsel__write_stat_event(counter, cpu, thread, count)) { | ||
| 296 | pr_err("failed to write stat event\n"); | ||
| 297 | return -1; | ||
| 298 | } | ||
| 299 | } | ||
| 211 | } | 300 | } |
| 212 | } | 301 | } |
| 213 | 302 | ||
| @@ -241,21 +330,26 @@ static void process_interval(void) | |||
| 241 | clock_gettime(CLOCK_MONOTONIC, &ts); | 330 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 242 | diff_timespec(&rs, &ts, &ref_time); | 331 | diff_timespec(&rs, &ts, &ref_time); |
| 243 | 332 | ||
| 333 | if (STAT_RECORD) { | ||
| 334 | if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSECS_PER_SEC + rs.tv_nsec, INTERVAL)) | ||
| 335 | pr_err("failed to write stat round event\n"); | ||
| 336 | } | ||
| 337 | |||
| 244 | print_counters(&rs, 0, NULL); | 338 | print_counters(&rs, 0, NULL); |
| 245 | } | 339 | } |
| 246 | 340 | ||
| 247 | static void handle_initial_delay(void) | 341 | static void enable_counters(void) |
| 248 | { | 342 | { |
| 249 | struct perf_evsel *counter; | 343 | if (initial_delay) |
| 250 | |||
| 251 | if (initial_delay) { | ||
| 252 | const int ncpus = cpu_map__nr(evsel_list->cpus), | ||
| 253 | nthreads = thread_map__nr(evsel_list->threads); | ||
| 254 | |||
| 255 | usleep(initial_delay * 1000); | 344 | usleep(initial_delay * 1000); |
| 256 | evlist__for_each(evsel_list, counter) | 345 | |
| 257 | perf_evsel__enable(counter, ncpus, nthreads); | 346 | /* |
| 258 | } | 347 | * We need to enable counters only if: |
| 348 | * - we don't have tracee (attaching to task or cpu) | ||
| 349 | * - we have initial delay configured | ||
| 350 | */ | ||
| 351 | if (!target__none(&target) || initial_delay) | ||
| 352 | perf_evlist__enable(evsel_list); | ||
| 259 | } | 353 | } |
| 260 | 354 | ||
| 261 | static volatile int workload_exec_errno; | 355 | static volatile int workload_exec_errno; |
| @@ -271,6 +365,135 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *inf | |||
| 271 | workload_exec_errno = info->si_value.sival_int; | 365 | workload_exec_errno = info->si_value.sival_int; |
| 272 | } | 366 | } |
| 273 | 367 | ||
| 368 | static bool has_unit(struct perf_evsel *counter) | ||
| 369 | { | ||
| 370 | return counter->unit && *counter->unit; | ||
| 371 | } | ||
| 372 | |||
| 373 | static bool has_scale(struct perf_evsel *counter) | ||
| 374 | { | ||
| 375 | return counter->scale != 1; | ||
| 376 | } | ||
| 377 | |||
| 378 | static int perf_stat_synthesize_config(bool is_pipe) | ||
| 379 | { | ||
| 380 | struct perf_evsel *counter; | ||
| 381 | int err; | ||
| 382 | |||
| 383 | if (is_pipe) { | ||
| 384 | err = perf_event__synthesize_attrs(NULL, perf_stat.session, | ||
| 385 | process_synthesized_event); | ||
| 386 | if (err < 0) { | ||
| 387 | pr_err("Couldn't synthesize attrs.\n"); | ||
| 388 | return err; | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | /* | ||
| 393 | * Synthesize other events stuff not carried within | ||
| 394 | * attr event - unit, scale, name | ||
| 395 | */ | ||
| 396 | evlist__for_each(evsel_list, counter) { | ||
| 397 | if (!counter->supported) | ||
| 398 | continue; | ||
| 399 | |||
| 400 | /* | ||
| 401 | * Synthesize unit and scale only if it's defined. | ||
| 402 | */ | ||
| 403 | if (has_unit(counter)) { | ||
| 404 | err = perf_event__synthesize_event_update_unit(NULL, counter, process_synthesized_event); | ||
| 405 | if (err < 0) { | ||
| 406 | pr_err("Couldn't synthesize evsel unit.\n"); | ||
| 407 | return err; | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | if (has_scale(counter)) { | ||
| 412 | err = perf_event__synthesize_event_update_scale(NULL, counter, process_synthesized_event); | ||
| 413 | if (err < 0) { | ||
| 414 | pr_err("Couldn't synthesize evsel scale.\n"); | ||
| 415 | return err; | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | if (counter->own_cpus) { | ||
| 420 | err = perf_event__synthesize_event_update_cpus(NULL, counter, process_synthesized_event); | ||
| 421 | if (err < 0) { | ||
| 422 | pr_err("Couldn't synthesize evsel scale.\n"); | ||
| 423 | return err; | ||
| 424 | } | ||
| 425 | } | ||
| 426 | |||
| 427 | /* | ||
| 428 | * Name is needed only for pipe output, | ||
| 429 | * perf.data carries event names. | ||
| 430 | */ | ||
| 431 | if (is_pipe) { | ||
| 432 | err = perf_event__synthesize_event_update_name(NULL, counter, process_synthesized_event); | ||
| 433 | if (err < 0) { | ||
| 434 | pr_err("Couldn't synthesize evsel name.\n"); | ||
| 435 | return err; | ||
| 436 | } | ||
| 437 | } | ||
| 438 | } | ||
| 439 | |||
| 440 | err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads, | ||
| 441 | process_synthesized_event, | ||
| 442 | NULL); | ||
| 443 | if (err < 0) { | ||
| 444 | pr_err("Couldn't synthesize thread map.\n"); | ||
| 445 | return err; | ||
| 446 | } | ||
| 447 | |||
| 448 | err = perf_event__synthesize_cpu_map(NULL, evsel_list->cpus, | ||
| 449 | process_synthesized_event, NULL); | ||
| 450 | if (err < 0) { | ||
| 451 | pr_err("Couldn't synthesize thread map.\n"); | ||
| 452 | return err; | ||
| 453 | } | ||
| 454 | |||
| 455 | err = perf_event__synthesize_stat_config(NULL, &stat_config, | ||
| 456 | process_synthesized_event, NULL); | ||
| 457 | if (err < 0) { | ||
| 458 | pr_err("Couldn't synthesize config.\n"); | ||
| 459 | return err; | ||
| 460 | } | ||
| 461 | |||
| 462 | return 0; | ||
| 463 | } | ||
| 464 | |||
| 465 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) | ||
| 466 | |||
| 467 | static int __store_counter_ids(struct perf_evsel *counter, | ||
| 468 | struct cpu_map *cpus, | ||
| 469 | struct thread_map *threads) | ||
| 470 | { | ||
| 471 | int cpu, thread; | ||
| 472 | |||
| 473 | for (cpu = 0; cpu < cpus->nr; cpu++) { | ||
| 474 | for (thread = 0; thread < threads->nr; thread++) { | ||
| 475 | int fd = FD(counter, cpu, thread); | ||
| 476 | |||
| 477 | if (perf_evlist__id_add_fd(evsel_list, counter, | ||
| 478 | cpu, thread, fd) < 0) | ||
| 479 | return -1; | ||
| 480 | } | ||
| 481 | } | ||
| 482 | |||
| 483 | return 0; | ||
| 484 | } | ||
| 485 | |||
| 486 | static int store_counter_ids(struct perf_evsel *counter) | ||
| 487 | { | ||
| 488 | struct cpu_map *cpus = counter->cpus; | ||
| 489 | struct thread_map *threads = counter->threads; | ||
| 490 | |||
| 491 | if (perf_evsel__alloc_id(counter, cpus->nr, threads->nr)) | ||
| 492 | return -ENOMEM; | ||
| 493 | |||
| 494 | return __store_counter_ids(counter, cpus, threads); | ||
| 495 | } | ||
| 496 | |||
| 274 | static int __run_perf_stat(int argc, const char **argv) | 497 | static int __run_perf_stat(int argc, const char **argv) |
| 275 | { | 498 | { |
| 276 | int interval = stat_config.interval; | 499 | int interval = stat_config.interval; |
| @@ -281,6 +504,7 @@ static int __run_perf_stat(int argc, const char **argv) | |||
| 281 | size_t l; | 504 | size_t l; |
| 282 | int status = 0; | 505 | int status = 0; |
| 283 | const bool forks = (argc > 0); | 506 | const bool forks = (argc > 0); |
| 507 | bool is_pipe = STAT_RECORD ? perf_stat.file.is_pipe : false; | ||
| 284 | 508 | ||
| 285 | if (interval) { | 509 | if (interval) { |
| 286 | ts.tv_sec = interval / 1000; | 510 | ts.tv_sec = interval / 1000; |
| @@ -291,7 +515,7 @@ static int __run_perf_stat(int argc, const char **argv) | |||
| 291 | } | 515 | } |
| 292 | 516 | ||
| 293 | if (forks) { | 517 | if (forks) { |
| 294 | if (perf_evlist__prepare_workload(evsel_list, &target, argv, false, | 518 | if (perf_evlist__prepare_workload(evsel_list, &target, argv, is_pipe, |
| 295 | workload_exec_failed_signal) < 0) { | 519 | workload_exec_failed_signal) < 0) { |
| 296 | perror("failed to prepare workload"); | 520 | perror("failed to prepare workload"); |
| 297 | return -1; | 521 | return -1; |
| @@ -335,6 +559,9 @@ static int __run_perf_stat(int argc, const char **argv) | |||
| 335 | l = strlen(counter->unit); | 559 | l = strlen(counter->unit); |
| 336 | if (l > unit_width) | 560 | if (l > unit_width) |
| 337 | unit_width = l; | 561 | unit_width = l; |
| 562 | |||
| 563 | if (STAT_RECORD && store_counter_ids(counter)) | ||
| 564 | return -1; | ||
| 338 | } | 565 | } |
| 339 | 566 | ||
| 340 | if (perf_evlist__apply_filters(evsel_list, &counter)) { | 567 | if (perf_evlist__apply_filters(evsel_list, &counter)) { |
| @@ -344,6 +571,24 @@ static int __run_perf_stat(int argc, const char **argv) | |||
| 344 | return -1; | 571 | return -1; |
| 345 | } | 572 | } |
| 346 | 573 | ||
| 574 | if (STAT_RECORD) { | ||
| 575 | int err, fd = perf_data_file__fd(&perf_stat.file); | ||
| 576 | |||
| 577 | if (is_pipe) { | ||
| 578 | err = perf_header__write_pipe(perf_data_file__fd(&perf_stat.file)); | ||
| 579 | } else { | ||
| 580 | err = perf_session__write_header(perf_stat.session, evsel_list, | ||
| 581 | fd, false); | ||
| 582 | } | ||
| 583 | |||
| 584 | if (err < 0) | ||
| 585 | return err; | ||
| 586 | |||
| 587 | err = perf_stat_synthesize_config(is_pipe); | ||
| 588 | if (err < 0) | ||
| 589 | return err; | ||
| 590 | } | ||
| 591 | |||
| 347 | /* | 592 | /* |
| 348 | * Enable counters and exec the command: | 593 | * Enable counters and exec the command: |
| 349 | */ | 594 | */ |
| @@ -352,7 +597,7 @@ static int __run_perf_stat(int argc, const char **argv) | |||
| 352 | 597 | ||
| 353 | if (forks) { | 598 | if (forks) { |
| 354 | perf_evlist__start_workload(evsel_list); | 599 | perf_evlist__start_workload(evsel_list); |
| 355 | handle_initial_delay(); | 600 | enable_counters(); |
| 356 | 601 | ||
| 357 | if (interval) { | 602 | if (interval) { |
| 358 | while (!waitpid(child_pid, &status, WNOHANG)) { | 603 | while (!waitpid(child_pid, &status, WNOHANG)) { |
| @@ -371,7 +616,7 @@ static int __run_perf_stat(int argc, const char **argv) | |||
| 371 | if (WIFSIGNALED(status)) | 616 | if (WIFSIGNALED(status)) |
| 372 | psignal(WTERMSIG(status), argv[0]); | 617 | psignal(WTERMSIG(status), argv[0]); |
| 373 | } else { | 618 | } else { |
| 374 | handle_initial_delay(); | 619 | enable_counters(); |
| 375 | while (!done) { | 620 | while (!done) { |
| 376 | nanosleep(&ts, NULL); | 621 | nanosleep(&ts, NULL); |
| 377 | if (interval) | 622 | if (interval) |
| @@ -810,8 +1055,8 @@ static void print_header(int argc, const char **argv) | |||
| 810 | else if (target.cpu_list) | 1055 | else if (target.cpu_list) |
| 811 | fprintf(output, "\'CPU(s) %s", target.cpu_list); | 1056 | fprintf(output, "\'CPU(s) %s", target.cpu_list); |
| 812 | else if (!target__has_task(&target)) { | 1057 | else if (!target__has_task(&target)) { |
| 813 | fprintf(output, "\'%s", argv[0]); | 1058 | fprintf(output, "\'%s", argv ? argv[0] : "pipe"); |
| 814 | for (i = 1; i < argc; i++) | 1059 | for (i = 1; argv && (i < argc); i++) |
| 815 | fprintf(output, " %s", argv[i]); | 1060 | fprintf(output, " %s", argv[i]); |
| 816 | } else if (target.pid) | 1061 | } else if (target.pid) |
| 817 | fprintf(output, "process id \'%s", target.pid); | 1062 | fprintf(output, "process id \'%s", target.pid); |
| @@ -847,6 +1092,10 @@ static void print_counters(struct timespec *ts, int argc, const char **argv) | |||
| 847 | struct perf_evsel *counter; | 1092 | struct perf_evsel *counter; |
| 848 | char buf[64], *prefix = NULL; | 1093 | char buf[64], *prefix = NULL; |
| 849 | 1094 | ||
| 1095 | /* Do not print anything if we record to the pipe. */ | ||
| 1096 | if (STAT_RECORD && perf_stat.file.is_pipe) | ||
| 1097 | return; | ||
| 1098 | |||
| 850 | if (interval) | 1099 | if (interval) |
| 851 | print_interval(prefix = buf, ts); | 1100 | print_interval(prefix = buf, ts); |
| 852 | else | 1101 | else |
| @@ -1077,6 +1326,109 @@ static int perf_stat_init_aggr_mode(void) | |||
| 1077 | return cpus_aggr_map ? 0 : -ENOMEM; | 1326 | return cpus_aggr_map ? 0 : -ENOMEM; |
| 1078 | } | 1327 | } |
| 1079 | 1328 | ||
| 1329 | static void perf_stat__exit_aggr_mode(void) | ||
| 1330 | { | ||
| 1331 | cpu_map__put(aggr_map); | ||
| 1332 | cpu_map__put(cpus_aggr_map); | ||
| 1333 | aggr_map = NULL; | ||
| 1334 | cpus_aggr_map = NULL; | ||
| 1335 | } | ||
| 1336 | |||
| 1337 | static inline int perf_env__get_cpu(struct perf_env *env, struct cpu_map *map, int idx) | ||
| 1338 | { | ||
| 1339 | int cpu; | ||
| 1340 | |||
| 1341 | if (idx > map->nr) | ||
| 1342 | return -1; | ||
| 1343 | |||
| 1344 | cpu = map->map[idx]; | ||
| 1345 | |||
| 1346 | if (cpu >= env->nr_cpus_online) | ||
| 1347 | return -1; | ||
| 1348 | |||
| 1349 | return cpu; | ||
| 1350 | } | ||
| 1351 | |||
| 1352 | static int perf_env__get_socket(struct cpu_map *map, int idx, void *data) | ||
| 1353 | { | ||
| 1354 | struct perf_env *env = data; | ||
| 1355 | int cpu = perf_env__get_cpu(env, map, idx); | ||
| 1356 | |||
| 1357 | return cpu == -1 ? -1 : env->cpu[cpu].socket_id; | ||
| 1358 | } | ||
| 1359 | |||
| 1360 | static int perf_env__get_core(struct cpu_map *map, int idx, void *data) | ||
| 1361 | { | ||
| 1362 | struct perf_env *env = data; | ||
| 1363 | int core = -1, cpu = perf_env__get_cpu(env, map, idx); | ||
| 1364 | |||
| 1365 | if (cpu != -1) { | ||
| 1366 | int socket_id = env->cpu[cpu].socket_id; | ||
| 1367 | |||
| 1368 | /* | ||
| 1369 | * Encode socket in upper 16 bits | ||
| 1370 | * core_id is relative to socket, and | ||
| 1371 | * we need a global id. So we combine | ||
| 1372 | * socket + core id. | ||
| 1373 | */ | ||
| 1374 | core = (socket_id << 16) | (env->cpu[cpu].core_id & 0xffff); | ||
| 1375 | } | ||
| 1376 | |||
| 1377 | return core; | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | static int perf_env__build_socket_map(struct perf_env *env, struct cpu_map *cpus, | ||
| 1381 | struct cpu_map **sockp) | ||
| 1382 | { | ||
| 1383 | return cpu_map__build_map(cpus, sockp, perf_env__get_socket, env); | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | static int perf_env__build_core_map(struct perf_env *env, struct cpu_map *cpus, | ||
| 1387 | struct cpu_map **corep) | ||
| 1388 | { | ||
| 1389 | return cpu_map__build_map(cpus, corep, perf_env__get_core, env); | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | static int perf_stat__get_socket_file(struct cpu_map *map, int idx) | ||
| 1393 | { | ||
| 1394 | return perf_env__get_socket(map, idx, &perf_stat.session->header.env); | ||
| 1395 | } | ||
| 1396 | |||
| 1397 | static int perf_stat__get_core_file(struct cpu_map *map, int idx) | ||
| 1398 | { | ||
| 1399 | return perf_env__get_core(map, idx, &perf_stat.session->header.env); | ||
| 1400 | } | ||
| 1401 | |||
| 1402 | static int perf_stat_init_aggr_mode_file(struct perf_stat *st) | ||
| 1403 | { | ||
| 1404 | struct perf_env *env = &st->session->header.env; | ||
| 1405 | |||
| 1406 | switch (stat_config.aggr_mode) { | ||
| 1407 | case AGGR_SOCKET: | ||
| 1408 | if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) { | ||
| 1409 | perror("cannot build socket map"); | ||
| 1410 | return -1; | ||
| 1411 | } | ||
| 1412 | aggr_get_id = perf_stat__get_socket_file; | ||
| 1413 | break; | ||
| 1414 | case AGGR_CORE: | ||
| 1415 | if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) { | ||
| 1416 | perror("cannot build core map"); | ||
| 1417 | return -1; | ||
| 1418 | } | ||
| 1419 | aggr_get_id = perf_stat__get_core_file; | ||
| 1420 | break; | ||
| 1421 | case AGGR_NONE: | ||
| 1422 | case AGGR_GLOBAL: | ||
| 1423 | case AGGR_THREAD: | ||
| 1424 | case AGGR_UNSET: | ||
| 1425 | default: | ||
| 1426 | break; | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | return 0; | ||
| 1430 | } | ||
| 1431 | |||
| 1080 | /* | 1432 | /* |
| 1081 | * Add default attributes, if there were no attributes specified or | 1433 | * Add default attributes, if there were no attributes specified or |
| 1082 | * if -d/--detailed, -d -d or -d -d -d is used: | 1434 | * if -d/--detailed, -d -d or -d -d -d is used: |
| @@ -1236,6 +1588,225 @@ static int add_default_attributes(void) | |||
| 1236 | return perf_evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); | 1588 | return perf_evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); |
| 1237 | } | 1589 | } |
| 1238 | 1590 | ||
| 1591 | static const char * const stat_record_usage[] = { | ||
| 1592 | "perf stat record [<options>]", | ||
| 1593 | NULL, | ||
| 1594 | }; | ||
| 1595 | |||
| 1596 | static void init_features(struct perf_session *session) | ||
| 1597 | { | ||
| 1598 | int feat; | ||
| 1599 | |||
| 1600 | for (feat = HEADER_FIRST_FEATURE; feat < HEADER_LAST_FEATURE; feat++) | ||
| 1601 | perf_header__set_feat(&session->header, feat); | ||
| 1602 | |||
| 1603 | perf_header__clear_feat(&session->header, HEADER_BUILD_ID); | ||
| 1604 | perf_header__clear_feat(&session->header, HEADER_TRACING_DATA); | ||
| 1605 | perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK); | ||
| 1606 | perf_header__clear_feat(&session->header, HEADER_AUXTRACE); | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | static int __cmd_record(int argc, const char **argv) | ||
| 1610 | { | ||
| 1611 | struct perf_session *session; | ||
| 1612 | struct perf_data_file *file = &perf_stat.file; | ||
| 1613 | |||
| 1614 | argc = parse_options(argc, argv, stat_options, stat_record_usage, | ||
| 1615 | PARSE_OPT_STOP_AT_NON_OPTION); | ||
| 1616 | |||
| 1617 | if (output_name) | ||
| 1618 | file->path = output_name; | ||
| 1619 | |||
| 1620 | if (run_count != 1 || forever) { | ||
| 1621 | pr_err("Cannot use -r option with perf stat record.\n"); | ||
| 1622 | return -1; | ||
| 1623 | } | ||
| 1624 | |||
| 1625 | session = perf_session__new(file, false, NULL); | ||
| 1626 | if (session == NULL) { | ||
| 1627 | pr_err("Perf session creation failed.\n"); | ||
| 1628 | return -1; | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | init_features(session); | ||
| 1632 | |||
| 1633 | session->evlist = evsel_list; | ||
| 1634 | perf_stat.session = session; | ||
| 1635 | perf_stat.record = true; | ||
| 1636 | return argc; | ||
| 1637 | } | ||
| 1638 | |||
| 1639 | static int process_stat_round_event(struct perf_tool *tool __maybe_unused, | ||
| 1640 | union perf_event *event, | ||
| 1641 | struct perf_session *session) | ||
| 1642 | { | ||
| 1643 | struct stat_round_event *round = &event->stat_round; | ||
| 1644 | struct perf_evsel *counter; | ||
| 1645 | struct timespec tsh, *ts = NULL; | ||
| 1646 | const char **argv = session->header.env.cmdline_argv; | ||
| 1647 | int argc = session->header.env.nr_cmdline; | ||
| 1648 | |||
| 1649 | evlist__for_each(evsel_list, counter) | ||
| 1650 | perf_stat_process_counter(&stat_config, counter); | ||
| 1651 | |||
| 1652 | if (round->type == PERF_STAT_ROUND_TYPE__FINAL) | ||
| 1653 | update_stats(&walltime_nsecs_stats, round->time); | ||
| 1654 | |||
| 1655 | if (stat_config.interval && round->time) { | ||
| 1656 | tsh.tv_sec = round->time / NSECS_PER_SEC; | ||
| 1657 | tsh.tv_nsec = round->time % NSECS_PER_SEC; | ||
| 1658 | ts = &tsh; | ||
| 1659 | } | ||
| 1660 | |||
| 1661 | print_counters(ts, argc, argv); | ||
| 1662 | return 0; | ||
| 1663 | } | ||
| 1664 | |||
| 1665 | static | ||
| 1666 | int process_stat_config_event(struct perf_tool *tool __maybe_unused, | ||
| 1667 | union perf_event *event, | ||
| 1668 | struct perf_session *session __maybe_unused) | ||
| 1669 | { | ||
| 1670 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); | ||
| 1671 | |||
| 1672 | perf_event__read_stat_config(&stat_config, &event->stat_config); | ||
| 1673 | |||
| 1674 | if (cpu_map__empty(st->cpus)) { | ||
| 1675 | if (st->aggr_mode != AGGR_UNSET) | ||
| 1676 | pr_warning("warning: processing task data, aggregation mode not set\n"); | ||
| 1677 | return 0; | ||
| 1678 | } | ||
| 1679 | |||
| 1680 | if (st->aggr_mode != AGGR_UNSET) | ||
| 1681 | stat_config.aggr_mode = st->aggr_mode; | ||
| 1682 | |||
| 1683 | if (perf_stat.file.is_pipe) | ||
| 1684 | perf_stat_init_aggr_mode(); | ||
| 1685 | else | ||
| 1686 | perf_stat_init_aggr_mode_file(st); | ||
| 1687 | |||
| 1688 | return 0; | ||
| 1689 | } | ||
| 1690 | |||
| 1691 | static int set_maps(struct perf_stat *st) | ||
| 1692 | { | ||
| 1693 | if (!st->cpus || !st->threads) | ||
| 1694 | return 0; | ||
| 1695 | |||
| 1696 | if (WARN_ONCE(st->maps_allocated, "stats double allocation\n")) | ||
| 1697 | return -EINVAL; | ||
| 1698 | |||
| 1699 | perf_evlist__set_maps(evsel_list, st->cpus, st->threads); | ||
| 1700 | |||
| 1701 | if (perf_evlist__alloc_stats(evsel_list, true)) | ||
| 1702 | return -ENOMEM; | ||
| 1703 | |||
| 1704 | st->maps_allocated = true; | ||
| 1705 | return 0; | ||
| 1706 | } | ||
| 1707 | |||
| 1708 | static | ||
| 1709 | int process_thread_map_event(struct perf_tool *tool __maybe_unused, | ||
| 1710 | union perf_event *event, | ||
| 1711 | struct perf_session *session __maybe_unused) | ||
| 1712 | { | ||
| 1713 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); | ||
| 1714 | |||
| 1715 | if (st->threads) { | ||
| 1716 | pr_warning("Extra thread map event, ignoring.\n"); | ||
| 1717 | return 0; | ||
| 1718 | } | ||
| 1719 | |||
| 1720 | st->threads = thread_map__new_event(&event->thread_map); | ||
| 1721 | if (!st->threads) | ||
| 1722 | return -ENOMEM; | ||
| 1723 | |||
| 1724 | return set_maps(st); | ||
| 1725 | } | ||
| 1726 | |||
| 1727 | static | ||
| 1728 | int process_cpu_map_event(struct perf_tool *tool __maybe_unused, | ||
| 1729 | union perf_event *event, | ||
| 1730 | struct perf_session *session __maybe_unused) | ||
| 1731 | { | ||
| 1732 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); | ||
| 1733 | struct cpu_map *cpus; | ||
| 1734 | |||
| 1735 | if (st->cpus) { | ||
| 1736 | pr_warning("Extra cpu map event, ignoring.\n"); | ||
| 1737 | return 0; | ||
| 1738 | } | ||
| 1739 | |||
| 1740 | cpus = cpu_map__new_data(&event->cpu_map.data); | ||
| 1741 | if (!cpus) | ||
| 1742 | return -ENOMEM; | ||
| 1743 | |||
| 1744 | st->cpus = cpus; | ||
| 1745 | return set_maps(st); | ||
| 1746 | } | ||
| 1747 | |||
| 1748 | static const char * const stat_report_usage[] = { | ||
| 1749 | "perf stat report [<options>]", | ||
| 1750 | NULL, | ||
| 1751 | }; | ||
| 1752 | |||
| 1753 | static struct perf_stat perf_stat = { | ||
| 1754 | .tool = { | ||
| 1755 | .attr = perf_event__process_attr, | ||
| 1756 | .event_update = perf_event__process_event_update, | ||
| 1757 | .thread_map = process_thread_map_event, | ||
| 1758 | .cpu_map = process_cpu_map_event, | ||
| 1759 | .stat_config = process_stat_config_event, | ||
| 1760 | .stat = perf_event__process_stat_event, | ||
| 1761 | .stat_round = process_stat_round_event, | ||
| 1762 | }, | ||
| 1763 | .aggr_mode = AGGR_UNSET, | ||
| 1764 | }; | ||
| 1765 | |||
| 1766 | static int __cmd_report(int argc, const char **argv) | ||
| 1767 | { | ||
| 1768 | struct perf_session *session; | ||
| 1769 | const struct option options[] = { | ||
| 1770 | OPT_STRING('i', "input", &input_name, "file", "input file name"), | ||
| 1771 | OPT_SET_UINT(0, "per-socket", &perf_stat.aggr_mode, | ||
| 1772 | "aggregate counts per processor socket", AGGR_SOCKET), | ||
| 1773 | OPT_SET_UINT(0, "per-core", &perf_stat.aggr_mode, | ||
| 1774 | "aggregate counts per physical processor core", AGGR_CORE), | ||
| 1775 | OPT_SET_UINT('A', "no-aggr", &perf_stat.aggr_mode, | ||
| 1776 | "disable CPU count aggregation", AGGR_NONE), | ||
| 1777 | OPT_END() | ||
| 1778 | }; | ||
| 1779 | struct stat st; | ||
| 1780 | int ret; | ||
| 1781 | |||
| 1782 | argc = parse_options(argc, argv, options, stat_report_usage, 0); | ||
| 1783 | |||
| 1784 | if (!input_name || !strlen(input_name)) { | ||
| 1785 | if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode)) | ||
| 1786 | input_name = "-"; | ||
| 1787 | else | ||
| 1788 | input_name = "perf.data"; | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | perf_stat.file.path = input_name; | ||
| 1792 | perf_stat.file.mode = PERF_DATA_MODE_READ; | ||
| 1793 | |||
| 1794 | session = perf_session__new(&perf_stat.file, false, &perf_stat.tool); | ||
| 1795 | if (session == NULL) | ||
| 1796 | return -1; | ||
| 1797 | |||
| 1798 | perf_stat.session = session; | ||
| 1799 | stat_config.output = stderr; | ||
| 1800 | evsel_list = session->evlist; | ||
| 1801 | |||
| 1802 | ret = perf_session__process_events(session); | ||
| 1803 | if (ret) | ||
| 1804 | return ret; | ||
| 1805 | |||
| 1806 | perf_session__delete(session); | ||
| 1807 | return 0; | ||
| 1808 | } | ||
| 1809 | |||
| 1239 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | 1810 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) |
| 1240 | { | 1811 | { |
| 1241 | const char * const stat_usage[] = { | 1812 | const char * const stat_usage[] = { |
| @@ -1246,6 +1817,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1246 | const char *mode; | 1817 | const char *mode; |
| 1247 | FILE *output = stderr; | 1818 | FILE *output = stderr; |
| 1248 | unsigned int interval; | 1819 | unsigned int interval; |
| 1820 | const char * const stat_subcommands[] = { "record", "report" }; | ||
| 1249 | 1821 | ||
| 1250 | setlocale(LC_ALL, ""); | 1822 | setlocale(LC_ALL, ""); |
| 1251 | 1823 | ||
| @@ -1253,12 +1825,30 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1253 | if (evsel_list == NULL) | 1825 | if (evsel_list == NULL) |
| 1254 | return -ENOMEM; | 1826 | return -ENOMEM; |
| 1255 | 1827 | ||
| 1256 | argc = parse_options(argc, argv, stat_options, stat_usage, | 1828 | argc = parse_options_subcommand(argc, argv, stat_options, stat_subcommands, |
| 1257 | PARSE_OPT_STOP_AT_NON_OPTION); | 1829 | (const char **) stat_usage, |
| 1830 | PARSE_OPT_STOP_AT_NON_OPTION); | ||
| 1831 | |||
| 1832 | if (csv_sep) { | ||
| 1833 | csv_output = true; | ||
| 1834 | if (!strcmp(csv_sep, "\\t")) | ||
| 1835 | csv_sep = "\t"; | ||
| 1836 | } else | ||
| 1837 | csv_sep = DEFAULT_SEPARATOR; | ||
| 1838 | |||
| 1839 | if (argc && !strncmp(argv[0], "rec", 3)) { | ||
| 1840 | argc = __cmd_record(argc, argv); | ||
| 1841 | if (argc < 0) | ||
| 1842 | return -1; | ||
| 1843 | } else if (argc && !strncmp(argv[0], "rep", 3)) | ||
| 1844 | return __cmd_report(argc, argv); | ||
| 1258 | 1845 | ||
| 1259 | interval = stat_config.interval; | 1846 | interval = stat_config.interval; |
| 1260 | 1847 | ||
| 1261 | if (output_name && strcmp(output_name, "-")) | 1848 | /* |
| 1849 | * For record command the -o is already taken care of. | ||
| 1850 | */ | ||
| 1851 | if (!STAT_RECORD && output_name && strcmp(output_name, "-")) | ||
| 1262 | output = NULL; | 1852 | output = NULL; |
| 1263 | 1853 | ||
| 1264 | if (output_name && output_fd) { | 1854 | if (output_name && output_fd) { |
| @@ -1296,13 +1886,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1296 | 1886 | ||
| 1297 | stat_config.output = output; | 1887 | stat_config.output = output; |
| 1298 | 1888 | ||
| 1299 | if (csv_sep) { | ||
| 1300 | csv_output = true; | ||
| 1301 | if (!strcmp(csv_sep, "\\t")) | ||
| 1302 | csv_sep = "\t"; | ||
| 1303 | } else | ||
| 1304 | csv_sep = DEFAULT_SEPARATOR; | ||
| 1305 | |||
| 1306 | /* | 1889 | /* |
| 1307 | * let the spreadsheet do the pretty-printing | 1890 | * let the spreadsheet do the pretty-printing |
| 1308 | */ | 1891 | */ |
| @@ -1425,6 +2008,42 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1425 | if (!forever && status != -1 && !interval) | 2008 | if (!forever && status != -1 && !interval) |
| 1426 | print_counters(NULL, argc, argv); | 2009 | print_counters(NULL, argc, argv); |
| 1427 | 2010 | ||
| 2011 | if (STAT_RECORD) { | ||
| 2012 | /* | ||
| 2013 | * We synthesize the kernel mmap record just so that older tools | ||
| 2014 | * don't emit warnings about not being able to resolve symbols | ||
| 2015 | * due to /proc/sys/kernel/kptr_restrict settings and instear provide | ||
| 2016 | * a saner message about no samples being in the perf.data file. | ||
| 2017 | * | ||
| 2018 | * This also serves to suppress a warning about f_header.data.size == 0 | ||
| 2019 | * in header.c at the moment 'perf stat record' gets introduced, which | ||
| 2020 | * is not really needed once we start adding the stat specific PERF_RECORD_ | ||
| 2021 | * records, but the need to suppress the kptr_restrict messages in older | ||
| 2022 | * tools remain -acme | ||
| 2023 | */ | ||
| 2024 | int fd = perf_data_file__fd(&perf_stat.file); | ||
| 2025 | int err = perf_event__synthesize_kernel_mmap((void *)&perf_stat, | ||
| 2026 | process_synthesized_event, | ||
| 2027 | &perf_stat.session->machines.host); | ||
| 2028 | if (err) { | ||
| 2029 | pr_warning("Couldn't synthesize the kernel mmap record, harmless, " | ||
| 2030 | "older tools may produce warnings about this file\n."); | ||
| 2031 | } | ||
| 2032 | |||
| 2033 | if (!interval) { | ||
| 2034 | if (WRITE_STAT_ROUND_EVENT(walltime_nsecs_stats.max, FINAL)) | ||
| 2035 | pr_err("failed to write stat round event\n"); | ||
| 2036 | } | ||
| 2037 | |||
| 2038 | if (!perf_stat.file.is_pipe) { | ||
| 2039 | perf_stat.session->header.data_size += perf_stat.bytes_written; | ||
| 2040 | perf_session__write_header(perf_stat.session, evsel_list, fd, true); | ||
| 2041 | } | ||
| 2042 | |||
| 2043 | perf_session__delete(perf_stat.session); | ||
| 2044 | } | ||
| 2045 | |||
| 2046 | perf_stat__exit_aggr_mode(); | ||
| 1428 | perf_evlist__free_stats(evsel_list); | 2047 | perf_evlist__free_stats(evsel_list); |
| 1429 | out: | 2048 | out: |
| 1430 | perf_evlist__delete(evsel_list); | 2049 | perf_evlist__delete(evsel_list); |
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 30e59620179d..bd7a7757176f 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c | |||
| @@ -30,7 +30,7 @@ | |||
| 30 | 30 | ||
| 31 | #include "perf.h" | 31 | #include "perf.h" |
| 32 | #include "util/header.h" | 32 | #include "util/header.h" |
| 33 | #include "util/parse-options.h" | 33 | #include <subcmd/parse-options.h> |
| 34 | #include "util/parse-events.h" | 34 | #include "util/parse-events.h" |
| 35 | #include "util/event.h" | 35 | #include "util/event.h" |
| 36 | #include "util/session.h" | 36 | #include "util/session.h" |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 7e2e72e6d9d1..bf01cbb0ef23 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
| @@ -34,7 +34,7 @@ | |||
| 34 | #include "util/top.h" | 34 | #include "util/top.h" |
| 35 | #include "util/util.h" | 35 | #include "util/util.h" |
| 36 | #include <linux/rbtree.h> | 36 | #include <linux/rbtree.h> |
| 37 | #include "util/parse-options.h" | 37 | #include <subcmd/parse-options.h> |
| 38 | #include "util/parse-events.h" | 38 | #include "util/parse-events.h" |
| 39 | #include "util/cpumap.h" | 39 | #include "util/cpumap.h" |
| 40 | #include "util/xyarray.h" | 40 | #include "util/xyarray.h" |
| @@ -175,42 +175,40 @@ static void perf_top__record_precise_ip(struct perf_top *top, | |||
| 175 | int counter, u64 ip) | 175 | int counter, u64 ip) |
| 176 | { | 176 | { |
| 177 | struct annotation *notes; | 177 | struct annotation *notes; |
| 178 | struct symbol *sym; | 178 | struct symbol *sym = he->ms.sym; |
| 179 | int err = 0; | 179 | int err = 0; |
| 180 | 180 | ||
| 181 | if (he == NULL || he->ms.sym == NULL || | 181 | if (sym == NULL || (use_browser == 0 && |
| 182 | ((top->sym_filter_entry == NULL || | 182 | (top->sym_filter_entry == NULL || |
| 183 | top->sym_filter_entry->ms.sym != he->ms.sym) && use_browser != 1)) | 183 | top->sym_filter_entry->ms.sym != sym))) |
| 184 | return; | 184 | return; |
| 185 | 185 | ||
| 186 | sym = he->ms.sym; | ||
| 187 | notes = symbol__annotation(sym); | 186 | notes = symbol__annotation(sym); |
| 188 | 187 | ||
| 189 | if (pthread_mutex_trylock(¬es->lock)) | 188 | if (pthread_mutex_trylock(¬es->lock)) |
| 190 | return; | 189 | return; |
| 191 | 190 | ||
| 192 | ip = he->ms.map->map_ip(he->ms.map, ip); | 191 | err = hist_entry__inc_addr_samples(he, counter, ip); |
| 193 | |||
| 194 | if (ui__has_annotation()) | ||
| 195 | err = hist_entry__inc_addr_samples(he, counter, ip); | ||
| 196 | 192 | ||
| 197 | pthread_mutex_unlock(¬es->lock); | 193 | pthread_mutex_unlock(¬es->lock); |
| 198 | 194 | ||
| 199 | /* | 195 | if (unlikely(err)) { |
| 200 | * This function is now called with he->hists->lock held. | 196 | /* |
| 201 | * Release it before going to sleep. | 197 | * This function is now called with he->hists->lock held. |
| 202 | */ | 198 | * Release it before going to sleep. |
| 203 | pthread_mutex_unlock(&he->hists->lock); | 199 | */ |
| 200 | pthread_mutex_unlock(&he->hists->lock); | ||
| 201 | |||
| 202 | if (err == -ERANGE && !he->ms.map->erange_warned) | ||
| 203 | ui__warn_map_erange(he->ms.map, sym, ip); | ||
| 204 | else if (err == -ENOMEM) { | ||
| 205 | pr_err("Not enough memory for annotating '%s' symbol!\n", | ||
| 206 | sym->name); | ||
| 207 | sleep(1); | ||
| 208 | } | ||
| 204 | 209 | ||
| 205 | if (err == -ERANGE && !he->ms.map->erange_warned) | 210 | pthread_mutex_lock(&he->hists->lock); |
| 206 | ui__warn_map_erange(he->ms.map, sym, ip); | ||
| 207 | else if (err == -ENOMEM) { | ||
| 208 | pr_err("Not enough memory for annotating '%s' symbol!\n", | ||
| 209 | sym->name); | ||
| 210 | sleep(1); | ||
| 211 | } | 211 | } |
| 212 | |||
| 213 | pthread_mutex_lock(&he->hists->lock); | ||
| 214 | } | 212 | } |
| 215 | 213 | ||
| 216 | static void perf_top__show_details(struct perf_top *top) | 214 | static void perf_top__show_details(struct perf_top *top) |
| @@ -687,14 +685,8 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter, | |||
| 687 | struct hist_entry *he = iter->he; | 685 | struct hist_entry *he = iter->he; |
| 688 | struct perf_evsel *evsel = iter->evsel; | 686 | struct perf_evsel *evsel = iter->evsel; |
| 689 | 687 | ||
| 690 | if (sort__has_sym && single) { | 688 | if (sort__has_sym && single) |
| 691 | u64 ip = al->addr; | 689 | perf_top__record_precise_ip(top, he, evsel->idx, al->addr); |
| 692 | |||
| 693 | if (al->map) | ||
| 694 | ip = al->map->unmap_ip(al->map, ip); | ||
| 695 | |||
| 696 | perf_top__record_precise_ip(top, he, evsel->idx, ip); | ||
| 697 | } | ||
| 698 | 690 | ||
| 699 | hist__account_cycles(iter->sample->branch_stack, al, iter->sample, | 691 | hist__account_cycles(iter->sample->branch_stack, al, iter->sample, |
| 700 | !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY)); | 692 | !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY)); |
| @@ -964,7 +956,7 @@ static int __cmd_top(struct perf_top *top) | |||
| 964 | if (ret) | 956 | if (ret) |
| 965 | goto out_delete; | 957 | goto out_delete; |
| 966 | 958 | ||
| 967 | if (perf_session__register_idle_thread(top->session) == NULL) | 959 | if (perf_session__register_idle_thread(top->session) < 0) |
| 968 | goto out_delete; | 960 | goto out_delete; |
| 969 | 961 | ||
| 970 | machine__synthesize_threads(&top->session->machines.host, &opts->target, | 962 | machine__synthesize_threads(&top->session->machines.host, &opts->target, |
| @@ -1218,6 +1210,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1218 | OPT_CALLBACK('j', "branch-filter", &opts->branch_stack, | 1210 | OPT_CALLBACK('j', "branch-filter", &opts->branch_stack, |
| 1219 | "branch filter mask", "branch stack filter modes", | 1211 | "branch filter mask", "branch stack filter modes", |
| 1220 | parse_branch_stack), | 1212 | parse_branch_stack), |
| 1213 | OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace, | ||
| 1214 | "Show raw trace event output (do not use print fmt or plugins)"), | ||
| 1221 | OPT_END() | 1215 | OPT_END() |
| 1222 | }; | 1216 | }; |
| 1223 | const char * const top_usage[] = { | 1217 | const char * const top_usage[] = { |
| @@ -1239,11 +1233,17 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1239 | if (argc) | 1233 | if (argc) |
| 1240 | usage_with_options(top_usage, options); | 1234 | usage_with_options(top_usage, options); |
| 1241 | 1235 | ||
| 1236 | if (!top.evlist->nr_entries && | ||
| 1237 | perf_evlist__add_default(top.evlist) < 0) { | ||
| 1238 | pr_err("Not enough memory for event selector list\n"); | ||
| 1239 | goto out_delete_evlist; | ||
| 1240 | } | ||
| 1241 | |||
| 1242 | sort__mode = SORT_MODE__TOP; | 1242 | sort__mode = SORT_MODE__TOP; |
| 1243 | /* display thread wants entries to be collapsed in a different tree */ | 1243 | /* display thread wants entries to be collapsed in a different tree */ |
| 1244 | sort__need_collapse = 1; | 1244 | sort__need_collapse = 1; |
| 1245 | 1245 | ||
| 1246 | if (setup_sorting() < 0) { | 1246 | if (setup_sorting(top.evlist) < 0) { |
| 1247 | if (sort_order) | 1247 | if (sort_order) |
| 1248 | parse_options_usage(top_usage, options, "s", 1); | 1248 | parse_options_usage(top_usage, options, "s", 1); |
| 1249 | if (field_order) | 1249 | if (field_order) |
| @@ -1279,12 +1279,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) | |||
| 1279 | if (target__none(target)) | 1279 | if (target__none(target)) |
| 1280 | target->system_wide = true; | 1280 | target->system_wide = true; |
| 1281 | 1281 | ||
| 1282 | if (perf_evlist__create_maps(top.evlist, target) < 0) | 1282 | if (perf_evlist__create_maps(top.evlist, target) < 0) { |
| 1283 | usage_with_options(top_usage, options); | 1283 | ui__error("Couldn't create thread/CPU maps: %s\n", |
| 1284 | 1284 | errno == ENOENT ? "No such process" : strerror_r(errno, errbuf, sizeof(errbuf))); | |
| 1285 | if (!top.evlist->nr_entries && | ||
| 1286 | perf_evlist__add_default(top.evlist) < 0) { | ||
| 1287 | ui__error("Not enough memory for event selector list\n"); | ||
| 1288 | goto out_delete_evlist; | 1285 | goto out_delete_evlist; |
| 1289 | } | 1286 | } |
| 1290 | 1287 | ||
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index c783d8fd3a80..20916dd77aac 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
| @@ -22,11 +22,11 @@ | |||
| 22 | #include "util/color.h" | 22 | #include "util/color.h" |
| 23 | #include "util/debug.h" | 23 | #include "util/debug.h" |
| 24 | #include "util/evlist.h" | 24 | #include "util/evlist.h" |
| 25 | #include "util/exec_cmd.h" | 25 | #include <subcmd/exec-cmd.h> |
| 26 | #include "util/machine.h" | 26 | #include "util/machine.h" |
| 27 | #include "util/session.h" | 27 | #include "util/session.h" |
| 28 | #include "util/thread.h" | 28 | #include "util/thread.h" |
| 29 | #include "util/parse-options.h" | 29 | #include <subcmd/parse-options.h> |
| 30 | #include "util/strlist.h" | 30 | #include "util/strlist.h" |
| 31 | #include "util/intlist.h" | 31 | #include "util/intlist.h" |
| 32 | #include "util/thread_map.h" | 32 | #include "util/thread_map.h" |
diff --git a/tools/perf/builtin-version.c b/tools/perf/builtin-version.c new file mode 100644 index 000000000000..9b10cda6b6dc --- /dev/null +++ b/tools/perf/builtin-version.c | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #include "util/util.h" | ||
| 2 | #include "builtin.h" | ||
| 3 | #include "perf.h" | ||
| 4 | |||
| 5 | int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused, | ||
| 6 | const char *prefix __maybe_unused) | ||
| 7 | { | ||
| 8 | printf("perf version %s\n", perf_version_string); | ||
| 9 | return 0; | ||
| 10 | } | ||
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 3688ad29085f..3f871b54e261 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h | |||
| @@ -17,6 +17,7 @@ extern int cmd_annotate(int argc, const char **argv, const char *prefix); | |||
| 17 | extern int cmd_bench(int argc, const char **argv, const char *prefix); | 17 | extern int cmd_bench(int argc, const char **argv, const char *prefix); |
| 18 | extern int cmd_buildid_cache(int argc, const char **argv, const char *prefix); | 18 | extern int cmd_buildid_cache(int argc, const char **argv, const char *prefix); |
| 19 | extern int cmd_buildid_list(int argc, const char **argv, const char *prefix); | 19 | extern int cmd_buildid_list(int argc, const char **argv, const char *prefix); |
| 20 | extern int cmd_config(int argc, const char **argv, const char *prefix); | ||
| 20 | extern int cmd_diff(int argc, const char **argv, const char *prefix); | 21 | extern int cmd_diff(int argc, const char **argv, const char *prefix); |
| 21 | extern int cmd_evlist(int argc, const char **argv, const char *prefix); | 22 | extern int cmd_evlist(int argc, const char **argv, const char *prefix); |
| 22 | extern int cmd_help(int argc, const char **argv, const char *prefix); | 23 | extern int cmd_help(int argc, const char **argv, const char *prefix); |
diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt index 00fcaf8a5b8d..ab5cbaa170d0 100644 --- a/tools/perf/command-list.txt +++ b/tools/perf/command-list.txt | |||
| @@ -9,6 +9,7 @@ perf-buildid-cache mainporcelain common | |||
| 9 | perf-buildid-list mainporcelain common | 9 | perf-buildid-list mainporcelain common |
| 10 | perf-data mainporcelain common | 10 | perf-data mainporcelain common |
| 11 | perf-diff mainporcelain common | 11 | perf-diff mainporcelain common |
| 12 | perf-config mainporcelain common | ||
| 12 | perf-evlist mainporcelain common | 13 | perf-evlist mainporcelain common |
| 13 | perf-inject mainporcelain common | 14 | perf-inject mainporcelain common |
| 14 | perf-kmem mainporcelain common | 15 | perf-kmem mainporcelain common |
| @@ -25,4 +26,4 @@ perf-stat mainporcelain common | |||
| 25 | perf-test mainporcelain common | 26 | perf-test mainporcelain common |
| 26 | perf-timechart mainporcelain common | 27 | perf-timechart mainporcelain common |
| 27 | perf-top mainporcelain common | 28 | perf-top mainporcelain common |
| 28 | perf-trace mainporcelain common | 29 | perf-trace mainporcelain audit |
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index de89ec574361..e5959c136a19 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
| @@ -17,7 +17,7 @@ detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) | |||
| 17 | 17 | ||
| 18 | CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) | 18 | CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) |
| 19 | 19 | ||
| 20 | include $(src-perf)/config/Makefile.arch | 20 | include $(srctree)/tools/scripts/Makefile.arch |
| 21 | 21 | ||
| 22 | $(call detected_var,ARCH) | 22 | $(call detected_var,ARCH) |
| 23 | 23 | ||
| @@ -135,8 +135,6 @@ endif | |||
| 135 | 135 | ||
| 136 | ifeq ($(DEBUG),0) | 136 | ifeq ($(DEBUG),0) |
| 137 | CFLAGS += -O6 | 137 | CFLAGS += -O6 |
| 138 | else | ||
| 139 | CFLAGS += $(call cc-option,-Og,-O0) | ||
| 140 | endif | 138 | endif |
| 141 | 139 | ||
| 142 | ifdef PARSER_DEBUG | 140 | ifdef PARSER_DEBUG |
| @@ -318,6 +316,18 @@ ifndef NO_LIBELF | |||
| 318 | CFLAGS += -DHAVE_LIBBPF_SUPPORT | 316 | CFLAGS += -DHAVE_LIBBPF_SUPPORT |
| 319 | $(call detected,CONFIG_LIBBPF) | 317 | $(call detected,CONFIG_LIBBPF) |
| 320 | endif | 318 | endif |
| 319 | |||
| 320 | ifndef NO_DWARF | ||
| 321 | ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET | ||
| 322 | CFLAGS += -DHAVE_BPF_PROLOGUE | ||
| 323 | $(call detected,CONFIG_BPF_PROLOGUE) | ||
| 324 | else | ||
| 325 | msg := $(warning BPF prologue is not supported by architecture $(ARCH), missing regs_query_register_offset()); | ||
| 326 | endif | ||
| 327 | else | ||
| 328 | msg := $(warning DWARF support is off, BPF prologue is disabled); | ||
| 329 | endif | ||
| 330 | |||
| 321 | endif # NO_LIBBPF | 331 | endif # NO_LIBBPF |
| 322 | endif # NO_LIBELF | 332 | endif # NO_LIBELF |
| 323 | 333 | ||
| @@ -483,7 +493,7 @@ else | |||
| 483 | 493 | ||
| 484 | PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) | 494 | PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) |
| 485 | PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) | 495 | PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) |
| 486 | PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) | 496 | PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil |
| 487 | PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null) | 497 | PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null) |
| 488 | FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) | 498 | FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) |
| 489 | 499 | ||
| @@ -681,6 +691,8 @@ sharedir = $(prefix)/share | |||
| 681 | template_dir = share/perf-core/templates | 691 | template_dir = share/perf-core/templates |
| 682 | STRACE_GROUPS_DIR = share/perf-core/strace/groups | 692 | STRACE_GROUPS_DIR = share/perf-core/strace/groups |
| 683 | htmldir = share/doc/perf-doc | 693 | htmldir = share/doc/perf-doc |
| 694 | tipdir = share/doc/perf-tip | ||
| 695 | srcdir = $(srctree)/tools/perf | ||
| 684 | ifeq ($(prefix),/usr) | 696 | ifeq ($(prefix),/usr) |
| 685 | sysconfdir = /etc | 697 | sysconfdir = /etc |
| 686 | ETC_PERFCONFIG = $(sysconfdir)/perfconfig | 698 | ETC_PERFCONFIG = $(sysconfdir)/perfconfig |
| @@ -707,19 +719,24 @@ infodir_SQ = $(subst ','\'',$(infodir)) | |||
| 707 | perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) | 719 | perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) |
| 708 | template_dir_SQ = $(subst ','\'',$(template_dir)) | 720 | template_dir_SQ = $(subst ','\'',$(template_dir)) |
| 709 | htmldir_SQ = $(subst ','\'',$(htmldir)) | 721 | htmldir_SQ = $(subst ','\'',$(htmldir)) |
| 722 | tipdir_SQ = $(subst ','\'',$(tipdir)) | ||
| 710 | prefix_SQ = $(subst ','\'',$(prefix)) | 723 | prefix_SQ = $(subst ','\'',$(prefix)) |
| 711 | sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) | 724 | sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) |
| 712 | libdir_SQ = $(subst ','\'',$(libdir)) | 725 | libdir_SQ = $(subst ','\'',$(libdir)) |
| 726 | srcdir_SQ = $(subst ','\'',$(srcdir)) | ||
| 713 | 727 | ||
| 714 | ifneq ($(filter /%,$(firstword $(perfexecdir))),) | 728 | ifneq ($(filter /%,$(firstword $(perfexecdir))),) |
| 715 | perfexec_instdir = $(perfexecdir) | 729 | perfexec_instdir = $(perfexecdir) |
| 716 | STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) | 730 | STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) |
| 731 | tip_instdir = $(tipdir) | ||
| 717 | else | 732 | else |
| 718 | perfexec_instdir = $(prefix)/$(perfexecdir) | 733 | perfexec_instdir = $(prefix)/$(perfexecdir) |
| 719 | STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) | 734 | STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) |
| 735 | tip_instdir = $(prefix)/$(tipdir) | ||
| 720 | endif | 736 | endif |
| 721 | perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) | 737 | perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) |
| 722 | STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) | 738 | STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) |
| 739 | tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) | ||
| 723 | 740 | ||
| 724 | # If we install to $(HOME) we keep the traceevent default: | 741 | # If we install to $(HOME) we keep the traceevent default: |
| 725 | # $(HOME)/.traceevent/plugins | 742 | # $(HOME)/.traceevent/plugins |
| @@ -741,6 +758,10 @@ ifeq ($(VF),1) | |||
| 741 | $(call print_var,sysconfdir) | 758 | $(call print_var,sysconfdir) |
| 742 | $(call print_var,LIBUNWIND_DIR) | 759 | $(call print_var,LIBUNWIND_DIR) |
| 743 | $(call print_var,LIBDW_DIR) | 760 | $(call print_var,LIBDW_DIR) |
| 761 | |||
| 762 | ifeq ($(dwarf-post-unwind),1) | ||
| 763 | $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) | ||
| 764 | endif | ||
| 744 | $(info ) | 765 | $(info ) |
| 745 | endif | 766 | endif |
| 746 | 767 | ||
| @@ -756,6 +777,8 @@ $(call detected_var,ETC_PERFCONFIG_SQ) | |||
| 756 | $(call detected_var,STRACE_GROUPS_DIR_SQ) | 777 | $(call detected_var,STRACE_GROUPS_DIR_SQ) |
| 757 | $(call detected_var,prefix_SQ) | 778 | $(call detected_var,prefix_SQ) |
| 758 | $(call detected_var,perfexecdir_SQ) | 779 | $(call detected_var,perfexecdir_SQ) |
| 780 | $(call detected_var,tipdir_SQ) | ||
| 781 | $(call detected_var,srcdir_SQ) | ||
| 759 | $(call detected_var,LIBDIR) | 782 | $(call detected_var,LIBDIR) |
| 760 | $(call detected_var,GTK_CFLAGS) | 783 | $(call detected_var,GTK_CFLAGS) |
| 761 | $(call detected_var,PERL_EMBED_CCOPTS) | 784 | $(call detected_var,PERL_EMBED_CCOPTS) |
diff --git a/tools/perf/config/Makefile.arch b/tools/perf/config/Makefile.arch deleted file mode 100644 index e11fbd6fae78..000000000000 --- a/tools/perf/config/Makefile.arch +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | ifndef ARCH | ||
| 2 | ARCH := $(shell uname -m 2>/dev/null || echo not) | ||
| 3 | endif | ||
| 4 | |||
| 5 | ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ | ||
| 6 | -e s/sun4u/sparc/ -e s/sparc64/sparc/ \ | ||
| 7 | -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \ | ||
| 8 | -e s/s390x/s390/ -e s/parisc64/parisc/ \ | ||
| 9 | -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ | ||
| 10 | -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ | ||
| 11 | -e s/tile.*/tile/ ) | ||
| 12 | |||
| 13 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) | ||
| 14 | ifeq ($(LP64), 1) | ||
| 15 | IS_64_BIT := 1 | ||
| 16 | else | ||
| 17 | IS_64_BIT := 0 | ||
| 18 | endif | ||
diff --git a/tools/perf/config/utilities.mak b/tools/perf/config/utilities.mak index 0ebef09c0842..c16ce833079c 100644 --- a/tools/perf/config/utilities.mak +++ b/tools/perf/config/utilities.mak | |||
| @@ -177,22 +177,3 @@ $(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2))) | |||
| 177 | endef | 177 | endef |
| 178 | _ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2))) | 178 | _ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2))) |
| 179 | _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) | 179 | _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) |
| 180 | |||
| 181 | # try-run | ||
| 182 | # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) | ||
| 183 | # Exit code chooses option. "$$TMP" is can be used as temporary file and | ||
| 184 | # is automatically cleaned up. | ||
| 185 | try-run = $(shell set -e; \ | ||
| 186 | TMP="$(TMPOUT).$$$$.tmp"; \ | ||
| 187 | TMPO="$(TMPOUT).$$$$.o"; \ | ||
| 188 | if ($(1)) >/dev/null 2>&1; \ | ||
| 189 | then echo "$(2)"; \ | ||
| 190 | else echo "$(3)"; \ | ||
| 191 | fi; \ | ||
| 192 | rm -f "$$TMP" "$$TMPO") | ||
| 193 | |||
| 194 | # cc-option | ||
| 195 | # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) | ||
| 196 | |||
| 197 | cc-option = $(call try-run,\ | ||
| 198 | $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) | ||
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 3d4c7c09adea..a929618b8eb6 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
| @@ -9,16 +9,18 @@ | |||
| 9 | #include "builtin.h" | 9 | #include "builtin.h" |
| 10 | 10 | ||
| 11 | #include "util/env.h" | 11 | #include "util/env.h" |
| 12 | #include "util/exec_cmd.h" | 12 | #include <subcmd/exec-cmd.h> |
| 13 | #include "util/cache.h" | 13 | #include "util/cache.h" |
| 14 | #include "util/quote.h" | 14 | #include "util/quote.h" |
| 15 | #include "util/run-command.h" | 15 | #include <subcmd/run-command.h> |
| 16 | #include "util/parse-events.h" | 16 | #include "util/parse-events.h" |
| 17 | #include "util/parse-options.h" | 17 | #include <subcmd/parse-options.h> |
| 18 | #include "util/bpf-loader.h" | 18 | #include "util/bpf-loader.h" |
| 19 | #include "util/debug.h" | 19 | #include "util/debug.h" |
| 20 | #include <api/fs/tracing_path.h> | 20 | #include <api/fs/tracing_path.h> |
| 21 | #include <pthread.h> | 21 | #include <pthread.h> |
| 22 | #include <stdlib.h> | ||
| 23 | #include <time.h> | ||
| 22 | 24 | ||
| 23 | const char perf_usage_string[] = | 25 | const char perf_usage_string[] = |
| 24 | "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; | 26 | "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; |
| @@ -39,6 +41,7 @@ struct cmd_struct { | |||
| 39 | static struct cmd_struct commands[] = { | 41 | static struct cmd_struct commands[] = { |
| 40 | { "buildid-cache", cmd_buildid_cache, 0 }, | 42 | { "buildid-cache", cmd_buildid_cache, 0 }, |
| 41 | { "buildid-list", cmd_buildid_list, 0 }, | 43 | { "buildid-list", cmd_buildid_list, 0 }, |
| 44 | { "config", cmd_config, 0 }, | ||
| 42 | { "diff", cmd_diff, 0 }, | 45 | { "diff", cmd_diff, 0 }, |
| 43 | { "evlist", cmd_evlist, 0 }, | 46 | { "evlist", cmd_evlist, 0 }, |
| 44 | { "help", cmd_help, 0 }, | 47 | { "help", cmd_help, 0 }, |
| @@ -118,7 +121,7 @@ static void commit_pager_choice(void) | |||
| 118 | { | 121 | { |
| 119 | switch (use_pager) { | 122 | switch (use_pager) { |
| 120 | case 0: | 123 | case 0: |
| 121 | setenv("PERF_PAGER", "cat", 1); | 124 | setenv(PERF_PAGER_ENVIRONMENT, "cat", 1); |
| 122 | break; | 125 | break; |
| 123 | case 1: | 126 | case 1: |
| 124 | /* setup_pager(); */ | 127 | /* setup_pager(); */ |
| @@ -182,9 +185,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) | |||
| 182 | if (!prefixcmp(cmd, CMD_EXEC_PATH)) { | 185 | if (!prefixcmp(cmd, CMD_EXEC_PATH)) { |
| 183 | cmd += strlen(CMD_EXEC_PATH); | 186 | cmd += strlen(CMD_EXEC_PATH); |
| 184 | if (*cmd == '=') | 187 | if (*cmd == '=') |
| 185 | perf_set_argv_exec_path(cmd + 1); | 188 | set_argv_exec_path(cmd + 1); |
| 186 | else { | 189 | else { |
| 187 | puts(perf_exec_path()); | 190 | puts(get_argv_exec_path()); |
| 188 | exit(0); | 191 | exit(0); |
| 189 | } | 192 | } |
| 190 | } else if (!strcmp(cmd, "--html-path")) { | 193 | } else if (!strcmp(cmd, "--html-path")) { |
| @@ -383,6 +386,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
| 383 | use_pager = 1; | 386 | use_pager = 1; |
| 384 | commit_pager_choice(); | 387 | commit_pager_choice(); |
| 385 | 388 | ||
| 389 | perf_env__set_cmdline(&perf_env, argc, argv); | ||
| 386 | status = p->fn(argc, argv, prefix); | 390 | status = p->fn(argc, argv, prefix); |
| 387 | exit_browser(status); | 391 | exit_browser(status); |
| 388 | perf_env__exit(&perf_env); | 392 | perf_env__exit(&perf_env); |
| @@ -528,14 +532,20 @@ int main(int argc, const char **argv) | |||
| 528 | const char *cmd; | 532 | const char *cmd; |
| 529 | char sbuf[STRERR_BUFSIZE]; | 533 | char sbuf[STRERR_BUFSIZE]; |
| 530 | 534 | ||
| 535 | /* libsubcmd init */ | ||
| 536 | exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT); | ||
| 537 | pager_init(PERF_PAGER_ENVIRONMENT); | ||
| 538 | |||
| 531 | /* The page_size is placed in util object. */ | 539 | /* The page_size is placed in util object. */ |
| 532 | page_size = sysconf(_SC_PAGE_SIZE); | 540 | page_size = sysconf(_SC_PAGE_SIZE); |
| 533 | cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); | 541 | cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); |
| 534 | 542 | ||
| 535 | cmd = perf_extract_argv0_path(argv[0]); | 543 | cmd = extract_argv0_path(argv[0]); |
| 536 | if (!cmd) | 544 | if (!cmd) |
| 537 | cmd = "perf-help"; | 545 | cmd = "perf-help"; |
| 538 | 546 | ||
| 547 | srandom(time(NULL)); | ||
| 548 | |||
| 539 | /* get debugfs/tracefs mount point from /proc/mounts */ | 549 | /* get debugfs/tracefs mount point from /proc/mounts */ |
| 540 | tracing_path_mount(); | 550 | tracing_path_mount(); |
| 541 | 551 | ||
diff --git a/tools/perf/scripts/python/stat-cpi.py b/tools/perf/scripts/python/stat-cpi.py new file mode 100644 index 000000000000..8b60f343dd07 --- /dev/null +++ b/tools/perf/scripts/python/stat-cpi.py | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | |||
| 3 | data = {} | ||
| 4 | times = [] | ||
| 5 | threads = [] | ||
| 6 | cpus = [] | ||
| 7 | |||
| 8 | def get_key(time, event, cpu, thread): | ||
| 9 | return "%d-%s-%d-%d" % (time, event, cpu, thread) | ||
| 10 | |||
| 11 | def store_key(time, cpu, thread): | ||
| 12 | if (time not in times): | ||
| 13 | times.append(time) | ||
| 14 | |||
| 15 | if (cpu not in cpus): | ||
| 16 | cpus.append(cpu) | ||
| 17 | |||
| 18 | if (thread not in threads): | ||
| 19 | threads.append(thread) | ||
| 20 | |||
| 21 | def store(time, event, cpu, thread, val, ena, run): | ||
| 22 | #print "event %s cpu %d, thread %d, time %d, val %d, ena %d, run %d" % \ | ||
| 23 | # (event, cpu, thread, time, val, ena, run) | ||
| 24 | |||
| 25 | store_key(time, cpu, thread) | ||
| 26 | key = get_key(time, event, cpu, thread) | ||
| 27 | data[key] = [ val, ena, run] | ||
| 28 | |||
| 29 | def get(time, event, cpu, thread): | ||
| 30 | key = get_key(time, event, cpu, thread) | ||
| 31 | return data[key][0] | ||
| 32 | |||
| 33 | def stat__cycles_k(cpu, thread, time, val, ena, run): | ||
| 34 | store(time, "cycles", cpu, thread, val, ena, run); | ||
| 35 | |||
| 36 | def stat__instructions_k(cpu, thread, time, val, ena, run): | ||
| 37 | store(time, "instructions", cpu, thread, val, ena, run); | ||
| 38 | |||
| 39 | def stat__cycles_u(cpu, thread, time, val, ena, run): | ||
| 40 | store(time, "cycles", cpu, thread, val, ena, run); | ||
| 41 | |||
| 42 | def stat__instructions_u(cpu, thread, time, val, ena, run): | ||
| 43 | store(time, "instructions", cpu, thread, val, ena, run); | ||
| 44 | |||
| 45 | def stat__cycles(cpu, thread, time, val, ena, run): | ||
| 46 | store(time, "cycles", cpu, thread, val, ena, run); | ||
| 47 | |||
| 48 | def stat__instructions(cpu, thread, time, val, ena, run): | ||
| 49 | store(time, "instructions", cpu, thread, val, ena, run); | ||
| 50 | |||
| 51 | def stat__interval(time): | ||
| 52 | for cpu in cpus: | ||
| 53 | for thread in threads: | ||
| 54 | cyc = get(time, "cycles", cpu, thread) | ||
| 55 | ins = get(time, "instructions", cpu, thread) | ||
| 56 | cpi = 0 | ||
| 57 | |||
| 58 | if ins != 0: | ||
| 59 | cpi = cyc/float(ins) | ||
| 60 | |||
| 61 | print "%15f: cpu %d, thread %d -> cpi %f (%d/%d)" % (time/(float(1000000000)), cpu, thread, cpi, cyc, ins) | ||
| 62 | |||
| 63 | def trace_end(): | ||
| 64 | pass | ||
| 65 | # XXX trace_end callback could be used as an alternative place | ||
| 66 | # to compute same values as in the script above: | ||
| 67 | # | ||
| 68 | # for time in times: | ||
| 69 | # for cpu in cpus: | ||
| 70 | # for thread in threads: | ||
| 71 | # cyc = get(time, "cycles", cpu, thread) | ||
| 72 | # ins = get(time, "instructions", cpu, thread) | ||
| 73 | # | ||
| 74 | # if ins != 0: | ||
| 75 | # cpi = cyc/float(ins) | ||
| 76 | # | ||
| 77 | # print "time %.9f, cpu %d, thread %d -> cpi %f" % (time/(float(1000000000)), cpu, thread, cpi) | ||
diff --git a/tools/perf/tests/.gitignore b/tools/perf/tests/.gitignore index 489fc9ffbcb0..bf016c439fbd 100644 --- a/tools/perf/tests/.gitignore +++ b/tools/perf/tests/.gitignore | |||
| @@ -1,2 +1,3 @@ | |||
| 1 | llvm-src-base.c | 1 | llvm-src-base.c |
| 2 | llvm-src-kbuild.c | 2 | llvm-src-kbuild.c |
| 3 | llvm-src-prologue.c | ||
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index f41ebf8849fe..614899b88b37 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build | |||
| @@ -31,24 +31,34 @@ perf-y += sample-parsing.o | |||
| 31 | perf-y += parse-no-sample-id-all.o | 31 | perf-y += parse-no-sample-id-all.o |
| 32 | perf-y += kmod-path.o | 32 | perf-y += kmod-path.o |
| 33 | perf-y += thread-map.o | 33 | perf-y += thread-map.o |
| 34 | perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o | 34 | perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o |
| 35 | perf-y += bpf.o | 35 | perf-y += bpf.o |
| 36 | perf-y += topology.o | 36 | perf-y += topology.o |
| 37 | perf-y += cpumap.o | ||
| 38 | perf-y += stat.o | ||
| 39 | perf-y += event_update.o | ||
| 37 | 40 | ||
| 38 | $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c | 41 | $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build |
| 39 | $(call rule_mkdir) | 42 | $(call rule_mkdir) |
| 40 | $(Q)echo '#include <tests/llvm.h>' > $@ | 43 | $(Q)echo '#include <tests/llvm.h>' > $@ |
| 41 | $(Q)echo 'const char test_llvm__bpf_base_prog[] =' >> $@ | 44 | $(Q)echo 'const char test_llvm__bpf_base_prog[] =' >> $@ |
| 42 | $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ | 45 | $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ |
| 43 | $(Q)echo ';' >> $@ | 46 | $(Q)echo ';' >> $@ |
| 44 | 47 | ||
| 45 | $(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c | 48 | $(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c tests/Build |
| 46 | $(call rule_mkdir) | 49 | $(call rule_mkdir) |
| 47 | $(Q)echo '#include <tests/llvm.h>' > $@ | 50 | $(Q)echo '#include <tests/llvm.h>' > $@ |
| 48 | $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@ | 51 | $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@ |
| 49 | $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ | 52 | $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ |
| 50 | $(Q)echo ';' >> $@ | 53 | $(Q)echo ';' >> $@ |
| 51 | 54 | ||
| 55 | $(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c tests/Build | ||
| 56 | $(call rule_mkdir) | ||
| 57 | $(Q)echo '#include <tests/llvm.h>' > $@ | ||
| 58 | $(Q)echo 'const char test_llvm__bpf_test_prologue_prog[] =' >> $@ | ||
| 59 | $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ | ||
| 60 | $(Q)echo ';' >> $@ | ||
| 61 | |||
| 52 | ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64)) | 62 | ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64)) |
| 53 | perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o | 63 | perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o |
| 54 | endif | 64 | endif |
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 638875a0960a..28d1605b0338 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
| 25 | #include "../perf.h" | 25 | #include "../perf.h" |
| 26 | #include "util.h" | 26 | #include "util.h" |
| 27 | #include "exec_cmd.h" | 27 | #include <subcmd/exec-cmd.h> |
| 28 | #include "tests.h" | 28 | #include "tests.h" |
| 29 | 29 | ||
| 30 | #define ENV "PERF_TEST_ATTR" | 30 | #define ENV "PERF_TEST_ATTR" |
| @@ -153,7 +153,7 @@ static int run_dir(const char *d, const char *perf) | |||
| 153 | return system(cmd); | 153 | return system(cmd); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | int test__attr(void) | 156 | int test__attr(int subtest __maybe_unused) |
| 157 | { | 157 | { |
| 158 | struct stat st; | 158 | struct stat st; |
| 159 | char path_perf[PATH_MAX]; | 159 | char path_perf[PATH_MAX]; |
| @@ -164,7 +164,7 @@ int test__attr(void) | |||
| 164 | return run_dir("./tests", "./perf"); | 164 | return run_dir("./tests", "./perf"); |
| 165 | 165 | ||
| 166 | /* Then installed path. */ | 166 | /* Then installed path. */ |
| 167 | snprintf(path_dir, PATH_MAX, "%s/tests", perf_exec_path()); | 167 | snprintf(path_dir, PATH_MAX, "%s/tests", get_argv_exec_path()); |
| 168 | snprintf(path_perf, PATH_MAX, "%s/perf", BINDIR); | 168 | snprintf(path_perf, PATH_MAX, "%s/perf", BINDIR); |
| 169 | 169 | ||
| 170 | if (!lstat(path_dir, &st) && | 170 | if (!lstat(path_dir, &st) && |
diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c index a02b035fd5aa..fb80c9eb6a95 100644 --- a/tools/perf/tests/bp_signal.c +++ b/tools/perf/tests/bp_signal.c | |||
| @@ -111,7 +111,7 @@ static long long bp_count(int fd) | |||
| 111 | return count; | 111 | return count; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | int test__bp_signal(void) | 114 | int test__bp_signal(int subtest __maybe_unused) |
| 115 | { | 115 | { |
| 116 | struct sigaction sa; | 116 | struct sigaction sa; |
| 117 | long long count1, count2; | 117 | long long count1, count2; |
diff --git a/tools/perf/tests/bp_signal_overflow.c b/tools/perf/tests/bp_signal_overflow.c index e76537724491..89f92fa67cc4 100644 --- a/tools/perf/tests/bp_signal_overflow.c +++ b/tools/perf/tests/bp_signal_overflow.c | |||
| @@ -58,7 +58,7 @@ static long long bp_count(int fd) | |||
| 58 | #define EXECUTIONS 10000 | 58 | #define EXECUTIONS 10000 |
| 59 | #define THRESHOLD 100 | 59 | #define THRESHOLD 100 |
| 60 | 60 | ||
| 61 | int test__bp_signal_overflow(void) | 61 | int test__bp_signal_overflow(int subtest __maybe_unused) |
| 62 | { | 62 | { |
| 63 | struct perf_event_attr pe; | 63 | struct perf_event_attr pe; |
| 64 | struct sigaction sa; | 64 | struct sigaction sa; |
diff --git a/tools/perf/tests/bpf-script-test-prologue.c b/tools/perf/tests/bpf-script-test-prologue.c new file mode 100644 index 000000000000..7230e62c70fc --- /dev/null +++ b/tools/perf/tests/bpf-script-test-prologue.c | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* | ||
| 2 | * bpf-script-test-prologue.c | ||
| 3 | * Test BPF prologue | ||
| 4 | */ | ||
| 5 | #ifndef LINUX_VERSION_CODE | ||
| 6 | # error Need LINUX_VERSION_CODE | ||
| 7 | # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' | ||
| 8 | #endif | ||
| 9 | #define SEC(NAME) __attribute__((section(NAME), used)) | ||
| 10 | |||
| 11 | #include <uapi/linux/fs.h> | ||
| 12 | |||
| 13 | #define FMODE_READ 0x1 | ||
| 14 | #define FMODE_WRITE 0x2 | ||
| 15 | |||
| 16 | static void (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) = | ||
| 17 | (void *) 6; | ||
| 18 | |||
| 19 | SEC("func=null_lseek file->f_mode offset orig") | ||
| 20 | int bpf_func__null_lseek(void *ctx, int err, unsigned long f_mode, | ||
| 21 | unsigned long offset, unsigned long orig) | ||
| 22 | { | ||
| 23 | if (err) | ||
| 24 | return 0; | ||
| 25 | if (f_mode & FMODE_WRITE) | ||
| 26 | return 0; | ||
| 27 | if (offset & 1) | ||
| 28 | return 0; | ||
| 29 | if (orig == SEEK_CUR) | ||
| 30 | return 0; | ||
| 31 | return 1; | ||
| 32 | } | ||
| 33 | |||
| 34 | char _license[] SEC("license") = "GPL"; | ||
| 35 | int _version SEC("version") = LINUX_VERSION_CODE; | ||
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index ec16f7812c8b..33689a0cf821 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c | |||
| @@ -19,6 +19,29 @@ static int epoll_pwait_loop(void) | |||
| 19 | return 0; | 19 | return 0; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | #ifdef HAVE_BPF_PROLOGUE | ||
| 23 | |||
| 24 | static int llseek_loop(void) | ||
| 25 | { | ||
| 26 | int fds[2], i; | ||
| 27 | |||
| 28 | fds[0] = open("/dev/null", O_RDONLY); | ||
| 29 | fds[1] = open("/dev/null", O_RDWR); | ||
| 30 | |||
| 31 | if (fds[0] < 0 || fds[1] < 0) | ||
| 32 | return -1; | ||
| 33 | |||
| 34 | for (i = 0; i < NR_ITERS; i++) { | ||
| 35 | lseek(fds[i % 2], i, (i / 2) % 2 ? SEEK_CUR : SEEK_SET); | ||
| 36 | lseek(fds[(i + 1) % 2], i, (i / 2) % 2 ? SEEK_CUR : SEEK_SET); | ||
| 37 | } | ||
| 38 | close(fds[0]); | ||
| 39 | close(fds[1]); | ||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | #endif | ||
| 44 | |||
| 22 | static struct { | 45 | static struct { |
| 23 | enum test_llvm__testcase prog_id; | 46 | enum test_llvm__testcase prog_id; |
| 24 | const char *desc; | 47 | const char *desc; |
| @@ -37,6 +60,17 @@ static struct { | |||
| 37 | &epoll_pwait_loop, | 60 | &epoll_pwait_loop, |
| 38 | (NR_ITERS + 1) / 2, | 61 | (NR_ITERS + 1) / 2, |
| 39 | }, | 62 | }, |
| 63 | #ifdef HAVE_BPF_PROLOGUE | ||
| 64 | { | ||
| 65 | LLVM_TESTCASE_BPF_PROLOGUE, | ||
| 66 | "Test BPF prologue generation", | ||
| 67 | "[bpf_prologue_test]", | ||
| 68 | "fix kbuild first", | ||
| 69 | "check your vmlinux setting?", | ||
| 70 | &llseek_loop, | ||
| 71 | (NR_ITERS + 1) / 4, | ||
| 72 | }, | ||
| 73 | #endif | ||
| 40 | }; | 74 | }; |
| 41 | 75 | ||
| 42 | static int do_test(struct bpf_object *obj, int (*func)(void), | 76 | static int do_test(struct bpf_object *obj, int (*func)(void), |
| @@ -68,8 +102,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void), | |||
| 68 | err = parse_events_load_bpf_obj(&parse_evlist, &parse_evlist.list, obj); | 102 | err = parse_events_load_bpf_obj(&parse_evlist, &parse_evlist.list, obj); |
| 69 | if (err || list_empty(&parse_evlist.list)) { | 103 | if (err || list_empty(&parse_evlist.list)) { |
| 70 | pr_debug("Failed to add events selected by BPF\n"); | 104 | pr_debug("Failed to add events selected by BPF\n"); |
| 71 | if (!err) | 105 | return TEST_FAIL; |
| 72 | return TEST_FAIL; | ||
| 73 | } | 106 | } |
| 74 | 107 | ||
| 75 | snprintf(pid, sizeof(pid), "%d", getpid()); | 108 | snprintf(pid, sizeof(pid), "%d", getpid()); |
| @@ -123,8 +156,10 @@ static int do_test(struct bpf_object *obj, int (*func)(void), | |||
| 123 | } | 156 | } |
| 124 | } | 157 | } |
| 125 | 158 | ||
| 126 | if (count != expect) | 159 | if (count != expect) { |
| 127 | pr_debug("BPF filter result incorrect\n"); | 160 | pr_debug("BPF filter result incorrect\n"); |
| 161 | goto out_delete_evlist; | ||
| 162 | } | ||
| 128 | 163 | ||
| 129 | ret = TEST_OK; | 164 | ret = TEST_OK; |
| 130 | 165 | ||
| @@ -146,7 +181,7 @@ prepare_bpf(void *obj_buf, size_t obj_buf_sz, const char *name) | |||
| 146 | return obj; | 181 | return obj; |
| 147 | } | 182 | } |
| 148 | 183 | ||
| 149 | static int __test__bpf(int index) | 184 | static int __test__bpf(int idx) |
| 150 | { | 185 | { |
| 151 | int ret; | 186 | int ret; |
| 152 | void *obj_buf; | 187 | void *obj_buf; |
| @@ -154,54 +189,72 @@ static int __test__bpf(int index) | |||
| 154 | struct bpf_object *obj; | 189 | struct bpf_object *obj; |
| 155 | 190 | ||
| 156 | ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, | 191 | ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, |
| 157 | bpf_testcase_table[index].prog_id, | 192 | bpf_testcase_table[idx].prog_id, |
| 158 | true); | 193 | true); |
| 159 | if (ret != TEST_OK || !obj_buf || !obj_buf_sz) { | 194 | if (ret != TEST_OK || !obj_buf || !obj_buf_sz) { |
| 160 | pr_debug("Unable to get BPF object, %s\n", | 195 | pr_debug("Unable to get BPF object, %s\n", |
| 161 | bpf_testcase_table[index].msg_compile_fail); | 196 | bpf_testcase_table[idx].msg_compile_fail); |
| 162 | if (index == 0) | 197 | if (idx == 0) |
| 163 | return TEST_SKIP; | 198 | return TEST_SKIP; |
| 164 | else | 199 | else |
| 165 | return TEST_FAIL; | 200 | return TEST_FAIL; |
| 166 | } | 201 | } |
| 167 | 202 | ||
| 168 | obj = prepare_bpf(obj_buf, obj_buf_sz, | 203 | obj = prepare_bpf(obj_buf, obj_buf_sz, |
| 169 | bpf_testcase_table[index].name); | 204 | bpf_testcase_table[idx].name); |
| 170 | if (!obj) { | 205 | if (!obj) { |
| 171 | ret = TEST_FAIL; | 206 | ret = TEST_FAIL; |
| 172 | goto out; | 207 | goto out; |
| 173 | } | 208 | } |
| 174 | 209 | ||
| 175 | ret = do_test(obj, | 210 | ret = do_test(obj, |
| 176 | bpf_testcase_table[index].target_func, | 211 | bpf_testcase_table[idx].target_func, |
| 177 | bpf_testcase_table[index].expect_result); | 212 | bpf_testcase_table[idx].expect_result); |
| 178 | out: | 213 | out: |
| 179 | bpf__clear(); | 214 | bpf__clear(); |
| 180 | return ret; | 215 | return ret; |
| 181 | } | 216 | } |
| 182 | 217 | ||
| 183 | int test__bpf(void) | 218 | int test__bpf_subtest_get_nr(void) |
| 219 | { | ||
| 220 | return (int)ARRAY_SIZE(bpf_testcase_table); | ||
| 221 | } | ||
| 222 | |||
| 223 | const char *test__bpf_subtest_get_desc(int i) | ||
| 224 | { | ||
| 225 | if (i < 0 || i >= (int)ARRAY_SIZE(bpf_testcase_table)) | ||
| 226 | return NULL; | ||
| 227 | return bpf_testcase_table[i].desc; | ||
| 228 | } | ||
| 229 | |||
| 230 | int test__bpf(int i) | ||
| 184 | { | 231 | { |
| 185 | unsigned int i; | ||
| 186 | int err; | 232 | int err; |
| 187 | 233 | ||
| 234 | if (i < 0 || i >= (int)ARRAY_SIZE(bpf_testcase_table)) | ||
| 235 | return TEST_FAIL; | ||
| 236 | |||
| 188 | if (geteuid() != 0) { | 237 | if (geteuid() != 0) { |
| 189 | pr_debug("Only root can run BPF test\n"); | 238 | pr_debug("Only root can run BPF test\n"); |
| 190 | return TEST_SKIP; | 239 | return TEST_SKIP; |
| 191 | } | 240 | } |
| 192 | 241 | ||
| 193 | for (i = 0; i < ARRAY_SIZE(bpf_testcase_table); i++) { | 242 | err = __test__bpf(i); |
| 194 | err = __test__bpf(i); | 243 | return err; |
| 244 | } | ||
| 195 | 245 | ||
| 196 | if (err != TEST_OK) | 246 | #else |
| 197 | return err; | 247 | int test__bpf_subtest_get_nr(void) |
| 198 | } | 248 | { |
| 249 | return 0; | ||
| 250 | } | ||
| 199 | 251 | ||
| 200 | return TEST_OK; | 252 | const char *test__bpf_subtest_get_desc(int i __maybe_unused) |
| 253 | { | ||
| 254 | return NULL; | ||
| 201 | } | 255 | } |
| 202 | 256 | ||
| 203 | #else | 257 | int test__bpf(int i __maybe_unused) |
| 204 | int test__bpf(void) | ||
| 205 | { | 258 | { |
| 206 | pr_debug("Skip BPF test because BPF support is not compiled\n"); | 259 | pr_debug("Skip BPF test because BPF support is not compiled\n"); |
| 207 | return TEST_SKIP; | 260 | return TEST_SKIP; |
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 80c442eab767..f2b1dcac45d3 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "tests.h" | 11 | #include "tests.h" |
| 12 | #include "debug.h" | 12 | #include "debug.h" |
| 13 | #include "color.h" | 13 | #include "color.h" |
| 14 | #include "parse-options.h" | 14 | #include <subcmd/parse-options.h> |
| 15 | #include "symbol.h" | 15 | #include "symbol.h" |
| 16 | 16 | ||
| 17 | struct test __weak arch_tests[] = { | 17 | struct test __weak arch_tests[] = { |
| @@ -160,6 +160,11 @@ static struct test generic_tests[] = { | |||
| 160 | { | 160 | { |
| 161 | .desc = "Test LLVM searching and compiling", | 161 | .desc = "Test LLVM searching and compiling", |
| 162 | .func = test__llvm, | 162 | .func = test__llvm, |
| 163 | .subtest = { | ||
| 164 | .skip_if_fail = true, | ||
| 165 | .get_nr = test__llvm_subtest_get_nr, | ||
| 166 | .get_desc = test__llvm_subtest_get_desc, | ||
| 167 | }, | ||
| 163 | }, | 168 | }, |
| 164 | { | 169 | { |
| 165 | .desc = "Test topology in session", | 170 | .desc = "Test topology in session", |
| @@ -168,6 +173,35 @@ static struct test generic_tests[] = { | |||
| 168 | { | 173 | { |
| 169 | .desc = "Test BPF filter", | 174 | .desc = "Test BPF filter", |
| 170 | .func = test__bpf, | 175 | .func = test__bpf, |
| 176 | .subtest = { | ||
| 177 | .skip_if_fail = true, | ||
| 178 | .get_nr = test__bpf_subtest_get_nr, | ||
| 179 | .get_desc = test__bpf_subtest_get_desc, | ||
| 180 | }, | ||
| 181 | }, | ||
| 182 | { | ||
| 183 | .desc = "Test thread map synthesize", | ||
| 184 | .func = test__thread_map_synthesize, | ||
| 185 | }, | ||
| 186 | { | ||
| 187 | .desc = "Test cpu map synthesize", | ||
| 188 | .func = test__cpu_map_synthesize, | ||
| 189 | }, | ||
| 190 | { | ||
| 191 | .desc = "Test stat config synthesize", | ||
| 192 | .func = test__synthesize_stat_config, | ||
| 193 | }, | ||
| 194 | { | ||
| 195 | .desc = "Test stat synthesize", | ||
| 196 | .func = test__synthesize_stat, | ||
| 197 | }, | ||
| 198 | { | ||
| 199 | .desc = "Test stat round synthesize", | ||
| 200 | .func = test__synthesize_stat_round, | ||
| 201 | }, | ||
| 202 | { | ||
| 203 | .desc = "Test attr update synthesize", | ||
| 204 | .func = test__event_update, | ||
| 171 | }, | 205 | }, |
| 172 | { | 206 | { |
| 173 | .func = NULL, | 207 | .func = NULL, |
| @@ -203,7 +237,7 @@ static bool perf_test__matches(struct test *test, int curr, int argc, const char | |||
| 203 | return false; | 237 | return false; |
| 204 | } | 238 | } |
| 205 | 239 | ||
| 206 | static int run_test(struct test *test) | 240 | static int run_test(struct test *test, int subtest) |
| 207 | { | 241 | { |
| 208 | int status, err = -1, child = fork(); | 242 | int status, err = -1, child = fork(); |
| 209 | char sbuf[STRERR_BUFSIZE]; | 243 | char sbuf[STRERR_BUFSIZE]; |
| @@ -216,7 +250,22 @@ static int run_test(struct test *test) | |||
| 216 | 250 | ||
| 217 | if (!child) { | 251 | if (!child) { |
| 218 | pr_debug("test child forked, pid %d\n", getpid()); | 252 | pr_debug("test child forked, pid %d\n", getpid()); |
| 219 | err = test->func(); | 253 | if (!verbose) { |
| 254 | int nullfd = open("/dev/null", O_WRONLY); | ||
| 255 | if (nullfd >= 0) { | ||
| 256 | close(STDERR_FILENO); | ||
| 257 | close(STDOUT_FILENO); | ||
| 258 | |||
| 259 | dup2(nullfd, STDOUT_FILENO); | ||
| 260 | dup2(STDOUT_FILENO, STDERR_FILENO); | ||
| 261 | close(nullfd); | ||
| 262 | } | ||
| 263 | } else { | ||
| 264 | signal(SIGSEGV, sighandler_dump_stack); | ||
| 265 | signal(SIGFPE, sighandler_dump_stack); | ||
| 266 | } | ||
| 267 | |||
| 268 | err = test->func(subtest); | ||
| 220 | exit(err); | 269 | exit(err); |
| 221 | } | 270 | } |
| 222 | 271 | ||
| @@ -237,6 +286,40 @@ static int run_test(struct test *test) | |||
| 237 | for (j = 0; j < ARRAY_SIZE(tests); j++) \ | 286 | for (j = 0; j < ARRAY_SIZE(tests); j++) \ |
| 238 | for (t = &tests[j][0]; t->func; t++) | 287 | for (t = &tests[j][0]; t->func; t++) |
| 239 | 288 | ||
| 289 | static int test_and_print(struct test *t, bool force_skip, int subtest) | ||
| 290 | { | ||
| 291 | int err; | ||
| 292 | |||
| 293 | if (!force_skip) { | ||
| 294 | pr_debug("\n--- start ---\n"); | ||
| 295 | err = run_test(t, subtest); | ||
| 296 | pr_debug("---- end ----\n"); | ||
| 297 | } else { | ||
| 298 | pr_debug("\n--- force skipped ---\n"); | ||
| 299 | err = TEST_SKIP; | ||
| 300 | } | ||
| 301 | |||
| 302 | if (!t->subtest.get_nr) | ||
| 303 | pr_debug("%s:", t->desc); | ||
| 304 | else | ||
| 305 | pr_debug("%s subtest %d:", t->desc, subtest); | ||
| 306 | |||
| 307 | switch (err) { | ||
| 308 | case TEST_OK: | ||
| 309 | pr_info(" Ok\n"); | ||
| 310 | break; | ||
| 311 | case TEST_SKIP: | ||
| 312 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); | ||
| 313 | break; | ||
| 314 | case TEST_FAIL: | ||
| 315 | default: | ||
| 316 | color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); | ||
| 317 | break; | ||
| 318 | } | ||
| 319 | |||
| 320 | return err; | ||
| 321 | } | ||
| 322 | |||
| 240 | static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) | 323 | static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) |
| 241 | { | 324 | { |
| 242 | struct test *t; | 325 | struct test *t; |
| @@ -264,21 +347,43 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) | |||
| 264 | continue; | 347 | continue; |
| 265 | } | 348 | } |
| 266 | 349 | ||
| 267 | pr_debug("\n--- start ---\n"); | 350 | if (!t->subtest.get_nr) { |
| 268 | err = run_test(t); | 351 | test_and_print(t, false, -1); |
| 269 | pr_debug("---- end ----\n%s:", t->desc); | 352 | } else { |
| 270 | 353 | int subn = t->subtest.get_nr(); | |
| 271 | switch (err) { | 354 | /* |
| 272 | case TEST_OK: | 355 | * minus 2 to align with normal testcases. |
| 273 | pr_info(" Ok\n"); | 356 | * For subtest we print additional '.x' in number. |
| 274 | break; | 357 | * for example: |
| 275 | case TEST_SKIP: | 358 | * |
| 276 | color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); | 359 | * 35: Test LLVM searching and compiling : |
| 277 | break; | 360 | * 35.1: Basic BPF llvm compiling test : Ok |
| 278 | case TEST_FAIL: | 361 | */ |
| 279 | default: | 362 | int subw = width > 2 ? width - 2 : width; |
| 280 | color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); | 363 | bool skip = false; |
| 281 | break; | 364 | int subi; |
| 365 | |||
| 366 | if (subn <= 0) { | ||
| 367 | color_fprintf(stderr, PERF_COLOR_YELLOW, | ||
| 368 | " Skip (not compiled in)\n"); | ||
| 369 | continue; | ||
| 370 | } | ||
| 371 | pr_info("\n"); | ||
| 372 | |||
| 373 | for (subi = 0; subi < subn; subi++) { | ||
| 374 | int len = strlen(t->subtest.get_desc(subi)); | ||
| 375 | |||
| 376 | if (subw < len) | ||
| 377 | subw = len; | ||
| 378 | } | ||
| 379 | |||
| 380 | for (subi = 0; subi < subn; subi++) { | ||
| 381 | pr_info("%2d.%1d: %-*s:", i, subi + 1, subw, | ||
| 382 | t->subtest.get_desc(subi)); | ||
| 383 | err = test_and_print(t, skip, subi); | ||
| 384 | if (err != TEST_OK && t->subtest.skip_if_fail) | ||
| 385 | skip = true; | ||
| 386 | } | ||
| 282 | } | 387 | } |
| 283 | } | 388 | } |
| 284 | 389 | ||
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index a767a6400c5c..313a48c6b2bc 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c | |||
| @@ -433,7 +433,6 @@ enum { | |||
| 433 | 433 | ||
| 434 | static int do_test_code_reading(bool try_kcore) | 434 | static int do_test_code_reading(bool try_kcore) |
| 435 | { | 435 | { |
| 436 | struct machines machines; | ||
| 437 | struct machine *machine; | 436 | struct machine *machine; |
| 438 | struct thread *thread; | 437 | struct thread *thread; |
| 439 | struct record_opts opts = { | 438 | struct record_opts opts = { |
| @@ -459,8 +458,7 @@ static int do_test_code_reading(bool try_kcore) | |||
| 459 | 458 | ||
| 460 | pid = getpid(); | 459 | pid = getpid(); |
| 461 | 460 | ||
| 462 | machines__init(&machines); | 461 | machine = machine__new_host(); |
| 463 | machine = &machines.host; | ||
| 464 | 462 | ||
| 465 | ret = machine__create_kernel_maps(machine); | 463 | ret = machine__create_kernel_maps(machine); |
| 466 | if (ret < 0) { | 464 | if (ret < 0) { |
| @@ -549,6 +547,13 @@ static int do_test_code_reading(bool try_kcore) | |||
| 549 | if (ret < 0) { | 547 | if (ret < 0) { |
| 550 | if (!excl_kernel) { | 548 | if (!excl_kernel) { |
| 551 | excl_kernel = true; | 549 | excl_kernel = true; |
| 550 | /* | ||
| 551 | * Both cpus and threads are now owned by evlist | ||
| 552 | * and will be freed by following perf_evlist__set_maps | ||
| 553 | * call. Getting refference to keep them alive. | ||
| 554 | */ | ||
| 555 | cpu_map__get(cpus); | ||
| 556 | thread_map__get(threads); | ||
| 552 | perf_evlist__set_maps(evlist, NULL, NULL); | 557 | perf_evlist__set_maps(evlist, NULL, NULL); |
| 553 | perf_evlist__delete(evlist); | 558 | perf_evlist__delete(evlist); |
| 554 | evlist = NULL; | 559 | evlist = NULL; |
| @@ -594,14 +599,13 @@ out_err: | |||
| 594 | cpu_map__put(cpus); | 599 | cpu_map__put(cpus); |
| 595 | thread_map__put(threads); | 600 | thread_map__put(threads); |
| 596 | } | 601 | } |
| 597 | machines__destroy_kernel_maps(&machines); | ||
| 598 | machine__delete_threads(machine); | 602 | machine__delete_threads(machine); |
| 599 | machines__exit(&machines); | 603 | machine__delete(machine); |
| 600 | 604 | ||
| 601 | return err; | 605 | return err; |
| 602 | } | 606 | } |
| 603 | 607 | ||
| 604 | int test__code_reading(void) | 608 | int test__code_reading(int subtest __maybe_unused) |
| 605 | { | 609 | { |
| 606 | int ret; | 610 | int ret; |
| 607 | 611 | ||
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c new file mode 100644 index 000000000000..4cb6418a8ffc --- /dev/null +++ b/tools/perf/tests/cpumap.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | #include "tests.h" | ||
| 2 | #include "cpumap.h" | ||
| 3 | |||
| 4 | static int process_event_mask(struct perf_tool *tool __maybe_unused, | ||
| 5 | union perf_event *event, | ||
| 6 | struct perf_sample *sample __maybe_unused, | ||
| 7 | struct machine *machine __maybe_unused) | ||
| 8 | { | ||
| 9 | struct cpu_map_event *map_event = &event->cpu_map; | ||
| 10 | struct cpu_map_mask *mask; | ||
| 11 | struct cpu_map_data *data; | ||
| 12 | struct cpu_map *map; | ||
| 13 | int i; | ||
| 14 | |||
| 15 | data = &map_event->data; | ||
| 16 | |||
| 17 | TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__MASK); | ||
| 18 | |||
| 19 | mask = (struct cpu_map_mask *)data->data; | ||
| 20 | |||
| 21 | TEST_ASSERT_VAL("wrong nr", mask->nr == 1); | ||
| 22 | |||
| 23 | for (i = 0; i < 20; i++) { | ||
| 24 | TEST_ASSERT_VAL("wrong cpu", test_bit(i, mask->mask)); | ||
| 25 | } | ||
| 26 | |||
| 27 | map = cpu_map__new_data(data); | ||
| 28 | TEST_ASSERT_VAL("wrong nr", map->nr == 20); | ||
| 29 | |||
| 30 | for (i = 0; i < 20; i++) { | ||
| 31 | TEST_ASSERT_VAL("wrong cpu", map->map[i] == i); | ||
| 32 | } | ||
| 33 | |||
| 34 | cpu_map__put(map); | ||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | static int process_event_cpus(struct perf_tool *tool __maybe_unused, | ||
| 39 | union perf_event *event, | ||
| 40 | struct perf_sample *sample __maybe_unused, | ||
| 41 | struct machine *machine __maybe_unused) | ||
| 42 | { | ||
| 43 | struct cpu_map_event *map_event = &event->cpu_map; | ||
| 44 | struct cpu_map_entries *cpus; | ||
| 45 | struct cpu_map_data *data; | ||
| 46 | struct cpu_map *map; | ||
| 47 | |||
| 48 | data = &map_event->data; | ||
| 49 | |||
| 50 | TEST_ASSERT_VAL("wrong type", data->type == PERF_CPU_MAP__CPUS); | ||
| 51 | |||
| 52 | cpus = (struct cpu_map_entries *)data->data; | ||
| 53 | |||
| 54 | TEST_ASSERT_VAL("wrong nr", cpus->nr == 2); | ||
| 55 | TEST_ASSERT_VAL("wrong cpu", cpus->cpu[0] == 1); | ||
| 56 | TEST_ASSERT_VAL("wrong cpu", cpus->cpu[1] == 256); | ||
| 57 | |||
| 58 | map = cpu_map__new_data(data); | ||
| 59 | TEST_ASSERT_VAL("wrong nr", map->nr == 2); | ||
| 60 | TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1); | ||
| 61 | TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256); | ||
| 62 | TEST_ASSERT_VAL("wrong refcnt", atomic_read(&map->refcnt) == 1); | ||
| 63 | cpu_map__put(map); | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | int test__cpu_map_synthesize(int subtest __maybe_unused) | ||
| 69 | { | ||
| 70 | struct cpu_map *cpus; | ||
| 71 | |||
| 72 | /* This one is better stores in mask. */ | ||
| 73 | cpus = cpu_map__new("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19"); | ||
| 74 | |||
| 75 | TEST_ASSERT_VAL("failed to synthesize map", | ||
| 76 | !perf_event__synthesize_cpu_map(NULL, cpus, process_event_mask, NULL)); | ||
| 77 | |||
| 78 | cpu_map__put(cpus); | ||
| 79 | |||
| 80 | /* This one is better stores in cpu values. */ | ||
| 81 | cpus = cpu_map__new("1,256"); | ||
| 82 | |||
| 83 | TEST_ASSERT_VAL("failed to synthesize map", | ||
| 84 | !perf_event__synthesize_cpu_map(NULL, cpus, process_event_cpus, NULL)); | ||
| 85 | |||
| 86 | cpu_map__put(cpus); | ||
| 87 | return 0; | ||
| 88 | } | ||
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c index a218aeaf56a0..dc673ff7c437 100644 --- a/tools/perf/tests/dso-data.c +++ b/tools/perf/tests/dso-data.c | |||
| @@ -110,7 +110,7 @@ static int dso__data_fd(struct dso *dso, struct machine *machine) | |||
| 110 | return fd; | 110 | return fd; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | int test__dso_data(void) | 113 | int test__dso_data(int subtest __maybe_unused) |
| 114 | { | 114 | { |
| 115 | struct machine machine; | 115 | struct machine machine; |
| 116 | struct dso *dso; | 116 | struct dso *dso; |
| @@ -245,7 +245,7 @@ static int set_fd_limit(int n) | |||
| 245 | return setrlimit(RLIMIT_NOFILE, &rlim); | 245 | return setrlimit(RLIMIT_NOFILE, &rlim); |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | int test__dso_data_cache(void) | 248 | int test__dso_data_cache(int subtest __maybe_unused) |
| 249 | { | 249 | { |
| 250 | struct machine machine; | 250 | struct machine machine; |
| 251 | long nr_end, nr = open_files_cnt(); | 251 | long nr_end, nr = open_files_cnt(); |
| @@ -302,7 +302,7 @@ int test__dso_data_cache(void) | |||
| 302 | return 0; | 302 | return 0; |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | int test__dso_data_reopen(void) | 305 | int test__dso_data_reopen(int subtest __maybe_unused) |
| 306 | { | 306 | { |
| 307 | struct machine machine; | 307 | struct machine machine; |
| 308 | long nr_end, nr = open_files_cnt(); | 308 | long nr_end, nr = open_files_cnt(); |
diff --git a/tools/perf/tests/dwarf-unwind.c b/tools/perf/tests/dwarf-unwind.c index 07221793a3ac..1c5c0221cea2 100644 --- a/tools/perf/tests/dwarf-unwind.c +++ b/tools/perf/tests/dwarf-unwind.c | |||
| @@ -51,6 +51,12 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) | |||
| 51 | "krava_1", | 51 | "krava_1", |
| 52 | "test__dwarf_unwind" | 52 | "test__dwarf_unwind" |
| 53 | }; | 53 | }; |
| 54 | /* | ||
| 55 | * The funcs[MAX_STACK] array index, based on the | ||
| 56 | * callchain order setup. | ||
| 57 | */ | ||
| 58 | int idx = callchain_param.order == ORDER_CALLER ? | ||
| 59 | MAX_STACK - *cnt - 1 : *cnt; | ||
| 54 | 60 | ||
| 55 | if (*cnt >= MAX_STACK) { | 61 | if (*cnt >= MAX_STACK) { |
| 56 | pr_debug("failed: crossed the max stack value %d\n", MAX_STACK); | 62 | pr_debug("failed: crossed the max stack value %d\n", MAX_STACK); |
| @@ -63,8 +69,10 @@ static int unwind_entry(struct unwind_entry *entry, void *arg) | |||
| 63 | return -1; | 69 | return -1; |
| 64 | } | 70 | } |
| 65 | 71 | ||
| 66 | pr_debug("got: %s 0x%" PRIx64 "\n", symbol, entry->ip); | 72 | (*cnt)++; |
| 67 | return strcmp((const char *) symbol, funcs[(*cnt)++]); | 73 | pr_debug("got: %s 0x%" PRIx64 ", expecting %s\n", |
| 74 | symbol, entry->ip, funcs[idx]); | ||
| 75 | return strcmp((const char *) symbol, funcs[idx]); | ||
| 68 | } | 76 | } |
| 69 | 77 | ||
| 70 | __attribute__ ((noinline)) | 78 | __attribute__ ((noinline)) |
| @@ -105,8 +113,16 @@ static int compare(void *p1, void *p2) | |||
| 105 | /* Any possible value should be 'thread' */ | 113 | /* Any possible value should be 'thread' */ |
| 106 | struct thread *thread = *(struct thread **)p1; | 114 | struct thread *thread = *(struct thread **)p1; |
| 107 | 115 | ||
| 108 | if (global_unwind_retval == -INT_MAX) | 116 | if (global_unwind_retval == -INT_MAX) { |
| 117 | /* Call unwinder twice for both callchain orders. */ | ||
| 118 | callchain_param.order = ORDER_CALLER; | ||
| 119 | |||
| 109 | global_unwind_retval = unwind_thread(thread); | 120 | global_unwind_retval = unwind_thread(thread); |
| 121 | if (!global_unwind_retval) { | ||
| 122 | callchain_param.order = ORDER_CALLEE; | ||
| 123 | global_unwind_retval = unwind_thread(thread); | ||
| 124 | } | ||
| 125 | } | ||
| 110 | 126 | ||
| 111 | return p1 - p2; | 127 | return p1 - p2; |
| 112 | } | 128 | } |
| @@ -142,21 +158,23 @@ static int krava_1(struct thread *thread) | |||
| 142 | return krava_2(thread); | 158 | return krava_2(thread); |
| 143 | } | 159 | } |
| 144 | 160 | ||
| 145 | int test__dwarf_unwind(void) | 161 | int test__dwarf_unwind(int subtest __maybe_unused) |
| 146 | { | 162 | { |
| 147 | struct machines machines; | ||
| 148 | struct machine *machine; | 163 | struct machine *machine; |
| 149 | struct thread *thread; | 164 | struct thread *thread; |
| 150 | int err = -1; | 165 | int err = -1; |
| 151 | 166 | ||
| 152 | machines__init(&machines); | 167 | machine = machine__new_host(); |
| 153 | |||
| 154 | machine = machines__find(&machines, HOST_KERNEL_ID); | ||
| 155 | if (!machine) { | 168 | if (!machine) { |
| 156 | pr_err("Could not get machine\n"); | 169 | pr_err("Could not get machine\n"); |
| 157 | return -1; | 170 | return -1; |
| 158 | } | 171 | } |
| 159 | 172 | ||
| 173 | if (machine__create_kernel_maps(machine)) { | ||
| 174 | pr_err("Failed to create kernel maps\n"); | ||
| 175 | return -1; | ||
| 176 | } | ||
| 177 | |||
| 160 | callchain_param.record_mode = CALLCHAIN_DWARF; | 178 | callchain_param.record_mode = CALLCHAIN_DWARF; |
| 161 | 179 | ||
| 162 | if (init_live_machine(machine)) { | 180 | if (init_live_machine(machine)) { |
| @@ -178,7 +196,6 @@ int test__dwarf_unwind(void) | |||
| 178 | 196 | ||
| 179 | out: | 197 | out: |
| 180 | machine__delete_threads(machine); | 198 | machine__delete_threads(machine); |
| 181 | machine__exit(machine); | 199 | machine__delete(machine); |
| 182 | machines__exit(&machines); | ||
| 183 | return err; | 200 | return err; |
| 184 | } | 201 | } |
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c new file mode 100644 index 000000000000..012eab5d1df1 --- /dev/null +++ b/tools/perf/tests/event_update.c | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | #include <linux/compiler.h> | ||
| 2 | #include "evlist.h" | ||
| 3 | #include "evsel.h" | ||
| 4 | #include "machine.h" | ||
| 5 | #include "tests.h" | ||
| 6 | #include "debug.h" | ||
| 7 | |||
| 8 | static int process_event_unit(struct perf_tool *tool __maybe_unused, | ||
| 9 | union perf_event *event, | ||
| 10 | struct perf_sample *sample __maybe_unused, | ||
| 11 | struct machine *machine __maybe_unused) | ||
| 12 | { | ||
| 13 | struct event_update_event *ev = (struct event_update_event *) event; | ||
| 14 | |||
| 15 | TEST_ASSERT_VAL("wrong id", ev->id == 123); | ||
| 16 | TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT); | ||
| 17 | TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA")); | ||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | static int process_event_scale(struct perf_tool *tool __maybe_unused, | ||
| 22 | union perf_event *event, | ||
| 23 | struct perf_sample *sample __maybe_unused, | ||
| 24 | struct machine *machine __maybe_unused) | ||
| 25 | { | ||
| 26 | struct event_update_event *ev = (struct event_update_event *) event; | ||
| 27 | struct event_update_event_scale *ev_data; | ||
| 28 | |||
| 29 | ev_data = (struct event_update_event_scale *) ev->data; | ||
| 30 | |||
| 31 | TEST_ASSERT_VAL("wrong id", ev->id == 123); | ||
| 32 | TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE); | ||
| 33 | TEST_ASSERT_VAL("wrong scale", ev_data->scale = 0.123); | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | struct event_name { | ||
| 38 | struct perf_tool tool; | ||
| 39 | const char *name; | ||
| 40 | }; | ||
| 41 | |||
| 42 | static int process_event_name(struct perf_tool *tool, | ||
| 43 | union perf_event *event, | ||
| 44 | struct perf_sample *sample __maybe_unused, | ||
| 45 | struct machine *machine __maybe_unused) | ||
| 46 | { | ||
| 47 | struct event_name *tmp = container_of(tool, struct event_name, tool); | ||
| 48 | struct event_update_event *ev = (struct event_update_event*) event; | ||
| 49 | |||
| 50 | TEST_ASSERT_VAL("wrong id", ev->id == 123); | ||
| 51 | TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME); | ||
| 52 | TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name)); | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | static int process_event_cpus(struct perf_tool *tool __maybe_unused, | ||
| 57 | union perf_event *event, | ||
| 58 | struct perf_sample *sample __maybe_unused, | ||
| 59 | struct machine *machine __maybe_unused) | ||
| 60 | { | ||
| 61 | struct event_update_event *ev = (struct event_update_event*) event; | ||
| 62 | struct event_update_event_cpus *ev_data; | ||
| 63 | struct cpu_map *map; | ||
| 64 | |||
| 65 | ev_data = (struct event_update_event_cpus*) ev->data; | ||
| 66 | |||
| 67 | map = cpu_map__new_data(&ev_data->cpus); | ||
| 68 | |||
| 69 | TEST_ASSERT_VAL("wrong id", ev->id == 123); | ||
| 70 | TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); | ||
| 71 | TEST_ASSERT_VAL("wrong cpus", map->nr == 3); | ||
| 72 | TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); | ||
| 73 | TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); | ||
| 74 | TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); | ||
| 75 | cpu_map__put(map); | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | int test__event_update(int subtest __maybe_unused) | ||
| 80 | { | ||
| 81 | struct perf_evlist *evlist; | ||
| 82 | struct perf_evsel *evsel; | ||
| 83 | struct event_name tmp; | ||
| 84 | |||
| 85 | evlist = perf_evlist__new_default(); | ||
| 86 | TEST_ASSERT_VAL("failed to get evlist", evlist); | ||
| 87 | |||
| 88 | evsel = perf_evlist__first(evlist); | ||
| 89 | |||
| 90 | TEST_ASSERT_VAL("failed to allos ids", | ||
| 91 | !perf_evsel__alloc_id(evsel, 1, 1)); | ||
| 92 | |||
| 93 | perf_evlist__id_add(evlist, evsel, 0, 0, 123); | ||
| 94 | |||
| 95 | evsel->unit = strdup("KRAVA"); | ||
| 96 | |||
| 97 | TEST_ASSERT_VAL("failed to synthesize attr update unit", | ||
| 98 | !perf_event__synthesize_event_update_unit(NULL, evsel, process_event_unit)); | ||
| 99 | |||
| 100 | evsel->scale = 0.123; | ||
| 101 | |||
| 102 | TEST_ASSERT_VAL("failed to synthesize attr update scale", | ||
| 103 | !perf_event__synthesize_event_update_scale(NULL, evsel, process_event_scale)); | ||
| 104 | |||
| 105 | tmp.name = perf_evsel__name(evsel); | ||
| 106 | |||
| 107 | TEST_ASSERT_VAL("failed to synthesize attr update name", | ||
| 108 | !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); | ||
| 109 | |||
| 110 | evsel->own_cpus = cpu_map__new("1,2,3"); | ||
| 111 | |||
| 112 | TEST_ASSERT_VAL("failed to synthesize attr update cpus", | ||
| 113 | !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); | ||
| 114 | |||
| 115 | cpu_map__put(evsel->own_cpus); | ||
| 116 | return 0; | ||
| 117 | } | ||
diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c index 3fa715987a5e..2de4a4f2c3ed 100644 --- a/tools/perf/tests/evsel-roundtrip-name.c +++ b/tools/perf/tests/evsel-roundtrip-name.c | |||
| @@ -95,7 +95,7 @@ out_delete_evlist: | |||
| 95 | #define perf_evsel__name_array_test(names) \ | 95 | #define perf_evsel__name_array_test(names) \ |
| 96 | __perf_evsel__name_array_test(names, ARRAY_SIZE(names)) | 96 | __perf_evsel__name_array_test(names, ARRAY_SIZE(names)) |
| 97 | 97 | ||
| 98 | int test__perf_evsel__roundtrip_name_test(void) | 98 | int test__perf_evsel__roundtrip_name_test(int subtest __maybe_unused) |
| 99 | { | 99 | { |
| 100 | int err = 0, ret = 0; | 100 | int err = 0, ret = 0; |
| 101 | 101 | ||
| @@ -103,7 +103,8 @@ int test__perf_evsel__roundtrip_name_test(void) | |||
| 103 | if (err) | 103 | if (err) |
| 104 | ret = err; | 104 | ret = err; |
| 105 | 105 | ||
| 106 | err = perf_evsel__name_array_test(perf_evsel__sw_names); | 106 | err = __perf_evsel__name_array_test(perf_evsel__sw_names, |
| 107 | PERF_COUNT_SW_DUMMY + 1); | ||
| 107 | if (err) | 108 | if (err) |
| 108 | ret = err; | 109 | ret = err; |
| 109 | 110 | ||
diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c index 790e413d9a1f..1984b3bbfe15 100644 --- a/tools/perf/tests/evsel-tp-sched.c +++ b/tools/perf/tests/evsel-tp-sched.c | |||
| @@ -32,7 +32,7 @@ static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, | |||
| 32 | return ret; | 32 | return ret; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | int test__perf_evsel__tp_sched_test(void) | 35 | int test__perf_evsel__tp_sched_test(int subtest __maybe_unused) |
| 36 | { | 36 | { |
| 37 | struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch"); | 37 | struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch"); |
| 38 | int ret = 0; | 38 | int ret = 0; |
diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c index d24b837951d4..c809463edbe5 100644 --- a/tools/perf/tests/fdarray.c +++ b/tools/perf/tests/fdarray.c | |||
| @@ -25,7 +25,7 @@ static int fdarray__fprintf_prefix(struct fdarray *fda, const char *prefix, FILE | |||
| 25 | return printed + fdarray__fprintf(fda, fp); | 25 | return printed + fdarray__fprintf(fda, fp); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | int test__fdarray__filter(void) | 28 | int test__fdarray__filter(int subtest __maybe_unused) |
| 29 | { | 29 | { |
| 30 | int nr_fds, expected_fd[2], fd, err = TEST_FAIL; | 30 | int nr_fds, expected_fd[2], fd, err = TEST_FAIL; |
| 31 | struct fdarray *fda = fdarray__new(5, 5); | 31 | struct fdarray *fda = fdarray__new(5, 5); |
| @@ -103,7 +103,7 @@ out: | |||
| 103 | return err; | 103 | return err; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | int test__fdarray__add(void) | 106 | int test__fdarray__add(int subtest __maybe_unused) |
| 107 | { | 107 | { |
| 108 | int err = TEST_FAIL; | 108 | int err = TEST_FAIL; |
| 109 | struct fdarray *fda = fdarray__new(2, 2); | 109 | struct fdarray *fda = fdarray__new(2, 2); |
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c index ce80b274b097..071a8b5f5232 100644 --- a/tools/perf/tests/hists_common.c +++ b/tools/perf/tests/hists_common.c | |||
| @@ -150,7 +150,6 @@ struct machine *setup_fake_machine(struct machines *machines) | |||
| 150 | out: | 150 | out: |
| 151 | pr_debug("Not enough memory for machine setup\n"); | 151 | pr_debug("Not enough memory for machine setup\n"); |
| 152 | machine__delete_threads(machine); | 152 | machine__delete_threads(machine); |
| 153 | machine__delete(machine); | ||
| 154 | return NULL; | 153 | return NULL; |
| 155 | } | 154 | } |
| 156 | 155 | ||
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c index 7ed737019de7..5e6a86e50fb9 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c | |||
| @@ -281,7 +281,7 @@ static int test1(struct perf_evsel *evsel, struct machine *machine) | |||
| 281 | symbol_conf.cumulate_callchain = false; | 281 | symbol_conf.cumulate_callchain = false; |
| 282 | perf_evsel__reset_sample_bit(evsel, CALLCHAIN); | 282 | perf_evsel__reset_sample_bit(evsel, CALLCHAIN); |
| 283 | 283 | ||
| 284 | setup_sorting(); | 284 | setup_sorting(NULL); |
| 285 | callchain_register_param(&callchain_param); | 285 | callchain_register_param(&callchain_param); |
| 286 | 286 | ||
| 287 | err = add_hist_entries(hists, machine); | 287 | err = add_hist_entries(hists, machine); |
| @@ -428,7 +428,7 @@ static int test2(struct perf_evsel *evsel, struct machine *machine) | |||
| 428 | symbol_conf.cumulate_callchain = false; | 428 | symbol_conf.cumulate_callchain = false; |
| 429 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); | 429 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); |
| 430 | 430 | ||
| 431 | setup_sorting(); | 431 | setup_sorting(NULL); |
| 432 | callchain_register_param(&callchain_param); | 432 | callchain_register_param(&callchain_param); |
| 433 | 433 | ||
| 434 | err = add_hist_entries(hists, machine); | 434 | err = add_hist_entries(hists, machine); |
| @@ -486,7 +486,7 @@ static int test3(struct perf_evsel *evsel, struct machine *machine) | |||
| 486 | symbol_conf.cumulate_callchain = true; | 486 | symbol_conf.cumulate_callchain = true; |
| 487 | perf_evsel__reset_sample_bit(evsel, CALLCHAIN); | 487 | perf_evsel__reset_sample_bit(evsel, CALLCHAIN); |
| 488 | 488 | ||
| 489 | setup_sorting(); | 489 | setup_sorting(NULL); |
| 490 | callchain_register_param(&callchain_param); | 490 | callchain_register_param(&callchain_param); |
| 491 | 491 | ||
| 492 | err = add_hist_entries(hists, machine); | 492 | err = add_hist_entries(hists, machine); |
| @@ -670,7 +670,7 @@ static int test4(struct perf_evsel *evsel, struct machine *machine) | |||
| 670 | symbol_conf.cumulate_callchain = true; | 670 | symbol_conf.cumulate_callchain = true; |
| 671 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); | 671 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); |
| 672 | 672 | ||
| 673 | setup_sorting(); | 673 | setup_sorting(NULL); |
| 674 | callchain_register_param(&callchain_param); | 674 | callchain_register_param(&callchain_param); |
| 675 | 675 | ||
| 676 | err = add_hist_entries(hists, machine); | 676 | err = add_hist_entries(hists, machine); |
| @@ -686,7 +686,7 @@ out: | |||
| 686 | return err; | 686 | return err; |
| 687 | } | 687 | } |
| 688 | 688 | ||
| 689 | int test__hists_cumulate(void) | 689 | int test__hists_cumulate(int subtest __maybe_unused) |
| 690 | { | 690 | { |
| 691 | int err = TEST_FAIL; | 691 | int err = TEST_FAIL; |
| 692 | struct machines machines; | 692 | struct machines machines; |
| @@ -706,6 +706,7 @@ int test__hists_cumulate(void) | |||
| 706 | err = parse_events(evlist, "cpu-clock", NULL); | 706 | err = parse_events(evlist, "cpu-clock", NULL); |
| 707 | if (err) | 707 | if (err) |
| 708 | goto out; | 708 | goto out; |
| 709 | err = TEST_FAIL; | ||
| 709 | 710 | ||
| 710 | machines__init(&machines); | 711 | machines__init(&machines); |
| 711 | 712 | ||
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c index 818acf875dd0..351a42463444 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c | |||
| @@ -104,7 +104,7 @@ out: | |||
| 104 | return TEST_FAIL; | 104 | return TEST_FAIL; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | int test__hists_filter(void) | 107 | int test__hists_filter(int subtest __maybe_unused) |
| 108 | { | 108 | { |
| 109 | int err = TEST_FAIL; | 109 | int err = TEST_FAIL; |
| 110 | struct machines machines; | 110 | struct machines machines; |
| @@ -120,9 +120,10 @@ int test__hists_filter(void) | |||
| 120 | err = parse_events(evlist, "task-clock", NULL); | 120 | err = parse_events(evlist, "task-clock", NULL); |
| 121 | if (err) | 121 | if (err) |
| 122 | goto out; | 122 | goto out; |
| 123 | err = TEST_FAIL; | ||
| 123 | 124 | ||
| 124 | /* default sort order (comm,dso,sym) will be used */ | 125 | /* default sort order (comm,dso,sym) will be used */ |
| 125 | if (setup_sorting() < 0) | 126 | if (setup_sorting(NULL) < 0) |
| 126 | goto out; | 127 | goto out; |
| 127 | 128 | ||
| 128 | machines__init(&machines); | 129 | machines__init(&machines); |
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 8c102b011424..64b257d8d557 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c | |||
| @@ -64,7 +64,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
| 64 | struct perf_evsel *evsel; | 64 | struct perf_evsel *evsel; |
| 65 | struct addr_location al; | 65 | struct addr_location al; |
| 66 | struct hist_entry *he; | 66 | struct hist_entry *he; |
| 67 | struct perf_sample sample = { .period = 1, }; | 67 | struct perf_sample sample = { .period = 1, .weight = 1, }; |
| 68 | size_t i = 0, k; | 68 | size_t i = 0, k; |
| 69 | 69 | ||
| 70 | /* | 70 | /* |
| @@ -90,7 +90,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
| 90 | goto out; | 90 | goto out; |
| 91 | 91 | ||
| 92 | he = __hists__add_entry(hists, &al, NULL, | 92 | he = __hists__add_entry(hists, &al, NULL, |
| 93 | NULL, NULL, 1, 1, 0, true); | 93 | NULL, NULL, &sample, true); |
| 94 | if (he == NULL) { | 94 | if (he == NULL) { |
| 95 | addr_location__put(&al); | 95 | addr_location__put(&al); |
| 96 | goto out; | 96 | goto out; |
| @@ -116,7 +116,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) | |||
| 116 | goto out; | 116 | goto out; |
| 117 | 117 | ||
| 118 | he = __hists__add_entry(hists, &al, NULL, | 118 | he = __hists__add_entry(hists, &al, NULL, |
| 119 | NULL, NULL, 1, 1, 0, true); | 119 | NULL, NULL, &sample, true); |
| 120 | if (he == NULL) { | 120 | if (he == NULL) { |
| 121 | addr_location__put(&al); | 121 | addr_location__put(&al); |
| 122 | goto out; | 122 | goto out; |
| @@ -274,7 +274,7 @@ static int validate_link(struct hists *leader, struct hists *other) | |||
| 274 | return __validate_link(leader, 0) || __validate_link(other, 1); | 274 | return __validate_link(leader, 0) || __validate_link(other, 1); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | int test__hists_link(void) | 277 | int test__hists_link(int subtest __maybe_unused) |
| 278 | { | 278 | { |
| 279 | int err = -1; | 279 | int err = -1; |
| 280 | struct hists *hists, *first_hists; | 280 | struct hists *hists, *first_hists; |
| @@ -293,8 +293,9 @@ int test__hists_link(void) | |||
| 293 | if (err) | 293 | if (err) |
| 294 | goto out; | 294 | goto out; |
| 295 | 295 | ||
| 296 | err = TEST_FAIL; | ||
| 296 | /* default sort order (comm,dso,sym) will be used */ | 297 | /* default sort order (comm,dso,sym) will be used */ |
| 297 | if (setup_sorting() < 0) | 298 | if (setup_sorting(NULL) < 0) |
| 298 | goto out; | 299 | goto out; |
| 299 | 300 | ||
| 300 | machines__init(&machines); | 301 | machines__init(&machines); |
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c index adbebc852cc8..b231265148d8 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c | |||
| @@ -134,7 +134,7 @@ static int test1(struct perf_evsel *evsel, struct machine *machine) | |||
| 134 | field_order = NULL; | 134 | field_order = NULL; |
| 135 | sort_order = NULL; /* equivalent to sort_order = "comm,dso,sym" */ | 135 | sort_order = NULL; /* equivalent to sort_order = "comm,dso,sym" */ |
| 136 | 136 | ||
| 137 | setup_sorting(); | 137 | setup_sorting(NULL); |
| 138 | 138 | ||
| 139 | /* | 139 | /* |
| 140 | * expected output: | 140 | * expected output: |
| @@ -236,7 +236,7 @@ static int test2(struct perf_evsel *evsel, struct machine *machine) | |||
| 236 | field_order = "overhead,cpu"; | 236 | field_order = "overhead,cpu"; |
| 237 | sort_order = "pid"; | 237 | sort_order = "pid"; |
| 238 | 238 | ||
| 239 | setup_sorting(); | 239 | setup_sorting(NULL); |
| 240 | 240 | ||
| 241 | /* | 241 | /* |
| 242 | * expected output: | 242 | * expected output: |
| @@ -292,7 +292,7 @@ static int test3(struct perf_evsel *evsel, struct machine *machine) | |||
| 292 | field_order = "comm,overhead,dso"; | 292 | field_order = "comm,overhead,dso"; |
| 293 | sort_order = NULL; | 293 | sort_order = NULL; |
| 294 | 294 | ||
| 295 | setup_sorting(); | 295 | setup_sorting(NULL); |
| 296 | 296 | ||
| 297 | /* | 297 | /* |
| 298 | * expected output: | 298 | * expected output: |
| @@ -366,7 +366,7 @@ static int test4(struct perf_evsel *evsel, struct machine *machine) | |||
| 366 | field_order = "dso,sym,comm,overhead,dso"; | 366 | field_order = "dso,sym,comm,overhead,dso"; |
| 367 | sort_order = "sym"; | 367 | sort_order = "sym"; |
| 368 | 368 | ||
| 369 | setup_sorting(); | 369 | setup_sorting(NULL); |
| 370 | 370 | ||
| 371 | /* | 371 | /* |
| 372 | * expected output: | 372 | * expected output: |
| @@ -468,7 +468,7 @@ static int test5(struct perf_evsel *evsel, struct machine *machine) | |||
| 468 | field_order = "cpu,pid,comm,dso,sym"; | 468 | field_order = "cpu,pid,comm,dso,sym"; |
| 469 | sort_order = "dso,pid"; | 469 | sort_order = "dso,pid"; |
| 470 | 470 | ||
| 471 | setup_sorting(); | 471 | setup_sorting(NULL); |
| 472 | 472 | ||
| 473 | /* | 473 | /* |
| 474 | * expected output: | 474 | * expected output: |
| @@ -576,7 +576,7 @@ out: | |||
| 576 | return err; | 576 | return err; |
| 577 | } | 577 | } |
| 578 | 578 | ||
| 579 | int test__hists_output(void) | 579 | int test__hists_output(int subtest __maybe_unused) |
| 580 | { | 580 | { |
| 581 | int err = TEST_FAIL; | 581 | int err = TEST_FAIL; |
| 582 | struct machines machines; | 582 | struct machines machines; |
| @@ -597,6 +597,7 @@ int test__hists_output(void) | |||
| 597 | err = parse_events(evlist, "cpu-clock", NULL); | 597 | err = parse_events(evlist, "cpu-clock", NULL); |
| 598 | if (err) | 598 | if (err) |
| 599 | goto out; | 599 | goto out; |
| 600 | err = TEST_FAIL; | ||
| 600 | 601 | ||
| 601 | machines__init(&machines); | 602 | machines__init(&machines); |
| 602 | 603 | ||
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c index a2e2269aa093..ddb78fae064a 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c | |||
| @@ -49,13 +49,12 @@ static int find_comm(struct perf_evlist *evlist, const char *comm) | |||
| 49 | * when an event is disabled but a dummy software event is not disabled. If the | 49 | * when an event is disabled but a dummy software event is not disabled. If the |
| 50 | * test passes %0 is returned, otherwise %-1 is returned. | 50 | * test passes %0 is returned, otherwise %-1 is returned. |
| 51 | */ | 51 | */ |
| 52 | int test__keep_tracking(void) | 52 | int test__keep_tracking(int subtest __maybe_unused) |
| 53 | { | 53 | { |
| 54 | struct record_opts opts = { | 54 | struct record_opts opts = { |
| 55 | .mmap_pages = UINT_MAX, | 55 | .mmap_pages = UINT_MAX, |
| 56 | .user_freq = UINT_MAX, | 56 | .user_freq = UINT_MAX, |
| 57 | .user_interval = ULLONG_MAX, | 57 | .user_interval = ULLONG_MAX, |
| 58 | .freq = 4000, | ||
| 59 | .target = { | 58 | .target = { |
| 60 | .uses_mmap = true, | 59 | .uses_mmap = true, |
| 61 | }, | 60 | }, |
| @@ -124,7 +123,7 @@ int test__keep_tracking(void) | |||
| 124 | 123 | ||
| 125 | evsel = perf_evlist__last(evlist); | 124 | evsel = perf_evlist__last(evlist); |
| 126 | 125 | ||
| 127 | CHECK__(perf_evlist__disable_event(evlist, evsel)); | 126 | CHECK__(perf_evsel__disable(evsel)); |
| 128 | 127 | ||
| 129 | comm = "Test COMM 2"; | 128 | comm = "Test COMM 2"; |
| 130 | CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0)); | 129 | CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0)); |
diff --git a/tools/perf/tests/kmod-path.c b/tools/perf/tests/kmod-path.c index 08c433b4bf4f..d2af78193153 100644 --- a/tools/perf/tests/kmod-path.c +++ b/tools/perf/tests/kmod-path.c | |||
| @@ -49,7 +49,7 @@ static int test_is_kernel_module(const char *path, int cpumode, bool expect) | |||
| 49 | #define M(path, c, e) \ | 49 | #define M(path, c, e) \ |
| 50 | TEST_ASSERT_VAL("failed", !test_is_kernel_module(path, c, e)) | 50 | TEST_ASSERT_VAL("failed", !test_is_kernel_module(path, c, e)) |
| 51 | 51 | ||
| 52 | int test__kmod_path__parse(void) | 52 | int test__kmod_path__parse(int subtest __maybe_unused) |
| 53 | { | 53 | { |
| 54 | /* path alloc_name alloc_ext kmod comp name ext */ | 54 | /* path alloc_name alloc_ext kmod comp name ext */ |
| 55 | T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL); | 55 | T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL); |
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c index bc4cf507cde5..06f45c1d4256 100644 --- a/tools/perf/tests/llvm.c +++ b/tools/perf/tests/llvm.c | |||
| @@ -44,13 +44,17 @@ static struct { | |||
| 44 | .source = test_llvm__bpf_test_kbuild_prog, | 44 | .source = test_llvm__bpf_test_kbuild_prog, |
| 45 | .desc = "Test kbuild searching", | 45 | .desc = "Test kbuild searching", |
| 46 | }, | 46 | }, |
| 47 | [LLVM_TESTCASE_BPF_PROLOGUE] = { | ||
| 48 | .source = test_llvm__bpf_test_prologue_prog, | ||
| 49 | .desc = "Compile source for BPF prologue generation test", | ||
| 50 | }, | ||
| 47 | }; | 51 | }; |
| 48 | 52 | ||
| 49 | 53 | ||
| 50 | int | 54 | int |
| 51 | test_llvm__fetch_bpf_obj(void **p_obj_buf, | 55 | test_llvm__fetch_bpf_obj(void **p_obj_buf, |
| 52 | size_t *p_obj_buf_sz, | 56 | size_t *p_obj_buf_sz, |
| 53 | enum test_llvm__testcase index, | 57 | enum test_llvm__testcase idx, |
| 54 | bool force) | 58 | bool force) |
| 55 | { | 59 | { |
| 56 | const char *source; | 60 | const char *source; |
| @@ -59,11 +63,11 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf, | |||
| 59 | char *tmpl_new = NULL, *clang_opt_new = NULL; | 63 | char *tmpl_new = NULL, *clang_opt_new = NULL; |
| 60 | int err, old_verbose, ret = TEST_FAIL; | 64 | int err, old_verbose, ret = TEST_FAIL; |
| 61 | 65 | ||
| 62 | if (index >= __LLVM_TESTCASE_MAX) | 66 | if (idx >= __LLVM_TESTCASE_MAX) |
| 63 | return TEST_FAIL; | 67 | return TEST_FAIL; |
| 64 | 68 | ||
| 65 | source = bpf_source_table[index].source; | 69 | source = bpf_source_table[idx].source; |
| 66 | desc = bpf_source_table[index].desc; | 70 | desc = bpf_source_table[idx].desc; |
| 67 | 71 | ||
| 68 | perf_config(perf_config_cb, NULL); | 72 | perf_config(perf_config_cb, NULL); |
| 69 | 73 | ||
| @@ -127,44 +131,39 @@ out: | |||
| 127 | return ret; | 131 | return ret; |
| 128 | } | 132 | } |
| 129 | 133 | ||
| 130 | int test__llvm(void) | 134 | int test__llvm(int subtest) |
| 131 | { | 135 | { |
| 132 | enum test_llvm__testcase i; | 136 | int ret; |
| 137 | void *obj_buf = NULL; | ||
| 138 | size_t obj_buf_sz = 0; | ||
| 133 | 139 | ||
| 134 | for (i = 0; i < __LLVM_TESTCASE_MAX; i++) { | 140 | if ((subtest < 0) || (subtest >= __LLVM_TESTCASE_MAX)) |
| 135 | int ret; | 141 | return TEST_FAIL; |
| 136 | void *obj_buf = NULL; | ||
| 137 | size_t obj_buf_sz = 0; | ||
| 138 | 142 | ||
| 139 | ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, | 143 | ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, |
| 140 | i, false); | 144 | subtest, false); |
| 141 | 145 | ||
| 142 | if (ret == TEST_OK) { | 146 | if (ret == TEST_OK) { |
| 143 | ret = test__bpf_parsing(obj_buf, obj_buf_sz); | 147 | ret = test__bpf_parsing(obj_buf, obj_buf_sz); |
| 144 | if (ret != TEST_OK) | 148 | if (ret != TEST_OK) { |
| 145 | pr_debug("Failed to parse test case '%s'\n", | 149 | pr_debug("Failed to parse test case '%s'\n", |
| 146 | bpf_source_table[i].desc); | 150 | bpf_source_table[subtest].desc); |
| 147 | } | ||
| 148 | free(obj_buf); | ||
| 149 | |||
| 150 | switch (ret) { | ||
| 151 | case TEST_SKIP: | ||
| 152 | return TEST_SKIP; | ||
| 153 | case TEST_OK: | ||
| 154 | break; | ||
| 155 | default: | ||
| 156 | /* | ||
| 157 | * Test 0 is the basic LLVM test. If test 0 | ||
| 158 | * fail, the basic LLVM support not functional | ||
| 159 | * so the whole test should fail. If other test | ||
| 160 | * case fail, it can be fixed by adjusting | ||
| 161 | * config so don't report error. | ||
| 162 | */ | ||
| 163 | if (i == 0) | ||
| 164 | return TEST_FAIL; | ||
| 165 | else | ||
| 166 | return TEST_SKIP; | ||
| 167 | } | 151 | } |
| 168 | } | 152 | } |
| 169 | return TEST_OK; | 153 | free(obj_buf); |
| 154 | |||
| 155 | return ret; | ||
| 156 | } | ||
| 157 | |||
| 158 | int test__llvm_subtest_get_nr(void) | ||
| 159 | { | ||
| 160 | return __LLVM_TESTCASE_MAX; | ||
| 161 | } | ||
| 162 | |||
| 163 | const char *test__llvm_subtest_get_desc(int subtest) | ||
| 164 | { | ||
| 165 | if ((subtest < 0) || (subtest >= __LLVM_TESTCASE_MAX)) | ||
| 166 | return NULL; | ||
| 167 | |||
| 168 | return bpf_source_table[subtest].desc; | ||
| 170 | } | 169 | } |
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h index d91d8f44efee..5150b4d6ef50 100644 --- a/tools/perf/tests/llvm.h +++ b/tools/perf/tests/llvm.h | |||
| @@ -6,10 +6,12 @@ | |||
| 6 | 6 | ||
| 7 | extern const char test_llvm__bpf_base_prog[]; | 7 | extern const char test_llvm__bpf_base_prog[]; |
| 8 | extern const char test_llvm__bpf_test_kbuild_prog[]; | 8 | extern const char test_llvm__bpf_test_kbuild_prog[]; |
| 9 | extern const char test_llvm__bpf_test_prologue_prog[]; | ||
| 9 | 10 | ||
| 10 | enum test_llvm__testcase { | 11 | enum test_llvm__testcase { |
| 11 | LLVM_TESTCASE_BASE, | 12 | LLVM_TESTCASE_BASE, |
| 12 | LLVM_TESTCASE_KBUILD, | 13 | LLVM_TESTCASE_KBUILD, |
| 14 | LLVM_TESTCASE_BPF_PROLOGUE, | ||
| 13 | __LLVM_TESTCASE_MAX, | 15 | __LLVM_TESTCASE_MAX, |
| 14 | }; | 16 | }; |
| 15 | 17 | ||
diff --git a/tools/perf/tests/make b/tools/perf/tests/make index 8ea3dffc5065..df38decc48c3 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | include ../scripts/Makefile.include | ||
| 2 | |||
| 1 | ifndef MK | 3 | ifndef MK |
| 2 | ifeq ($(MAKECMDGOALS),) | 4 | ifeq ($(MAKECMDGOALS),) |
| 3 | # no target specified, trigger the whole suite | 5 | # no target specified, trigger the whole suite |
| @@ -12,7 +14,19 @@ endif | |||
| 12 | else | 14 | else |
| 13 | PERF := . | 15 | PERF := . |
| 14 | 16 | ||
| 15 | include config/Makefile.arch | 17 | # As per kernel Makefile, avoid funny character set dependencies |
| 18 | unexport LC_ALL | ||
| 19 | LC_COLLATE=C | ||
| 20 | LC_NUMERIC=C | ||
| 21 | export LC_COLLATE LC_NUMERIC | ||
| 22 | |||
| 23 | ifeq ($(srctree),) | ||
| 24 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) | ||
| 25 | srctree := $(patsubst %/,%,$(dir $(srctree))) | ||
| 26 | #$(info Determined 'srctree' to be $(srctree)) | ||
| 27 | endif | ||
| 28 | |||
| 29 | include $(srctree)/tools/scripts/Makefile.arch | ||
| 16 | 30 | ||
| 17 | # FIXME looks like x86 is the only arch running tests ;-) | 31 | # FIXME looks like x86 is the only arch running tests ;-) |
| 18 | # we need some IS_(32/64) flag to make this generic | 32 | # we need some IS_(32/64) flag to make this generic |
| @@ -259,7 +273,8 @@ $(run_O): | |||
| 259 | tarpkg: | 273 | tarpkg: |
| 260 | @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \ | 274 | @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \ |
| 261 | echo "- $@: $$cmd" && echo $$cmd > $@ && \ | 275 | echo "- $@: $$cmd" && echo $$cmd > $@ && \ |
| 262 | ( eval $$cmd ) >> $@ 2>&1 | 276 | ( eval $$cmd ) >> $@ 2>&1 && \ |
| 277 | rm -f $@ | ||
| 263 | 278 | ||
| 264 | make_kernelsrc: | 279 | make_kernelsrc: |
| 265 | @echo "- make -C <kernelsrc> tools/perf" | 280 | @echo "- make -C <kernelsrc> tools/perf" |
| @@ -279,5 +294,5 @@ all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools | |||
| 279 | out: $(run_O) | 294 | out: $(run_O) |
| 280 | @echo OK | 295 | @echo OK |
| 281 | 296 | ||
| 282 | .PHONY: all $(run) $(run_O) tarpkg clean | 297 | .PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools |
| 283 | endif # ifndef MK | 298 | endif # ifndef MK |
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 4495493c9431..359e98fcd94c 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | * Then it checks if the number of syscalls reported as perf events by | 16 | * Then it checks if the number of syscalls reported as perf events by |
| 17 | * the kernel corresponds to the number of syscalls made. | 17 | * the kernel corresponds to the number of syscalls made. |
| 18 | */ | 18 | */ |
| 19 | int test__basic_mmap(void) | 19 | int test__basic_mmap(int subtest __maybe_unused) |
| 20 | { | 20 | { |
| 21 | int err = -1; | 21 | int err = -1; |
| 22 | union perf_event *event; | 22 | union perf_event *event; |
diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c index 145050e2e544..0c5ce44f723f 100644 --- a/tools/perf/tests/mmap-thread-lookup.c +++ b/tools/perf/tests/mmap-thread-lookup.c | |||
| @@ -149,7 +149,6 @@ static int synth_process(struct machine *machine) | |||
| 149 | 149 | ||
| 150 | static int mmap_events(synth_cb synth) | 150 | static int mmap_events(synth_cb synth) |
| 151 | { | 151 | { |
| 152 | struct machines machines; | ||
| 153 | struct machine *machine; | 152 | struct machine *machine; |
| 154 | int err, i; | 153 | int err, i; |
| 155 | 154 | ||
| @@ -162,8 +161,7 @@ static int mmap_events(synth_cb synth) | |||
| 162 | */ | 161 | */ |
| 163 | TEST_ASSERT_VAL("failed to create threads", !threads_create()); | 162 | TEST_ASSERT_VAL("failed to create threads", !threads_create()); |
| 164 | 163 | ||
| 165 | machines__init(&machines); | 164 | machine = machine__new_host(); |
| 166 | machine = &machines.host; | ||
| 167 | 165 | ||
| 168 | dump_trace = verbose > 1 ? 1 : 0; | 166 | dump_trace = verbose > 1 ? 1 : 0; |
| 169 | 167 | ||
| @@ -203,7 +201,7 @@ static int mmap_events(synth_cb synth) | |||
| 203 | } | 201 | } |
| 204 | 202 | ||
| 205 | machine__delete_threads(machine); | 203 | machine__delete_threads(machine); |
| 206 | machines__exit(&machines); | 204 | machine__delete(machine); |
| 207 | return err; | 205 | return err; |
| 208 | } | 206 | } |
| 209 | 207 | ||
| @@ -221,7 +219,7 @@ static int mmap_events(synth_cb synth) | |||
| 221 | * | 219 | * |
| 222 | * by using all thread objects. | 220 | * by using all thread objects. |
| 223 | */ | 221 | */ |
| 224 | int test__mmap_thread_lookup(void) | 222 | int test__mmap_thread_lookup(int subtest __maybe_unused) |
| 225 | { | 223 | { |
| 226 | /* perf_event__synthesize_threads synthesize */ | 224 | /* perf_event__synthesize_threads synthesize */ |
| 227 | TEST_ASSERT_VAL("failed with sythesizing all", | 225 | TEST_ASSERT_VAL("failed with sythesizing all", |
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c index 2006485a2859..53c2273e8859 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "debug.h" | 7 | #include "debug.h" |
| 8 | #include "stat.h" | 8 | #include "stat.h" |
| 9 | 9 | ||
| 10 | int test__openat_syscall_event_on_all_cpus(void) | 10 | int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused) |
| 11 | { | 11 | { |
| 12 | int err = -1, fd, cpu; | 12 | int err = -1, fd, cpu; |
| 13 | struct cpu_map *cpus; | 13 | struct cpu_map *cpus; |
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c index 5e811cd8f1c3..eb99a105f31c 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | #include "tests.h" | 6 | #include "tests.h" |
| 7 | #include "debug.h" | 7 | #include "debug.h" |
| 8 | 8 | ||
| 9 | int test__syscall_openat_tp_fields(void) | 9 | int test__syscall_openat_tp_fields(int subtest __maybe_unused) |
| 10 | { | 10 | { |
| 11 | struct record_opts opts = { | 11 | struct record_opts opts = { |
| 12 | .target = { | 12 | .target = { |
diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c index 033b54797b8a..1184f9ba6499 100644 --- a/tools/perf/tests/openat-syscall.c +++ b/tools/perf/tests/openat-syscall.c | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include "debug.h" | 5 | #include "debug.h" |
| 6 | #include "tests.h" | 6 | #include "tests.h" |
| 7 | 7 | ||
| 8 | int test__openat_syscall_event(void) | 8 | int test__openat_syscall_event(int subtest __maybe_unused) |
| 9 | { | 9 | { |
| 10 | int err = -1, fd; | 10 | int err = -1, fd; |
| 11 | struct perf_evsel *evsel; | 11 | struct perf_evsel *evsel; |
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 636d7b42d844..abe8849d1d70 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c | |||
| @@ -1765,7 +1765,7 @@ static void debug_warn(const char *warn, va_list params) | |||
| 1765 | fprintf(stderr, " Warning: %s\n", msg); | 1765 | fprintf(stderr, " Warning: %s\n", msg); |
| 1766 | } | 1766 | } |
| 1767 | 1767 | ||
| 1768 | int test__parse_events(void) | 1768 | int test__parse_events(int subtest __maybe_unused) |
| 1769 | { | 1769 | { |
| 1770 | int ret1, ret2 = 0; | 1770 | int ret1, ret2 = 0; |
| 1771 | 1771 | ||
diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c index 2c63ea658541..294c76b01b41 100644 --- a/tools/perf/tests/parse-no-sample-id-all.c +++ b/tools/perf/tests/parse-no-sample-id-all.c | |||
| @@ -67,7 +67,7 @@ struct test_attr_event { | |||
| 67 | * | 67 | * |
| 68 | * Return: %0 on success, %-1 if the test fails. | 68 | * Return: %0 on success, %-1 if the test fails. |
| 69 | */ | 69 | */ |
| 70 | int test__parse_no_sample_id_all(void) | 70 | int test__parse_no_sample_id_all(int subtest __maybe_unused) |
| 71 | { | 71 | { |
| 72 | int err; | 72 | int err; |
| 73 | 73 | ||
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 7a228a2a070b..1cc78cefe399 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c | |||
| @@ -32,7 +32,7 @@ realloc: | |||
| 32 | return cpu; | 32 | return cpu; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | int test__PERF_RECORD(void) | 35 | int test__PERF_RECORD(int subtest __maybe_unused) |
| 36 | { | 36 | { |
| 37 | struct record_opts opts = { | 37 | struct record_opts opts = { |
| 38 | .target = { | 38 | .target = { |
| @@ -40,12 +40,11 @@ int test__PERF_RECORD(void) | |||
| 40 | .uses_mmap = true, | 40 | .uses_mmap = true, |
| 41 | }, | 41 | }, |
| 42 | .no_buffering = true, | 42 | .no_buffering = true, |
| 43 | .freq = 10, | ||
| 44 | .mmap_pages = 256, | 43 | .mmap_pages = 256, |
| 45 | }; | 44 | }; |
| 46 | cpu_set_t cpu_mask; | 45 | cpu_set_t cpu_mask; |
| 47 | size_t cpu_mask_size = sizeof(cpu_mask); | 46 | size_t cpu_mask_size = sizeof(cpu_mask); |
| 48 | struct perf_evlist *evlist = perf_evlist__new_default(); | 47 | struct perf_evlist *evlist = perf_evlist__new_dummy(); |
| 49 | struct perf_evsel *evsel; | 48 | struct perf_evsel *evsel; |
| 50 | struct perf_sample sample; | 49 | struct perf_sample sample; |
| 51 | const char *cmd = "sleep"; | 50 | const char *cmd = "sleep"; |
| @@ -61,6 +60,9 @@ int test__PERF_RECORD(void) | |||
| 61 | int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, }; | 60 | int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, }; |
| 62 | char sbuf[STRERR_BUFSIZE]; | 61 | char sbuf[STRERR_BUFSIZE]; |
| 63 | 62 | ||
| 63 | if (evlist == NULL) /* Fallback for kernels lacking PERF_COUNT_SW_DUMMY */ | ||
| 64 | evlist = perf_evlist__new_default(); | ||
| 65 | |||
| 64 | if (evlist == NULL || argv == NULL) { | 66 | if (evlist == NULL || argv == NULL) { |
| 65 | pr_debug("Not enough memory to create evlist\n"); | 67 | pr_debug("Not enough memory to create evlist\n"); |
| 66 | goto out; | 68 | goto out; |
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index faa04e9d5d5f..1e2ba2602930 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c | |||
| @@ -133,7 +133,7 @@ static struct list_head *test_terms_list(void) | |||
| 133 | return &terms; | 133 | return &terms; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | int test__pmu(void) | 136 | int test__pmu(int subtest __maybe_unused) |
| 137 | { | 137 | { |
| 138 | char *format = test_format_dir_get(); | 138 | char *format = test_format_dir_get(); |
| 139 | LIST_HEAD(formats); | 139 | LIST_HEAD(formats); |
diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c index 7760277c6def..7a52834ee0d0 100644 --- a/tools/perf/tests/python-use.c +++ b/tools/perf/tests/python-use.c | |||
| @@ -4,11 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 7 | #include <linux/compiler.h> | ||
| 7 | #include "tests.h" | 8 | #include "tests.h" |
| 8 | 9 | ||
| 9 | extern int verbose; | 10 | extern int verbose; |
| 10 | 11 | ||
| 11 | int test__python_use(void) | 12 | int test__python_use(int subtest __maybe_unused) |
| 12 | { | 13 | { |
| 13 | char *cmd; | 14 | char *cmd; |
| 14 | int ret; | 15 | int ret; |
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c index 30c02181e78b..5f23710b9fee 100644 --- a/tools/perf/tests/sample-parsing.c +++ b/tools/perf/tests/sample-parsing.c | |||
| @@ -290,7 +290,7 @@ out_free: | |||
| 290 | * checks sample format bits separately and together. If the test passes %0 is | 290 | * checks sample format bits separately and together. If the test passes %0 is |
| 291 | * returned, otherwise %-1 is returned. | 291 | * returned, otherwise %-1 is returned. |
| 292 | */ | 292 | */ |
| 293 | int test__sample_parsing(void) | 293 | int test__sample_parsing(int subtest __maybe_unused) |
| 294 | { | 294 | { |
| 295 | const u64 rf[] = {4, 5, 6, 7, 12, 13, 14, 15}; | 295 | const u64 rf[] = {4, 5, 6, 7, 12, 13, 14, 15}; |
| 296 | u64 sample_type; | 296 | u64 sample_type; |
diff --git a/tools/perf/tests/stat.c b/tools/perf/tests/stat.c new file mode 100644 index 000000000000..6a20ff2326bb --- /dev/null +++ b/tools/perf/tests/stat.c | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | #include <linux/compiler.h> | ||
| 2 | #include "event.h" | ||
| 3 | #include "tests.h" | ||
| 4 | #include "stat.h" | ||
| 5 | #include "counts.h" | ||
| 6 | #include "debug.h" | ||
| 7 | |||
| 8 | static bool has_term(struct stat_config_event *config, | ||
| 9 | u64 tag, u64 val) | ||
| 10 | { | ||
| 11 | unsigned i; | ||
| 12 | |||
| 13 | for (i = 0; i < config->nr; i++) { | ||
| 14 | if ((config->data[i].tag == tag) && | ||
| 15 | (config->data[i].val == val)) | ||
| 16 | return true; | ||
| 17 | } | ||
| 18 | |||
| 19 | return false; | ||
| 20 | } | ||
| 21 | |||
| 22 | static int process_stat_config_event(struct perf_tool *tool __maybe_unused, | ||
| 23 | union perf_event *event, | ||
| 24 | struct perf_sample *sample __maybe_unused, | ||
| 25 | struct machine *machine __maybe_unused) | ||
| 26 | { | ||
| 27 | struct stat_config_event *config = &event->stat_config; | ||
| 28 | struct perf_stat_config stat_config; | ||
| 29 | |||
| 30 | #define HAS(term, val) \ | ||
| 31 | has_term(config, PERF_STAT_CONFIG_TERM__##term, val) | ||
| 32 | |||
| 33 | TEST_ASSERT_VAL("wrong nr", config->nr == PERF_STAT_CONFIG_TERM__MAX); | ||
| 34 | TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE)); | ||
| 35 | TEST_ASSERT_VAL("wrong scale", HAS(SCALE, 1)); | ||
| 36 | TEST_ASSERT_VAL("wrong interval", HAS(INTERVAL, 1)); | ||
| 37 | |||
| 38 | #undef HAS | ||
| 39 | |||
| 40 | perf_event__read_stat_config(&stat_config, config); | ||
| 41 | |||
| 42 | TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE); | ||
| 43 | TEST_ASSERT_VAL("wrong scale", stat_config.scale == 1); | ||
| 44 | TEST_ASSERT_VAL("wrong interval", stat_config.interval == 1); | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | |||
| 48 | int test__synthesize_stat_config(int subtest __maybe_unused) | ||
| 49 | { | ||
| 50 | struct perf_stat_config stat_config = { | ||
| 51 | .aggr_mode = AGGR_CORE, | ||
| 52 | .scale = 1, | ||
| 53 | .interval = 1, | ||
| 54 | }; | ||
| 55 | |||
| 56 | TEST_ASSERT_VAL("failed to synthesize stat_config", | ||
| 57 | !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL)); | ||
| 58 | |||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | static int process_stat_event(struct perf_tool *tool __maybe_unused, | ||
| 63 | union perf_event *event, | ||
| 64 | struct perf_sample *sample __maybe_unused, | ||
| 65 | struct machine *machine __maybe_unused) | ||
| 66 | { | ||
| 67 | struct stat_event *st = &event->stat; | ||
| 68 | |||
| 69 | TEST_ASSERT_VAL("wrong cpu", st->cpu == 1); | ||
| 70 | TEST_ASSERT_VAL("wrong thread", st->thread == 2); | ||
| 71 | TEST_ASSERT_VAL("wrong id", st->id == 3); | ||
| 72 | TEST_ASSERT_VAL("wrong val", st->val == 100); | ||
| 73 | TEST_ASSERT_VAL("wrong run", st->ena == 200); | ||
| 74 | TEST_ASSERT_VAL("wrong ena", st->run == 300); | ||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | int test__synthesize_stat(int subtest __maybe_unused) | ||
| 79 | { | ||
| 80 | struct perf_counts_values count; | ||
| 81 | |||
| 82 | count.val = 100; | ||
| 83 | count.ena = 200; | ||
| 84 | count.run = 300; | ||
| 85 | |||
| 86 | TEST_ASSERT_VAL("failed to synthesize stat_config", | ||
| 87 | !perf_event__synthesize_stat(NULL, 1, 2, 3, &count, process_stat_event, NULL)); | ||
| 88 | |||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | static int process_stat_round_event(struct perf_tool *tool __maybe_unused, | ||
| 93 | union perf_event *event, | ||
| 94 | struct perf_sample *sample __maybe_unused, | ||
| 95 | struct machine *machine __maybe_unused) | ||
| 96 | { | ||
| 97 | struct stat_round_event *stat_round = &event->stat_round; | ||
| 98 | |||
| 99 | TEST_ASSERT_VAL("wrong time", stat_round->time == 0xdeadbeef); | ||
| 100 | TEST_ASSERT_VAL("wrong type", stat_round->type == PERF_STAT_ROUND_TYPE__INTERVAL); | ||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | int test__synthesize_stat_round(int subtest __maybe_unused) | ||
| 105 | { | ||
| 106 | TEST_ASSERT_VAL("failed to synthesize stat_config", | ||
| 107 | !perf_event__synthesize_stat_round(NULL, 0xdeadbeef, PERF_STAT_ROUND_TYPE__INTERVAL, | ||
| 108 | process_stat_round_event, NULL)); | ||
| 109 | |||
| 110 | return 0; | ||
| 111 | } | ||
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c index 5b83f56a3b6f..36e8ce1550e3 100644 --- a/tools/perf/tests/sw-clock.c +++ b/tools/perf/tests/sw-clock.c | |||
| @@ -122,7 +122,7 @@ out_delete_evlist: | |||
| 122 | return err; | 122 | return err; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | int test__sw_clock_freq(void) | 125 | int test__sw_clock_freq(int subtest __maybe_unused) |
| 126 | { | 126 | { |
| 127 | int ret; | 127 | int ret; |
| 128 | 128 | ||
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c index a02af503100c..ebd80168d51e 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c | |||
| @@ -305,7 +305,7 @@ out_free_nodes: | |||
| 305 | * evsel->system_wide and evsel->tracking flags (respectively) with other events | 305 | * evsel->system_wide and evsel->tracking flags (respectively) with other events |
| 306 | * sometimes enabled or disabled. | 306 | * sometimes enabled or disabled. |
| 307 | */ | 307 | */ |
| 308 | int test__switch_tracking(void) | 308 | int test__switch_tracking(int subtest __maybe_unused) |
| 309 | { | 309 | { |
| 310 | const char *sched_switch = "sched:sched_switch"; | 310 | const char *sched_switch = "sched:sched_switch"; |
| 311 | struct switch_tracking switch_tracking = { .tids = NULL, }; | 311 | struct switch_tracking switch_tracking = { .tids = NULL, }; |
| @@ -455,7 +455,7 @@ int test__switch_tracking(void) | |||
| 455 | 455 | ||
| 456 | perf_evlist__enable(evlist); | 456 | perf_evlist__enable(evlist); |
| 457 | 457 | ||
| 458 | err = perf_evlist__disable_event(evlist, cpu_clocks_evsel); | 458 | err = perf_evsel__disable(cpu_clocks_evsel); |
| 459 | if (err) { | 459 | if (err) { |
| 460 | pr_debug("perf_evlist__disable_event failed!\n"); | 460 | pr_debug("perf_evlist__disable_event failed!\n"); |
| 461 | goto out_err; | 461 | goto out_err; |
| @@ -474,7 +474,7 @@ int test__switch_tracking(void) | |||
| 474 | goto out_err; | 474 | goto out_err; |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | err = perf_evlist__disable_event(evlist, cycles_evsel); | 477 | err = perf_evsel__disable(cycles_evsel); |
| 478 | if (err) { | 478 | if (err) { |
| 479 | pr_debug("perf_evlist__disable_event failed!\n"); | 479 | pr_debug("perf_evlist__disable_event failed!\n"); |
| 480 | goto out_err; | 480 | goto out_err; |
| @@ -500,7 +500,7 @@ int test__switch_tracking(void) | |||
| 500 | goto out_err; | 500 | goto out_err; |
| 501 | } | 501 | } |
| 502 | 502 | ||
| 503 | err = perf_evlist__enable_event(evlist, cycles_evsel); | 503 | err = perf_evsel__enable(cycles_evsel); |
| 504 | if (err) { | 504 | if (err) { |
| 505 | pr_debug("perf_evlist__disable_event failed!\n"); | 505 | pr_debug("perf_evlist__disable_event failed!\n"); |
| 506 | goto out_err; | 506 | goto out_err; |
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c index add16385f13e..2dfff7ac8ef3 100644 --- a/tools/perf/tests/task-exit.c +++ b/tools/perf/tests/task-exit.c | |||
| @@ -31,7 +31,7 @@ static void workload_exec_failed_signal(int signo __maybe_unused, | |||
| 31 | * if the number of exit event reported by the kernel is 1 or not | 31 | * if the number of exit event reported by the kernel is 1 or not |
| 32 | * in order to check the kernel returns correct number of event. | 32 | * in order to check the kernel returns correct number of event. |
| 33 | */ | 33 | */ |
| 34 | int test__task_exit(void) | 34 | int test__task_exit(int subtest __maybe_unused) |
| 35 | { | 35 | { |
| 36 | int err = -1; | 36 | int err = -1; |
| 37 | union perf_event *event; | 37 | union perf_event *event; |
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 3c8734a3abbc..82b2b5e6ba7c 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | #ifndef TESTS_H | 1 | #ifndef TESTS_H |
| 2 | #define TESTS_H | 2 | #define TESTS_H |
| 3 | 3 | ||
| 4 | #include <stdbool.h> | ||
| 5 | |||
| 4 | #define TEST_ASSERT_VAL(text, cond) \ | 6 | #define TEST_ASSERT_VAL(text, cond) \ |
| 5 | do { \ | 7 | do { \ |
| 6 | if (!(cond)) { \ | 8 | if (!(cond)) { \ |
| @@ -26,48 +28,63 @@ enum { | |||
| 26 | 28 | ||
| 27 | struct test { | 29 | struct test { |
| 28 | const char *desc; | 30 | const char *desc; |
| 29 | int (*func)(void); | 31 | int (*func)(int subtest); |
| 32 | struct { | ||
| 33 | bool skip_if_fail; | ||
| 34 | int (*get_nr)(void); | ||
| 35 | const char *(*get_desc)(int subtest); | ||
| 36 | } subtest; | ||
| 30 | }; | 37 | }; |
| 31 | 38 | ||
| 32 | /* Tests */ | 39 | /* Tests */ |
| 33 | int test__vmlinux_matches_kallsyms(void); | 40 | int test__vmlinux_matches_kallsyms(int subtest); |
| 34 | int test__openat_syscall_event(void); | 41 | int test__openat_syscall_event(int subtest); |
| 35 | int test__openat_syscall_event_on_all_cpus(void); | 42 | int test__openat_syscall_event_on_all_cpus(int subtest); |
| 36 | int test__basic_mmap(void); | 43 | int test__basic_mmap(int subtest); |
| 37 | int test__PERF_RECORD(void); | 44 | int test__PERF_RECORD(int subtest); |
| 38 | int test__perf_evsel__roundtrip_name_test(void); | 45 | int test__perf_evsel__roundtrip_name_test(int subtest); |
| 39 | int test__perf_evsel__tp_sched_test(void); | 46 | int test__perf_evsel__tp_sched_test(int subtest); |
| 40 | int test__syscall_openat_tp_fields(void); | 47 | int test__syscall_openat_tp_fields(int subtest); |
| 41 | int test__pmu(void); | 48 | int test__pmu(int subtest); |
| 42 | int test__attr(void); | 49 | int test__attr(int subtest); |
| 43 | int test__dso_data(void); | 50 | int test__dso_data(int subtest); |
| 44 | int test__dso_data_cache(void); | 51 | int test__dso_data_cache(int subtest); |
| 45 | int test__dso_data_reopen(void); | 52 | int test__dso_data_reopen(int subtest); |
| 46 | int test__parse_events(void); | 53 | int test__parse_events(int subtest); |
| 47 | int test__hists_link(void); | 54 | int test__hists_link(int subtest); |
| 48 | int test__python_use(void); | 55 | int test__python_use(int subtest); |
| 49 | int test__bp_signal(void); | 56 | int test__bp_signal(int subtest); |
| 50 | int test__bp_signal_overflow(void); | 57 | int test__bp_signal_overflow(int subtest); |
| 51 | int test__task_exit(void); | 58 | int test__task_exit(int subtest); |
| 52 | int test__sw_clock_freq(void); | 59 | int test__sw_clock_freq(int subtest); |
| 53 | int test__code_reading(void); | 60 | int test__code_reading(int subtest); |
| 54 | int test__sample_parsing(void); | 61 | int test__sample_parsing(int subtest); |
| 55 | int test__keep_tracking(void); | 62 | int test__keep_tracking(int subtest); |
| 56 | int test__parse_no_sample_id_all(void); | 63 | int test__parse_no_sample_id_all(int subtest); |
| 57 | int test__dwarf_unwind(void); | 64 | int test__dwarf_unwind(int subtest); |
| 58 | int test__hists_filter(void); | 65 | int test__hists_filter(int subtest); |
| 59 | int test__mmap_thread_lookup(void); | 66 | int test__mmap_thread_lookup(int subtest); |
| 60 | int test__thread_mg_share(void); | 67 | int test__thread_mg_share(int subtest); |
| 61 | int test__hists_output(void); | 68 | int test__hists_output(int subtest); |
| 62 | int test__hists_cumulate(void); | 69 | int test__hists_cumulate(int subtest); |
| 63 | int test__switch_tracking(void); | 70 | int test__switch_tracking(int subtest); |
| 64 | int test__fdarray__filter(void); | 71 | int test__fdarray__filter(int subtest); |
| 65 | int test__fdarray__add(void); | 72 | int test__fdarray__add(int subtest); |
| 66 | int test__kmod_path__parse(void); | 73 | int test__kmod_path__parse(int subtest); |
| 67 | int test__thread_map(void); | 74 | int test__thread_map(int subtest); |
| 68 | int test__llvm(void); | 75 | int test__llvm(int subtest); |
| 69 | int test__bpf(void); | 76 | const char *test__llvm_subtest_get_desc(int subtest); |
| 70 | int test_session_topology(void); | 77 | int test__llvm_subtest_get_nr(void); |
| 78 | int test__bpf(int subtest); | ||
| 79 | const char *test__bpf_subtest_get_desc(int subtest); | ||
| 80 | int test__bpf_subtest_get_nr(void); | ||
| 81 | int test_session_topology(int subtest); | ||
| 82 | int test__thread_map_synthesize(int subtest); | ||
| 83 | int test__cpu_map_synthesize(int subtest); | ||
| 84 | int test__synthesize_stat_config(int subtest); | ||
| 85 | int test__synthesize_stat(int subtest); | ||
| 86 | int test__synthesize_stat_round(int subtest); | ||
| 87 | int test__event_update(int subtest); | ||
| 71 | 88 | ||
| 72 | #if defined(__arm__) || defined(__aarch64__) | 89 | #if defined(__arm__) || defined(__aarch64__) |
| 73 | #ifdef HAVE_DWARF_UNWIND_SUPPORT | 90 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c index 138a0e3431fa..fccde848fe9c 100644 --- a/tools/perf/tests/thread-map.c +++ b/tools/perf/tests/thread-map.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include "thread_map.h" | 4 | #include "thread_map.h" |
| 5 | #include "debug.h" | 5 | #include "debug.h" |
| 6 | 6 | ||
| 7 | int test__thread_map(void) | 7 | int test__thread_map(int subtest __maybe_unused) |
| 8 | { | 8 | { |
| 9 | struct thread_map *map; | 9 | struct thread_map *map; |
| 10 | 10 | ||
| @@ -40,3 +40,46 @@ int test__thread_map(void) | |||
| 40 | thread_map__put(map); | 40 | thread_map__put(map); |
| 41 | return 0; | 41 | return 0; |
| 42 | } | 42 | } |
| 43 | |||
| 44 | static int process_event(struct perf_tool *tool __maybe_unused, | ||
| 45 | union perf_event *event, | ||
| 46 | struct perf_sample *sample __maybe_unused, | ||
| 47 | struct machine *machine __maybe_unused) | ||
| 48 | { | ||
| 49 | struct thread_map_event *map = &event->thread_map; | ||
| 50 | struct thread_map *threads; | ||
| 51 | |||
| 52 | TEST_ASSERT_VAL("wrong nr", map->nr == 1); | ||
| 53 | TEST_ASSERT_VAL("wrong pid", map->entries[0].pid == (u64) getpid()); | ||
| 54 | TEST_ASSERT_VAL("wrong comm", !strcmp(map->entries[0].comm, "perf")); | ||
| 55 | |||
| 56 | threads = thread_map__new_event(&event->thread_map); | ||
| 57 | TEST_ASSERT_VAL("failed to alloc map", threads); | ||
| 58 | |||
| 59 | TEST_ASSERT_VAL("wrong nr", threads->nr == 1); | ||
| 60 | TEST_ASSERT_VAL("wrong pid", | ||
| 61 | thread_map__pid(threads, 0) == getpid()); | ||
| 62 | TEST_ASSERT_VAL("wrong comm", | ||
| 63 | thread_map__comm(threads, 0) && | ||
| 64 | !strcmp(thread_map__comm(threads, 0), "perf")); | ||
| 65 | TEST_ASSERT_VAL("wrong refcnt", | ||
| 66 | atomic_read(&threads->refcnt) == 1); | ||
| 67 | thread_map__put(threads); | ||
| 68 | return 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | int test__thread_map_synthesize(int subtest __maybe_unused) | ||
| 72 | { | ||
| 73 | struct thread_map *threads; | ||
| 74 | |||
| 75 | /* test map on current pid */ | ||
| 76 | threads = thread_map__new_by_pid(getpid()); | ||
| 77 | TEST_ASSERT_VAL("failed to alloc map", threads); | ||
| 78 | |||
| 79 | thread_map__read_comms(threads); | ||
| 80 | |||
| 81 | TEST_ASSERT_VAL("failed to synthesize map", | ||
| 82 | !perf_event__synthesize_thread_map2(NULL, threads, process_event, NULL)); | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
diff --git a/tools/perf/tests/thread-mg-share.c b/tools/perf/tests/thread-mg-share.c index 01fabb19d746..188b63140fc8 100644 --- a/tools/perf/tests/thread-mg-share.c +++ b/tools/perf/tests/thread-mg-share.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include "map.h" | 4 | #include "map.h" |
| 5 | #include "debug.h" | 5 | #include "debug.h" |
| 6 | 6 | ||
| 7 | int test__thread_mg_share(void) | 7 | int test__thread_mg_share(int subtest __maybe_unused) |
| 8 | { | 8 | { |
| 9 | struct machines machines; | 9 | struct machines machines; |
| 10 | struct machine *machine; | 10 | struct machine *machine; |
diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index f5bb096c3bd9..98fe69ac553c 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c | |||
| @@ -84,7 +84,7 @@ static int check_cpu_topology(char *path, struct cpu_map *map) | |||
| 84 | return 0; | 84 | return 0; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | int test_session_topology(void) | 87 | int test_session_topology(int subtest __maybe_unused) |
| 88 | { | 88 | { |
| 89 | char path[PATH_MAX]; | 89 | char path[PATH_MAX]; |
| 90 | struct cpu_map *map; | 90 | struct cpu_map *map; |
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c index d677e018e504..f0bfc9e8fd9f 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c | |||
| @@ -18,7 +18,7 @@ static int vmlinux_matches_kallsyms_filter(struct map *map __maybe_unused, | |||
| 18 | 18 | ||
| 19 | #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x)) | 19 | #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x)) |
| 20 | 20 | ||
| 21 | int test__vmlinux_matches_kallsyms(void) | 21 | int test__vmlinux_matches_kallsyms(int subtest __maybe_unused) |
| 22 | { | 22 | { |
| 23 | int err = -1; | 23 | int err = -1; |
| 24 | struct rb_node *nd; | 24 | struct rb_node *nd; |
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c index e9703c0829f1..d37202121689 100644 --- a/tools/perf/ui/browser.c +++ b/tools/perf/ui/browser.c | |||
| @@ -528,7 +528,7 @@ static struct ui_browser_colorset { | |||
| 528 | .colorset = HE_COLORSET_SELECTED, | 528 | .colorset = HE_COLORSET_SELECTED, |
| 529 | .name = "selected", | 529 | .name = "selected", |
| 530 | .fg = "black", | 530 | .fg = "black", |
| 531 | .bg = "lightgray", | 531 | .bg = "yellow", |
| 532 | }, | 532 | }, |
| 533 | { | 533 | { |
| 534 | .colorset = HE_COLORSET_CODE, | 534 | .colorset = HE_COLORSET_CODE, |
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index e5afb8936040..08c09ad755d2 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
| @@ -178,12 +178,51 @@ static int callchain_node__count_rows_rb_tree(struct callchain_node *node) | |||
| 178 | return n; | 178 | return n; |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | static int callchain_node__count_flat_rows(struct callchain_node *node) | ||
| 182 | { | ||
| 183 | struct callchain_list *chain; | ||
| 184 | char folded_sign = 0; | ||
| 185 | int n = 0; | ||
| 186 | |||
| 187 | list_for_each_entry(chain, &node->parent_val, list) { | ||
| 188 | if (!folded_sign) { | ||
| 189 | /* only check first chain list entry */ | ||
| 190 | folded_sign = callchain_list__folded(chain); | ||
| 191 | if (folded_sign == '+') | ||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | n++; | ||
| 195 | } | ||
| 196 | |||
| 197 | list_for_each_entry(chain, &node->val, list) { | ||
| 198 | if (!folded_sign) { | ||
| 199 | /* node->parent_val list might be empty */ | ||
| 200 | folded_sign = callchain_list__folded(chain); | ||
| 201 | if (folded_sign == '+') | ||
| 202 | return 1; | ||
| 203 | } | ||
| 204 | n++; | ||
| 205 | } | ||
| 206 | |||
| 207 | return n; | ||
| 208 | } | ||
| 209 | |||
| 210 | static int callchain_node__count_folded_rows(struct callchain_node *node __maybe_unused) | ||
| 211 | { | ||
| 212 | return 1; | ||
| 213 | } | ||
| 214 | |||
| 181 | static int callchain_node__count_rows(struct callchain_node *node) | 215 | static int callchain_node__count_rows(struct callchain_node *node) |
| 182 | { | 216 | { |
| 183 | struct callchain_list *chain; | 217 | struct callchain_list *chain; |
| 184 | bool unfolded = false; | 218 | bool unfolded = false; |
| 185 | int n = 0; | 219 | int n = 0; |
| 186 | 220 | ||
| 221 | if (callchain_param.mode == CHAIN_FLAT) | ||
| 222 | return callchain_node__count_flat_rows(node); | ||
| 223 | else if (callchain_param.mode == CHAIN_FOLDED) | ||
| 224 | return callchain_node__count_folded_rows(node); | ||
| 225 | |||
| 187 | list_for_each_entry(chain, &node->val, list) { | 226 | list_for_each_entry(chain, &node->val, list) { |
| 188 | ++n; | 227 | ++n; |
| 189 | unfolded = chain->unfolded; | 228 | unfolded = chain->unfolded; |
| @@ -263,7 +302,7 @@ static void callchain_node__init_have_children(struct callchain_node *node, | |||
| 263 | chain = list_entry(node->val.next, struct callchain_list, list); | 302 | chain = list_entry(node->val.next, struct callchain_list, list); |
| 264 | chain->has_children = has_sibling; | 303 | chain->has_children = has_sibling; |
| 265 | 304 | ||
| 266 | if (!list_empty(&node->val)) { | 305 | if (node->val.next != node->val.prev) { |
| 267 | chain = list_entry(node->val.prev, struct callchain_list, list); | 306 | chain = list_entry(node->val.prev, struct callchain_list, list); |
| 268 | chain->has_children = !RB_EMPTY_ROOT(&node->rb_root); | 307 | chain->has_children = !RB_EMPTY_ROOT(&node->rb_root); |
| 269 | } | 308 | } |
| @@ -279,6 +318,9 @@ static void callchain__init_have_children(struct rb_root *root) | |||
| 279 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { | 318 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 280 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); | 319 | struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node); |
| 281 | callchain_node__init_have_children(node, has_sibling); | 320 | callchain_node__init_have_children(node, has_sibling); |
| 321 | if (callchain_param.mode == CHAIN_FLAT || | ||
| 322 | callchain_param.mode == CHAIN_FOLDED) | ||
| 323 | callchain_node__make_parent_list(node); | ||
| 282 | } | 324 | } |
| 283 | } | 325 | } |
| 284 | 326 | ||
| @@ -298,6 +340,9 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser) | |||
| 298 | struct callchain_list *cl = container_of(ms, struct callchain_list, ms); | 340 | struct callchain_list *cl = container_of(ms, struct callchain_list, ms); |
| 299 | bool has_children; | 341 | bool has_children; |
| 300 | 342 | ||
| 343 | if (!he || !ms) | ||
| 344 | return false; | ||
| 345 | |||
| 301 | if (ms == &he->ms) | 346 | if (ms == &he->ms) |
| 302 | has_children = hist_entry__toggle_fold(he); | 347 | has_children = hist_entry__toggle_fold(he); |
| 303 | else | 348 | else |
| @@ -435,7 +480,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *help) | |||
| 435 | 480 | ||
| 436 | hists__browser_title(browser->hists, hbt, title, sizeof(title)); | 481 | hists__browser_title(browser->hists, hbt, title, sizeof(title)); |
| 437 | 482 | ||
| 438 | if (ui_browser__show(&browser->b, title, help) < 0) | 483 | if (ui_browser__show(&browser->b, title, "%s", help) < 0) |
| 439 | return -1; | 484 | return -1; |
| 440 | 485 | ||
| 441 | while (1) { | 486 | while (1) { |
| @@ -574,6 +619,231 @@ static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_u | |||
| 574 | 619 | ||
| 575 | #define LEVEL_OFFSET_STEP 3 | 620 | #define LEVEL_OFFSET_STEP 3 |
| 576 | 621 | ||
| 622 | static int hist_browser__show_callchain_list(struct hist_browser *browser, | ||
| 623 | struct callchain_node *node, | ||
| 624 | struct callchain_list *chain, | ||
| 625 | unsigned short row, u64 total, | ||
| 626 | bool need_percent, int offset, | ||
| 627 | print_callchain_entry_fn print, | ||
| 628 | struct callchain_print_arg *arg) | ||
| 629 | { | ||
| 630 | char bf[1024], *alloc_str; | ||
| 631 | const char *str; | ||
| 632 | |||
| 633 | if (arg->row_offset != 0) { | ||
| 634 | arg->row_offset--; | ||
| 635 | return 0; | ||
| 636 | } | ||
| 637 | |||
| 638 | alloc_str = NULL; | ||
| 639 | str = callchain_list__sym_name(chain, bf, sizeof(bf), | ||
| 640 | browser->show_dso); | ||
| 641 | |||
| 642 | if (need_percent) { | ||
| 643 | char buf[64]; | ||
| 644 | |||
| 645 | callchain_node__scnprintf_value(node, buf, sizeof(buf), | ||
| 646 | total); | ||
| 647 | |||
| 648 | if (asprintf(&alloc_str, "%s %s", buf, str) < 0) | ||
| 649 | str = "Not enough memory!"; | ||
| 650 | else | ||
| 651 | str = alloc_str; | ||
| 652 | } | ||
| 653 | |||
| 654 | print(browser, chain, str, offset, row, arg); | ||
| 655 | |||
| 656 | free(alloc_str); | ||
| 657 | return 1; | ||
| 658 | } | ||
| 659 | |||
| 660 | static int hist_browser__show_callchain_flat(struct hist_browser *browser, | ||
| 661 | struct rb_root *root, | ||
| 662 | unsigned short row, u64 total, | ||
| 663 | print_callchain_entry_fn print, | ||
| 664 | struct callchain_print_arg *arg, | ||
| 665 | check_output_full_fn is_output_full) | ||
| 666 | { | ||
| 667 | struct rb_node *node; | ||
| 668 | int first_row = row, offset = LEVEL_OFFSET_STEP; | ||
| 669 | bool need_percent; | ||
| 670 | |||
| 671 | node = rb_first(root); | ||
| 672 | need_percent = node && rb_next(node); | ||
| 673 | |||
| 674 | while (node) { | ||
| 675 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); | ||
| 676 | struct rb_node *next = rb_next(node); | ||
| 677 | struct callchain_list *chain; | ||
| 678 | char folded_sign = ' '; | ||
| 679 | int first = true; | ||
| 680 | int extra_offset = 0; | ||
| 681 | |||
| 682 | list_for_each_entry(chain, &child->parent_val, list) { | ||
| 683 | bool was_first = first; | ||
| 684 | |||
| 685 | if (first) | ||
| 686 | first = false; | ||
| 687 | else if (need_percent) | ||
| 688 | extra_offset = LEVEL_OFFSET_STEP; | ||
| 689 | |||
| 690 | folded_sign = callchain_list__folded(chain); | ||
| 691 | |||
| 692 | row += hist_browser__show_callchain_list(browser, child, | ||
| 693 | chain, row, total, | ||
| 694 | was_first && need_percent, | ||
| 695 | offset + extra_offset, | ||
| 696 | print, arg); | ||
| 697 | |||
| 698 | if (is_output_full(browser, row)) | ||
| 699 | goto out; | ||
| 700 | |||
| 701 | if (folded_sign == '+') | ||
| 702 | goto next; | ||
| 703 | } | ||
| 704 | |||
| 705 | list_for_each_entry(chain, &child->val, list) { | ||
| 706 | bool was_first = first; | ||
| 707 | |||
| 708 | if (first) | ||
| 709 | first = false; | ||
| 710 | else if (need_percent) | ||
| 711 | extra_offset = LEVEL_OFFSET_STEP; | ||
| 712 | |||
| 713 | folded_sign = callchain_list__folded(chain); | ||
| 714 | |||
| 715 | row += hist_browser__show_callchain_list(browser, child, | ||
| 716 | chain, row, total, | ||
| 717 | was_first && need_percent, | ||
| 718 | offset + extra_offset, | ||
| 719 | print, arg); | ||
| 720 | |||
| 721 | if (is_output_full(browser, row)) | ||
| 722 | goto out; | ||
| 723 | |||
| 724 | if (folded_sign == '+') | ||
| 725 | break; | ||
| 726 | } | ||
| 727 | |||
| 728 | next: | ||
| 729 | if (is_output_full(browser, row)) | ||
| 730 | break; | ||
| 731 | node = next; | ||
| 732 | } | ||
| 733 | out: | ||
| 734 | return row - first_row; | ||
| 735 | } | ||
| 736 | |||
| 737 | static char *hist_browser__folded_callchain_str(struct hist_browser *browser, | ||
| 738 | struct callchain_list *chain, | ||
| 739 | char *value_str, char *old_str) | ||
| 740 | { | ||
| 741 | char bf[1024]; | ||
| 742 | const char *str; | ||
| 743 | char *new; | ||
| 744 | |||
| 745 | str = callchain_list__sym_name(chain, bf, sizeof(bf), | ||
| 746 | browser->show_dso); | ||
| 747 | if (old_str) { | ||
| 748 | if (asprintf(&new, "%s%s%s", old_str, | ||
| 749 | symbol_conf.field_sep ?: ";", str) < 0) | ||
| 750 | new = NULL; | ||
| 751 | } else { | ||
| 752 | if (value_str) { | ||
| 753 | if (asprintf(&new, "%s %s", value_str, str) < 0) | ||
| 754 | new = NULL; | ||
| 755 | } else { | ||
| 756 | if (asprintf(&new, "%s", str) < 0) | ||
| 757 | new = NULL; | ||
| 758 | } | ||
| 759 | } | ||
| 760 | return new; | ||
| 761 | } | ||
| 762 | |||
| 763 | static int hist_browser__show_callchain_folded(struct hist_browser *browser, | ||
| 764 | struct rb_root *root, | ||
| 765 | unsigned short row, u64 total, | ||
| 766 | print_callchain_entry_fn print, | ||
| 767 | struct callchain_print_arg *arg, | ||
| 768 | check_output_full_fn is_output_full) | ||
| 769 | { | ||
| 770 | struct rb_node *node; | ||
| 771 | int first_row = row, offset = LEVEL_OFFSET_STEP; | ||
| 772 | bool need_percent; | ||
| 773 | |||
| 774 | node = rb_first(root); | ||
| 775 | need_percent = node && rb_next(node); | ||
| 776 | |||
| 777 | while (node) { | ||
| 778 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); | ||
| 779 | struct rb_node *next = rb_next(node); | ||
| 780 | struct callchain_list *chain, *first_chain = NULL; | ||
| 781 | int first = true; | ||
| 782 | char *value_str = NULL, *value_str_alloc = NULL; | ||
| 783 | char *chain_str = NULL, *chain_str_alloc = NULL; | ||
| 784 | |||
| 785 | if (arg->row_offset != 0) { | ||
| 786 | arg->row_offset--; | ||
| 787 | goto next; | ||
| 788 | } | ||
| 789 | |||
| 790 | if (need_percent) { | ||
| 791 | char buf[64]; | ||
| 792 | |||
| 793 | callchain_node__scnprintf_value(child, buf, sizeof(buf), total); | ||
| 794 | if (asprintf(&value_str, "%s", buf) < 0) { | ||
| 795 | value_str = (char *)"<...>"; | ||
| 796 | goto do_print; | ||
| 797 | } | ||
| 798 | value_str_alloc = value_str; | ||
| 799 | } | ||
| 800 | |||
| 801 | list_for_each_entry(chain, &child->parent_val, list) { | ||
| 802 | chain_str = hist_browser__folded_callchain_str(browser, | ||
| 803 | chain, value_str, chain_str); | ||
| 804 | if (first) { | ||
| 805 | first = false; | ||
| 806 | first_chain = chain; | ||
| 807 | } | ||
| 808 | |||
| 809 | if (chain_str == NULL) { | ||
| 810 | chain_str = (char *)"Not enough memory!"; | ||
| 811 | goto do_print; | ||
| 812 | } | ||
| 813 | |||
| 814 | chain_str_alloc = chain_str; | ||
| 815 | } | ||
| 816 | |||
| 817 | list_for_each_entry(chain, &child->val, list) { | ||
| 818 | chain_str = hist_browser__folded_callchain_str(browser, | ||
| 819 | chain, value_str, chain_str); | ||
| 820 | if (first) { | ||
| 821 | first = false; | ||
| 822 | first_chain = chain; | ||
| 823 | } | ||
| 824 | |||
| 825 | if (chain_str == NULL) { | ||
| 826 | chain_str = (char *)"Not enough memory!"; | ||
| 827 | goto do_print; | ||
| 828 | } | ||
| 829 | |||
| 830 | chain_str_alloc = chain_str; | ||
| 831 | } | ||
| 832 | |||
| 833 | do_print: | ||
| 834 | print(browser, first_chain, chain_str, offset, row++, arg); | ||
| 835 | free(value_str_alloc); | ||
| 836 | free(chain_str_alloc); | ||
| 837 | |||
| 838 | next: | ||
| 839 | if (is_output_full(browser, row)) | ||
| 840 | break; | ||
| 841 | node = next; | ||
| 842 | } | ||
| 843 | |||
| 844 | return row - first_row; | ||
| 845 | } | ||
| 846 | |||
| 577 | static int hist_browser__show_callchain(struct hist_browser *browser, | 847 | static int hist_browser__show_callchain(struct hist_browser *browser, |
| 578 | struct rb_root *root, int level, | 848 | struct rb_root *root, int level, |
| 579 | unsigned short row, u64 total, | 849 | unsigned short row, u64 total, |
| @@ -592,15 +862,12 @@ static int hist_browser__show_callchain(struct hist_browser *browser, | |||
| 592 | while (node) { | 862 | while (node) { |
| 593 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); | 863 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); |
| 594 | struct rb_node *next = rb_next(node); | 864 | struct rb_node *next = rb_next(node); |
| 595 | u64 cumul = callchain_cumul_hits(child); | ||
| 596 | struct callchain_list *chain; | 865 | struct callchain_list *chain; |
| 597 | char folded_sign = ' '; | 866 | char folded_sign = ' '; |
| 598 | int first = true; | 867 | int first = true; |
| 599 | int extra_offset = 0; | 868 | int extra_offset = 0; |
| 600 | 869 | ||
| 601 | list_for_each_entry(chain, &child->val, list) { | 870 | list_for_each_entry(chain, &child->val, list) { |
| 602 | char bf[1024], *alloc_str; | ||
| 603 | const char *str; | ||
| 604 | bool was_first = first; | 871 | bool was_first = first; |
| 605 | 872 | ||
| 606 | if (first) | 873 | if (first) |
| @@ -609,31 +876,16 @@ static int hist_browser__show_callchain(struct hist_browser *browser, | |||
| 609 | extra_offset = LEVEL_OFFSET_STEP; | 876 | extra_offset = LEVEL_OFFSET_STEP; |
| 610 | 877 | ||
| 611 | folded_sign = callchain_list__folded(chain); | 878 | folded_sign = callchain_list__folded(chain); |
| 612 | if (arg->row_offset != 0) { | ||
| 613 | arg->row_offset--; | ||
| 614 | goto do_next; | ||
| 615 | } | ||
| 616 | |||
| 617 | alloc_str = NULL; | ||
| 618 | str = callchain_list__sym_name(chain, bf, sizeof(bf), | ||
| 619 | browser->show_dso); | ||
| 620 | |||
| 621 | if (was_first && need_percent) { | ||
| 622 | double percent = cumul * 100.0 / total; | ||
| 623 | 879 | ||
| 624 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) | 880 | row += hist_browser__show_callchain_list(browser, child, |
| 625 | str = "Not enough memory!"; | 881 | chain, row, total, |
| 626 | else | 882 | was_first && need_percent, |
| 627 | str = alloc_str; | 883 | offset + extra_offset, |
| 628 | } | 884 | print, arg); |
| 629 | |||
| 630 | print(browser, chain, str, offset + extra_offset, row, arg); | ||
| 631 | 885 | ||
| 632 | free(alloc_str); | 886 | if (is_output_full(browser, row)) |
| 633 | |||
| 634 | if (is_output_full(browser, ++row)) | ||
| 635 | goto out; | 887 | goto out; |
| 636 | do_next: | 888 | |
| 637 | if (folded_sign == '+') | 889 | if (folded_sign == '+') |
| 638 | break; | 890 | break; |
| 639 | } | 891 | } |
| @@ -789,7 +1041,8 @@ static int hist_browser__show_entry(struct hist_browser *browser, | |||
| 789 | hist_browser__gotorc(browser, row, 0); | 1041 | hist_browser__gotorc(browser, row, 0); |
| 790 | 1042 | ||
| 791 | perf_hpp__for_each_format(fmt) { | 1043 | perf_hpp__for_each_format(fmt) { |
| 792 | if (perf_hpp__should_skip(fmt) || column++ < browser->b.horiz_scroll) | 1044 | if (perf_hpp__should_skip(fmt, entry->hists) || |
| 1045 | column++ < browser->b.horiz_scroll) | ||
| 793 | continue; | 1046 | continue; |
| 794 | 1047 | ||
| 795 | if (current_entry && browser->b.navkeypressed) { | 1048 | if (current_entry && browser->b.navkeypressed) { |
| @@ -844,10 +1097,22 @@ static int hist_browser__show_entry(struct hist_browser *browser, | |||
| 844 | total = entry->stat.period; | 1097 | total = entry->stat.period; |
| 845 | } | 1098 | } |
| 846 | 1099 | ||
| 847 | printed += hist_browser__show_callchain(browser, | 1100 | if (callchain_param.mode == CHAIN_FLAT) { |
| 1101 | printed += hist_browser__show_callchain_flat(browser, | ||
| 1102 | &entry->sorted_chain, row, total, | ||
| 1103 | hist_browser__show_callchain_entry, &arg, | ||
| 1104 | hist_browser__check_output_full); | ||
| 1105 | } else if (callchain_param.mode == CHAIN_FOLDED) { | ||
| 1106 | printed += hist_browser__show_callchain_folded(browser, | ||
| 1107 | &entry->sorted_chain, row, total, | ||
| 1108 | hist_browser__show_callchain_entry, &arg, | ||
| 1109 | hist_browser__check_output_full); | ||
| 1110 | } else { | ||
| 1111 | printed += hist_browser__show_callchain(browser, | ||
| 848 | &entry->sorted_chain, 1, row, total, | 1112 | &entry->sorted_chain, 1, row, total, |
| 849 | hist_browser__show_callchain_entry, &arg, | 1113 | hist_browser__show_callchain_entry, &arg, |
| 850 | hist_browser__check_output_full); | 1114 | hist_browser__check_output_full); |
| 1115 | } | ||
| 851 | 1116 | ||
| 852 | if (arg.is_current_entry) | 1117 | if (arg.is_current_entry) |
| 853 | browser->he_selection = entry; | 1118 | browser->he_selection = entry; |
| @@ -880,7 +1145,7 @@ static int hists_browser__scnprintf_headers(struct hist_browser *browser, char * | |||
| 880 | } | 1145 | } |
| 881 | 1146 | ||
| 882 | perf_hpp__for_each_format(fmt) { | 1147 | perf_hpp__for_each_format(fmt) { |
| 883 | if (perf_hpp__should_skip(fmt) || column++ < browser->b.horiz_scroll) | 1148 | if (perf_hpp__should_skip(fmt, hists) || column++ < browser->b.horiz_scroll) |
| 884 | continue; | 1149 | continue; |
| 885 | 1150 | ||
| 886 | ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); | 1151 | ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); |
| @@ -928,6 +1193,8 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser) | |||
| 928 | } | 1193 | } |
| 929 | 1194 | ||
| 930 | ui_browser__hists_init_top(browser); | 1195 | ui_browser__hists_init_top(browser); |
| 1196 | hb->he_selection = NULL; | ||
| 1197 | hb->selection = NULL; | ||
| 931 | 1198 | ||
| 932 | for (nd = browser->top; nd; nd = rb_next(nd)) { | 1199 | for (nd = browser->top; nd; nd = rb_next(nd)) { |
| 933 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 1200 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| @@ -1033,6 +1300,9 @@ static void ui_browser__hists_seek(struct ui_browser *browser, | |||
| 1033 | * and stop when we printed enough lines to fill the screen. | 1300 | * and stop when we printed enough lines to fill the screen. |
| 1034 | */ | 1301 | */ |
| 1035 | do_offset: | 1302 | do_offset: |
| 1303 | if (!nd) | ||
| 1304 | return; | ||
| 1305 | |||
| 1036 | if (offset > 0) { | 1306 | if (offset > 0) { |
| 1037 | do { | 1307 | do { |
| 1038 | h = rb_entry(nd, struct hist_entry, rb_node); | 1308 | h = rb_entry(nd, struct hist_entry, rb_node); |
| @@ -1145,7 +1415,7 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, | |||
| 1145 | printed += fprintf(fp, "%c ", folded_sign); | 1415 | printed += fprintf(fp, "%c ", folded_sign); |
| 1146 | 1416 | ||
| 1147 | perf_hpp__for_each_format(fmt) { | 1417 | perf_hpp__for_each_format(fmt) { |
| 1148 | if (perf_hpp__should_skip(fmt)) | 1418 | if (perf_hpp__should_skip(fmt, he->hists)) |
| 1149 | continue; | 1419 | continue; |
| 1150 | 1420 | ||
| 1151 | if (!first) { | 1421 | if (!first) { |
| @@ -1430,7 +1700,6 @@ close_file_and_continue: | |||
| 1430 | 1700 | ||
| 1431 | struct popup_action { | 1701 | struct popup_action { |
| 1432 | struct thread *thread; | 1702 | struct thread *thread; |
| 1433 | struct dso *dso; | ||
| 1434 | struct map_symbol ms; | 1703 | struct map_symbol ms; |
| 1435 | int socket; | 1704 | int socket; |
| 1436 | 1705 | ||
| @@ -1565,7 +1834,6 @@ add_dso_opt(struct hist_browser *browser, struct popup_action *act, | |||
| 1565 | return 0; | 1834 | return 0; |
| 1566 | 1835 | ||
| 1567 | act->ms.map = map; | 1836 | act->ms.map = map; |
| 1568 | act->dso = map->dso; | ||
| 1569 | act->fn = do_zoom_dso; | 1837 | act->fn = do_zoom_dso; |
| 1570 | return 1; | 1838 | return 1; |
| 1571 | } | 1839 | } |
| @@ -1796,10 +2064,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
| 1796 | SLang_reset_tty(); | 2064 | SLang_reset_tty(); |
| 1797 | SLang_init_tty(0, 0, 0); | 2065 | SLang_init_tty(0, 0, 0); |
| 1798 | 2066 | ||
| 1799 | if (min_pcnt) { | 2067 | if (min_pcnt) |
| 1800 | browser->min_pcnt = min_pcnt; | 2068 | browser->min_pcnt = min_pcnt; |
| 1801 | hist_browser__update_nr_entries(browser); | 2069 | hist_browser__update_nr_entries(browser); |
| 1802 | } | ||
| 1803 | 2070 | ||
| 1804 | browser->pstack = pstack__new(3); | 2071 | browser->pstack = pstack__new(3); |
| 1805 | if (browser->pstack == NULL) | 2072 | if (browser->pstack == NULL) |
| @@ -1827,7 +2094,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
| 1827 | 2094 | ||
| 1828 | while (1) { | 2095 | while (1) { |
| 1829 | struct thread *thread = NULL; | 2096 | struct thread *thread = NULL; |
| 1830 | struct dso *dso = NULL; | ||
| 1831 | struct map *map = NULL; | 2097 | struct map *map = NULL; |
| 1832 | int choice = 0; | 2098 | int choice = 0; |
| 1833 | int socked_id = -1; | 2099 | int socked_id = -1; |
| @@ -1839,8 +2105,6 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
| 1839 | if (browser->he_selection != NULL) { | 2105 | if (browser->he_selection != NULL) { |
| 1840 | thread = hist_browser__selected_thread(browser); | 2106 | thread = hist_browser__selected_thread(browser); |
| 1841 | map = browser->selection->map; | 2107 | map = browser->selection->map; |
| 1842 | if (map) | ||
| 1843 | dso = map->dso; | ||
| 1844 | socked_id = browser->he_selection->socket; | 2108 | socked_id = browser->he_selection->socket; |
| 1845 | } | 2109 | } |
| 1846 | switch (key) { | 2110 | switch (key) { |
| @@ -1874,7 +2138,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, | |||
| 1874 | hist_browser__dump(browser); | 2138 | hist_browser__dump(browser); |
| 1875 | continue; | 2139 | continue; |
| 1876 | case 'd': | 2140 | case 'd': |
| 1877 | actions->dso = dso; | 2141 | actions->ms.map = map; |
| 1878 | do_zoom_dso(browser, actions); | 2142 | do_zoom_dso(browser, actions); |
| 1879 | continue; | 2143 | continue; |
| 1880 | case 'V': | 2144 | case 'V': |
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c index 4b3585eed1e8..0f8dcfdfb10f 100644 --- a/tools/perf/ui/gtk/hists.c +++ b/tools/perf/ui/gtk/hists.c | |||
| @@ -89,8 +89,8 @@ void perf_gtk__init_hpp(void) | |||
| 89 | perf_gtk__hpp_color_overhead_acc; | 89 | perf_gtk__hpp_color_overhead_acc; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store, | 92 | static void perf_gtk__add_callchain_flat(struct rb_root *root, GtkTreeStore *store, |
| 93 | GtkTreeIter *parent, int col, u64 total) | 93 | GtkTreeIter *parent, int col, u64 total) |
| 94 | { | 94 | { |
| 95 | struct rb_node *nd; | 95 | struct rb_node *nd; |
| 96 | bool has_single_node = (rb_first(root) == rb_last(root)); | 96 | bool has_single_node = (rb_first(root) == rb_last(root)); |
| @@ -100,13 +100,132 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store, | |||
| 100 | struct callchain_list *chain; | 100 | struct callchain_list *chain; |
| 101 | GtkTreeIter iter, new_parent; | 101 | GtkTreeIter iter, new_parent; |
| 102 | bool need_new_parent; | 102 | bool need_new_parent; |
| 103 | double percent; | ||
| 104 | u64 hits, child_total; | ||
| 105 | 103 | ||
| 106 | node = rb_entry(nd, struct callchain_node, rb_node); | 104 | node = rb_entry(nd, struct callchain_node, rb_node); |
| 107 | 105 | ||
| 108 | hits = callchain_cumul_hits(node); | 106 | new_parent = *parent; |
| 109 | percent = 100.0 * hits / total; | 107 | need_new_parent = !has_single_node; |
| 108 | |||
| 109 | callchain_node__make_parent_list(node); | ||
| 110 | |||
| 111 | list_for_each_entry(chain, &node->parent_val, list) { | ||
| 112 | char buf[128]; | ||
| 113 | |||
| 114 | gtk_tree_store_append(store, &iter, &new_parent); | ||
| 115 | |||
| 116 | callchain_node__scnprintf_value(node, buf, sizeof(buf), total); | ||
| 117 | gtk_tree_store_set(store, &iter, 0, buf, -1); | ||
| 118 | |||
| 119 | callchain_list__sym_name(chain, buf, sizeof(buf), false); | ||
| 120 | gtk_tree_store_set(store, &iter, col, buf, -1); | ||
| 121 | |||
| 122 | if (need_new_parent) { | ||
| 123 | /* | ||
| 124 | * Only show the top-most symbol in a callchain | ||
| 125 | * if it's not the only callchain. | ||
| 126 | */ | ||
| 127 | new_parent = iter; | ||
| 128 | need_new_parent = false; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | list_for_each_entry(chain, &node->val, list) { | ||
| 133 | char buf[128]; | ||
| 134 | |||
| 135 | gtk_tree_store_append(store, &iter, &new_parent); | ||
| 136 | |||
| 137 | callchain_node__scnprintf_value(node, buf, sizeof(buf), total); | ||
| 138 | gtk_tree_store_set(store, &iter, 0, buf, -1); | ||
| 139 | |||
| 140 | callchain_list__sym_name(chain, buf, sizeof(buf), false); | ||
| 141 | gtk_tree_store_set(store, &iter, col, buf, -1); | ||
| 142 | |||
| 143 | if (need_new_parent) { | ||
| 144 | /* | ||
| 145 | * Only show the top-most symbol in a callchain | ||
| 146 | * if it's not the only callchain. | ||
| 147 | */ | ||
| 148 | new_parent = iter; | ||
| 149 | need_new_parent = false; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | static void perf_gtk__add_callchain_folded(struct rb_root *root, GtkTreeStore *store, | ||
| 156 | GtkTreeIter *parent, int col, u64 total) | ||
| 157 | { | ||
| 158 | struct rb_node *nd; | ||
| 159 | |||
| 160 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { | ||
| 161 | struct callchain_node *node; | ||
| 162 | struct callchain_list *chain; | ||
| 163 | GtkTreeIter iter; | ||
| 164 | char buf[64]; | ||
| 165 | char *str, *str_alloc = NULL; | ||
| 166 | bool first = true; | ||
| 167 | |||
| 168 | node = rb_entry(nd, struct callchain_node, rb_node); | ||
| 169 | |||
| 170 | callchain_node__make_parent_list(node); | ||
| 171 | |||
| 172 | list_for_each_entry(chain, &node->parent_val, list) { | ||
| 173 | char name[1024]; | ||
| 174 | |||
| 175 | callchain_list__sym_name(chain, name, sizeof(name), false); | ||
| 176 | |||
| 177 | if (asprintf(&str, "%s%s%s", | ||
| 178 | first ? "" : str_alloc, | ||
| 179 | first ? "" : symbol_conf.field_sep ?: "; ", | ||
| 180 | name) < 0) | ||
| 181 | return; | ||
| 182 | |||
| 183 | first = false; | ||
| 184 | free(str_alloc); | ||
| 185 | str_alloc = str; | ||
| 186 | } | ||
| 187 | |||
| 188 | list_for_each_entry(chain, &node->val, list) { | ||
| 189 | char name[1024]; | ||
| 190 | |||
| 191 | callchain_list__sym_name(chain, name, sizeof(name), false); | ||
| 192 | |||
| 193 | if (asprintf(&str, "%s%s%s", | ||
| 194 | first ? "" : str_alloc, | ||
| 195 | first ? "" : symbol_conf.field_sep ?: "; ", | ||
| 196 | name) < 0) | ||
| 197 | return; | ||
| 198 | |||
| 199 | first = false; | ||
| 200 | free(str_alloc); | ||
| 201 | str_alloc = str; | ||
| 202 | } | ||
| 203 | |||
| 204 | gtk_tree_store_append(store, &iter, parent); | ||
| 205 | |||
| 206 | callchain_node__scnprintf_value(node, buf, sizeof(buf), total); | ||
| 207 | gtk_tree_store_set(store, &iter, 0, buf, -1); | ||
| 208 | |||
| 209 | gtk_tree_store_set(store, &iter, col, str, -1); | ||
| 210 | |||
| 211 | free(str_alloc); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | static void perf_gtk__add_callchain_graph(struct rb_root *root, GtkTreeStore *store, | ||
| 216 | GtkTreeIter *parent, int col, u64 total) | ||
| 217 | { | ||
| 218 | struct rb_node *nd; | ||
| 219 | bool has_single_node = (rb_first(root) == rb_last(root)); | ||
| 220 | |||
| 221 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { | ||
| 222 | struct callchain_node *node; | ||
| 223 | struct callchain_list *chain; | ||
| 224 | GtkTreeIter iter, new_parent; | ||
| 225 | bool need_new_parent; | ||
| 226 | u64 child_total; | ||
| 227 | |||
| 228 | node = rb_entry(nd, struct callchain_node, rb_node); | ||
| 110 | 229 | ||
| 111 | new_parent = *parent; | 230 | new_parent = *parent; |
| 112 | need_new_parent = !has_single_node && (node->val_nr > 1); | 231 | need_new_parent = !has_single_node && (node->val_nr > 1); |
| @@ -116,7 +235,7 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store, | |||
| 116 | 235 | ||
| 117 | gtk_tree_store_append(store, &iter, &new_parent); | 236 | gtk_tree_store_append(store, &iter, &new_parent); |
| 118 | 237 | ||
| 119 | scnprintf(buf, sizeof(buf), "%5.2f%%", percent); | 238 | callchain_node__scnprintf_value(node, buf, sizeof(buf), total); |
| 120 | gtk_tree_store_set(store, &iter, 0, buf, -1); | 239 | gtk_tree_store_set(store, &iter, 0, buf, -1); |
| 121 | 240 | ||
| 122 | callchain_list__sym_name(chain, buf, sizeof(buf), false); | 241 | callchain_list__sym_name(chain, buf, sizeof(buf), false); |
| @@ -138,11 +257,22 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store, | |||
| 138 | child_total = total; | 257 | child_total = total; |
| 139 | 258 | ||
| 140 | /* Now 'iter' contains info of the last callchain_list */ | 259 | /* Now 'iter' contains info of the last callchain_list */ |
| 141 | perf_gtk__add_callchain(&node->rb_root, store, &iter, col, | 260 | perf_gtk__add_callchain_graph(&node->rb_root, store, &iter, col, |
| 142 | child_total); | 261 | child_total); |
| 143 | } | 262 | } |
| 144 | } | 263 | } |
| 145 | 264 | ||
| 265 | static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store, | ||
| 266 | GtkTreeIter *parent, int col, u64 total) | ||
| 267 | { | ||
| 268 | if (callchain_param.mode == CHAIN_FLAT) | ||
| 269 | perf_gtk__add_callchain_flat(root, store, parent, col, total); | ||
| 270 | else if (callchain_param.mode == CHAIN_FOLDED) | ||
| 271 | perf_gtk__add_callchain_folded(root, store, parent, col, total); | ||
| 272 | else | ||
| 273 | perf_gtk__add_callchain_graph(root, store, parent, col, total); | ||
| 274 | } | ||
| 275 | |||
| 146 | static void on_row_activated(GtkTreeView *view, GtkTreePath *path, | 276 | static void on_row_activated(GtkTreeView *view, GtkTreePath *path, |
| 147 | GtkTreeViewColumn *col __maybe_unused, | 277 | GtkTreeViewColumn *col __maybe_unused, |
| 148 | gpointer user_data __maybe_unused) | 278 | gpointer user_data __maybe_unused) |
| @@ -188,7 +318,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
| 188 | col_idx = 0; | 318 | col_idx = 0; |
| 189 | 319 | ||
| 190 | perf_hpp__for_each_format(fmt) { | 320 | perf_hpp__for_each_format(fmt) { |
| 191 | if (perf_hpp__should_skip(fmt)) | 321 | if (perf_hpp__should_skip(fmt, hists)) |
| 192 | continue; | 322 | continue; |
| 193 | 323 | ||
| 194 | /* | 324 | /* |
| @@ -238,7 +368,7 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, | |||
| 238 | col_idx = 0; | 368 | col_idx = 0; |
| 239 | 369 | ||
| 240 | perf_hpp__for_each_format(fmt) { | 370 | perf_hpp__for_each_format(fmt) { |
| 241 | if (perf_hpp__should_skip(fmt)) | 371 | if (perf_hpp__should_skip(fmt, h->hists)) |
| 242 | continue; | 372 | continue; |
| 243 | 373 | ||
| 244 | if (fmt->color) | 374 | if (fmt->color) |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 5029ba2b55af..bf2a66e254ea 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
| @@ -443,7 +443,6 @@ LIST_HEAD(perf_hpp__sort_list); | |||
| 443 | 443 | ||
| 444 | void perf_hpp__init(void) | 444 | void perf_hpp__init(void) |
| 445 | { | 445 | { |
| 446 | struct list_head *list; | ||
| 447 | int i; | 446 | int i; |
| 448 | 447 | ||
| 449 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { | 448 | for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { |
| @@ -484,17 +483,6 @@ void perf_hpp__init(void) | |||
| 484 | 483 | ||
| 485 | if (symbol_conf.show_total_period) | 484 | if (symbol_conf.show_total_period) |
| 486 | hpp_dimension__add_output(PERF_HPP__PERIOD); | 485 | hpp_dimension__add_output(PERF_HPP__PERIOD); |
| 487 | |||
| 488 | /* prepend overhead field for backward compatiblity. */ | ||
| 489 | list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list; | ||
| 490 | if (list_empty(list)) | ||
| 491 | list_add(list, &perf_hpp__sort_list); | ||
| 492 | |||
| 493 | if (symbol_conf.cumulate_callchain) { | ||
| 494 | list = &perf_hpp__format[PERF_HPP__OVERHEAD_ACC].sort_list; | ||
| 495 | if (list_empty(list)) | ||
| 496 | list_add(list, &perf_hpp__sort_list); | ||
| 497 | } | ||
| 498 | } | 486 | } |
| 499 | 487 | ||
| 500 | void perf_hpp__column_register(struct perf_hpp_fmt *format) | 488 | void perf_hpp__column_register(struct perf_hpp_fmt *format) |
| @@ -619,7 +607,7 @@ unsigned int hists__sort_list_width(struct hists *hists) | |||
| 619 | struct perf_hpp dummy_hpp; | 607 | struct perf_hpp dummy_hpp; |
| 620 | 608 | ||
| 621 | perf_hpp__for_each_format(fmt) { | 609 | perf_hpp__for_each_format(fmt) { |
| 622 | if (perf_hpp__should_skip(fmt)) | 610 | if (perf_hpp__should_skip(fmt, hists)) |
| 623 | continue; | 611 | continue; |
| 624 | 612 | ||
| 625 | if (first) | 613 | if (first) |
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index dfcbc90146ef..387110d50b00 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c | |||
| @@ -34,10 +34,10 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, | |||
| 34 | return ret; | 34 | return ret; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | 37 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node, |
| 38 | struct callchain_list *chain, | ||
| 38 | int depth, int depth_mask, int period, | 39 | int depth, int depth_mask, int period, |
| 39 | u64 total_samples, u64 hits, | 40 | u64 total_samples, int left_margin) |
| 40 | int left_margin) | ||
| 41 | { | 41 | { |
| 42 | int i; | 42 | int i; |
| 43 | size_t ret = 0; | 43 | size_t ret = 0; |
| @@ -50,10 +50,9 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | |||
| 50 | else | 50 | else |
| 51 | ret += fprintf(fp, " "); | 51 | ret += fprintf(fp, " "); |
| 52 | if (!period && i == depth - 1) { | 52 | if (!period && i == depth - 1) { |
| 53 | double percent; | 53 | ret += fprintf(fp, "--"); |
| 54 | 54 | ret += callchain_node__fprintf_value(node, fp, total_samples); | |
| 55 | percent = hits * 100.0 / total_samples; | 55 | ret += fprintf(fp, "--"); |
| 56 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); | ||
| 57 | } else | 56 | } else |
| 58 | ret += fprintf(fp, "%s", " "); | 57 | ret += fprintf(fp, "%s", " "); |
| 59 | } | 58 | } |
| @@ -82,13 +81,14 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
| 82 | int depth_mask, int left_margin) | 81 | int depth_mask, int left_margin) |
| 83 | { | 82 | { |
| 84 | struct rb_node *node, *next; | 83 | struct rb_node *node, *next; |
| 85 | struct callchain_node *child; | 84 | struct callchain_node *child = NULL; |
| 86 | struct callchain_list *chain; | 85 | struct callchain_list *chain; |
| 87 | int new_depth_mask = depth_mask; | 86 | int new_depth_mask = depth_mask; |
| 88 | u64 remaining; | 87 | u64 remaining; |
| 89 | size_t ret = 0; | 88 | size_t ret = 0; |
| 90 | int i; | 89 | int i; |
| 91 | uint entries_printed = 0; | 90 | uint entries_printed = 0; |
| 91 | int cumul_count = 0; | ||
| 92 | 92 | ||
| 93 | remaining = total_samples; | 93 | remaining = total_samples; |
| 94 | 94 | ||
| @@ -100,6 +100,7 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
| 100 | child = rb_entry(node, struct callchain_node, rb_node); | 100 | child = rb_entry(node, struct callchain_node, rb_node); |
| 101 | cumul = callchain_cumul_hits(child); | 101 | cumul = callchain_cumul_hits(child); |
| 102 | remaining -= cumul; | 102 | remaining -= cumul; |
| 103 | cumul_count += callchain_cumul_counts(child); | ||
| 103 | 104 | ||
| 104 | /* | 105 | /* |
| 105 | * The depth mask manages the output of pipes that show | 106 | * The depth mask manages the output of pipes that show |
| @@ -120,10 +121,9 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
| 120 | left_margin); | 121 | left_margin); |
| 121 | i = 0; | 122 | i = 0; |
| 122 | list_for_each_entry(chain, &child->val, list) { | 123 | list_for_each_entry(chain, &child->val, list) { |
| 123 | ret += ipchain__fprintf_graph(fp, chain, depth, | 124 | ret += ipchain__fprintf_graph(fp, child, chain, depth, |
| 124 | new_depth_mask, i++, | 125 | new_depth_mask, i++, |
| 125 | total_samples, | 126 | total_samples, |
| 126 | cumul, | ||
| 127 | left_margin); | 127 | left_margin); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| @@ -143,14 +143,23 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, | |||
| 143 | 143 | ||
| 144 | if (callchain_param.mode == CHAIN_GRAPH_REL && | 144 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
| 145 | remaining && remaining != total_samples) { | 145 | remaining && remaining != total_samples) { |
| 146 | struct callchain_node rem_node = { | ||
| 147 | .hit = remaining, | ||
| 148 | }; | ||
| 146 | 149 | ||
| 147 | if (!rem_sq_bracket) | 150 | if (!rem_sq_bracket) |
| 148 | return ret; | 151 | return ret; |
| 149 | 152 | ||
| 153 | if (callchain_param.value == CCVAL_COUNT && child && child->parent) { | ||
| 154 | rem_node.count = child->parent->children_count - cumul_count; | ||
| 155 | if (rem_node.count <= 0) | ||
| 156 | return ret; | ||
| 157 | } | ||
| 158 | |||
| 150 | new_depth_mask &= ~(1 << (depth - 1)); | 159 | new_depth_mask &= ~(1 << (depth - 1)); |
| 151 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, | 160 | ret += ipchain__fprintf_graph(fp, &rem_node, &rem_hits, depth, |
| 152 | new_depth_mask, 0, total_samples, | 161 | new_depth_mask, 0, total_samples, |
| 153 | remaining, left_margin); | 162 | left_margin); |
| 154 | } | 163 | } |
| 155 | 164 | ||
| 156 | return ret; | 165 | return ret; |
| @@ -243,12 +252,11 @@ static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree, | |||
| 243 | struct rb_node *rb_node = rb_first(tree); | 252 | struct rb_node *rb_node = rb_first(tree); |
| 244 | 253 | ||
| 245 | while (rb_node) { | 254 | while (rb_node) { |
| 246 | double percent; | ||
| 247 | |||
| 248 | chain = rb_entry(rb_node, struct callchain_node, rb_node); | 255 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 249 | percent = chain->hit * 100.0 / total_samples; | ||
| 250 | 256 | ||
| 251 | ret = percent_color_fprintf(fp, " %6.2f%%\n", percent); | 257 | ret += fprintf(fp, " "); |
| 258 | ret += callchain_node__fprintf_value(chain, fp, total_samples); | ||
| 259 | ret += fprintf(fp, "\n"); | ||
| 252 | ret += __callchain__fprintf_flat(fp, chain, total_samples); | 260 | ret += __callchain__fprintf_flat(fp, chain, total_samples); |
| 253 | ret += fprintf(fp, "\n"); | 261 | ret += fprintf(fp, "\n"); |
| 254 | if (++entries_printed == callchain_param.print_limit) | 262 | if (++entries_printed == callchain_param.print_limit) |
| @@ -260,6 +268,57 @@ static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree, | |||
| 260 | return ret; | 268 | return ret; |
| 261 | } | 269 | } |
| 262 | 270 | ||
| 271 | static size_t __callchain__fprintf_folded(FILE *fp, struct callchain_node *node) | ||
| 272 | { | ||
| 273 | const char *sep = symbol_conf.field_sep ?: ";"; | ||
| 274 | struct callchain_list *chain; | ||
| 275 | size_t ret = 0; | ||
| 276 | char bf[1024]; | ||
| 277 | bool first; | ||
| 278 | |||
| 279 | if (!node) | ||
| 280 | return 0; | ||
| 281 | |||
| 282 | ret += __callchain__fprintf_folded(fp, node->parent); | ||
| 283 | |||
| 284 | first = (ret == 0); | ||
| 285 | list_for_each_entry(chain, &node->val, list) { | ||
| 286 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
| 287 | continue; | ||
| 288 | ret += fprintf(fp, "%s%s", first ? "" : sep, | ||
| 289 | callchain_list__sym_name(chain, | ||
| 290 | bf, sizeof(bf), false)); | ||
| 291 | first = false; | ||
| 292 | } | ||
| 293 | |||
| 294 | return ret; | ||
| 295 | } | ||
| 296 | |||
| 297 | static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree, | ||
| 298 | u64 total_samples) | ||
| 299 | { | ||
| 300 | size_t ret = 0; | ||
| 301 | u32 entries_printed = 0; | ||
| 302 | struct callchain_node *chain; | ||
| 303 | struct rb_node *rb_node = rb_first(tree); | ||
| 304 | |||
| 305 | while (rb_node) { | ||
| 306 | |||
| 307 | chain = rb_entry(rb_node, struct callchain_node, rb_node); | ||
| 308 | |||
| 309 | ret += callchain_node__fprintf_value(chain, fp, total_samples); | ||
| 310 | ret += fprintf(fp, " "); | ||
| 311 | ret += __callchain__fprintf_folded(fp, chain); | ||
| 312 | ret += fprintf(fp, "\n"); | ||
| 313 | if (++entries_printed == callchain_param.print_limit) | ||
| 314 | break; | ||
| 315 | |||
| 316 | rb_node = rb_next(rb_node); | ||
| 317 | } | ||
| 318 | |||
| 319 | return ret; | ||
| 320 | } | ||
| 321 | |||
| 263 | static size_t hist_entry_callchain__fprintf(struct hist_entry *he, | 322 | static size_t hist_entry_callchain__fprintf(struct hist_entry *he, |
| 264 | u64 total_samples, int left_margin, | 323 | u64 total_samples, int left_margin, |
| 265 | FILE *fp) | 324 | FILE *fp) |
| @@ -278,6 +337,9 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, | |||
| 278 | case CHAIN_FLAT: | 337 | case CHAIN_FLAT: |
| 279 | return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples); | 338 | return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples); |
| 280 | break; | 339 | break; |
| 340 | case CHAIN_FOLDED: | ||
| 341 | return callchain__fprintf_folded(fp, &he->sorted_chain, total_samples); | ||
| 342 | break; | ||
| 281 | case CHAIN_NONE: | 343 | case CHAIN_NONE: |
| 282 | break; | 344 | break; |
| 283 | default: | 345 | default: |
| @@ -323,7 +385,7 @@ static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp) | |||
| 323 | return 0; | 385 | return 0; |
| 324 | 386 | ||
| 325 | perf_hpp__for_each_format(fmt) { | 387 | perf_hpp__for_each_format(fmt) { |
| 326 | if (perf_hpp__should_skip(fmt)) | 388 | if (perf_hpp__should_skip(fmt, he->hists)) |
| 327 | continue; | 389 | continue; |
| 328 | 390 | ||
| 329 | /* | 391 | /* |
| @@ -402,7 +464,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, | |||
| 402 | fprintf(fp, "# "); | 464 | fprintf(fp, "# "); |
| 403 | 465 | ||
| 404 | perf_hpp__for_each_format(fmt) { | 466 | perf_hpp__for_each_format(fmt) { |
| 405 | if (perf_hpp__should_skip(fmt)) | 467 | if (perf_hpp__should_skip(fmt, hists)) |
| 406 | continue; | 468 | continue; |
| 407 | 469 | ||
| 408 | if (!first) | 470 | if (!first) |
| @@ -428,7 +490,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, | |||
| 428 | perf_hpp__for_each_format(fmt) { | 490 | perf_hpp__for_each_format(fmt) { |
| 429 | unsigned int i; | 491 | unsigned int i; |
| 430 | 492 | ||
| 431 | if (perf_hpp__should_skip(fmt)) | 493 | if (perf_hpp__should_skip(fmt, hists)) |
| 432 | continue; | 494 | continue; |
| 433 | 495 | ||
| 434 | if (!first) | 496 | if (!first) |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 591b3fe3ed49..5eec53a3f4ac 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
| @@ -6,24 +6,20 @@ libperf-y += config.o | |||
| 6 | libperf-y += ctype.o | 6 | libperf-y += ctype.o |
| 7 | libperf-y += db-export.o | 7 | libperf-y += db-export.o |
| 8 | libperf-y += env.o | 8 | libperf-y += env.o |
| 9 | libperf-y += environment.o | ||
| 10 | libperf-y += event.o | 9 | libperf-y += event.o |
| 11 | libperf-y += evlist.o | 10 | libperf-y += evlist.o |
| 12 | libperf-y += evsel.o | 11 | libperf-y += evsel.o |
| 13 | libperf-y += exec_cmd.o | 12 | libperf-y += find_bit.o |
| 14 | libperf-y += find_next_bit.o | ||
| 15 | libperf-y += help.o | ||
| 16 | libperf-y += kallsyms.o | 13 | libperf-y += kallsyms.o |
| 17 | libperf-y += levenshtein.o | 14 | libperf-y += levenshtein.o |
| 18 | libperf-y += llvm-utils.o | 15 | libperf-y += llvm-utils.o |
| 19 | libperf-y += parse-options.o | ||
| 20 | libperf-y += parse-events.o | 16 | libperf-y += parse-events.o |
| 21 | libperf-y += perf_regs.o | 17 | libperf-y += perf_regs.o |
| 22 | libperf-y += path.o | 18 | libperf-y += path.o |
| 23 | libperf-y += rbtree.o | 19 | libperf-y += rbtree.o |
| 20 | libperf-y += libstring.o | ||
| 24 | libperf-y += bitmap.o | 21 | libperf-y += bitmap.o |
| 25 | libperf-y += hweight.o | 22 | libperf-y += hweight.o |
| 26 | libperf-y += run-command.o | ||
| 27 | libperf-y += quote.o | 23 | libperf-y += quote.o |
| 28 | libperf-y += strbuf.o | 24 | libperf-y += strbuf.o |
| 29 | libperf-y += string.o | 25 | libperf-y += string.o |
| @@ -32,11 +28,9 @@ libperf-y += strfilter.o | |||
| 32 | libperf-y += top.o | 28 | libperf-y += top.o |
| 33 | libperf-y += usage.o | 29 | libperf-y += usage.o |
| 34 | libperf-y += wrapper.o | 30 | libperf-y += wrapper.o |
| 35 | libperf-y += sigchain.o | ||
| 36 | libperf-y += dso.o | 31 | libperf-y += dso.o |
| 37 | libperf-y += symbol.o | 32 | libperf-y += symbol.o |
| 38 | libperf-y += color.o | 33 | libperf-y += color.o |
| 39 | libperf-y += pager.o | ||
| 40 | libperf-y += header.o | 34 | libperf-y += header.o |
| 41 | libperf-y += callchain.o | 35 | libperf-y += callchain.o |
| 42 | libperf-y += values.o | 36 | libperf-y += values.o |
| @@ -86,8 +80,11 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt.o | |||
| 86 | libperf-$(CONFIG_AUXTRACE) += intel-bts.o | 80 | libperf-$(CONFIG_AUXTRACE) += intel-bts.o |
| 87 | libperf-y += parse-branch-options.o | 81 | libperf-y += parse-branch-options.o |
| 88 | libperf-y += parse-regs-options.o | 82 | libperf-y += parse-regs-options.o |
| 83 | libperf-y += term.o | ||
| 84 | libperf-y += help-unknown-cmd.o | ||
| 89 | 85 | ||
| 90 | libperf-$(CONFIG_LIBBPF) += bpf-loader.o | 86 | libperf-$(CONFIG_LIBBPF) += bpf-loader.o |
| 87 | libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o | ||
| 91 | libperf-$(CONFIG_LIBELF) += symbol-elf.o | 88 | libperf-$(CONFIG_LIBELF) += symbol-elf.o |
| 92 | libperf-$(CONFIG_LIBELF) += probe-file.o | 89 | libperf-$(CONFIG_LIBELF) += probe-file.o |
| 93 | libperf-$(CONFIG_LIBELF) += probe-event.o | 90 | libperf-$(CONFIG_LIBELF) += probe-event.o |
| @@ -110,7 +107,6 @@ libperf-$(CONFIG_ZLIB) += zlib.o | |||
| 110 | libperf-$(CONFIG_LZMA) += lzma.o | 107 | libperf-$(CONFIG_LZMA) += lzma.o |
| 111 | 108 | ||
| 112 | CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | 109 | CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" |
| 113 | CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))" | ||
| 114 | 110 | ||
| 115 | $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c | 111 | $(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c |
| 116 | $(call rule_mkdir) | 112 | $(call rule_mkdir) |
| @@ -136,8 +132,10 @@ CFLAGS_pmu-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w | |||
| 136 | $(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c | 132 | $(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c |
| 137 | $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c | 133 | $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c |
| 138 | 134 | ||
| 139 | CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | 135 | CFLAGS_bitmap.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" |
| 136 | CFLAGS_find_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | ||
| 140 | CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | 137 | CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" |
| 138 | CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | ||
| 141 | CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" | 139 | CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" |
| 142 | CFLAGS_parse-events.o += -Wno-redundant-decls | 140 | CFLAGS_parse-events.o += -Wno-redundant-decls |
| 143 | 141 | ||
| @@ -145,7 +143,11 @@ $(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE | |||
| 145 | $(call rule_mkdir) | 143 | $(call rule_mkdir) |
| 146 | $(call if_changed_dep,cc_o_c) | 144 | $(call if_changed_dep,cc_o_c) |
| 147 | 145 | ||
| 148 | $(OUTPUT)util/find_next_bit.o: ../lib/util/find_next_bit.c FORCE | 146 | $(OUTPUT)util/bitmap.o: ../lib/bitmap.c FORCE |
| 147 | $(call rule_mkdir) | ||
| 148 | $(call if_changed_dep,cc_o_c) | ||
| 149 | |||
| 150 | $(OUTPUT)util/find_bit.o: ../lib/find_bit.c FORCE | ||
| 149 | $(call rule_mkdir) | 151 | $(call rule_mkdir) |
| 150 | $(call if_changed_dep,cc_o_c) | 152 | $(call if_changed_dep,cc_o_c) |
| 151 | 153 | ||
| @@ -153,6 +155,10 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE | |||
| 153 | $(call rule_mkdir) | 155 | $(call rule_mkdir) |
| 154 | $(call if_changed_dep,cc_o_c) | 156 | $(call if_changed_dep,cc_o_c) |
| 155 | 157 | ||
| 158 | $(OUTPUT)util/libstring.o: ../lib/string.c FORCE | ||
| 159 | $(call rule_mkdir) | ||
| 160 | $(call if_changed_dep,cc_o_c) | ||
| 161 | |||
| 156 | $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE | 162 | $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE |
| 157 | $(call rule_mkdir) | 163 | $(call rule_mkdir) |
| 158 | $(call if_changed_dep,cc_o_c) | 164 | $(call if_changed_dep,cc_o_c) |
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 1dd1949b0e79..b795b6994144 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
| @@ -65,6 +65,11 @@ static int call__parse(struct ins_operands *ops) | |||
| 65 | 65 | ||
| 66 | name++; | 66 | name++; |
| 67 | 67 | ||
| 68 | #ifdef __arm__ | ||
| 69 | if (strchr(name, '+')) | ||
| 70 | return -1; | ||
| 71 | #endif | ||
| 72 | |||
| 68 | tok = strchr(name, '>'); | 73 | tok = strchr(name, '>'); |
| 69 | if (tok == NULL) | 74 | if (tok == NULL) |
| 70 | return -1; | 75 | return -1; |
| @@ -246,7 +251,11 @@ static int mov__parse(struct ins_operands *ops) | |||
| 246 | return -1; | 251 | return -1; |
| 247 | 252 | ||
| 248 | target = ++s; | 253 | target = ++s; |
| 254 | #ifdef __arm__ | ||
| 255 | comment = strchr(s, ';'); | ||
| 256 | #else | ||
| 249 | comment = strchr(s, '#'); | 257 | comment = strchr(s, '#'); |
| 258 | #endif | ||
| 250 | 259 | ||
| 251 | if (comment != NULL) | 260 | if (comment != NULL) |
| 252 | s = comment - 1; | 261 | s = comment - 1; |
| @@ -354,6 +363,20 @@ static struct ins instructions[] = { | |||
| 354 | { .name = "addq", .ops = &mov_ops, }, | 363 | { .name = "addq", .ops = &mov_ops, }, |
| 355 | { .name = "addw", .ops = &mov_ops, }, | 364 | { .name = "addw", .ops = &mov_ops, }, |
| 356 | { .name = "and", .ops = &mov_ops, }, | 365 | { .name = "and", .ops = &mov_ops, }, |
| 366 | #ifdef __arm__ | ||
| 367 | { .name = "b", .ops = &jump_ops, }, // might also be a call | ||
| 368 | { .name = "bcc", .ops = &jump_ops, }, | ||
| 369 | { .name = "bcs", .ops = &jump_ops, }, | ||
| 370 | { .name = "beq", .ops = &jump_ops, }, | ||
| 371 | { .name = "bge", .ops = &jump_ops, }, | ||
| 372 | { .name = "bgt", .ops = &jump_ops, }, | ||
| 373 | { .name = "bhi", .ops = &jump_ops, }, | ||
| 374 | { .name = "bl", .ops = &call_ops, }, | ||
| 375 | { .name = "blt", .ops = &jump_ops, }, | ||
| 376 | { .name = "bls", .ops = &jump_ops, }, | ||
| 377 | { .name = "blx", .ops = &call_ops, }, | ||
| 378 | { .name = "bne", .ops = &jump_ops, }, | ||
| 379 | #endif | ||
| 357 | { .name = "bts", .ops = &mov_ops, }, | 380 | { .name = "bts", .ops = &mov_ops, }, |
| 358 | { .name = "call", .ops = &call_ops, }, | 381 | { .name = "call", .ops = &call_ops, }, |
| 359 | { .name = "callq", .ops = &call_ops, }, | 382 | { .name = "callq", .ops = &call_ops, }, |
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 7f10430af39c..360fda01f3b0 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c | |||
| @@ -45,7 +45,7 @@ | |||
| 45 | #include "event.h" | 45 | #include "event.h" |
| 46 | #include "session.h" | 46 | #include "session.h" |
| 47 | #include "debug.h" | 47 | #include "debug.h" |
| 48 | #include "parse-options.h" | 48 | #include <subcmd/parse-options.h> |
| 49 | 49 | ||
| 50 | #include "intel-pt.h" | 50 | #include "intel-pt.h" |
| 51 | #include "intel-bts.h" | 51 | #include "intel-bts.h" |
diff --git a/tools/perf/util/bitmap.c b/tools/perf/util/bitmap.c deleted file mode 100644 index 0a1adc1111fd..000000000000 --- a/tools/perf/util/bitmap.c +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * From lib/bitmap.c | ||
| 3 | * Helper functions for bitmap.h. | ||
| 4 | * | ||
| 5 | * This source code is licensed under the GNU General Public License, | ||
| 6 | * Version 2. See the file COPYING for more details. | ||
| 7 | */ | ||
| 8 | #include <linux/bitmap.h> | ||
| 9 | |||
| 10 | int __bitmap_weight(const unsigned long *bitmap, int bits) | ||
| 11 | { | ||
| 12 | int k, w = 0, lim = bits/BITS_PER_LONG; | ||
| 13 | |||
| 14 | for (k = 0; k < lim; k++) | ||
| 15 | w += hweight_long(bitmap[k]); | ||
| 16 | |||
| 17 | if (bits % BITS_PER_LONG) | ||
| 18 | w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); | ||
| 19 | |||
| 20 | return w; | ||
| 21 | } | ||
| 22 | |||
| 23 | void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, | ||
| 24 | const unsigned long *bitmap2, int bits) | ||
| 25 | { | ||
| 26 | int k; | ||
| 27 | int nr = BITS_TO_LONGS(bits); | ||
| 28 | |||
| 29 | for (k = 0; k < nr; k++) | ||
| 30 | dst[k] = bitmap1[k] | bitmap2[k]; | ||
| 31 | } | ||
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 4c50411371db..540a7efa657e 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c | |||
| @@ -5,11 +5,15 @@ | |||
| 5 | * Copyright (C) 2015 Huawei Inc. | 5 | * Copyright (C) 2015 Huawei Inc. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <linux/bpf.h> | ||
| 8 | #include <bpf/libbpf.h> | 9 | #include <bpf/libbpf.h> |
| 9 | #include <linux/err.h> | 10 | #include <linux/err.h> |
| 11 | #include <linux/string.h> | ||
| 10 | #include "perf.h" | 12 | #include "perf.h" |
| 11 | #include "debug.h" | 13 | #include "debug.h" |
| 12 | #include "bpf-loader.h" | 14 | #include "bpf-loader.h" |
| 15 | #include "bpf-prologue.h" | ||
| 16 | #include "llvm-utils.h" | ||
| 13 | #include "probe-event.h" | 17 | #include "probe-event.h" |
| 14 | #include "probe-finder.h" // for MAX_PROBES | 18 | #include "probe-finder.h" // for MAX_PROBES |
| 15 | #include "llvm-utils.h" | 19 | #include "llvm-utils.h" |
| @@ -32,6 +36,10 @@ DEFINE_PRINT_FN(debug, 1) | |||
| 32 | 36 | ||
| 33 | struct bpf_prog_priv { | 37 | struct bpf_prog_priv { |
| 34 | struct perf_probe_event pev; | 38 | struct perf_probe_event pev; |
| 39 | bool need_prologue; | ||
| 40 | struct bpf_insn *insns_buf; | ||
| 41 | int nr_types; | ||
| 42 | int *type_mapping; | ||
| 35 | }; | 43 | }; |
| 36 | 44 | ||
| 37 | static bool libbpf_initialized; | 45 | static bool libbpf_initialized; |
| @@ -106,10 +114,178 @@ bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused, | |||
| 106 | struct bpf_prog_priv *priv = _priv; | 114 | struct bpf_prog_priv *priv = _priv; |
| 107 | 115 | ||
| 108 | cleanup_perf_probe_events(&priv->pev, 1); | 116 | cleanup_perf_probe_events(&priv->pev, 1); |
| 117 | zfree(&priv->insns_buf); | ||
| 118 | zfree(&priv->type_mapping); | ||
| 109 | free(priv); | 119 | free(priv); |
| 110 | } | 120 | } |
| 111 | 121 | ||
| 112 | static int | 122 | static int |
| 123 | prog_config__exec(const char *value, struct perf_probe_event *pev) | ||
| 124 | { | ||
| 125 | pev->uprobes = true; | ||
| 126 | pev->target = strdup(value); | ||
| 127 | if (!pev->target) | ||
| 128 | return -ENOMEM; | ||
| 129 | return 0; | ||
| 130 | } | ||
| 131 | |||
| 132 | static int | ||
| 133 | prog_config__module(const char *value, struct perf_probe_event *pev) | ||
| 134 | { | ||
| 135 | pev->uprobes = false; | ||
| 136 | pev->target = strdup(value); | ||
| 137 | if (!pev->target) | ||
| 138 | return -ENOMEM; | ||
| 139 | return 0; | ||
| 140 | } | ||
| 141 | |||
| 142 | static int | ||
| 143 | prog_config__bool(const char *value, bool *pbool, bool invert) | ||
| 144 | { | ||
| 145 | int err; | ||
| 146 | bool bool_value; | ||
| 147 | |||
| 148 | if (!pbool) | ||
| 149 | return -EINVAL; | ||
| 150 | |||
| 151 | err = strtobool(value, &bool_value); | ||
| 152 | if (err) | ||
| 153 | return err; | ||
| 154 | |||
| 155 | *pbool = invert ? !bool_value : bool_value; | ||
| 156 | return 0; | ||
| 157 | } | ||
| 158 | |||
| 159 | static int | ||
| 160 | prog_config__inlines(const char *value, | ||
| 161 | struct perf_probe_event *pev __maybe_unused) | ||
| 162 | { | ||
| 163 | return prog_config__bool(value, &probe_conf.no_inlines, true); | ||
| 164 | } | ||
| 165 | |||
| 166 | static int | ||
| 167 | prog_config__force(const char *value, | ||
| 168 | struct perf_probe_event *pev __maybe_unused) | ||
| 169 | { | ||
| 170 | return prog_config__bool(value, &probe_conf.force_add, false); | ||
| 171 | } | ||
| 172 | |||
| 173 | static struct { | ||
| 174 | const char *key; | ||
| 175 | const char *usage; | ||
| 176 | const char *desc; | ||
| 177 | int (*func)(const char *, struct perf_probe_event *); | ||
| 178 | } bpf_prog_config_terms[] = { | ||
| 179 | { | ||
| 180 | .key = "exec", | ||
| 181 | .usage = "exec=<full path of file>", | ||
| 182 | .desc = "Set uprobe target", | ||
| 183 | .func = prog_config__exec, | ||
| 184 | }, | ||
| 185 | { | ||
| 186 | .key = "module", | ||
| 187 | .usage = "module=<module name> ", | ||
| 188 | .desc = "Set kprobe module", | ||
| 189 | .func = prog_config__module, | ||
| 190 | }, | ||
| 191 | { | ||
| 192 | .key = "inlines", | ||
| 193 | .usage = "inlines=[yes|no] ", | ||
| 194 | .desc = "Probe at inline symbol", | ||
| 195 | .func = prog_config__inlines, | ||
| 196 | }, | ||
| 197 | { | ||
| 198 | .key = "force", | ||
| 199 | .usage = "force=[yes|no] ", | ||
| 200 | .desc = "Forcibly add events with existing name", | ||
| 201 | .func = prog_config__force, | ||
| 202 | }, | ||
| 203 | }; | ||
| 204 | |||
| 205 | static int | ||
| 206 | do_prog_config(const char *key, const char *value, | ||
| 207 | struct perf_probe_event *pev) | ||
| 208 | { | ||
| 209 | unsigned int i; | ||
| 210 | |||
| 211 | pr_debug("config bpf program: %s=%s\n", key, value); | ||
| 212 | for (i = 0; i < ARRAY_SIZE(bpf_prog_config_terms); i++) | ||
| 213 | if (strcmp(key, bpf_prog_config_terms[i].key) == 0) | ||
| 214 | return bpf_prog_config_terms[i].func(value, pev); | ||
| 215 | |||
| 216 | pr_debug("BPF: ERROR: invalid program config option: %s=%s\n", | ||
| 217 | key, value); | ||
| 218 | |||
| 219 | pr_debug("\nHint: Valid options are:\n"); | ||
| 220 | for (i = 0; i < ARRAY_SIZE(bpf_prog_config_terms); i++) | ||
| 221 | pr_debug("\t%s:\t%s\n", bpf_prog_config_terms[i].usage, | ||
| 222 | bpf_prog_config_terms[i].desc); | ||
| 223 | pr_debug("\n"); | ||
| 224 | |||
| 225 | return -BPF_LOADER_ERRNO__PROGCONF_TERM; | ||
| 226 | } | ||
| 227 | |||
| 228 | static const char * | ||
| 229 | parse_prog_config_kvpair(const char *config_str, struct perf_probe_event *pev) | ||
| 230 | { | ||
| 231 | char *text = strdup(config_str); | ||
| 232 | char *sep, *line; | ||
| 233 | const char *main_str = NULL; | ||
| 234 | int err = 0; | ||
| 235 | |||
| 236 | if (!text) { | ||
| 237 | pr_debug("No enough memory: dup config_str failed\n"); | ||
| 238 | return ERR_PTR(-ENOMEM); | ||
| 239 | } | ||
| 240 | |||
| 241 | line = text; | ||
| 242 | while ((sep = strchr(line, ';'))) { | ||
| 243 | char *equ; | ||
| 244 | |||
| 245 | *sep = '\0'; | ||
| 246 | equ = strchr(line, '='); | ||
| 247 | if (!equ) { | ||
| 248 | pr_warning("WARNING: invalid config in BPF object: %s\n", | ||
| 249 | line); | ||
| 250 | pr_warning("\tShould be 'key=value'.\n"); | ||
| 251 | goto nextline; | ||
| 252 | } | ||
| 253 | *equ = '\0'; | ||
| 254 | |||
| 255 | err = do_prog_config(line, equ + 1, pev); | ||
| 256 | if (err) | ||
| 257 | break; | ||
| 258 | nextline: | ||
| 259 | line = sep + 1; | ||
| 260 | } | ||
| 261 | |||
| 262 | if (!err) | ||
| 263 | main_str = config_str + (line - text); | ||
| 264 | free(text); | ||
| 265 | |||
| 266 | return err ? ERR_PTR(err) : main_str; | ||
| 267 | } | ||
| 268 | |||
| 269 | static int | ||
| 270 | parse_prog_config(const char *config_str, struct perf_probe_event *pev) | ||
| 271 | { | ||
| 272 | int err; | ||
| 273 | const char *main_str = parse_prog_config_kvpair(config_str, pev); | ||
| 274 | |||
| 275 | if (IS_ERR(main_str)) | ||
| 276 | return PTR_ERR(main_str); | ||
| 277 | |||
| 278 | err = parse_perf_probe_command(main_str, pev); | ||
| 279 | if (err < 0) { | ||
| 280 | pr_debug("bpf: '%s' is not a valid config string\n", | ||
| 281 | config_str); | ||
| 282 | /* parse failed, don't need clear pev. */ | ||
| 283 | return -BPF_LOADER_ERRNO__CONFIG; | ||
| 284 | } | ||
| 285 | return 0; | ||
| 286 | } | ||
| 287 | |||
| 288 | static int | ||
| 113 | config_bpf_program(struct bpf_program *prog) | 289 | config_bpf_program(struct bpf_program *prog) |
| 114 | { | 290 | { |
| 115 | struct perf_probe_event *pev = NULL; | 291 | struct perf_probe_event *pev = NULL; |
| @@ -117,6 +293,10 @@ config_bpf_program(struct bpf_program *prog) | |||
| 117 | const char *config_str; | 293 | const char *config_str; |
| 118 | int err; | 294 | int err; |
| 119 | 295 | ||
| 296 | /* Initialize per-program probing setting */ | ||
| 297 | probe_conf.no_inlines = false; | ||
| 298 | probe_conf.force_add = false; | ||
| 299 | |||
| 120 | config_str = bpf_program__title(prog, false); | 300 | config_str = bpf_program__title(prog, false); |
| 121 | if (IS_ERR(config_str)) { | 301 | if (IS_ERR(config_str)) { |
| 122 | pr_debug("bpf: unable to get title for program\n"); | 302 | pr_debug("bpf: unable to get title for program\n"); |
| @@ -131,13 +311,9 @@ config_bpf_program(struct bpf_program *prog) | |||
| 131 | pev = &priv->pev; | 311 | pev = &priv->pev; |
| 132 | 312 | ||
| 133 | pr_debug("bpf: config program '%s'\n", config_str); | 313 | pr_debug("bpf: config program '%s'\n", config_str); |
| 134 | err = parse_perf_probe_command(config_str, pev); | 314 | err = parse_prog_config(config_str, pev); |
| 135 | if (err < 0) { | 315 | if (err) |
| 136 | pr_debug("bpf: '%s' is not a valid config string\n", | ||
| 137 | config_str); | ||
| 138 | err = -BPF_LOADER_ERRNO__CONFIG; | ||
| 139 | goto errout; | 316 | goto errout; |
| 140 | } | ||
| 141 | 317 | ||
| 142 | if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) { | 318 | if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) { |
| 143 | pr_debug("bpf: '%s': group for event is set and not '%s'.\n", | 319 | pr_debug("bpf: '%s': group for event is set and not '%s'.\n", |
| @@ -197,6 +373,220 @@ static int bpf__prepare_probe(void) | |||
| 197 | return err; | 373 | return err; |
| 198 | } | 374 | } |
| 199 | 375 | ||
| 376 | static int | ||
| 377 | preproc_gen_prologue(struct bpf_program *prog, int n, | ||
| 378 | struct bpf_insn *orig_insns, int orig_insns_cnt, | ||
| 379 | struct bpf_prog_prep_result *res) | ||
| 380 | { | ||
| 381 | struct probe_trace_event *tev; | ||
| 382 | struct perf_probe_event *pev; | ||
| 383 | struct bpf_prog_priv *priv; | ||
| 384 | struct bpf_insn *buf; | ||
| 385 | size_t prologue_cnt = 0; | ||
| 386 | int i, err; | ||
| 387 | |||
| 388 | err = bpf_program__get_private(prog, (void **)&priv); | ||
| 389 | if (err || !priv) | ||
| 390 | goto errout; | ||
| 391 | |||
| 392 | pev = &priv->pev; | ||
| 393 | |||
| 394 | if (n < 0 || n >= priv->nr_types) | ||
| 395 | goto errout; | ||
| 396 | |||
| 397 | /* Find a tev belongs to that type */ | ||
| 398 | for (i = 0; i < pev->ntevs; i++) { | ||
| 399 | if (priv->type_mapping[i] == n) | ||
| 400 | break; | ||
| 401 | } | ||
| 402 | |||
| 403 | if (i >= pev->ntevs) { | ||
| 404 | pr_debug("Internal error: prologue type %d not found\n", n); | ||
| 405 | return -BPF_LOADER_ERRNO__PROLOGUE; | ||
| 406 | } | ||
| 407 | |||
| 408 | tev = &pev->tevs[i]; | ||
| 409 | |||
| 410 | buf = priv->insns_buf; | ||
| 411 | err = bpf__gen_prologue(tev->args, tev->nargs, | ||
| 412 | buf, &prologue_cnt, | ||
| 413 | BPF_MAXINSNS - orig_insns_cnt); | ||
| 414 | if (err) { | ||
| 415 | const char *title; | ||
| 416 | |||
| 417 | title = bpf_program__title(prog, false); | ||
| 418 | if (!title) | ||
| 419 | title = "[unknown]"; | ||
| 420 | |||
| 421 | pr_debug("Failed to generate prologue for program %s\n", | ||
| 422 | title); | ||
| 423 | return err; | ||
| 424 | } | ||
| 425 | |||
| 426 | memcpy(&buf[prologue_cnt], orig_insns, | ||
| 427 | sizeof(struct bpf_insn) * orig_insns_cnt); | ||
| 428 | |||
| 429 | res->new_insn_ptr = buf; | ||
| 430 | res->new_insn_cnt = prologue_cnt + orig_insns_cnt; | ||
| 431 | res->pfd = NULL; | ||
| 432 | return 0; | ||
| 433 | |||
| 434 | errout: | ||
| 435 | pr_debug("Internal error in preproc_gen_prologue\n"); | ||
| 436 | return -BPF_LOADER_ERRNO__PROLOGUE; | ||
| 437 | } | ||
| 438 | |||
| 439 | /* | ||
| 440 | * compare_tev_args is reflexive, transitive and antisymmetric. | ||
| 441 | * I can proof it but this margin is too narrow to contain. | ||
| 442 | */ | ||
| 443 | static int compare_tev_args(const void *ptev1, const void *ptev2) | ||
| 444 | { | ||
| 445 | int i, ret; | ||
| 446 | const struct probe_trace_event *tev1 = | ||
| 447 | *(const struct probe_trace_event **)ptev1; | ||
| 448 | const struct probe_trace_event *tev2 = | ||
| 449 | *(const struct probe_trace_event **)ptev2; | ||
| 450 | |||
| 451 | ret = tev2->nargs - tev1->nargs; | ||
| 452 | if (ret) | ||
| 453 | return ret; | ||
| 454 | |||
| 455 | for (i = 0; i < tev1->nargs; i++) { | ||
| 456 | struct probe_trace_arg *arg1, *arg2; | ||
| 457 | struct probe_trace_arg_ref *ref1, *ref2; | ||
| 458 | |||
| 459 | arg1 = &tev1->args[i]; | ||
| 460 | arg2 = &tev2->args[i]; | ||
| 461 | |||
| 462 | ret = strcmp(arg1->value, arg2->value); | ||
| 463 | if (ret) | ||
| 464 | return ret; | ||
| 465 | |||
| 466 | ref1 = arg1->ref; | ||
| 467 | ref2 = arg2->ref; | ||
| 468 | |||
| 469 | while (ref1 && ref2) { | ||
| 470 | ret = ref2->offset - ref1->offset; | ||
| 471 | if (ret) | ||
| 472 | return ret; | ||
| 473 | |||
| 474 | ref1 = ref1->next; | ||
| 475 | ref2 = ref2->next; | ||
| 476 | } | ||
| 477 | |||
| 478 | if (ref1 || ref2) | ||
| 479 | return ref2 ? 1 : -1; | ||
| 480 | } | ||
| 481 | |||
| 482 | return 0; | ||
| 483 | } | ||
| 484 | |||
| 485 | /* | ||
| 486 | * Assign a type number to each tevs in a pev. | ||
| 487 | * mapping is an array with same slots as tevs in that pev. | ||
| 488 | * nr_types will be set to number of types. | ||
| 489 | */ | ||
| 490 | static int map_prologue(struct perf_probe_event *pev, int *mapping, | ||
| 491 | int *nr_types) | ||
| 492 | { | ||
| 493 | int i, type = 0; | ||
| 494 | struct probe_trace_event **ptevs; | ||
| 495 | |||
| 496 | size_t array_sz = sizeof(*ptevs) * pev->ntevs; | ||
| 497 | |||
| 498 | ptevs = malloc(array_sz); | ||
| 499 | if (!ptevs) { | ||
| 500 | pr_debug("No ehough memory: alloc ptevs failed\n"); | ||
| 501 | return -ENOMEM; | ||
| 502 | } | ||
| 503 | |||
| 504 | pr_debug("In map_prologue, ntevs=%d\n", pev->ntevs); | ||
| 505 | for (i = 0; i < pev->ntevs; i++) | ||
| 506 | ptevs[i] = &pev->tevs[i]; | ||
| 507 | |||
| 508 | qsort(ptevs, pev->ntevs, sizeof(*ptevs), | ||
| 509 | compare_tev_args); | ||
| 510 | |||
| 511 | for (i = 0; i < pev->ntevs; i++) { | ||
| 512 | int n; | ||
| 513 | |||
| 514 | n = ptevs[i] - pev->tevs; | ||
| 515 | if (i == 0) { | ||
| 516 | mapping[n] = type; | ||
| 517 | pr_debug("mapping[%d]=%d\n", n, type); | ||
| 518 | continue; | ||
| 519 | } | ||
| 520 | |||
| 521 | if (compare_tev_args(ptevs + i, ptevs + i - 1) == 0) | ||
| 522 | mapping[n] = type; | ||
| 523 | else | ||
| 524 | mapping[n] = ++type; | ||
| 525 | |||
| 526 | pr_debug("mapping[%d]=%d\n", n, mapping[n]); | ||
| 527 | } | ||
| 528 | free(ptevs); | ||
| 529 | *nr_types = type + 1; | ||
| 530 | |||
| 531 | return 0; | ||
| 532 | } | ||
| 533 | |||
| 534 | static int hook_load_preprocessor(struct bpf_program *prog) | ||
| 535 | { | ||
| 536 | struct perf_probe_event *pev; | ||
| 537 | struct bpf_prog_priv *priv; | ||
| 538 | bool need_prologue = false; | ||
| 539 | int err, i; | ||
| 540 | |||
| 541 | err = bpf_program__get_private(prog, (void **)&priv); | ||
| 542 | if (err || !priv) { | ||
| 543 | pr_debug("Internal error when hook preprocessor\n"); | ||
| 544 | return -BPF_LOADER_ERRNO__INTERNAL; | ||
| 545 | } | ||
| 546 | |||
| 547 | pev = &priv->pev; | ||
| 548 | for (i = 0; i < pev->ntevs; i++) { | ||
| 549 | struct probe_trace_event *tev = &pev->tevs[i]; | ||
| 550 | |||
| 551 | if (tev->nargs > 0) { | ||
| 552 | need_prologue = true; | ||
| 553 | break; | ||
| 554 | } | ||
| 555 | } | ||
| 556 | |||
| 557 | /* | ||
| 558 | * Since all tevs don't have argument, we don't need generate | ||
| 559 | * prologue. | ||
| 560 | */ | ||
| 561 | if (!need_prologue) { | ||
| 562 | priv->need_prologue = false; | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | |||
| 566 | priv->need_prologue = true; | ||
| 567 | priv->insns_buf = malloc(sizeof(struct bpf_insn) * BPF_MAXINSNS); | ||
| 568 | if (!priv->insns_buf) { | ||
| 569 | pr_debug("No enough memory: alloc insns_buf failed\n"); | ||
| 570 | return -ENOMEM; | ||
| 571 | } | ||
| 572 | |||
| 573 | priv->type_mapping = malloc(sizeof(int) * pev->ntevs); | ||
| 574 | if (!priv->type_mapping) { | ||
| 575 | pr_debug("No enough memory: alloc type_mapping failed\n"); | ||
| 576 | return -ENOMEM; | ||
| 577 | } | ||
| 578 | memset(priv->type_mapping, -1, | ||
| 579 | sizeof(int) * pev->ntevs); | ||
| 580 | |||
| 581 | err = map_prologue(pev, priv->type_mapping, &priv->nr_types); | ||
| 582 | if (err) | ||
| 583 | return err; | ||
| 584 | |||
| 585 | err = bpf_program__set_prep(prog, priv->nr_types, | ||
| 586 | preproc_gen_prologue); | ||
| 587 | return err; | ||
| 588 | } | ||
| 589 | |||
| 200 | int bpf__probe(struct bpf_object *obj) | 590 | int bpf__probe(struct bpf_object *obj) |
| 201 | { | 591 | { |
| 202 | int err = 0; | 592 | int err = 0; |
| @@ -231,6 +621,18 @@ int bpf__probe(struct bpf_object *obj) | |||
| 231 | pr_debug("bpf_probe: failed to apply perf probe events"); | 621 | pr_debug("bpf_probe: failed to apply perf probe events"); |
| 232 | goto out; | 622 | goto out; |
| 233 | } | 623 | } |
| 624 | |||
| 625 | /* | ||
| 626 | * After probing, let's consider prologue, which | ||
| 627 | * adds program fetcher to BPF programs. | ||
| 628 | * | ||
| 629 | * hook_load_preprocessorr() hooks pre-processor | ||
| 630 | * to bpf_program, let it generate prologue | ||
| 631 | * dynamically during loading. | ||
| 632 | */ | ||
| 633 | err = hook_load_preprocessor(prog); | ||
| 634 | if (err) | ||
| 635 | goto out; | ||
| 234 | } | 636 | } |
| 235 | out: | 637 | out: |
| 236 | return err < 0 ? err : 0; | 638 | return err < 0 ? err : 0; |
| @@ -314,7 +716,14 @@ int bpf__foreach_tev(struct bpf_object *obj, | |||
| 314 | for (i = 0; i < pev->ntevs; i++) { | 716 | for (i = 0; i < pev->ntevs; i++) { |
| 315 | tev = &pev->tevs[i]; | 717 | tev = &pev->tevs[i]; |
| 316 | 718 | ||
| 317 | fd = bpf_program__fd(prog); | 719 | if (priv->need_prologue) { |
| 720 | int type = priv->type_mapping[i]; | ||
| 721 | |||
| 722 | fd = bpf_program__nth_fd(prog, type); | ||
| 723 | } else { | ||
| 724 | fd = bpf_program__fd(prog); | ||
| 725 | } | ||
| 726 | |||
| 318 | if (fd < 0) { | 727 | if (fd < 0) { |
| 319 | pr_debug("bpf: failed to get file descriptor\n"); | 728 | pr_debug("bpf: failed to get file descriptor\n"); |
| 320 | return fd; | 729 | return fd; |
| @@ -340,6 +749,10 @@ static const char *bpf_loader_strerror_table[NR_ERRNO] = { | |||
| 340 | [ERRCODE_OFFSET(EVENTNAME)] = "No event name found in config string", | 749 | [ERRCODE_OFFSET(EVENTNAME)] = "No event name found in config string", |
| 341 | [ERRCODE_OFFSET(INTERNAL)] = "BPF loader internal error", | 750 | [ERRCODE_OFFSET(INTERNAL)] = "BPF loader internal error", |
| 342 | [ERRCODE_OFFSET(COMPILE)] = "Error when compiling BPF scriptlet", | 751 | [ERRCODE_OFFSET(COMPILE)] = "Error when compiling BPF scriptlet", |
| 752 | [ERRCODE_OFFSET(PROGCONF_TERM)] = "Invalid program config term in config string", | ||
| 753 | [ERRCODE_OFFSET(PROLOGUE)] = "Failed to generate prologue", | ||
| 754 | [ERRCODE_OFFSET(PROLOGUE2BIG)] = "Prologue too big for program", | ||
| 755 | [ERRCODE_OFFSET(PROLOGUEOOB)] = "Offset out of bound for prologue", | ||
| 343 | }; | 756 | }; |
| 344 | 757 | ||
| 345 | static int | 758 | static int |
| @@ -420,7 +833,11 @@ int bpf__strerror_probe(struct bpf_object *obj __maybe_unused, | |||
| 420 | int err, char *buf, size_t size) | 833 | int err, char *buf, size_t size) |
| 421 | { | 834 | { |
| 422 | bpf__strerror_head(err, buf, size); | 835 | bpf__strerror_head(err, buf, size); |
| 423 | bpf__strerror_entry(EEXIST, "Probe point exist. Try use 'perf probe -d \"*\"'"); | 836 | case BPF_LOADER_ERRNO__PROGCONF_TERM: { |
| 837 | scnprintf(buf, size, "%s (add -v to see detail)", emsg); | ||
| 838 | break; | ||
| 839 | } | ||
| 840 | bpf__strerror_entry(EEXIST, "Probe point exist. Try 'perf probe -d \"*\"' and set 'force=yes'"); | ||
| 424 | bpf__strerror_entry(EACCES, "You need to be root"); | 841 | bpf__strerror_entry(EACCES, "You need to be root"); |
| 425 | bpf__strerror_entry(EPERM, "You need to be root, and /proc/sys/kernel/kptr_restrict should be 0"); | 842 | bpf__strerror_entry(EPERM, "You need to be root, and /proc/sys/kernel/kptr_restrict should be 0"); |
| 426 | bpf__strerror_entry(ENOENT, "You need to check probing points in BPF file"); | 843 | bpf__strerror_entry(ENOENT, "You need to check probing points in BPF file"); |
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index 9caf3ae4acf3..6fdc0457e2b6 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h | |||
| @@ -20,6 +20,10 @@ enum bpf_loader_errno { | |||
| 20 | BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */ | 20 | BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */ |
| 21 | BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */ | 21 | BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */ |
| 22 | BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */ | 22 | BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */ |
| 23 | BPF_LOADER_ERRNO__PROGCONF_TERM,/* Invalid program config term in config string */ | ||
| 24 | BPF_LOADER_ERRNO__PROLOGUE, /* Failed to generate prologue */ | ||
| 25 | BPF_LOADER_ERRNO__PROLOGUE2BIG, /* Prologue too big for program */ | ||
| 26 | BPF_LOADER_ERRNO__PROLOGUEOOB, /* Offset out of bound for prologue */ | ||
| 23 | __BPF_LOADER_ERRNO__END, | 27 | __BPF_LOADER_ERRNO__END, |
| 24 | }; | 28 | }; |
| 25 | 29 | ||
diff --git a/tools/perf/util/bpf-prologue.c b/tools/perf/util/bpf-prologue.c new file mode 100644 index 000000000000..6cdbee119ceb --- /dev/null +++ b/tools/perf/util/bpf-prologue.c | |||
| @@ -0,0 +1,455 @@ | |||
| 1 | /* | ||
| 2 | * bpf-prologue.c | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 He Kuang <hekuang@huawei.com> | ||
| 5 | * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com> | ||
| 6 | * Copyright (C) 2015 Huawei Inc. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <bpf/libbpf.h> | ||
| 10 | #include "perf.h" | ||
| 11 | #include "debug.h" | ||
| 12 | #include "bpf-loader.h" | ||
| 13 | #include "bpf-prologue.h" | ||
| 14 | #include "probe-finder.h" | ||
| 15 | #include <dwarf-regs.h> | ||
| 16 | #include <linux/filter.h> | ||
| 17 | |||
| 18 | #define BPF_REG_SIZE 8 | ||
| 19 | |||
| 20 | #define JMP_TO_ERROR_CODE -1 | ||
| 21 | #define JMP_TO_SUCCESS_CODE -2 | ||
| 22 | #define JMP_TO_USER_CODE -3 | ||
| 23 | |||
| 24 | struct bpf_insn_pos { | ||
| 25 | struct bpf_insn *begin; | ||
| 26 | struct bpf_insn *end; | ||
| 27 | struct bpf_insn *pos; | ||
| 28 | }; | ||
| 29 | |||
| 30 | static inline int | ||
| 31 | pos_get_cnt(struct bpf_insn_pos *pos) | ||
| 32 | { | ||
| 33 | return pos->pos - pos->begin; | ||
| 34 | } | ||
| 35 | |||
| 36 | static int | ||
| 37 | append_insn(struct bpf_insn new_insn, struct bpf_insn_pos *pos) | ||
| 38 | { | ||
| 39 | if (!pos->pos) | ||
| 40 | return -BPF_LOADER_ERRNO__PROLOGUE2BIG; | ||
| 41 | |||
| 42 | if (pos->pos + 1 >= pos->end) { | ||
| 43 | pr_err("bpf prologue: prologue too long\n"); | ||
| 44 | pos->pos = NULL; | ||
| 45 | return -BPF_LOADER_ERRNO__PROLOGUE2BIG; | ||
| 46 | } | ||
| 47 | |||
| 48 | *(pos->pos)++ = new_insn; | ||
| 49 | return 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | static int | ||
| 53 | check_pos(struct bpf_insn_pos *pos) | ||
| 54 | { | ||
| 55 | if (!pos->pos || pos->pos >= pos->end) | ||
| 56 | return -BPF_LOADER_ERRNO__PROLOGUE2BIG; | ||
| 57 | return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | /* Give it a shorter name */ | ||
| 61 | #define ins(i, p) append_insn((i), (p)) | ||
| 62 | |||
| 63 | /* | ||
| 64 | * Give a register name (in 'reg'), generate instruction to | ||
| 65 | * load register into an eBPF register rd: | ||
| 66 | * 'ldd target_reg, offset(ctx_reg)', where: | ||
| 67 | * ctx_reg is pre initialized to pointer of 'struct pt_regs'. | ||
| 68 | */ | ||
| 69 | static int | ||
| 70 | gen_ldx_reg_from_ctx(struct bpf_insn_pos *pos, int ctx_reg, | ||
| 71 | const char *reg, int target_reg) | ||
| 72 | { | ||
| 73 | int offset = regs_query_register_offset(reg); | ||
| 74 | |||
| 75 | if (offset < 0) { | ||
| 76 | pr_err("bpf: prologue: failed to get register %s\n", | ||
| 77 | reg); | ||
| 78 | return offset; | ||
| 79 | } | ||
| 80 | ins(BPF_LDX_MEM(BPF_DW, target_reg, ctx_reg, offset), pos); | ||
| 81 | |||
| 82 | return check_pos(pos); | ||
| 83 | } | ||
| 84 | |||
| 85 | /* | ||
| 86 | * Generate a BPF_FUNC_probe_read function call. | ||
| 87 | * | ||
| 88 | * src_base_addr_reg is a register holding base address, | ||
| 89 | * dst_addr_reg is a register holding dest address (on stack), | ||
| 90 | * result is: | ||
| 91 | * | ||
| 92 | * *[dst_addr_reg] = *([src_base_addr_reg] + offset) | ||
| 93 | * | ||
| 94 | * Arguments of BPF_FUNC_probe_read: | ||
| 95 | * ARG1: ptr to stack (dest) | ||
| 96 | * ARG2: size (8) | ||
| 97 | * ARG3: unsafe ptr (src) | ||
| 98 | */ | ||
| 99 | static int | ||
| 100 | gen_read_mem(struct bpf_insn_pos *pos, | ||
| 101 | int src_base_addr_reg, | ||
| 102 | int dst_addr_reg, | ||
| 103 | long offset) | ||
| 104 | { | ||
| 105 | /* mov arg3, src_base_addr_reg */ | ||
| 106 | if (src_base_addr_reg != BPF_REG_ARG3) | ||
| 107 | ins(BPF_MOV64_REG(BPF_REG_ARG3, src_base_addr_reg), pos); | ||
| 108 | /* add arg3, #offset */ | ||
| 109 | if (offset) | ||
| 110 | ins(BPF_ALU64_IMM(BPF_ADD, BPF_REG_ARG3, offset), pos); | ||
| 111 | |||
| 112 | /* mov arg2, #reg_size */ | ||
| 113 | ins(BPF_ALU64_IMM(BPF_MOV, BPF_REG_ARG2, BPF_REG_SIZE), pos); | ||
| 114 | |||
| 115 | /* mov arg1, dst_addr_reg */ | ||
| 116 | if (dst_addr_reg != BPF_REG_ARG1) | ||
| 117 | ins(BPF_MOV64_REG(BPF_REG_ARG1, dst_addr_reg), pos); | ||
| 118 | |||
| 119 | /* Call probe_read */ | ||
| 120 | ins(BPF_EMIT_CALL(BPF_FUNC_probe_read), pos); | ||
| 121 | /* | ||
| 122 | * Error processing: if read fail, goto error code, | ||
| 123 | * will be relocated. Target should be the start of | ||
| 124 | * error processing code. | ||
| 125 | */ | ||
| 126 | ins(BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, JMP_TO_ERROR_CODE), | ||
| 127 | pos); | ||
| 128 | |||
| 129 | return check_pos(pos); | ||
| 130 | } | ||
| 131 | |||
| 132 | /* | ||
| 133 | * Each arg should be bare register. Fetch and save them into argument | ||
| 134 | * registers (r3 - r5). | ||
| 135 | * | ||
| 136 | * BPF_REG_1 should have been initialized with pointer to | ||
| 137 | * 'struct pt_regs'. | ||
| 138 | */ | ||
| 139 | static int | ||
| 140 | gen_prologue_fastpath(struct bpf_insn_pos *pos, | ||
| 141 | struct probe_trace_arg *args, int nargs) | ||
| 142 | { | ||
| 143 | int i, err = 0; | ||
| 144 | |||
| 145 | for (i = 0; i < nargs; i++) { | ||
| 146 | err = gen_ldx_reg_from_ctx(pos, BPF_REG_1, args[i].value, | ||
| 147 | BPF_PROLOGUE_START_ARG_REG + i); | ||
| 148 | if (err) | ||
| 149 | goto errout; | ||
| 150 | } | ||
| 151 | |||
| 152 | return check_pos(pos); | ||
| 153 | errout: | ||
| 154 | return err; | ||
| 155 | } | ||
| 156 | |||
| 157 | /* | ||
| 158 | * Slow path: | ||
| 159 | * At least one argument has the form of 'offset($rx)'. | ||
| 160 | * | ||
| 161 | * Following code first stores them into stack, then loads all of then | ||
| 162 | * to r2 - r5. | ||
| 163 | * Before final loading, the final result should be: | ||
| 164 | * | ||
| 165 | * low address | ||
| 166 | * BPF_REG_FP - 24 ARG3 | ||
| 167 | * BPF_REG_FP - 16 ARG2 | ||
| 168 | * BPF_REG_FP - 8 ARG1 | ||
| 169 | * BPF_REG_FP | ||
| 170 | * high address | ||
| 171 | * | ||
| 172 | * For each argument (described as: offn(...off2(off1(reg)))), | ||
| 173 | * generates following code: | ||
| 174 | * | ||
| 175 | * r7 <- fp | ||
| 176 | * r7 <- r7 - stack_offset // Ideal code should initialize r7 using | ||
| 177 | * // fp before generating args. However, | ||
| 178 | * // eBPF won't regard r7 as stack pointer | ||
| 179 | * // if it is generated by minus 8 from | ||
| 180 | * // another stack pointer except fp. | ||
| 181 | * // This is why we have to set r7 | ||
| 182 | * // to fp for each variable. | ||
| 183 | * r3 <- value of 'reg'-> generated using gen_ldx_reg_from_ctx() | ||
| 184 | * (r7) <- r3 // skip following instructions for bare reg | ||
| 185 | * r3 <- r3 + off1 . // skip if off1 == 0 | ||
| 186 | * r2 <- 8 \ | ||
| 187 | * r1 <- r7 |-> generated by gen_read_mem() | ||
| 188 | * call probe_read / | ||
| 189 | * jnei r0, 0, err ./ | ||
| 190 | * r3 <- (r7) | ||
| 191 | * r3 <- r3 + off2 . // skip if off2 == 0 | ||
| 192 | * r2 <- 8 \ // r2 may be broken by probe_read, so set again | ||
| 193 | * r1 <- r7 |-> generated by gen_read_mem() | ||
| 194 | * call probe_read / | ||
| 195 | * jnei r0, 0, err ./ | ||
| 196 | * ... | ||
| 197 | */ | ||
| 198 | static int | ||
| 199 | gen_prologue_slowpath(struct bpf_insn_pos *pos, | ||
| 200 | struct probe_trace_arg *args, int nargs) | ||
| 201 | { | ||
| 202 | int err, i; | ||
| 203 | |||
| 204 | for (i = 0; i < nargs; i++) { | ||
| 205 | struct probe_trace_arg *arg = &args[i]; | ||
| 206 | const char *reg = arg->value; | ||
| 207 | struct probe_trace_arg_ref *ref = NULL; | ||
| 208 | int stack_offset = (i + 1) * -8; | ||
| 209 | |||
| 210 | pr_debug("prologue: fetch arg %d, base reg is %s\n", | ||
| 211 | i, reg); | ||
| 212 | |||
| 213 | /* value of base register is stored into ARG3 */ | ||
| 214 | err = gen_ldx_reg_from_ctx(pos, BPF_REG_CTX, reg, | ||
| 215 | BPF_REG_ARG3); | ||
| 216 | if (err) { | ||
| 217 | pr_err("prologue: failed to get offset of register %s\n", | ||
| 218 | reg); | ||
| 219 | goto errout; | ||
| 220 | } | ||
| 221 | |||
| 222 | /* Make r7 the stack pointer. */ | ||
| 223 | ins(BPF_MOV64_REG(BPF_REG_7, BPF_REG_FP), pos); | ||
| 224 | /* r7 += -8 */ | ||
| 225 | ins(BPF_ALU64_IMM(BPF_ADD, BPF_REG_7, stack_offset), pos); | ||
| 226 | /* | ||
| 227 | * Store r3 (base register) onto stack | ||
| 228 | * Ensure fp[offset] is set. | ||
| 229 | * fp is the only valid base register when storing | ||
| 230 | * into stack. We are not allowed to use r7 as base | ||
| 231 | * register here. | ||
| 232 | */ | ||
| 233 | ins(BPF_STX_MEM(BPF_DW, BPF_REG_FP, BPF_REG_ARG3, | ||
| 234 | stack_offset), pos); | ||
| 235 | |||
| 236 | ref = arg->ref; | ||
| 237 | while (ref) { | ||
| 238 | pr_debug("prologue: arg %d: offset %ld\n", | ||
| 239 | i, ref->offset); | ||
| 240 | err = gen_read_mem(pos, BPF_REG_3, BPF_REG_7, | ||
| 241 | ref->offset); | ||
| 242 | if (err) { | ||
| 243 | pr_err("prologue: failed to generate probe_read function call\n"); | ||
| 244 | goto errout; | ||
| 245 | } | ||
| 246 | |||
| 247 | ref = ref->next; | ||
| 248 | /* | ||
| 249 | * Load previous result into ARG3. Use | ||
| 250 | * BPF_REG_FP instead of r7 because verifier | ||
| 251 | * allows FP based addressing only. | ||
| 252 | */ | ||
| 253 | if (ref) | ||
| 254 | ins(BPF_LDX_MEM(BPF_DW, BPF_REG_ARG3, | ||
| 255 | BPF_REG_FP, stack_offset), pos); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | /* Final pass: read to registers */ | ||
| 260 | for (i = 0; i < nargs; i++) | ||
| 261 | ins(BPF_LDX_MEM(BPF_DW, BPF_PROLOGUE_START_ARG_REG + i, | ||
| 262 | BPF_REG_FP, -BPF_REG_SIZE * (i + 1)), pos); | ||
| 263 | |||
| 264 | ins(BPF_JMP_IMM(BPF_JA, BPF_REG_0, 0, JMP_TO_SUCCESS_CODE), pos); | ||
| 265 | |||
| 266 | return check_pos(pos); | ||
| 267 | errout: | ||
| 268 | return err; | ||
| 269 | } | ||
| 270 | |||
| 271 | static int | ||
| 272 | prologue_relocate(struct bpf_insn_pos *pos, struct bpf_insn *error_code, | ||
| 273 | struct bpf_insn *success_code, struct bpf_insn *user_code) | ||
| 274 | { | ||
| 275 | struct bpf_insn *insn; | ||
| 276 | |||
| 277 | if (check_pos(pos)) | ||
| 278 | return -BPF_LOADER_ERRNO__PROLOGUE2BIG; | ||
| 279 | |||
| 280 | for (insn = pos->begin; insn < pos->pos; insn++) { | ||
| 281 | struct bpf_insn *target; | ||
| 282 | u8 class = BPF_CLASS(insn->code); | ||
| 283 | u8 opcode; | ||
| 284 | |||
| 285 | if (class != BPF_JMP) | ||
| 286 | continue; | ||
| 287 | opcode = BPF_OP(insn->code); | ||
| 288 | if (opcode == BPF_CALL) | ||
| 289 | continue; | ||
| 290 | |||
| 291 | switch (insn->off) { | ||
| 292 | case JMP_TO_ERROR_CODE: | ||
| 293 | target = error_code; | ||
| 294 | break; | ||
| 295 | case JMP_TO_SUCCESS_CODE: | ||
| 296 | target = success_code; | ||
| 297 | break; | ||
| 298 | case JMP_TO_USER_CODE: | ||
| 299 | target = user_code; | ||
| 300 | break; | ||
| 301 | default: | ||
| 302 | pr_err("bpf prologue: internal error: relocation failed\n"); | ||
| 303 | return -BPF_LOADER_ERRNO__PROLOGUE; | ||
| 304 | } | ||
| 305 | |||
| 306 | insn->off = target - (insn + 1); | ||
| 307 | } | ||
| 308 | return 0; | ||
| 309 | } | ||
| 310 | |||
| 311 | int bpf__gen_prologue(struct probe_trace_arg *args, int nargs, | ||
| 312 | struct bpf_insn *new_prog, size_t *new_cnt, | ||
| 313 | size_t cnt_space) | ||
| 314 | { | ||
| 315 | struct bpf_insn *success_code = NULL; | ||
| 316 | struct bpf_insn *error_code = NULL; | ||
| 317 | struct bpf_insn *user_code = NULL; | ||
| 318 | struct bpf_insn_pos pos; | ||
| 319 | bool fastpath = true; | ||
| 320 | int err = 0, i; | ||
| 321 | |||
| 322 | if (!new_prog || !new_cnt) | ||
| 323 | return -EINVAL; | ||
| 324 | |||
| 325 | if (cnt_space > BPF_MAXINSNS) | ||
| 326 | cnt_space = BPF_MAXINSNS; | ||
| 327 | |||
| 328 | pos.begin = new_prog; | ||
| 329 | pos.end = new_prog + cnt_space; | ||
| 330 | pos.pos = new_prog; | ||
| 331 | |||
| 332 | if (!nargs) { | ||
| 333 | ins(BPF_ALU64_IMM(BPF_MOV, BPF_PROLOGUE_FETCH_RESULT_REG, 0), | ||
| 334 | &pos); | ||
| 335 | |||
| 336 | if (check_pos(&pos)) | ||
| 337 | goto errout; | ||
| 338 | |||
| 339 | *new_cnt = pos_get_cnt(&pos); | ||
| 340 | return 0; | ||
| 341 | } | ||
| 342 | |||
| 343 | if (nargs > BPF_PROLOGUE_MAX_ARGS) { | ||
| 344 | pr_warning("bpf: prologue: %d arguments are dropped\n", | ||
| 345 | nargs - BPF_PROLOGUE_MAX_ARGS); | ||
| 346 | nargs = BPF_PROLOGUE_MAX_ARGS; | ||
| 347 | } | ||
| 348 | |||
| 349 | /* First pass: validation */ | ||
| 350 | for (i = 0; i < nargs; i++) { | ||
| 351 | struct probe_trace_arg_ref *ref = args[i].ref; | ||
| 352 | |||
| 353 | if (args[i].value[0] == '@') { | ||
| 354 | /* TODO: fetch global variable */ | ||
| 355 | pr_err("bpf: prologue: global %s%+ld not support\n", | ||
| 356 | args[i].value, ref ? ref->offset : 0); | ||
| 357 | return -ENOTSUP; | ||
| 358 | } | ||
| 359 | |||
| 360 | while (ref) { | ||
| 361 | /* fastpath is true if all args has ref == NULL */ | ||
| 362 | fastpath = false; | ||
| 363 | |||
| 364 | /* | ||
| 365 | * Instruction encodes immediate value using | ||
| 366 | * s32, ref->offset is long. On systems which | ||
| 367 | * can't fill long in s32, refuse to process if | ||
| 368 | * ref->offset too large (or small). | ||
| 369 | */ | ||
| 370 | #ifdef __LP64__ | ||
| 371 | #define OFFSET_MAX ((1LL << 31) - 1) | ||
| 372 | #define OFFSET_MIN ((1LL << 31) * -1) | ||
| 373 | if (ref->offset > OFFSET_MAX || | ||
| 374 | ref->offset < OFFSET_MIN) { | ||
| 375 | pr_err("bpf: prologue: offset out of bound: %ld\n", | ||
| 376 | ref->offset); | ||
| 377 | return -BPF_LOADER_ERRNO__PROLOGUEOOB; | ||
| 378 | } | ||
| 379 | #endif | ||
| 380 | ref = ref->next; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | pr_debug("prologue: pass validation\n"); | ||
| 384 | |||
| 385 | if (fastpath) { | ||
| 386 | /* If all variables are registers... */ | ||
| 387 | pr_debug("prologue: fast path\n"); | ||
| 388 | err = gen_prologue_fastpath(&pos, args, nargs); | ||
| 389 | if (err) | ||
| 390 | goto errout; | ||
| 391 | } else { | ||
| 392 | pr_debug("prologue: slow path\n"); | ||
| 393 | |||
| 394 | /* Initialization: move ctx to a callee saved register. */ | ||
| 395 | ins(BPF_MOV64_REG(BPF_REG_CTX, BPF_REG_ARG1), &pos); | ||
| 396 | |||
| 397 | err = gen_prologue_slowpath(&pos, args, nargs); | ||
| 398 | if (err) | ||
| 399 | goto errout; | ||
| 400 | /* | ||
| 401 | * start of ERROR_CODE (only slow pass needs error code) | ||
| 402 | * mov r2 <- 1 // r2 is error number | ||
| 403 | * mov r3 <- 0 // r3, r4... should be touched or | ||
| 404 | * // verifier would complain | ||
| 405 | * mov r4 <- 0 | ||
| 406 | * ... | ||
| 407 | * goto usercode | ||
| 408 | */ | ||
| 409 | error_code = pos.pos; | ||
| 410 | ins(BPF_ALU64_IMM(BPF_MOV, BPF_PROLOGUE_FETCH_RESULT_REG, 1), | ||
| 411 | &pos); | ||
| 412 | |||
| 413 | for (i = 0; i < nargs; i++) | ||
| 414 | ins(BPF_ALU64_IMM(BPF_MOV, | ||
| 415 | BPF_PROLOGUE_START_ARG_REG + i, | ||
| 416 | 0), | ||
| 417 | &pos); | ||
| 418 | ins(BPF_JMP_IMM(BPF_JA, BPF_REG_0, 0, JMP_TO_USER_CODE), | ||
| 419 | &pos); | ||
| 420 | } | ||
| 421 | |||
| 422 | /* | ||
| 423 | * start of SUCCESS_CODE: | ||
| 424 | * mov r2 <- 0 | ||
| 425 | * goto usercode // skip | ||
| 426 | */ | ||
| 427 | success_code = pos.pos; | ||
| 428 | ins(BPF_ALU64_IMM(BPF_MOV, BPF_PROLOGUE_FETCH_RESULT_REG, 0), &pos); | ||
| 429 | |||
| 430 | /* | ||
| 431 | * start of USER_CODE: | ||
| 432 | * Restore ctx to r1 | ||
| 433 | */ | ||
| 434 | user_code = pos.pos; | ||
| 435 | if (!fastpath) { | ||
| 436 | /* | ||
| 437 | * Only slow path needs restoring of ctx. In fast path, | ||
| 438 | * register are loaded directly from r1. | ||
| 439 | */ | ||
| 440 | ins(BPF_MOV64_REG(BPF_REG_ARG1, BPF_REG_CTX), &pos); | ||
| 441 | err = prologue_relocate(&pos, error_code, success_code, | ||
| 442 | user_code); | ||
| 443 | if (err) | ||
| 444 | goto errout; | ||
| 445 | } | ||
| 446 | |||
| 447 | err = check_pos(&pos); | ||
| 448 | if (err) | ||
| 449 | goto errout; | ||
| 450 | |||
| 451 | *new_cnt = pos_get_cnt(&pos); | ||
| 452 | return 0; | ||
| 453 | errout: | ||
| 454 | return err; | ||
| 455 | } | ||
diff --git a/tools/perf/util/bpf-prologue.h b/tools/perf/util/bpf-prologue.h new file mode 100644 index 000000000000..d94cbea12899 --- /dev/null +++ b/tools/perf/util/bpf-prologue.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2015, He Kuang <hekuang@huawei.com> | ||
| 3 | * Copyright (C) 2015, Huawei Inc. | ||
| 4 | */ | ||
| 5 | #ifndef __BPF_PROLOGUE_H | ||
| 6 | #define __BPF_PROLOGUE_H | ||
| 7 | |||
| 8 | #include <linux/compiler.h> | ||
| 9 | #include <linux/filter.h> | ||
| 10 | #include "probe-event.h" | ||
| 11 | |||
| 12 | #define BPF_PROLOGUE_MAX_ARGS 3 | ||
| 13 | #define BPF_PROLOGUE_START_ARG_REG BPF_REG_3 | ||
| 14 | #define BPF_PROLOGUE_FETCH_RESULT_REG BPF_REG_2 | ||
| 15 | |||
| 16 | #ifdef HAVE_BPF_PROLOGUE | ||
| 17 | int bpf__gen_prologue(struct probe_trace_arg *args, int nargs, | ||
| 18 | struct bpf_insn *new_prog, size_t *new_cnt, | ||
| 19 | size_t cnt_space); | ||
| 20 | #else | ||
| 21 | static inline int | ||
| 22 | bpf__gen_prologue(struct probe_trace_arg *args __maybe_unused, | ||
| 23 | int nargs __maybe_unused, | ||
| 24 | struct bpf_insn *new_prog __maybe_unused, | ||
| 25 | size_t *new_cnt, | ||
| 26 | size_t cnt_space __maybe_unused) | ||
| 27 | { | ||
| 28 | if (!new_cnt) | ||
| 29 | return -EINVAL; | ||
| 30 | *new_cnt = 0; | ||
| 31 | return -ENOTSUP; | ||
| 32 | } | ||
| 33 | #endif | ||
| 34 | #endif /* __BPF_PROLOGUE_H */ | ||
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index d909459fb54c..6a7e273a514a 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
| @@ -76,6 +76,7 @@ struct perf_tool build_id__mark_dso_hit_ops = { | |||
| 76 | .exit = perf_event__exit_del_thread, | 76 | .exit = perf_event__exit_del_thread, |
| 77 | .attr = perf_event__process_attr, | 77 | .attr = perf_event__process_attr, |
| 78 | .build_id = perf_event__process_build_id, | 78 | .build_id = perf_event__process_build_id, |
| 79 | .ordered_events = true, | ||
| 79 | }; | 80 | }; |
| 80 | 81 | ||
| 81 | int build_id__sprintf(const u8 *build_id, int len, char *bf) | 82 | int build_id__sprintf(const u8 *build_id, int len, char *bf) |
| @@ -90,7 +91,7 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf) | |||
| 90 | bid += 2; | 91 | bid += 2; |
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | return raw - build_id; | 94 | return (bid - bf) + 1; |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id) | 97 | int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id) |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index c861373aaed3..07b5d63947b1 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
| @@ -4,9 +4,12 @@ | |||
| 4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 5 | #include "util.h" | 5 | #include "util.h" |
| 6 | #include "strbuf.h" | 6 | #include "strbuf.h" |
| 7 | #include <subcmd/pager.h> | ||
| 7 | #include "../perf.h" | 8 | #include "../perf.h" |
| 8 | #include "../ui/ui.h" | 9 | #include "../ui/ui.h" |
| 9 | 10 | ||
| 11 | #include <linux/string.h> | ||
| 12 | |||
| 10 | #define CMD_EXEC_PATH "--exec-path" | 13 | #define CMD_EXEC_PATH "--exec-path" |
| 11 | #define CMD_PERF_DIR "--perf-dir=" | 14 | #define CMD_PERF_DIR "--perf-dir=" |
| 12 | #define CMD_WORK_TREE "--work-tree=" | 15 | #define CMD_WORK_TREE "--work-tree=" |
| @@ -18,6 +21,7 @@ | |||
| 18 | #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" | 21 | #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" |
| 19 | #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" | 22 | #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" |
| 20 | #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" | 23 | #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" |
| 24 | #define PERF_PAGER_ENVIRONMENT "PERF_PAGER" | ||
| 21 | 25 | ||
| 22 | typedef int (*config_fn_t)(const char *, const char *, void *); | 26 | typedef int (*config_fn_t)(const char *, const char *, void *); |
| 23 | extern int perf_default_config(const char *, const char *, void *); | 27 | extern int perf_default_config(const char *, const char *, void *); |
| @@ -28,11 +32,6 @@ extern int perf_config_bool(const char *, const char *); | |||
| 28 | extern int config_error_nonbool(const char *); | 32 | extern int config_error_nonbool(const char *); |
| 29 | extern const char *perf_config_dirname(const char *, const char *); | 33 | extern const char *perf_config_dirname(const char *, const char *); |
| 30 | 34 | ||
| 31 | /* pager.c */ | ||
| 32 | extern void setup_pager(void); | ||
| 33 | extern int pager_in_use(void); | ||
| 34 | extern int pager_use_color; | ||
| 35 | |||
| 36 | char *alias_lookup(const char *alias); | 35 | char *alias_lookup(const char *alias); |
| 37 | int split_cmdline(char *cmdline, const char ***argv); | 36 | int split_cmdline(char *cmdline, const char ***argv); |
| 38 | 37 | ||
| @@ -71,9 +70,4 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2 | |||
| 71 | extern char *perf_pathdup(const char *fmt, ...) | 70 | extern char *perf_pathdup(const char *fmt, ...) |
| 72 | __attribute__((format (printf, 1, 2))); | 71 | __attribute__((format (printf, 1, 2))); |
| 73 | 72 | ||
| 74 | #ifndef __UCLIBC__ | ||
| 75 | /* Matches the libc/libbsd function attribute so we declare this unconditionally: */ | ||
| 76 | extern size_t strlcpy(char *dest, const char *src, size_t size); | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #endif /* __PERF_CACHE_H */ | 73 | #endif /* __PERF_CACHE_H */ |
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 735ad48e1858..53c43eb9489e 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
| @@ -44,6 +44,10 @@ static int parse_callchain_mode(const char *value) | |||
| 44 | callchain_param.mode = CHAIN_GRAPH_REL; | 44 | callchain_param.mode = CHAIN_GRAPH_REL; |
| 45 | return 0; | 45 | return 0; |
| 46 | } | 46 | } |
| 47 | if (!strncmp(value, "folded", strlen(value))) { | ||
| 48 | callchain_param.mode = CHAIN_FOLDED; | ||
| 49 | return 0; | ||
| 50 | } | ||
| 47 | return -1; | 51 | return -1; |
| 48 | } | 52 | } |
| 49 | 53 | ||
| @@ -79,6 +83,23 @@ static int parse_callchain_sort_key(const char *value) | |||
| 79 | return -1; | 83 | return -1; |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 86 | static int parse_callchain_value(const char *value) | ||
| 87 | { | ||
| 88 | if (!strncmp(value, "percent", strlen(value))) { | ||
| 89 | callchain_param.value = CCVAL_PERCENT; | ||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | if (!strncmp(value, "period", strlen(value))) { | ||
| 93 | callchain_param.value = CCVAL_PERIOD; | ||
| 94 | return 0; | ||
| 95 | } | ||
| 96 | if (!strncmp(value, "count", strlen(value))) { | ||
| 97 | callchain_param.value = CCVAL_COUNT; | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | return -1; | ||
| 101 | } | ||
| 102 | |||
| 82 | static int | 103 | static int |
| 83 | __parse_callchain_report_opt(const char *arg, bool allow_record_opt) | 104 | __parse_callchain_report_opt(const char *arg, bool allow_record_opt) |
| 84 | { | 105 | { |
| @@ -102,7 +123,8 @@ __parse_callchain_report_opt(const char *arg, bool allow_record_opt) | |||
| 102 | 123 | ||
| 103 | if (!parse_callchain_mode(tok) || | 124 | if (!parse_callchain_mode(tok) || |
| 104 | !parse_callchain_order(tok) || | 125 | !parse_callchain_order(tok) || |
| 105 | !parse_callchain_sort_key(tok)) { | 126 | !parse_callchain_sort_key(tok) || |
| 127 | !parse_callchain_value(tok)) { | ||
| 106 | /* parsing ok - move on to the next */ | 128 | /* parsing ok - move on to the next */ |
| 107 | try_stack_size = false; | 129 | try_stack_size = false; |
| 108 | goto next; | 130 | goto next; |
| @@ -218,6 +240,7 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain, | |||
| 218 | 240 | ||
| 219 | switch (mode) { | 241 | switch (mode) { |
| 220 | case CHAIN_FLAT: | 242 | case CHAIN_FLAT: |
| 243 | case CHAIN_FOLDED: | ||
| 221 | if (rnode->hit < chain->hit) | 244 | if (rnode->hit < chain->hit) |
| 222 | p = &(*p)->rb_left; | 245 | p = &(*p)->rb_left; |
| 223 | else | 246 | else |
| @@ -267,6 +290,7 @@ static void | |||
| 267 | sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root, | 290 | sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root, |
| 268 | u64 min_hit, struct callchain_param *param __maybe_unused) | 291 | u64 min_hit, struct callchain_param *param __maybe_unused) |
| 269 | { | 292 | { |
| 293 | *rb_root = RB_ROOT; | ||
| 270 | __sort_chain_flat(rb_root, &root->node, min_hit); | 294 | __sort_chain_flat(rb_root, &root->node, min_hit); |
| 271 | } | 295 | } |
| 272 | 296 | ||
| @@ -338,6 +362,7 @@ int callchain_register_param(struct callchain_param *param) | |||
| 338 | param->sort = sort_chain_graph_rel; | 362 | param->sort = sort_chain_graph_rel; |
| 339 | break; | 363 | break; |
| 340 | case CHAIN_FLAT: | 364 | case CHAIN_FLAT: |
| 365 | case CHAIN_FOLDED: | ||
| 341 | param->sort = sort_chain_flat; | 366 | param->sort = sort_chain_flat; |
| 342 | break; | 367 | break; |
| 343 | case CHAIN_NONE: | 368 | case CHAIN_NONE: |
| @@ -363,6 +388,7 @@ create_child(struct callchain_node *parent, bool inherit_children) | |||
| 363 | } | 388 | } |
| 364 | new->parent = parent; | 389 | new->parent = parent; |
| 365 | INIT_LIST_HEAD(&new->val); | 390 | INIT_LIST_HEAD(&new->val); |
| 391 | INIT_LIST_HEAD(&new->parent_val); | ||
| 366 | 392 | ||
| 367 | if (inherit_children) { | 393 | if (inherit_children) { |
| 368 | struct rb_node *n; | 394 | struct rb_node *n; |
| @@ -431,6 +457,8 @@ add_child(struct callchain_node *parent, | |||
| 431 | 457 | ||
| 432 | new->children_hit = 0; | 458 | new->children_hit = 0; |
| 433 | new->hit = period; | 459 | new->hit = period; |
| 460 | new->children_count = 0; | ||
| 461 | new->count = 1; | ||
| 434 | return new; | 462 | return new; |
| 435 | } | 463 | } |
| 436 | 464 | ||
| @@ -478,6 +506,9 @@ split_add_child(struct callchain_node *parent, | |||
| 478 | parent->children_hit = callchain_cumul_hits(new); | 506 | parent->children_hit = callchain_cumul_hits(new); |
| 479 | new->val_nr = parent->val_nr - idx_local; | 507 | new->val_nr = parent->val_nr - idx_local; |
| 480 | parent->val_nr = idx_local; | 508 | parent->val_nr = idx_local; |
| 509 | new->count = parent->count; | ||
| 510 | new->children_count = parent->children_count; | ||
| 511 | parent->children_count = callchain_cumul_counts(new); | ||
| 481 | 512 | ||
| 482 | /* create a new child for the new branch if any */ | 513 | /* create a new child for the new branch if any */ |
| 483 | if (idx_total < cursor->nr) { | 514 | if (idx_total < cursor->nr) { |
| @@ -488,6 +519,8 @@ split_add_child(struct callchain_node *parent, | |||
| 488 | 519 | ||
| 489 | parent->hit = 0; | 520 | parent->hit = 0; |
| 490 | parent->children_hit += period; | 521 | parent->children_hit += period; |
| 522 | parent->count = 0; | ||
| 523 | parent->children_count += 1; | ||
| 491 | 524 | ||
| 492 | node = callchain_cursor_current(cursor); | 525 | node = callchain_cursor_current(cursor); |
| 493 | new = add_child(parent, cursor, period); | 526 | new = add_child(parent, cursor, period); |
| @@ -510,6 +543,7 @@ split_add_child(struct callchain_node *parent, | |||
| 510 | rb_insert_color(&new->rb_node_in, &parent->rb_root_in); | 543 | rb_insert_color(&new->rb_node_in, &parent->rb_root_in); |
| 511 | } else { | 544 | } else { |
| 512 | parent->hit = period; | 545 | parent->hit = period; |
| 546 | parent->count = 1; | ||
| 513 | } | 547 | } |
| 514 | } | 548 | } |
| 515 | 549 | ||
| @@ -556,6 +590,7 @@ append_chain_children(struct callchain_node *root, | |||
| 556 | 590 | ||
| 557 | inc_children_hit: | 591 | inc_children_hit: |
| 558 | root->children_hit += period; | 592 | root->children_hit += period; |
| 593 | root->children_count++; | ||
| 559 | } | 594 | } |
| 560 | 595 | ||
| 561 | static int | 596 | static int |
| @@ -608,6 +643,7 @@ append_chain(struct callchain_node *root, | |||
| 608 | /* we match 100% of the path, increment the hit */ | 643 | /* we match 100% of the path, increment the hit */ |
| 609 | if (matches == root->val_nr && cursor->pos == cursor->nr) { | 644 | if (matches == root->val_nr && cursor->pos == cursor->nr) { |
| 610 | root->hit += period; | 645 | root->hit += period; |
| 646 | root->count++; | ||
| 611 | return 0; | 647 | return 0; |
| 612 | } | 648 | } |
| 613 | 649 | ||
| @@ -799,12 +835,72 @@ char *callchain_list__sym_name(struct callchain_list *cl, | |||
| 799 | return bf; | 835 | return bf; |
| 800 | } | 836 | } |
| 801 | 837 | ||
| 838 | char *callchain_node__scnprintf_value(struct callchain_node *node, | ||
| 839 | char *bf, size_t bfsize, u64 total) | ||
| 840 | { | ||
| 841 | double percent = 0.0; | ||
| 842 | u64 period = callchain_cumul_hits(node); | ||
| 843 | unsigned count = callchain_cumul_counts(node); | ||
| 844 | |||
| 845 | if (callchain_param.mode == CHAIN_FOLDED) { | ||
| 846 | period = node->hit; | ||
| 847 | count = node->count; | ||
| 848 | } | ||
| 849 | |||
| 850 | switch (callchain_param.value) { | ||
| 851 | case CCVAL_PERIOD: | ||
| 852 | scnprintf(bf, bfsize, "%"PRIu64, period); | ||
| 853 | break; | ||
| 854 | case CCVAL_COUNT: | ||
| 855 | scnprintf(bf, bfsize, "%u", count); | ||
| 856 | break; | ||
| 857 | case CCVAL_PERCENT: | ||
| 858 | default: | ||
| 859 | if (total) | ||
| 860 | percent = period * 100.0 / total; | ||
| 861 | scnprintf(bf, bfsize, "%.2f%%", percent); | ||
| 862 | break; | ||
| 863 | } | ||
| 864 | return bf; | ||
| 865 | } | ||
| 866 | |||
| 867 | int callchain_node__fprintf_value(struct callchain_node *node, | ||
| 868 | FILE *fp, u64 total) | ||
| 869 | { | ||
| 870 | double percent = 0.0; | ||
| 871 | u64 period = callchain_cumul_hits(node); | ||
| 872 | unsigned count = callchain_cumul_counts(node); | ||
| 873 | |||
| 874 | if (callchain_param.mode == CHAIN_FOLDED) { | ||
| 875 | period = node->hit; | ||
| 876 | count = node->count; | ||
| 877 | } | ||
| 878 | |||
| 879 | switch (callchain_param.value) { | ||
| 880 | case CCVAL_PERIOD: | ||
| 881 | return fprintf(fp, "%"PRIu64, period); | ||
| 882 | case CCVAL_COUNT: | ||
| 883 | return fprintf(fp, "%u", count); | ||
| 884 | case CCVAL_PERCENT: | ||
| 885 | default: | ||
| 886 | if (total) | ||
| 887 | percent = period * 100.0 / total; | ||
| 888 | return percent_color_fprintf(fp, "%.2f%%", percent); | ||
| 889 | } | ||
| 890 | return 0; | ||
| 891 | } | ||
| 892 | |||
| 802 | static void free_callchain_node(struct callchain_node *node) | 893 | static void free_callchain_node(struct callchain_node *node) |
| 803 | { | 894 | { |
| 804 | struct callchain_list *list, *tmp; | 895 | struct callchain_list *list, *tmp; |
| 805 | struct callchain_node *child; | 896 | struct callchain_node *child; |
| 806 | struct rb_node *n; | 897 | struct rb_node *n; |
| 807 | 898 | ||
| 899 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { | ||
| 900 | list_del(&list->list); | ||
| 901 | free(list); | ||
| 902 | } | ||
| 903 | |||
| 808 | list_for_each_entry_safe(list, tmp, &node->val, list) { | 904 | list_for_each_entry_safe(list, tmp, &node->val, list) { |
| 809 | list_del(&list->list); | 905 | list_del(&list->list); |
| 810 | free(list); | 906 | free(list); |
| @@ -828,3 +924,69 @@ void free_callchain(struct callchain_root *root) | |||
| 828 | 924 | ||
| 829 | free_callchain_node(&root->node); | 925 | free_callchain_node(&root->node); |
| 830 | } | 926 | } |
| 927 | |||
| 928 | static u64 decay_callchain_node(struct callchain_node *node) | ||
| 929 | { | ||
| 930 | struct callchain_node *child; | ||
| 931 | struct rb_node *n; | ||
| 932 | u64 child_hits = 0; | ||
| 933 | |||
| 934 | n = rb_first(&node->rb_root_in); | ||
| 935 | while (n) { | ||
| 936 | child = container_of(n, struct callchain_node, rb_node_in); | ||
| 937 | |||
| 938 | child_hits += decay_callchain_node(child); | ||
| 939 | n = rb_next(n); | ||
| 940 | } | ||
| 941 | |||
| 942 | node->hit = (node->hit * 7) / 8; | ||
| 943 | node->children_hit = child_hits; | ||
| 944 | |||
| 945 | return node->hit; | ||
| 946 | } | ||
| 947 | |||
| 948 | void decay_callchain(struct callchain_root *root) | ||
| 949 | { | ||
| 950 | if (!symbol_conf.use_callchain) | ||
| 951 | return; | ||
| 952 | |||
| 953 | decay_callchain_node(&root->node); | ||
| 954 | } | ||
| 955 | |||
| 956 | int callchain_node__make_parent_list(struct callchain_node *node) | ||
| 957 | { | ||
| 958 | struct callchain_node *parent = node->parent; | ||
| 959 | struct callchain_list *chain, *new; | ||
| 960 | LIST_HEAD(head); | ||
| 961 | |||
| 962 | while (parent) { | ||
| 963 | list_for_each_entry_reverse(chain, &parent->val, list) { | ||
| 964 | new = malloc(sizeof(*new)); | ||
| 965 | if (new == NULL) | ||
| 966 | goto out; | ||
| 967 | *new = *chain; | ||
| 968 | new->has_children = false; | ||
| 969 | list_add_tail(&new->list, &head); | ||
| 970 | } | ||
| 971 | parent = parent->parent; | ||
| 972 | } | ||
| 973 | |||
| 974 | list_for_each_entry_safe_reverse(chain, new, &head, list) | ||
| 975 | list_move_tail(&chain->list, &node->parent_val); | ||
| 976 | |||
| 977 | if (!list_empty(&node->parent_val)) { | ||
| 978 | chain = list_first_entry(&node->parent_val, struct callchain_list, list); | ||
| 979 | chain->has_children = rb_prev(&node->rb_node) || rb_next(&node->rb_node); | ||
| 980 | |||
| 981 | chain = list_first_entry(&node->val, struct callchain_list, list); | ||
| 982 | chain->has_children = false; | ||
| 983 | } | ||
| 984 | return 0; | ||
| 985 | |||
| 986 | out: | ||
| 987 | list_for_each_entry_safe(chain, new, &head, list) { | ||
| 988 | list_del(&chain->list); | ||
| 989 | free(chain); | ||
| 990 | } | ||
| 991 | return -ENOMEM; | ||
| 992 | } | ||
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index fce8161e54db..18dd22269764 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
| @@ -24,12 +24,13 @@ | |||
| 24 | #define CALLCHAIN_RECORD_HELP CALLCHAIN_HELP RECORD_MODE_HELP RECORD_SIZE_HELP | 24 | #define CALLCHAIN_RECORD_HELP CALLCHAIN_HELP RECORD_MODE_HELP RECORD_SIZE_HELP |
| 25 | 25 | ||
| 26 | #define CALLCHAIN_REPORT_HELP \ | 26 | #define CALLCHAIN_REPORT_HELP \ |
| 27 | HELP_PAD "print_type:\tcall graph printing style (graph|flat|fractal|none)\n" \ | 27 | HELP_PAD "print_type:\tcall graph printing style (graph|flat|fractal|folded|none)\n" \ |
| 28 | HELP_PAD "threshold:\tminimum call graph inclusion threshold (<percent>)\n" \ | 28 | HELP_PAD "threshold:\tminimum call graph inclusion threshold (<percent>)\n" \ |
| 29 | HELP_PAD "print_limit:\tmaximum number of call graph entry (<number>)\n" \ | 29 | HELP_PAD "print_limit:\tmaximum number of call graph entry (<number>)\n" \ |
| 30 | HELP_PAD "order:\t\tcall graph order (caller|callee)\n" \ | 30 | HELP_PAD "order:\t\tcall graph order (caller|callee)\n" \ |
| 31 | HELP_PAD "sort_key:\tcall graph sort key (function|address)\n" \ | 31 | HELP_PAD "sort_key:\tcall graph sort key (function|address)\n" \ |
| 32 | HELP_PAD "branch:\t\tinclude last branch info to call graph (branch)\n" | 32 | HELP_PAD "branch:\t\tinclude last branch info to call graph (branch)\n" \ |
| 33 | HELP_PAD "value:\t\tcall graph value (percent|period|count)\n" | ||
| 33 | 34 | ||
| 34 | enum perf_call_graph_mode { | 35 | enum perf_call_graph_mode { |
| 35 | CALLCHAIN_NONE, | 36 | CALLCHAIN_NONE, |
| @@ -43,7 +44,8 @@ enum chain_mode { | |||
| 43 | CHAIN_NONE, | 44 | CHAIN_NONE, |
| 44 | CHAIN_FLAT, | 45 | CHAIN_FLAT, |
| 45 | CHAIN_GRAPH_ABS, | 46 | CHAIN_GRAPH_ABS, |
| 46 | CHAIN_GRAPH_REL | 47 | CHAIN_GRAPH_REL, |
| 48 | CHAIN_FOLDED, | ||
| 47 | }; | 49 | }; |
| 48 | 50 | ||
| 49 | enum chain_order { | 51 | enum chain_order { |
| @@ -54,11 +56,14 @@ enum chain_order { | |||
| 54 | struct callchain_node { | 56 | struct callchain_node { |
| 55 | struct callchain_node *parent; | 57 | struct callchain_node *parent; |
| 56 | struct list_head val; | 58 | struct list_head val; |
| 59 | struct list_head parent_val; | ||
| 57 | struct rb_node rb_node_in; /* to insert nodes in an rbtree */ | 60 | struct rb_node rb_node_in; /* to insert nodes in an rbtree */ |
| 58 | struct rb_node rb_node; /* to sort nodes in an output tree */ | 61 | struct rb_node rb_node; /* to sort nodes in an output tree */ |
| 59 | struct rb_root rb_root_in; /* input tree of children */ | 62 | struct rb_root rb_root_in; /* input tree of children */ |
| 60 | struct rb_root rb_root; /* sorted output tree of children */ | 63 | struct rb_root rb_root; /* sorted output tree of children */ |
| 61 | unsigned int val_nr; | 64 | unsigned int val_nr; |
| 65 | unsigned int count; | ||
| 66 | unsigned int children_count; | ||
| 62 | u64 hit; | 67 | u64 hit; |
| 63 | u64 children_hit; | 68 | u64 children_hit; |
| 64 | }; | 69 | }; |
| @@ -78,6 +83,12 @@ enum chain_key { | |||
| 78 | CCKEY_ADDRESS | 83 | CCKEY_ADDRESS |
| 79 | }; | 84 | }; |
| 80 | 85 | ||
| 86 | enum chain_value { | ||
| 87 | CCVAL_PERCENT, | ||
| 88 | CCVAL_PERIOD, | ||
| 89 | CCVAL_COUNT, | ||
| 90 | }; | ||
| 91 | |||
| 81 | struct callchain_param { | 92 | struct callchain_param { |
| 82 | bool enabled; | 93 | bool enabled; |
| 83 | enum perf_call_graph_mode record_mode; | 94 | enum perf_call_graph_mode record_mode; |
| @@ -90,6 +101,7 @@ struct callchain_param { | |||
| 90 | bool order_set; | 101 | bool order_set; |
| 91 | enum chain_key key; | 102 | enum chain_key key; |
| 92 | bool branch_callstack; | 103 | bool branch_callstack; |
| 104 | enum chain_value value; | ||
| 93 | }; | 105 | }; |
| 94 | 106 | ||
| 95 | extern struct callchain_param callchain_param; | 107 | extern struct callchain_param callchain_param; |
| @@ -131,6 +143,7 @@ extern __thread struct callchain_cursor callchain_cursor; | |||
| 131 | static inline void callchain_init(struct callchain_root *root) | 143 | static inline void callchain_init(struct callchain_root *root) |
| 132 | { | 144 | { |
| 133 | INIT_LIST_HEAD(&root->node.val); | 145 | INIT_LIST_HEAD(&root->node.val); |
| 146 | INIT_LIST_HEAD(&root->node.parent_val); | ||
| 134 | 147 | ||
| 135 | root->node.parent = NULL; | 148 | root->node.parent = NULL; |
| 136 | root->node.hit = 0; | 149 | root->node.hit = 0; |
| @@ -144,6 +157,11 @@ static inline u64 callchain_cumul_hits(struct callchain_node *node) | |||
| 144 | return node->hit + node->children_hit; | 157 | return node->hit + node->children_hit; |
| 145 | } | 158 | } |
| 146 | 159 | ||
| 160 | static inline unsigned callchain_cumul_counts(struct callchain_node *node) | ||
| 161 | { | ||
| 162 | return node->count + node->children_count; | ||
| 163 | } | ||
| 164 | |||
| 147 | int callchain_register_param(struct callchain_param *param); | 165 | int callchain_register_param(struct callchain_param *param); |
| 148 | int callchain_append(struct callchain_root *root, | 166 | int callchain_append(struct callchain_root *root, |
| 149 | struct callchain_cursor *cursor, | 167 | struct callchain_cursor *cursor, |
| @@ -229,7 +247,13 @@ static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused, | |||
| 229 | 247 | ||
| 230 | char *callchain_list__sym_name(struct callchain_list *cl, | 248 | char *callchain_list__sym_name(struct callchain_list *cl, |
| 231 | char *bf, size_t bfsize, bool show_dso); | 249 | char *bf, size_t bfsize, bool show_dso); |
| 250 | char *callchain_node__scnprintf_value(struct callchain_node *node, | ||
| 251 | char *bf, size_t bfsize, u64 total); | ||
| 252 | int callchain_node__fprintf_value(struct callchain_node *node, | ||
| 253 | FILE *fp, u64 total); | ||
| 232 | 254 | ||
| 233 | void free_callchain(struct callchain_root *root); | 255 | void free_callchain(struct callchain_root *root); |
| 256 | void decay_callchain(struct callchain_root *root); | ||
| 257 | int callchain_node__make_parent_list(struct callchain_node *node); | ||
| 234 | 258 | ||
| 235 | #endif /* __PERF_CALLCHAIN_H */ | 259 | #endif /* __PERF_CALLCHAIN_H */ |
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 32e12ecfe9c5..90aa1b46b2e5 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #include "util.h" | 1 | #include "util.h" |
| 2 | #include "../perf.h" | 2 | #include "../perf.h" |
| 3 | #include "parse-options.h" | 3 | #include <subcmd/parse-options.h> |
| 4 | #include "evsel.h" | 4 | #include "evsel.h" |
| 5 | #include "cgroup.h" | 5 | #include "cgroup.h" |
| 6 | #include "evlist.h" | 6 | #include "evlist.h" |
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index 9b9565416f90..e5fb88bab9e1 100644 --- a/tools/perf/util/color.c +++ b/tools/perf/util/color.c | |||
| @@ -24,7 +24,7 @@ int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty) | |||
| 24 | auto_color: | 24 | auto_color: |
| 25 | if (stdout_is_tty < 0) | 25 | if (stdout_is_tty < 0) |
| 26 | stdout_is_tty = isatty(1); | 26 | stdout_is_tty = isatty(1); |
| 27 | if (stdout_is_tty || (pager_in_use() && pager_use_color)) { | 27 | if (stdout_is_tty || pager_in_use()) { |
| 28 | char *term = getenv("TERM"); | 28 | char *term = getenv("TERM"); |
| 29 | if (term && strcmp(term, "dumb")) | 29 | if (term && strcmp(term, "dumb")) |
| 30 | return 1; | 30 | return 1; |
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 2e452ac1353d..d3e12e30e1d5 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | */ | 10 | */ |
| 11 | #include "util.h" | 11 | #include "util.h" |
| 12 | #include "cache.h" | 12 | #include "cache.h" |
| 13 | #include "exec_cmd.h" | 13 | #include <subcmd/exec-cmd.h> |
| 14 | #include "util/hist.h" /* perf_hist_config */ | 14 | #include "util/hist.h" /* perf_hist_config */ |
| 15 | #include "util/llvm-utils.h" /* perf_llvm_config */ | 15 | #include "util/llvm-utils.h" /* perf_llvm_config */ |
| 16 | 16 | ||
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 10af1e7524fb..fa935093a599 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <assert.h> | 5 | #include <assert.h> |
| 6 | #include <stdio.h> | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 8 | #include <linux/bitmap.h> | ||
| 8 | #include "asm/bug.h" | 9 | #include "asm/bug.h" |
| 9 | 10 | ||
| 10 | static struct cpu_map *cpu_map__default_new(void) | 11 | static struct cpu_map *cpu_map__default_new(void) |
| @@ -179,6 +180,56 @@ out: | |||
| 179 | return cpus; | 180 | return cpus; |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 183 | static struct cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus) | ||
| 184 | { | ||
| 185 | struct cpu_map *map; | ||
| 186 | |||
| 187 | map = cpu_map__empty_new(cpus->nr); | ||
| 188 | if (map) { | ||
| 189 | unsigned i; | ||
| 190 | |||
| 191 | for (i = 0; i < cpus->nr; i++) { | ||
| 192 | /* | ||
| 193 | * Special treatment for -1, which is not real cpu number, | ||
| 194 | * and we need to use (int) -1 to initialize map[i], | ||
| 195 | * otherwise it would become 65535. | ||
| 196 | */ | ||
| 197 | if (cpus->cpu[i] == (u16) -1) | ||
| 198 | map->map[i] = -1; | ||
| 199 | else | ||
| 200 | map->map[i] = (int) cpus->cpu[i]; | ||
| 201 | } | ||
| 202 | } | ||
| 203 | |||
| 204 | return map; | ||
| 205 | } | ||
| 206 | |||
| 207 | static struct cpu_map *cpu_map__from_mask(struct cpu_map_mask *mask) | ||
| 208 | { | ||
| 209 | struct cpu_map *map; | ||
| 210 | int nr, nbits = mask->nr * mask->long_size * BITS_PER_BYTE; | ||
| 211 | |||
| 212 | nr = bitmap_weight(mask->mask, nbits); | ||
| 213 | |||
| 214 | map = cpu_map__empty_new(nr); | ||
| 215 | if (map) { | ||
| 216 | int cpu, i = 0; | ||
| 217 | |||
| 218 | for_each_set_bit(cpu, mask->mask, nbits) | ||
| 219 | map->map[i++] = cpu; | ||
| 220 | } | ||
| 221 | return map; | ||
| 222 | |||
| 223 | } | ||
| 224 | |||
| 225 | struct cpu_map *cpu_map__new_data(struct cpu_map_data *data) | ||
| 226 | { | ||
| 227 | if (data->type == PERF_CPU_MAP__CPUS) | ||
| 228 | return cpu_map__from_entries((struct cpu_map_entries *)data->data); | ||
| 229 | else | ||
| 230 | return cpu_map__from_mask((struct cpu_map_mask *)data->data); | ||
| 231 | } | ||
| 232 | |||
| 182 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp) | 233 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp) |
| 183 | { | 234 | { |
| 184 | int i; | 235 | int i; |
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 85f7772457fa..71c41b9efabb 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h | |||
| @@ -17,6 +17,7 @@ struct cpu_map { | |||
| 17 | struct cpu_map *cpu_map__new(const char *cpu_list); | 17 | struct cpu_map *cpu_map__new(const char *cpu_list); |
| 18 | struct cpu_map *cpu_map__empty_new(int nr); | 18 | struct cpu_map *cpu_map__empty_new(int nr); |
| 19 | struct cpu_map *cpu_map__dummy_new(void); | 19 | struct cpu_map *cpu_map__dummy_new(void); |
| 20 | struct cpu_map *cpu_map__new_data(struct cpu_map_data *data); | ||
| 20 | struct cpu_map *cpu_map__read(FILE *file); | 21 | struct cpu_map *cpu_map__read(FILE *file); |
| 21 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); | 22 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); |
| 22 | int cpu_map__get_socket_id(int cpu); | 23 | int cpu_map__get_socket_id(int cpu); |
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c index 5bfc1198ab46..34cd1e4039d3 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c | |||
| @@ -63,6 +63,7 @@ struct ctf_writer { | |||
| 63 | struct bt_ctf_field_type *s32; | 63 | struct bt_ctf_field_type *s32; |
| 64 | struct bt_ctf_field_type *u32; | 64 | struct bt_ctf_field_type *u32; |
| 65 | struct bt_ctf_field_type *string; | 65 | struct bt_ctf_field_type *string; |
| 66 | struct bt_ctf_field_type *u32_hex; | ||
| 66 | struct bt_ctf_field_type *u64_hex; | 67 | struct bt_ctf_field_type *u64_hex; |
| 67 | }; | 68 | }; |
| 68 | struct bt_ctf_field_type *array[6]; | 69 | struct bt_ctf_field_type *array[6]; |
| @@ -982,6 +983,7 @@ do { \ | |||
| 982 | CREATE_INT_TYPE(cw->data.u64, 64, false, false); | 983 | CREATE_INT_TYPE(cw->data.u64, 64, false, false); |
| 983 | CREATE_INT_TYPE(cw->data.s32, 32, true, false); | 984 | CREATE_INT_TYPE(cw->data.s32, 32, true, false); |
| 984 | CREATE_INT_TYPE(cw->data.u32, 32, false, false); | 985 | CREATE_INT_TYPE(cw->data.u32, 32, false, false); |
| 986 | CREATE_INT_TYPE(cw->data.u32_hex, 32, false, true); | ||
| 985 | CREATE_INT_TYPE(cw->data.u64_hex, 64, false, true); | 987 | CREATE_INT_TYPE(cw->data.u64_hex, 64, false, true); |
| 986 | 988 | ||
| 987 | cw->data.string = bt_ctf_field_type_string_create(); | 989 | cw->data.string = bt_ctf_field_type_string_create(); |
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 7c0c08386a1d..e8e9a9dbf5e3 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
| @@ -933,6 +933,7 @@ static struct dso *__dso__findlink_by_longname(struct rb_root *root, | |||
| 933 | /* Add new node and rebalance tree */ | 933 | /* Add new node and rebalance tree */ |
| 934 | rb_link_node(&dso->rb_node, parent, p); | 934 | rb_link_node(&dso->rb_node, parent, p); |
| 935 | rb_insert_color(&dso->rb_node, root); | 935 | rb_insert_color(&dso->rb_node, root); |
| 936 | dso->root = root; | ||
| 936 | } | 937 | } |
| 937 | return NULL; | 938 | return NULL; |
| 938 | } | 939 | } |
| @@ -945,15 +946,30 @@ static inline struct dso *__dso__find_by_longname(struct rb_root *root, | |||
| 945 | 946 | ||
| 946 | void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated) | 947 | void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated) |
| 947 | { | 948 | { |
| 949 | struct rb_root *root = dso->root; | ||
| 950 | |||
| 948 | if (name == NULL) | 951 | if (name == NULL) |
| 949 | return; | 952 | return; |
| 950 | 953 | ||
| 951 | if (dso->long_name_allocated) | 954 | if (dso->long_name_allocated) |
| 952 | free((char *)dso->long_name); | 955 | free((char *)dso->long_name); |
| 953 | 956 | ||
| 957 | if (root) { | ||
| 958 | rb_erase(&dso->rb_node, root); | ||
| 959 | /* | ||
| 960 | * __dso__findlink_by_longname() isn't guaranteed to add it | ||
| 961 | * back, so a clean removal is required here. | ||
| 962 | */ | ||
| 963 | RB_CLEAR_NODE(&dso->rb_node); | ||
| 964 | dso->root = NULL; | ||
| 965 | } | ||
| 966 | |||
| 954 | dso->long_name = name; | 967 | dso->long_name = name; |
| 955 | dso->long_name_len = strlen(name); | 968 | dso->long_name_len = strlen(name); |
| 956 | dso->long_name_allocated = name_allocated; | 969 | dso->long_name_allocated = name_allocated; |
| 970 | |||
| 971 | if (root) | ||
| 972 | __dso__findlink_by_longname(root, dso, NULL); | ||
| 957 | } | 973 | } |
| 958 | 974 | ||
| 959 | void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated) | 975 | void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated) |
| @@ -1046,6 +1062,7 @@ struct dso *dso__new(const char *name) | |||
| 1046 | dso->kernel = DSO_TYPE_USER; | 1062 | dso->kernel = DSO_TYPE_USER; |
| 1047 | dso->needs_swap = DSO_SWAP__UNSET; | 1063 | dso->needs_swap = DSO_SWAP__UNSET; |
| 1048 | RB_CLEAR_NODE(&dso->rb_node); | 1064 | RB_CLEAR_NODE(&dso->rb_node); |
| 1065 | dso->root = NULL; | ||
| 1049 | INIT_LIST_HEAD(&dso->node); | 1066 | INIT_LIST_HEAD(&dso->node); |
| 1050 | INIT_LIST_HEAD(&dso->data.open_entry); | 1067 | INIT_LIST_HEAD(&dso->data.open_entry); |
| 1051 | pthread_mutex_init(&dso->lock, NULL); | 1068 | pthread_mutex_init(&dso->lock, NULL); |
| @@ -1226,6 +1243,8 @@ struct dso *__dsos__addnew(struct dsos *dsos, const char *name) | |||
| 1226 | if (dso != NULL) { | 1243 | if (dso != NULL) { |
| 1227 | __dsos__add(dsos, dso); | 1244 | __dsos__add(dsos, dso); |
| 1228 | dso__set_basename(dso); | 1245 | dso__set_basename(dso); |
| 1246 | /* Put dso here because __dsos_add already got it */ | ||
| 1247 | dso__put(dso); | ||
| 1229 | } | 1248 | } |
| 1230 | return dso; | 1249 | return dso; |
| 1231 | } | 1250 | } |
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index fc8db9c764ac..45ec4d0a50ed 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h | |||
| @@ -135,6 +135,7 @@ struct dso { | |||
| 135 | pthread_mutex_t lock; | 135 | pthread_mutex_t lock; |
| 136 | struct list_head node; | 136 | struct list_head node; |
| 137 | struct rb_node rb_node; /* rbtree node sorted by long name */ | 137 | struct rb_node rb_node; /* rbtree node sorted by long name */ |
| 138 | struct rb_root *root; /* root of rbtree that rb_node is in */ | ||
| 138 | struct rb_root symbols[MAP__NR_TYPES]; | 139 | struct rb_root symbols[MAP__NR_TYPES]; |
| 139 | struct rb_root symbol_names[MAP__NR_TYPES]; | 140 | struct rb_root symbol_names[MAP__NR_TYPES]; |
| 140 | struct { | 141 | struct { |
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 6af4f7c36820..7dd5939dea2e 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c | |||
| @@ -25,15 +25,6 @@ int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) | |||
| 25 | { | 25 | { |
| 26 | int i; | 26 | int i; |
| 27 | 27 | ||
| 28 | /* | ||
| 29 | * If env->cmdline_argv has already been set, do not override it. This allows | ||
| 30 | * a command to set the cmdline, parse args and then call another | ||
| 31 | * builtin function that implements a command -- e.g, cmd_kvm calling | ||
| 32 | * cmd_record. | ||
| 33 | */ | ||
| 34 | if (env->cmdline_argv != NULL) | ||
| 35 | return 0; | ||
| 36 | |||
| 37 | /* do not include NULL termination */ | 28 | /* do not include NULL termination */ |
| 38 | env->cmdline_argv = calloc(argc, sizeof(char *)); | 29 | env->cmdline_argv = calloc(argc, sizeof(char *)); |
| 39 | if (env->cmdline_argv == NULL) | 30 | if (env->cmdline_argv == NULL) |
diff --git a/tools/perf/util/environment.c b/tools/perf/util/environment.c deleted file mode 100644 index 7405123692f1..000000000000 --- a/tools/perf/util/environment.c +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * We put all the perf config variables in this same object | ||
| 3 | * file, so that programs can link against the config parser | ||
| 4 | * without having to link against all the rest of perf. | ||
| 5 | */ | ||
| 6 | #include "cache.h" | ||
| 7 | |||
| 8 | int pager_use_color = 1; | ||
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 8b10621b415c..85155e91b61b 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
| @@ -10,6 +10,8 @@ | |||
| 10 | #include "thread.h" | 10 | #include "thread.h" |
| 11 | #include "thread_map.h" | 11 | #include "thread_map.h" |
| 12 | #include "symbol/kallsyms.h" | 12 | #include "symbol/kallsyms.h" |
| 13 | #include "asm/bug.h" | ||
| 14 | #include "stat.h" | ||
| 13 | 15 | ||
| 14 | static const char *perf_event__names[] = { | 16 | static const char *perf_event__names[] = { |
| 15 | [0] = "TOTAL", | 17 | [0] = "TOTAL", |
| @@ -37,6 +39,12 @@ static const char *perf_event__names[] = { | |||
| 37 | [PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO", | 39 | [PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO", |
| 38 | [PERF_RECORD_AUXTRACE] = "AUXTRACE", | 40 | [PERF_RECORD_AUXTRACE] = "AUXTRACE", |
| 39 | [PERF_RECORD_AUXTRACE_ERROR] = "AUXTRACE_ERROR", | 41 | [PERF_RECORD_AUXTRACE_ERROR] = "AUXTRACE_ERROR", |
| 42 | [PERF_RECORD_THREAD_MAP] = "THREAD_MAP", | ||
| 43 | [PERF_RECORD_CPU_MAP] = "CPU_MAP", | ||
| 44 | [PERF_RECORD_STAT_CONFIG] = "STAT_CONFIG", | ||
| 45 | [PERF_RECORD_STAT] = "STAT", | ||
| 46 | [PERF_RECORD_STAT_ROUND] = "STAT_ROUND", | ||
| 47 | [PERF_RECORD_EVENT_UPDATE] = "EVENT_UPDATE", | ||
| 40 | }; | 48 | }; |
| 41 | 49 | ||
| 42 | const char *perf_event__name(unsigned int id) | 50 | const char *perf_event__name(unsigned int id) |
| @@ -495,7 +503,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, | |||
| 495 | if (comm_event == NULL) | 503 | if (comm_event == NULL) |
| 496 | goto out; | 504 | goto out; |
| 497 | 505 | ||
| 498 | mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size); | 506 | mmap_event = malloc(sizeof(mmap_event->mmap2) + machine->id_hdr_size); |
| 499 | if (mmap_event == NULL) | 507 | if (mmap_event == NULL) |
| 500 | goto out_free_comm; | 508 | goto out_free_comm; |
| 501 | 509 | ||
| @@ -569,7 +577,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, | |||
| 569 | if (comm_event == NULL) | 577 | if (comm_event == NULL) |
| 570 | goto out; | 578 | goto out; |
| 571 | 579 | ||
| 572 | mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size); | 580 | mmap_event = malloc(sizeof(mmap_event->mmap2) + machine->id_hdr_size); |
| 573 | if (mmap_event == NULL) | 581 | if (mmap_event == NULL) |
| 574 | goto out_free_comm; | 582 | goto out_free_comm; |
| 575 | 583 | ||
| @@ -699,6 +707,274 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, | |||
| 699 | return err; | 707 | return err; |
| 700 | } | 708 | } |
| 701 | 709 | ||
| 710 | int perf_event__synthesize_thread_map2(struct perf_tool *tool, | ||
| 711 | struct thread_map *threads, | ||
| 712 | perf_event__handler_t process, | ||
| 713 | struct machine *machine) | ||
| 714 | { | ||
| 715 | union perf_event *event; | ||
| 716 | int i, err, size; | ||
| 717 | |||
| 718 | size = sizeof(event->thread_map); | ||
| 719 | size += threads->nr * sizeof(event->thread_map.entries[0]); | ||
| 720 | |||
| 721 | event = zalloc(size); | ||
| 722 | if (!event) | ||
| 723 | return -ENOMEM; | ||
| 724 | |||
| 725 | event->header.type = PERF_RECORD_THREAD_MAP; | ||
| 726 | event->header.size = size; | ||
| 727 | event->thread_map.nr = threads->nr; | ||
| 728 | |||
| 729 | for (i = 0; i < threads->nr; i++) { | ||
| 730 | struct thread_map_event_entry *entry = &event->thread_map.entries[i]; | ||
| 731 | char *comm = thread_map__comm(threads, i); | ||
| 732 | |||
| 733 | if (!comm) | ||
| 734 | comm = (char *) ""; | ||
| 735 | |||
| 736 | entry->pid = thread_map__pid(threads, i); | ||
| 737 | strncpy((char *) &entry->comm, comm, sizeof(entry->comm)); | ||
| 738 | } | ||
| 739 | |||
| 740 | err = process(tool, event, NULL, machine); | ||
| 741 | |||
| 742 | free(event); | ||
| 743 | return err; | ||
| 744 | } | ||
| 745 | |||
| 746 | static void synthesize_cpus(struct cpu_map_entries *cpus, | ||
| 747 | struct cpu_map *map) | ||
| 748 | { | ||
| 749 | int i; | ||
| 750 | |||
| 751 | cpus->nr = map->nr; | ||
| 752 | |||
| 753 | for (i = 0; i < map->nr; i++) | ||
| 754 | cpus->cpu[i] = map->map[i]; | ||
| 755 | } | ||
| 756 | |||
| 757 | static void synthesize_mask(struct cpu_map_mask *mask, | ||
| 758 | struct cpu_map *map, int max) | ||
| 759 | { | ||
| 760 | int i; | ||
| 761 | |||
| 762 | mask->nr = BITS_TO_LONGS(max); | ||
| 763 | mask->long_size = sizeof(long); | ||
| 764 | |||
| 765 | for (i = 0; i < map->nr; i++) | ||
| 766 | set_bit(map->map[i], mask->mask); | ||
| 767 | } | ||
| 768 | |||
| 769 | static size_t cpus_size(struct cpu_map *map) | ||
| 770 | { | ||
| 771 | return sizeof(struct cpu_map_entries) + map->nr * sizeof(u16); | ||
| 772 | } | ||
| 773 | |||
| 774 | static size_t mask_size(struct cpu_map *map, int *max) | ||
| 775 | { | ||
| 776 | int i; | ||
| 777 | |||
| 778 | *max = 0; | ||
| 779 | |||
| 780 | for (i = 0; i < map->nr; i++) { | ||
| 781 | /* bit possition of the cpu is + 1 */ | ||
| 782 | int bit = map->map[i] + 1; | ||
| 783 | |||
| 784 | if (bit > *max) | ||
| 785 | *max = bit; | ||
| 786 | } | ||
| 787 | |||
| 788 | return sizeof(struct cpu_map_mask) + BITS_TO_LONGS(*max) * sizeof(long); | ||
| 789 | } | ||
| 790 | |||
| 791 | void *cpu_map_data__alloc(struct cpu_map *map, size_t *size, u16 *type, int *max) | ||
| 792 | { | ||
| 793 | size_t size_cpus, size_mask; | ||
| 794 | bool is_dummy = cpu_map__empty(map); | ||
| 795 | |||
| 796 | /* | ||
| 797 | * Both array and mask data have variable size based | ||
| 798 | * on the number of cpus and their actual values. | ||
| 799 | * The size of the 'struct cpu_map_data' is: | ||
| 800 | * | ||
| 801 | * array = size of 'struct cpu_map_entries' + | ||
| 802 | * number of cpus * sizeof(u64) | ||
| 803 | * | ||
| 804 | * mask = size of 'struct cpu_map_mask' + | ||
| 805 | * maximum cpu bit converted to size of longs | ||
| 806 | * | ||
| 807 | * and finaly + the size of 'struct cpu_map_data'. | ||
| 808 | */ | ||
| 809 | size_cpus = cpus_size(map); | ||
| 810 | size_mask = mask_size(map, max); | ||
| 811 | |||
| 812 | if (is_dummy || (size_cpus < size_mask)) { | ||
| 813 | *size += size_cpus; | ||
| 814 | *type = PERF_CPU_MAP__CPUS; | ||
| 815 | } else { | ||
| 816 | *size += size_mask; | ||
| 817 | *type = PERF_CPU_MAP__MASK; | ||
| 818 | } | ||
| 819 | |||
| 820 | *size += sizeof(struct cpu_map_data); | ||
| 821 | return zalloc(*size); | ||
| 822 | } | ||
| 823 | |||
| 824 | void cpu_map_data__synthesize(struct cpu_map_data *data, struct cpu_map *map, | ||
| 825 | u16 type, int max) | ||
| 826 | { | ||
| 827 | data->type = type; | ||
| 828 | |||
| 829 | switch (type) { | ||
| 830 | case PERF_CPU_MAP__CPUS: | ||
| 831 | synthesize_cpus((struct cpu_map_entries *) data->data, map); | ||
| 832 | break; | ||
| 833 | case PERF_CPU_MAP__MASK: | ||
| 834 | synthesize_mask((struct cpu_map_mask *) data->data, map, max); | ||
| 835 | default: | ||
| 836 | break; | ||
| 837 | }; | ||
| 838 | } | ||
| 839 | |||
| 840 | static struct cpu_map_event* cpu_map_event__new(struct cpu_map *map) | ||
| 841 | { | ||
| 842 | size_t size = sizeof(struct cpu_map_event); | ||
| 843 | struct cpu_map_event *event; | ||
| 844 | int max; | ||
| 845 | u16 type; | ||
| 846 | |||
| 847 | event = cpu_map_data__alloc(map, &size, &type, &max); | ||
| 848 | if (!event) | ||
| 849 | return NULL; | ||
| 850 | |||
| 851 | event->header.type = PERF_RECORD_CPU_MAP; | ||
| 852 | event->header.size = size; | ||
| 853 | event->data.type = type; | ||
| 854 | |||
| 855 | cpu_map_data__synthesize(&event->data, map, type, max); | ||
| 856 | return event; | ||
| 857 | } | ||
| 858 | |||
| 859 | int perf_event__synthesize_cpu_map(struct perf_tool *tool, | ||
| 860 | struct cpu_map *map, | ||
| 861 | perf_event__handler_t process, | ||
| 862 | struct machine *machine) | ||
| 863 | { | ||
| 864 | struct cpu_map_event *event; | ||
| 865 | int err; | ||
| 866 | |||
| 867 | event = cpu_map_event__new(map); | ||
| 868 | if (!event) | ||
| 869 | return -ENOMEM; | ||
| 870 | |||
| 871 | err = process(tool, (union perf_event *) event, NULL, machine); | ||
| 872 | |||
| 873 | free(event); | ||
| 874 | return err; | ||
| 875 | } | ||
| 876 | |||
| 877 | int perf_event__synthesize_stat_config(struct perf_tool *tool, | ||
| 878 | struct perf_stat_config *config, | ||
| 879 | perf_event__handler_t process, | ||
| 880 | struct machine *machine) | ||
| 881 | { | ||
| 882 | struct stat_config_event *event; | ||
| 883 | int size, i = 0, err; | ||
| 884 | |||
| 885 | size = sizeof(*event); | ||
| 886 | size += (PERF_STAT_CONFIG_TERM__MAX * sizeof(event->data[0])); | ||
| 887 | |||
| 888 | event = zalloc(size); | ||
| 889 | if (!event) | ||
| 890 | return -ENOMEM; | ||
| 891 | |||
| 892 | event->header.type = PERF_RECORD_STAT_CONFIG; | ||
| 893 | event->header.size = size; | ||
| 894 | event->nr = PERF_STAT_CONFIG_TERM__MAX; | ||
| 895 | |||
| 896 | #define ADD(__term, __val) \ | ||
| 897 | event->data[i].tag = PERF_STAT_CONFIG_TERM__##__term; \ | ||
| 898 | event->data[i].val = __val; \ | ||
| 899 | i++; | ||
| 900 | |||
| 901 | ADD(AGGR_MODE, config->aggr_mode) | ||
| 902 | ADD(INTERVAL, config->interval) | ||
| 903 | ADD(SCALE, config->scale) | ||
| 904 | |||
| 905 | WARN_ONCE(i != PERF_STAT_CONFIG_TERM__MAX, | ||
| 906 | "stat config terms unbalanced\n"); | ||
| 907 | #undef ADD | ||
| 908 | |||
| 909 | err = process(tool, (union perf_event *) event, NULL, machine); | ||
| 910 | |||
| 911 | free(event); | ||
| 912 | return err; | ||
| 913 | } | ||
| 914 | |||
| 915 | int perf_event__synthesize_stat(struct perf_tool *tool, | ||
| 916 | u32 cpu, u32 thread, u64 id, | ||
| 917 | struct perf_counts_values *count, | ||
| 918 | perf_event__handler_t process, | ||
| 919 | struct machine *machine) | ||
| 920 | { | ||
| 921 | struct stat_event event; | ||
| 922 | |||
| 923 | event.header.type = PERF_RECORD_STAT; | ||
| 924 | event.header.size = sizeof(event); | ||
| 925 | event.header.misc = 0; | ||
| 926 | |||
| 927 | event.id = id; | ||
| 928 | event.cpu = cpu; | ||
| 929 | event.thread = thread; | ||
| 930 | event.val = count->val; | ||
| 931 | event.ena = count->ena; | ||
| 932 | event.run = count->run; | ||
| 933 | |||
| 934 | return process(tool, (union perf_event *) &event, NULL, machine); | ||
| 935 | } | ||
| 936 | |||
| 937 | int perf_event__synthesize_stat_round(struct perf_tool *tool, | ||
| 938 | u64 evtime, u64 type, | ||
| 939 | perf_event__handler_t process, | ||
| 940 | struct machine *machine) | ||
| 941 | { | ||
| 942 | struct stat_round_event event; | ||
| 943 | |||
| 944 | event.header.type = PERF_RECORD_STAT_ROUND; | ||
| 945 | event.header.size = sizeof(event); | ||
| 946 | event.header.misc = 0; | ||
| 947 | |||
| 948 | event.time = evtime; | ||
| 949 | event.type = type; | ||
| 950 | |||
| 951 | return process(tool, (union perf_event *) &event, NULL, machine); | ||
| 952 | } | ||
| 953 | |||
| 954 | void perf_event__read_stat_config(struct perf_stat_config *config, | ||
| 955 | struct stat_config_event *event) | ||
| 956 | { | ||
| 957 | unsigned i; | ||
| 958 | |||
| 959 | for (i = 0; i < event->nr; i++) { | ||
| 960 | |||
| 961 | switch (event->data[i].tag) { | ||
| 962 | #define CASE(__term, __val) \ | ||
| 963 | case PERF_STAT_CONFIG_TERM__##__term: \ | ||
| 964 | config->__val = event->data[i].val; \ | ||
| 965 | break; | ||
| 966 | |||
| 967 | CASE(AGGR_MODE, aggr_mode) | ||
| 968 | CASE(SCALE, scale) | ||
| 969 | CASE(INTERVAL, interval) | ||
| 970 | #undef CASE | ||
| 971 | default: | ||
| 972 | pr_warning("unknown stat config term %" PRIu64 "\n", | ||
| 973 | event->data[i].tag); | ||
| 974 | } | ||
| 975 | } | ||
| 976 | } | ||
| 977 | |||
| 702 | size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp) | 978 | size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp) |
| 703 | { | 979 | { |
| 704 | const char *s; | 980 | const char *s; |
| @@ -783,6 +1059,38 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp) | |||
| 783 | event->mmap2.filename); | 1059 | event->mmap2.filename); |
| 784 | } | 1060 | } |
| 785 | 1061 | ||
| 1062 | size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp) | ||
| 1063 | { | ||
| 1064 | struct thread_map *threads = thread_map__new_event(&event->thread_map); | ||
| 1065 | size_t ret; | ||
| 1066 | |||
| 1067 | ret = fprintf(fp, " nr: "); | ||
| 1068 | |||
| 1069 | if (threads) | ||
| 1070 | ret += thread_map__fprintf(threads, fp); | ||
| 1071 | else | ||
| 1072 | ret += fprintf(fp, "failed to get threads from event\n"); | ||
| 1073 | |||
| 1074 | thread_map__put(threads); | ||
| 1075 | return ret; | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp) | ||
| 1079 | { | ||
| 1080 | struct cpu_map *cpus = cpu_map__new_data(&event->cpu_map.data); | ||
| 1081 | size_t ret; | ||
| 1082 | |||
| 1083 | ret = fprintf(fp, " nr: "); | ||
| 1084 | |||
| 1085 | if (cpus) | ||
| 1086 | ret += cpu_map__fprintf(cpus, fp); | ||
| 1087 | else | ||
| 1088 | ret += fprintf(fp, "failed to get cpumap from event\n"); | ||
| 1089 | |||
| 1090 | cpu_map__put(cpus); | ||
| 1091 | return ret; | ||
| 1092 | } | ||
| 1093 | |||
| 786 | int perf_event__process_mmap(struct perf_tool *tool __maybe_unused, | 1094 | int perf_event__process_mmap(struct perf_tool *tool __maybe_unused, |
| 787 | union perf_event *event, | 1095 | union perf_event *event, |
| 788 | struct perf_sample *sample, | 1096 | struct perf_sample *sample, |
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index a0dbcbd4f6d8..b7ffb7ee9971 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
| @@ -226,6 +226,12 @@ enum perf_user_event_type { /* above any possible kernel type */ | |||
| 226 | PERF_RECORD_AUXTRACE_INFO = 70, | 226 | PERF_RECORD_AUXTRACE_INFO = 70, |
| 227 | PERF_RECORD_AUXTRACE = 71, | 227 | PERF_RECORD_AUXTRACE = 71, |
| 228 | PERF_RECORD_AUXTRACE_ERROR = 72, | 228 | PERF_RECORD_AUXTRACE_ERROR = 72, |
| 229 | PERF_RECORD_THREAD_MAP = 73, | ||
| 230 | PERF_RECORD_CPU_MAP = 74, | ||
| 231 | PERF_RECORD_STAT_CONFIG = 75, | ||
| 232 | PERF_RECORD_STAT = 76, | ||
| 233 | PERF_RECORD_STAT_ROUND = 77, | ||
| 234 | PERF_RECORD_EVENT_UPDATE = 78, | ||
| 229 | PERF_RECORD_HEADER_MAX | 235 | PERF_RECORD_HEADER_MAX |
| 230 | }; | 236 | }; |
| 231 | 237 | ||
| @@ -270,12 +276,61 @@ struct events_stats { | |||
| 270 | u32 nr_proc_map_timeout; | 276 | u32 nr_proc_map_timeout; |
| 271 | }; | 277 | }; |
| 272 | 278 | ||
| 279 | enum { | ||
| 280 | PERF_CPU_MAP__CPUS = 0, | ||
| 281 | PERF_CPU_MAP__MASK = 1, | ||
| 282 | }; | ||
| 283 | |||
| 284 | struct cpu_map_entries { | ||
| 285 | u16 nr; | ||
| 286 | u16 cpu[]; | ||
| 287 | }; | ||
| 288 | |||
| 289 | struct cpu_map_mask { | ||
| 290 | u16 nr; | ||
| 291 | u16 long_size; | ||
| 292 | unsigned long mask[]; | ||
| 293 | }; | ||
| 294 | |||
| 295 | struct cpu_map_data { | ||
| 296 | u16 type; | ||
| 297 | char data[]; | ||
| 298 | }; | ||
| 299 | |||
| 300 | struct cpu_map_event { | ||
| 301 | struct perf_event_header header; | ||
| 302 | struct cpu_map_data data; | ||
| 303 | }; | ||
| 304 | |||
| 273 | struct attr_event { | 305 | struct attr_event { |
| 274 | struct perf_event_header header; | 306 | struct perf_event_header header; |
| 275 | struct perf_event_attr attr; | 307 | struct perf_event_attr attr; |
| 276 | u64 id[]; | 308 | u64 id[]; |
| 277 | }; | 309 | }; |
| 278 | 310 | ||
| 311 | enum { | ||
| 312 | PERF_EVENT_UPDATE__UNIT = 0, | ||
| 313 | PERF_EVENT_UPDATE__SCALE = 1, | ||
| 314 | PERF_EVENT_UPDATE__NAME = 2, | ||
| 315 | PERF_EVENT_UPDATE__CPUS = 3, | ||
| 316 | }; | ||
| 317 | |||
| 318 | struct event_update_event_cpus { | ||
| 319 | struct cpu_map_data cpus; | ||
| 320 | }; | ||
| 321 | |||
| 322 | struct event_update_event_scale { | ||
| 323 | double scale; | ||
| 324 | }; | ||
| 325 | |||
| 326 | struct event_update_event { | ||
| 327 | struct perf_event_header header; | ||
| 328 | u64 type; | ||
| 329 | u64 id; | ||
| 330 | |||
| 331 | char data[]; | ||
| 332 | }; | ||
| 333 | |||
| 279 | #define MAX_EVENT_NAME 64 | 334 | #define MAX_EVENT_NAME 64 |
| 280 | 335 | ||
| 281 | struct perf_trace_event_type { | 336 | struct perf_trace_event_type { |
| @@ -356,6 +411,63 @@ struct context_switch_event { | |||
| 356 | u32 next_prev_tid; | 411 | u32 next_prev_tid; |
| 357 | }; | 412 | }; |
| 358 | 413 | ||
| 414 | struct thread_map_event_entry { | ||
| 415 | u64 pid; | ||
| 416 | char comm[16]; | ||
| 417 | }; | ||
| 418 | |||
| 419 | struct thread_map_event { | ||
| 420 | struct perf_event_header header; | ||
| 421 | u64 nr; | ||
| 422 | struct thread_map_event_entry entries[]; | ||
| 423 | }; | ||
| 424 | |||
| 425 | enum { | ||
| 426 | PERF_STAT_CONFIG_TERM__AGGR_MODE = 0, | ||
| 427 | PERF_STAT_CONFIG_TERM__INTERVAL = 1, | ||
| 428 | PERF_STAT_CONFIG_TERM__SCALE = 2, | ||
| 429 | PERF_STAT_CONFIG_TERM__MAX = 3, | ||
| 430 | }; | ||
| 431 | |||
| 432 | struct stat_config_event_entry { | ||
| 433 | u64 tag; | ||
| 434 | u64 val; | ||
| 435 | }; | ||
| 436 | |||
| 437 | struct stat_config_event { | ||
| 438 | struct perf_event_header header; | ||
| 439 | u64 nr; | ||
| 440 | struct stat_config_event_entry data[]; | ||
| 441 | }; | ||
| 442 | |||
| 443 | struct stat_event { | ||
| 444 | struct perf_event_header header; | ||
| 445 | |||
| 446 | u64 id; | ||
| 447 | u32 cpu; | ||
| 448 | u32 thread; | ||
| 449 | |||
| 450 | union { | ||
| 451 | struct { | ||
| 452 | u64 val; | ||
| 453 | u64 ena; | ||
| 454 | u64 run; | ||
| 455 | }; | ||
| 456 | u64 values[3]; | ||
| 457 | }; | ||
| 458 | }; | ||
| 459 | |||
| 460 | enum { | ||
| 461 | PERF_STAT_ROUND_TYPE__INTERVAL = 0, | ||
| 462 | PERF_STAT_ROUND_TYPE__FINAL = 1, | ||
| 463 | }; | ||
| 464 | |||
| 465 | struct stat_round_event { | ||
| 466 | struct perf_event_header header; | ||
| 467 | u64 type; | ||
| 468 | u64 time; | ||
| 469 | }; | ||
| 470 | |||
| 359 | union perf_event { | 471 | union perf_event { |
| 360 | struct perf_event_header header; | 472 | struct perf_event_header header; |
| 361 | struct mmap_event mmap; | 473 | struct mmap_event mmap; |
| @@ -368,6 +480,7 @@ union perf_event { | |||
| 368 | struct throttle_event throttle; | 480 | struct throttle_event throttle; |
| 369 | struct sample_event sample; | 481 | struct sample_event sample; |
| 370 | struct attr_event attr; | 482 | struct attr_event attr; |
| 483 | struct event_update_event event_update; | ||
| 371 | struct event_type_event event_type; | 484 | struct event_type_event event_type; |
| 372 | struct tracing_data_event tracing_data; | 485 | struct tracing_data_event tracing_data; |
| 373 | struct build_id_event build_id; | 486 | struct build_id_event build_id; |
| @@ -378,12 +491,20 @@ union perf_event { | |||
| 378 | struct aux_event aux; | 491 | struct aux_event aux; |
| 379 | struct itrace_start_event itrace_start; | 492 | struct itrace_start_event itrace_start; |
| 380 | struct context_switch_event context_switch; | 493 | struct context_switch_event context_switch; |
| 494 | struct thread_map_event thread_map; | ||
| 495 | struct cpu_map_event cpu_map; | ||
| 496 | struct stat_config_event stat_config; | ||
| 497 | struct stat_event stat; | ||
| 498 | struct stat_round_event stat_round; | ||
| 381 | }; | 499 | }; |
| 382 | 500 | ||
| 383 | void perf_event__print_totals(void); | 501 | void perf_event__print_totals(void); |
| 384 | 502 | ||
| 385 | struct perf_tool; | 503 | struct perf_tool; |
| 386 | struct thread_map; | 504 | struct thread_map; |
| 505 | struct cpu_map; | ||
| 506 | struct perf_stat_config; | ||
| 507 | struct perf_counts_values; | ||
| 387 | 508 | ||
| 388 | typedef int (*perf_event__handler_t)(struct perf_tool *tool, | 509 | typedef int (*perf_event__handler_t)(struct perf_tool *tool, |
| 389 | union perf_event *event, | 510 | union perf_event *event, |
| @@ -395,6 +516,14 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool, | |||
| 395 | perf_event__handler_t process, | 516 | perf_event__handler_t process, |
| 396 | struct machine *machine, bool mmap_data, | 517 | struct machine *machine, bool mmap_data, |
| 397 | unsigned int proc_map_timeout); | 518 | unsigned int proc_map_timeout); |
| 519 | int perf_event__synthesize_thread_map2(struct perf_tool *tool, | ||
| 520 | struct thread_map *threads, | ||
| 521 | perf_event__handler_t process, | ||
| 522 | struct machine *machine); | ||
| 523 | int perf_event__synthesize_cpu_map(struct perf_tool *tool, | ||
| 524 | struct cpu_map *cpus, | ||
| 525 | perf_event__handler_t process, | ||
| 526 | struct machine *machine); | ||
| 398 | int perf_event__synthesize_threads(struct perf_tool *tool, | 527 | int perf_event__synthesize_threads(struct perf_tool *tool, |
| 399 | perf_event__handler_t process, | 528 | perf_event__handler_t process, |
| 400 | struct machine *machine, bool mmap_data, | 529 | struct machine *machine, bool mmap_data, |
| @@ -402,7 +531,21 @@ int perf_event__synthesize_threads(struct perf_tool *tool, | |||
| 402 | int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, | 531 | int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, |
| 403 | perf_event__handler_t process, | 532 | perf_event__handler_t process, |
| 404 | struct machine *machine); | 533 | struct machine *machine); |
| 405 | 534 | int perf_event__synthesize_stat_config(struct perf_tool *tool, | |
| 535 | struct perf_stat_config *config, | ||
| 536 | perf_event__handler_t process, | ||
| 537 | struct machine *machine); | ||
| 538 | void perf_event__read_stat_config(struct perf_stat_config *config, | ||
| 539 | struct stat_config_event *event); | ||
| 540 | int perf_event__synthesize_stat(struct perf_tool *tool, | ||
| 541 | u32 cpu, u32 thread, u64 id, | ||
| 542 | struct perf_counts_values *count, | ||
| 543 | perf_event__handler_t process, | ||
| 544 | struct machine *machine); | ||
| 545 | int perf_event__synthesize_stat_round(struct perf_tool *tool, | ||
| 546 | u64 time, u64 type, | ||
| 547 | perf_event__handler_t process, | ||
| 548 | struct machine *machine); | ||
| 406 | int perf_event__synthesize_modules(struct perf_tool *tool, | 549 | int perf_event__synthesize_modules(struct perf_tool *tool, |
| 407 | perf_event__handler_t process, | 550 | perf_event__handler_t process, |
| 408 | struct machine *machine); | 551 | struct machine *machine); |
| @@ -499,9 +642,14 @@ size_t perf_event__fprintf_task(union perf_event *event, FILE *fp); | |||
| 499 | size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp); | 642 | size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp); |
| 500 | size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp); | 643 | size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp); |
| 501 | size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp); | 644 | size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp); |
| 645 | size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp); | ||
| 646 | size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp); | ||
| 502 | size_t perf_event__fprintf(union perf_event *event, FILE *fp); | 647 | size_t perf_event__fprintf(union perf_event *event, FILE *fp); |
| 503 | 648 | ||
| 504 | u64 kallsyms__get_function_start(const char *kallsyms_filename, | 649 | u64 kallsyms__get_function_start(const char *kallsyms_filename, |
| 505 | const char *symbol_name); | 650 | const char *symbol_name); |
| 506 | 651 | ||
| 652 | void *cpu_map_data__alloc(struct cpu_map *map, size_t *size, u16 *type, int *max); | ||
| 653 | void cpu_map_data__synthesize(struct cpu_map_data *data, struct cpu_map *map, | ||
| 654 | u16 type, int max); | ||
| 507 | #endif /* __PERF_RECORD_H */ | 655 | #endif /* __PERF_RECORD_H */ |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index d1392194a9a9..d81f13de2476 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
| @@ -18,7 +18,7 @@ | |||
| 18 | #include <unistd.h> | 18 | #include <unistd.h> |
| 19 | 19 | ||
| 20 | #include "parse-events.h" | 20 | #include "parse-events.h" |
| 21 | #include "parse-options.h" | 21 | #include <subcmd/parse-options.h> |
| 22 | 22 | ||
| 23 | #include <sys/mman.h> | 23 | #include <sys/mman.h> |
| 24 | 24 | ||
| @@ -68,6 +68,18 @@ struct perf_evlist *perf_evlist__new_default(void) | |||
| 68 | return evlist; | 68 | return evlist; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | struct perf_evlist *perf_evlist__new_dummy(void) | ||
| 72 | { | ||
| 73 | struct perf_evlist *evlist = perf_evlist__new(); | ||
| 74 | |||
| 75 | if (evlist && perf_evlist__add_dummy(evlist)) { | ||
| 76 | perf_evlist__delete(evlist); | ||
| 77 | evlist = NULL; | ||
| 78 | } | ||
| 79 | |||
| 80 | return evlist; | ||
| 81 | } | ||
| 82 | |||
| 71 | /** | 83 | /** |
| 72 | * perf_evlist__set_id_pos - set the positions of event ids. | 84 | * perf_evlist__set_id_pos - set the positions of event ids. |
| 73 | * @evlist: selected event list | 85 | * @evlist: selected event list |
| @@ -248,6 +260,22 @@ error: | |||
| 248 | return -ENOMEM; | 260 | return -ENOMEM; |
| 249 | } | 261 | } |
| 250 | 262 | ||
| 263 | int perf_evlist__add_dummy(struct perf_evlist *evlist) | ||
| 264 | { | ||
| 265 | struct perf_event_attr attr = { | ||
| 266 | .type = PERF_TYPE_SOFTWARE, | ||
| 267 | .config = PERF_COUNT_SW_DUMMY, | ||
| 268 | .size = sizeof(attr), /* to capture ABI version */ | ||
| 269 | }; | ||
| 270 | struct perf_evsel *evsel = perf_evsel__new(&attr); | ||
| 271 | |||
| 272 | if (evsel == NULL) | ||
| 273 | return -ENOMEM; | ||
| 274 | |||
| 275 | perf_evlist__add(evlist, evsel); | ||
| 276 | return 0; | ||
| 277 | } | ||
| 278 | |||
| 251 | static int perf_evlist__add_attrs(struct perf_evlist *evlist, | 279 | static int perf_evlist__add_attrs(struct perf_evlist *evlist, |
| 252 | struct perf_event_attr *attrs, size_t nr_attrs) | 280 | struct perf_event_attr *attrs, size_t nr_attrs) |
| 253 | { | 281 | { |
| @@ -336,20 +364,12 @@ static int perf_evlist__nr_threads(struct perf_evlist *evlist, | |||
| 336 | 364 | ||
| 337 | void perf_evlist__disable(struct perf_evlist *evlist) | 365 | void perf_evlist__disable(struct perf_evlist *evlist) |
| 338 | { | 366 | { |
| 339 | int cpu, thread; | ||
| 340 | struct perf_evsel *pos; | 367 | struct perf_evsel *pos; |
| 341 | int nr_cpus = cpu_map__nr(evlist->cpus); | ||
| 342 | int nr_threads; | ||
| 343 | 368 | ||
| 344 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 369 | evlist__for_each(evlist, pos) { |
| 345 | evlist__for_each(evlist, pos) { | 370 | if (!perf_evsel__is_group_leader(pos) || !pos->fd) |
| 346 | if (!perf_evsel__is_group_leader(pos) || !pos->fd) | 371 | continue; |
| 347 | continue; | 372 | perf_evsel__disable(pos); |
| 348 | nr_threads = perf_evlist__nr_threads(evlist, pos); | ||
| 349 | for (thread = 0; thread < nr_threads; thread++) | ||
| 350 | ioctl(FD(pos, cpu, thread), | ||
| 351 | PERF_EVENT_IOC_DISABLE, 0); | ||
| 352 | } | ||
| 353 | } | 373 | } |
| 354 | 374 | ||
| 355 | evlist->enabled = false; | 375 | evlist->enabled = false; |
| @@ -357,20 +377,12 @@ void perf_evlist__disable(struct perf_evlist *evlist) | |||
| 357 | 377 | ||
| 358 | void perf_evlist__enable(struct perf_evlist *evlist) | 378 | void perf_evlist__enable(struct perf_evlist *evlist) |
| 359 | { | 379 | { |
| 360 | int cpu, thread; | ||
| 361 | struct perf_evsel *pos; | 380 | struct perf_evsel *pos; |
| 362 | int nr_cpus = cpu_map__nr(evlist->cpus); | ||
| 363 | int nr_threads; | ||
| 364 | 381 | ||
| 365 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 382 | evlist__for_each(evlist, pos) { |
| 366 | evlist__for_each(evlist, pos) { | 383 | if (!perf_evsel__is_group_leader(pos) || !pos->fd) |
| 367 | if (!perf_evsel__is_group_leader(pos) || !pos->fd) | 384 | continue; |
| 368 | continue; | 385 | perf_evsel__enable(pos); |
| 369 | nr_threads = perf_evlist__nr_threads(evlist, pos); | ||
| 370 | for (thread = 0; thread < nr_threads; thread++) | ||
| 371 | ioctl(FD(pos, cpu, thread), | ||
| 372 | PERF_EVENT_IOC_ENABLE, 0); | ||
| 373 | } | ||
| 374 | } | 386 | } |
| 375 | 387 | ||
| 376 | evlist->enabled = true; | 388 | evlist->enabled = true; |
| @@ -381,48 +393,6 @@ void perf_evlist__toggle_enable(struct perf_evlist *evlist) | |||
| 381 | (evlist->enabled ? perf_evlist__disable : perf_evlist__enable)(evlist); | 393 | (evlist->enabled ? perf_evlist__disable : perf_evlist__enable)(evlist); |
| 382 | } | 394 | } |
| 383 | 395 | ||
| 384 | int perf_evlist__disable_event(struct perf_evlist *evlist, | ||
| 385 | struct perf_evsel *evsel) | ||
| 386 | { | ||
| 387 | int cpu, thread, err; | ||
| 388 | int nr_cpus = cpu_map__nr(evlist->cpus); | ||
| 389 | int nr_threads = perf_evlist__nr_threads(evlist, evsel); | ||
| 390 | |||
| 391 | if (!evsel->fd) | ||
| 392 | return 0; | ||
| 393 | |||
| 394 | for (cpu = 0; cpu < nr_cpus; cpu++) { | ||
| 395 | for (thread = 0; thread < nr_threads; thread++) { | ||
| 396 | err = ioctl(FD(evsel, cpu, thread), | ||
| 397 | PERF_EVENT_IOC_DISABLE, 0); | ||
| 398 | if (err) | ||
| 399 | return err; | ||
| 400 | } | ||
| 401 | } | ||
| 402 | return 0; | ||
| 403 | } | ||
| 404 | |||
| 405 | int perf_evlist__enable_event(struct perf_evlist *evlist, | ||
| 406 | struct perf_evsel *evsel) | ||
| 407 | { | ||
| 408 | int cpu, thread, err; | ||
| 409 | int nr_cpus = cpu_map__nr(evlist->cpus); | ||
| 410 | int nr_threads = perf_evlist__nr_threads(evlist, evsel); | ||
| 411 | |||
| 412 | if (!evsel->fd) | ||
| 413 | return -EINVAL; | ||
| 414 | |||
| 415 | for (cpu = 0; cpu < nr_cpus; cpu++) { | ||
| 416 | for (thread = 0; thread < nr_threads; thread++) { | ||
| 417 | err = ioctl(FD(evsel, cpu, thread), | ||
| 418 | PERF_EVENT_IOC_ENABLE, 0); | ||
| 419 | if (err) | ||
| 420 | return err; | ||
| 421 | } | ||
| 422 | } | ||
| 423 | return 0; | ||
| 424 | } | ||
| 425 | |||
| 426 | static int perf_evlist__enable_event_cpu(struct perf_evlist *evlist, | 396 | static int perf_evlist__enable_event_cpu(struct perf_evlist *evlist, |
| 427 | struct perf_evsel *evsel, int cpu) | 397 | struct perf_evsel *evsel, int cpu) |
| 428 | { | 398 | { |
| @@ -550,9 +520,9 @@ void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, | |||
| 550 | evsel->id[evsel->ids++] = id; | 520 | evsel->id[evsel->ids++] = id; |
| 551 | } | 521 | } |
| 552 | 522 | ||
| 553 | static int perf_evlist__id_add_fd(struct perf_evlist *evlist, | 523 | int perf_evlist__id_add_fd(struct perf_evlist *evlist, |
| 554 | struct perf_evsel *evsel, | 524 | struct perf_evsel *evsel, |
| 555 | int cpu, int thread, int fd) | 525 | int cpu, int thread, int fd) |
| 556 | { | 526 | { |
| 557 | u64 read_data[4] = { 0, }; | 527 | u64 read_data[4] = { 0, }; |
| 558 | int id_idx = 1; /* The first entry is the counter value */ | 528 | int id_idx = 1; /* The first entry is the counter value */ |
| @@ -1486,7 +1456,7 @@ int perf_evlist__open(struct perf_evlist *evlist) | |||
| 1486 | perf_evlist__update_id_pos(evlist); | 1456 | perf_evlist__update_id_pos(evlist); |
| 1487 | 1457 | ||
| 1488 | evlist__for_each(evlist, evsel) { | 1458 | evlist__for_each(evlist, evsel) { |
| 1489 | err = perf_evsel__open(evsel, evlist->cpus, evlist->threads); | 1459 | err = perf_evsel__open(evsel, evsel->cpus, evsel->threads); |
| 1490 | if (err < 0) | 1460 | if (err < 0) |
| 1491 | goto out_err; | 1461 | goto out_err; |
| 1492 | } | 1462 | } |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index a459fe71b452..7c4d9a206776 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
| @@ -67,6 +67,7 @@ struct perf_evsel_str_handler { | |||
| 67 | 67 | ||
| 68 | struct perf_evlist *perf_evlist__new(void); | 68 | struct perf_evlist *perf_evlist__new(void); |
| 69 | struct perf_evlist *perf_evlist__new_default(void); | 69 | struct perf_evlist *perf_evlist__new_default(void); |
| 70 | struct perf_evlist *perf_evlist__new_dummy(void); | ||
| 70 | void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, | 71 | void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, |
| 71 | struct thread_map *threads); | 72 | struct thread_map *threads); |
| 72 | void perf_evlist__exit(struct perf_evlist *evlist); | 73 | void perf_evlist__exit(struct perf_evlist *evlist); |
| @@ -81,6 +82,8 @@ int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, | |||
| 81 | #define perf_evlist__add_default_attrs(evlist, array) \ | 82 | #define perf_evlist__add_default_attrs(evlist, array) \ |
| 82 | __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) | 83 | __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) |
| 83 | 84 | ||
| 85 | int perf_evlist__add_dummy(struct perf_evlist *evlist); | ||
| 86 | |||
| 84 | int perf_evlist__add_newtp(struct perf_evlist *evlist, | 87 | int perf_evlist__add_newtp(struct perf_evlist *evlist, |
| 85 | const char *sys, const char *name, void *handler); | 88 | const char *sys, const char *name, void *handler); |
| 86 | 89 | ||
| @@ -97,6 +100,9 @@ perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist, | |||
| 97 | 100 | ||
| 98 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, | 101 | void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, |
| 99 | int cpu, int thread, u64 id); | 102 | int cpu, int thread, u64 id); |
| 103 | int perf_evlist__id_add_fd(struct perf_evlist *evlist, | ||
| 104 | struct perf_evsel *evsel, | ||
| 105 | int cpu, int thread, int fd); | ||
| 100 | 106 | ||
| 101 | int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd); | 107 | int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd); |
| 102 | int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); | 108 | int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); |
| @@ -149,10 +155,6 @@ void perf_evlist__disable(struct perf_evlist *evlist); | |||
| 149 | void perf_evlist__enable(struct perf_evlist *evlist); | 155 | void perf_evlist__enable(struct perf_evlist *evlist); |
| 150 | void perf_evlist__toggle_enable(struct perf_evlist *evlist); | 156 | void perf_evlist__toggle_enable(struct perf_evlist *evlist); |
| 151 | 157 | ||
| 152 | int perf_evlist__disable_event(struct perf_evlist *evlist, | ||
| 153 | struct perf_evsel *evsel); | ||
| 154 | int perf_evlist__enable_event(struct perf_evlist *evlist, | ||
| 155 | struct perf_evsel *evsel); | ||
| 156 | int perf_evlist__enable_event_idx(struct perf_evlist *evlist, | 158 | int perf_evlist__enable_event_idx(struct perf_evlist *evlist, |
| 157 | struct perf_evsel *evsel, int idx); | 159 | struct perf_evsel *evsel, int idx); |
| 158 | 160 | ||
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 397fb4ed3c97..cdbaf9b51e42 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
| @@ -36,6 +36,7 @@ static struct { | |||
| 36 | bool cloexec; | 36 | bool cloexec; |
| 37 | bool clockid; | 37 | bool clockid; |
| 38 | bool clockid_wrong; | 38 | bool clockid_wrong; |
| 39 | bool lbr_flags; | ||
| 39 | } perf_missing_features; | 40 | } perf_missing_features; |
| 40 | 41 | ||
| 41 | static clockid_t clockid; | 42 | static clockid_t clockid; |
| @@ -574,7 +575,9 @@ perf_evsel__config_callgraph(struct perf_evsel *evsel, | |||
| 574 | } else { | 575 | } else { |
| 575 | perf_evsel__set_sample_bit(evsel, BRANCH_STACK); | 576 | perf_evsel__set_sample_bit(evsel, BRANCH_STACK); |
| 576 | attr->branch_sample_type = PERF_SAMPLE_BRANCH_USER | | 577 | attr->branch_sample_type = PERF_SAMPLE_BRANCH_USER | |
| 577 | PERF_SAMPLE_BRANCH_CALL_STACK; | 578 | PERF_SAMPLE_BRANCH_CALL_STACK | |
| 579 | PERF_SAMPLE_BRANCH_NO_CYCLES | | ||
| 580 | PERF_SAMPLE_BRANCH_NO_FLAGS; | ||
| 578 | } | 581 | } |
| 579 | } else | 582 | } else |
| 580 | pr_warning("Cannot use LBR callstack with branch stack. " | 583 | pr_warning("Cannot use LBR callstack with branch stack. " |
| @@ -981,13 +984,26 @@ int perf_evsel__append_filter(struct perf_evsel *evsel, | |||
| 981 | return -1; | 984 | return -1; |
| 982 | } | 985 | } |
| 983 | 986 | ||
| 984 | int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads) | 987 | int perf_evsel__enable(struct perf_evsel *evsel) |
| 985 | { | 988 | { |
| 989 | int nthreads = thread_map__nr(evsel->threads); | ||
| 990 | int ncpus = cpu_map__nr(evsel->cpus); | ||
| 991 | |||
| 986 | return perf_evsel__run_ioctl(evsel, ncpus, nthreads, | 992 | return perf_evsel__run_ioctl(evsel, ncpus, nthreads, |
| 987 | PERF_EVENT_IOC_ENABLE, | 993 | PERF_EVENT_IOC_ENABLE, |
| 988 | 0); | 994 | 0); |
| 989 | } | 995 | } |
| 990 | 996 | ||
| 997 | int perf_evsel__disable(struct perf_evsel *evsel) | ||
| 998 | { | ||
| 999 | int nthreads = thread_map__nr(evsel->threads); | ||
| 1000 | int ncpus = cpu_map__nr(evsel->cpus); | ||
| 1001 | |||
| 1002 | return perf_evsel__run_ioctl(evsel, ncpus, nthreads, | ||
| 1003 | PERF_EVENT_IOC_DISABLE, | ||
| 1004 | 0); | ||
| 1005 | } | ||
| 1006 | |||
| 991 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) | 1007 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 992 | { | 1008 | { |
| 993 | if (ncpus == 0 || nthreads == 0) | 1009 | if (ncpus == 0 || nthreads == 0) |
| @@ -1192,6 +1208,7 @@ static void __p_sample_type(char *buf, size_t size, u64 value) | |||
| 1192 | bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW), | 1208 | bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW), |
| 1193 | bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER), | 1209 | bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER), |
| 1194 | bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC), | 1210 | bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC), |
| 1211 | bit_name(WEIGHT), | ||
| 1195 | { .name = NULL, } | 1212 | { .name = NULL, } |
| 1196 | }; | 1213 | }; |
| 1197 | #undef bit_name | 1214 | #undef bit_name |
| @@ -1323,6 +1340,9 @@ fallback_missing_features: | |||
| 1323 | evsel->attr.mmap2 = 0; | 1340 | evsel->attr.mmap2 = 0; |
| 1324 | if (perf_missing_features.exclude_guest) | 1341 | if (perf_missing_features.exclude_guest) |
| 1325 | evsel->attr.exclude_guest = evsel->attr.exclude_host = 0; | 1342 | evsel->attr.exclude_guest = evsel->attr.exclude_host = 0; |
| 1343 | if (perf_missing_features.lbr_flags) | ||
| 1344 | evsel->attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS | | ||
| 1345 | PERF_SAMPLE_BRANCH_NO_CYCLES); | ||
| 1326 | retry_sample_id: | 1346 | retry_sample_id: |
| 1327 | if (perf_missing_features.sample_id_all) | 1347 | if (perf_missing_features.sample_id_all) |
| 1328 | evsel->attr.sample_id_all = 0; | 1348 | evsel->attr.sample_id_all = 0; |
| @@ -1441,6 +1461,12 @@ try_fallback: | |||
| 1441 | } else if (!perf_missing_features.sample_id_all) { | 1461 | } else if (!perf_missing_features.sample_id_all) { |
| 1442 | perf_missing_features.sample_id_all = true; | 1462 | perf_missing_features.sample_id_all = true; |
| 1443 | goto retry_sample_id; | 1463 | goto retry_sample_id; |
| 1464 | } else if (!perf_missing_features.lbr_flags && | ||
| 1465 | (evsel->attr.branch_sample_type & | ||
| 1466 | (PERF_SAMPLE_BRANCH_NO_CYCLES | | ||
| 1467 | PERF_SAMPLE_BRANCH_NO_FLAGS))) { | ||
| 1468 | perf_missing_features.lbr_flags = true; | ||
| 1469 | goto fallback_missing_features; | ||
| 1444 | } | 1470 | } |
| 1445 | 1471 | ||
| 1446 | out_close: | 1472 | out_close: |
| @@ -2272,6 +2298,29 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, | |||
| 2272 | printed += comma_fprintf(fp, &first, " %s=%" PRIu64, | 2298 | printed += comma_fprintf(fp, &first, " %s=%" PRIu64, |
| 2273 | term, (u64)evsel->attr.sample_freq); | 2299 | term, (u64)evsel->attr.sample_freq); |
| 2274 | } | 2300 | } |
| 2301 | |||
| 2302 | if (details->trace_fields) { | ||
| 2303 | struct format_field *field; | ||
| 2304 | |||
| 2305 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { | ||
| 2306 | printed += comma_fprintf(fp, &first, " (not a tracepoint)"); | ||
| 2307 | goto out; | ||
| 2308 | } | ||
| 2309 | |||
| 2310 | field = evsel->tp_format->format.fields; | ||
| 2311 | if (field == NULL) { | ||
| 2312 | printed += comma_fprintf(fp, &first, " (no trace field)"); | ||
| 2313 | goto out; | ||
| 2314 | } | ||
| 2315 | |||
| 2316 | printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name); | ||
| 2317 | |||
| 2318 | field = field->next; | ||
| 2319 | while (field) { | ||
| 2320 | printed += comma_fprintf(fp, &first, "%s", field->name); | ||
| 2321 | field = field->next; | ||
| 2322 | } | ||
| 2323 | } | ||
| 2275 | out: | 2324 | out: |
| 2276 | fputc('\n', fp); | 2325 | fputc('\n', fp); |
| 2277 | return ++printed; | 2326 | return ++printed; |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 0e49bd742c63..8e75434bd01c 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
| @@ -227,7 +227,8 @@ int perf_evsel__append_filter(struct perf_evsel *evsel, | |||
| 227 | const char *op, const char *filter); | 227 | const char *op, const char *filter); |
| 228 | int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads, | 228 | int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads, |
| 229 | const char *filter); | 229 | const char *filter); |
| 230 | int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads); | 230 | int perf_evsel__enable(struct perf_evsel *evsel); |
| 231 | int perf_evsel__disable(struct perf_evsel *evsel); | ||
| 231 | 232 | ||
| 232 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, | 233 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, |
| 233 | struct cpu_map *cpus); | 234 | struct cpu_map *cpus); |
| @@ -368,6 +369,7 @@ struct perf_attr_details { | |||
| 368 | bool verbose; | 369 | bool verbose; |
| 369 | bool event_group; | 370 | bool event_group; |
| 370 | bool force; | 371 | bool force; |
| 372 | bool trace_fields; | ||
| 371 | }; | 373 | }; |
| 372 | 374 | ||
| 373 | int perf_evsel__fprintf(struct perf_evsel *evsel, | 375 | int perf_evsel__fprintf(struct perf_evsel *evsel, |
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c deleted file mode 100644 index 7adf4ad15d8f..000000000000 --- a/tools/perf/util/exec_cmd.c +++ /dev/null | |||
| @@ -1,148 +0,0 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include "exec_cmd.h" | ||
| 3 | #include "quote.h" | ||
| 4 | |||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | #define MAX_ARGS 32 | ||
| 8 | |||
| 9 | static const char *argv_exec_path; | ||
| 10 | static const char *argv0_path; | ||
| 11 | |||
| 12 | const char *system_path(const char *path) | ||
| 13 | { | ||
| 14 | static const char *prefix = PREFIX; | ||
| 15 | struct strbuf d = STRBUF_INIT; | ||
| 16 | |||
| 17 | if (is_absolute_path(path)) | ||
| 18 | return path; | ||
| 19 | |||
| 20 | strbuf_addf(&d, "%s/%s", prefix, path); | ||
| 21 | path = strbuf_detach(&d, NULL); | ||
| 22 | return path; | ||
| 23 | } | ||
| 24 | |||
| 25 | const char *perf_extract_argv0_path(const char *argv0) | ||
| 26 | { | ||
| 27 | const char *slash; | ||
| 28 | |||
| 29 | if (!argv0 || !*argv0) | ||
| 30 | return NULL; | ||
| 31 | slash = argv0 + strlen(argv0); | ||
| 32 | |||
| 33 | while (argv0 <= slash && !is_dir_sep(*slash)) | ||
| 34 | slash--; | ||
| 35 | |||
| 36 | if (slash >= argv0) { | ||
| 37 | argv0_path = strndup(argv0, slash - argv0); | ||
| 38 | return argv0_path ? slash + 1 : NULL; | ||
| 39 | } | ||
| 40 | |||
| 41 | return argv0; | ||
| 42 | } | ||
| 43 | |||
| 44 | void perf_set_argv_exec_path(const char *exec_path) | ||
| 45 | { | ||
| 46 | argv_exec_path = exec_path; | ||
| 47 | /* | ||
| 48 | * Propagate this setting to external programs. | ||
| 49 | */ | ||
| 50 | setenv(EXEC_PATH_ENVIRONMENT, exec_path, 1); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | /* Returns the highest-priority, location to look for perf programs. */ | ||
| 55 | const char *perf_exec_path(void) | ||
| 56 | { | ||
| 57 | const char *env; | ||
| 58 | |||
| 59 | if (argv_exec_path) | ||
| 60 | return argv_exec_path; | ||
| 61 | |||
| 62 | env = getenv(EXEC_PATH_ENVIRONMENT); | ||
| 63 | if (env && *env) { | ||
| 64 | return env; | ||
| 65 | } | ||
| 66 | |||
| 67 | return system_path(PERF_EXEC_PATH); | ||
| 68 | } | ||
| 69 | |||
| 70 | static void add_path(struct strbuf *out, const char *path) | ||
| 71 | { | ||
| 72 | if (path && *path) { | ||
| 73 | if (is_absolute_path(path)) | ||
| 74 | strbuf_addstr(out, path); | ||
| 75 | else | ||
| 76 | strbuf_addstr(out, make_nonrelative_path(path)); | ||
| 77 | |||
| 78 | strbuf_addch(out, PATH_SEP); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | void setup_path(void) | ||
| 83 | { | ||
| 84 | const char *old_path = getenv("PATH"); | ||
| 85 | struct strbuf new_path = STRBUF_INIT; | ||
| 86 | |||
| 87 | add_path(&new_path, perf_exec_path()); | ||
| 88 | add_path(&new_path, argv0_path); | ||
| 89 | |||
| 90 | if (old_path) | ||
| 91 | strbuf_addstr(&new_path, old_path); | ||
| 92 | else | ||
| 93 | strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin"); | ||
| 94 | |||
| 95 | setenv("PATH", new_path.buf, 1); | ||
| 96 | |||
| 97 | strbuf_release(&new_path); | ||
| 98 | } | ||
| 99 | |||
| 100 | static const char **prepare_perf_cmd(const char **argv) | ||
| 101 | { | ||
| 102 | int argc; | ||
| 103 | const char **nargv; | ||
| 104 | |||
| 105 | for (argc = 0; argv[argc]; argc++) | ||
| 106 | ; /* just counting */ | ||
| 107 | nargv = malloc(sizeof(*nargv) * (argc + 2)); | ||
| 108 | |||
| 109 | nargv[0] = "perf"; | ||
| 110 | for (argc = 0; argv[argc]; argc++) | ||
| 111 | nargv[argc + 1] = argv[argc]; | ||
| 112 | nargv[argc + 1] = NULL; | ||
| 113 | return nargv; | ||
| 114 | } | ||
| 115 | |||
| 116 | int execv_perf_cmd(const char **argv) { | ||
| 117 | const char **nargv = prepare_perf_cmd(argv); | ||
| 118 | |||
| 119 | /* execvp() can only ever return if it fails */ | ||
| 120 | execvp("perf", (char **)nargv); | ||
| 121 | |||
| 122 | free(nargv); | ||
| 123 | return -1; | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | int execl_perf_cmd(const char *cmd,...) | ||
| 128 | { | ||
| 129 | int argc; | ||
| 130 | const char *argv[MAX_ARGS + 1]; | ||
| 131 | const char *arg; | ||
| 132 | va_list param; | ||
| 133 | |||
| 134 | va_start(param, cmd); | ||
| 135 | argv[0] = cmd; | ||
| 136 | argc = 1; | ||
| 137 | while (argc < MAX_ARGS) { | ||
| 138 | arg = argv[argc++] = va_arg(param, char *); | ||
| 139 | if (!arg) | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | va_end(param); | ||
| 143 | if (MAX_ARGS <= argc) | ||
| 144 | return error("too many args to run %s", cmd); | ||
| 145 | |||
| 146 | argv[argc] = NULL; | ||
| 147 | return execv_perf_cmd(argv); | ||
| 148 | } | ||
diff --git a/tools/perf/util/exec_cmd.h b/tools/perf/util/exec_cmd.h deleted file mode 100644 index bc4b915963f5..000000000000 --- a/tools/perf/util/exec_cmd.h +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | #ifndef __PERF_EXEC_CMD_H | ||
| 2 | #define __PERF_EXEC_CMD_H | ||
| 3 | |||
| 4 | extern void perf_set_argv_exec_path(const char *exec_path); | ||
| 5 | extern const char *perf_extract_argv0_path(const char *path); | ||
| 6 | extern const char *perf_exec_path(void); | ||
| 7 | extern void setup_path(void); | ||
| 8 | extern int execv_perf_cmd(const char **argv); /* NULL terminated */ | ||
| 9 | extern int execl_perf_cmd(const char *cmd, ...); | ||
| 10 | extern const char *system_path(const char *path); | ||
| 11 | |||
| 12 | #endif /* __PERF_EXEC_CMD_H */ | ||
diff --git a/tools/perf/util/generate-cmdlist.sh b/tools/perf/util/generate-cmdlist.sh index 36a885d2cd22..0ac2037c970c 100755 --- a/tools/perf/util/generate-cmdlist.sh +++ b/tools/perf/util/generate-cmdlist.sh | |||
| @@ -36,4 +36,19 @@ do | |||
| 36 | }' "Documentation/perf-$cmd.txt" | 36 | }' "Documentation/perf-$cmd.txt" |
| 37 | done | 37 | done |
| 38 | echo "#endif /* HAVE_LIBELF_SUPPORT */" | 38 | echo "#endif /* HAVE_LIBELF_SUPPORT */" |
| 39 | |||
| 40 | echo "#ifdef HAVE_LIBAUDIT_SUPPORT" | ||
| 41 | sed -n -e 's/^perf-\([^ ]*\)[ ].* audit*/\1/p' command-list.txt | | ||
| 42 | sort | | ||
| 43 | while read cmd | ||
| 44 | do | ||
| 45 | sed -n ' | ||
| 46 | /^NAME/,/perf-'"$cmd"'/H | ||
| 47 | ${ | ||
| 48 | x | ||
| 49 | s/.*perf-'"$cmd"' - \(.*\)/ {"'"$cmd"'", "\1"},/ | ||
| 50 | p | ||
| 51 | }' "Documentation/perf-$cmd.txt" | ||
| 52 | done | ||
| 53 | echo "#endif /* HAVE_LIBELF_SUPPORT */" | ||
| 39 | echo "};" | 54 | echo "};" |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 43838003c1a1..f50b7235ecb6 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
| @@ -724,7 +724,7 @@ static int write_numa_topology(int fd, struct perf_header *h __maybe_unused, | |||
| 724 | done: | 724 | done: |
| 725 | free(buf); | 725 | free(buf); |
| 726 | fclose(fp); | 726 | fclose(fp); |
| 727 | free(node_map); | 727 | cpu_map__put(node_map); |
| 728 | return ret; | 728 | return ret; |
| 729 | } | 729 | } |
| 730 | 730 | ||
| @@ -868,6 +868,13 @@ static int write_auxtrace(int fd, struct perf_header *h, | |||
| 868 | return err; | 868 | return err; |
| 869 | } | 869 | } |
| 870 | 870 | ||
| 871 | static int write_stat(int fd __maybe_unused, | ||
| 872 | struct perf_header *h __maybe_unused, | ||
| 873 | struct perf_evlist *evlist __maybe_unused) | ||
| 874 | { | ||
| 875 | return 0; | ||
| 876 | } | ||
| 877 | |||
| 871 | static void print_hostname(struct perf_header *ph, int fd __maybe_unused, | 878 | static void print_hostname(struct perf_header *ph, int fd __maybe_unused, |
| 872 | FILE *fp) | 879 | FILE *fp) |
| 873 | { | 880 | { |
| @@ -1159,6 +1166,12 @@ static void print_auxtrace(struct perf_header *ph __maybe_unused, | |||
| 1159 | fprintf(fp, "# contains AUX area data (e.g. instruction trace)\n"); | 1166 | fprintf(fp, "# contains AUX area data (e.g. instruction trace)\n"); |
| 1160 | } | 1167 | } |
| 1161 | 1168 | ||
| 1169 | static void print_stat(struct perf_header *ph __maybe_unused, | ||
| 1170 | int fd __maybe_unused, FILE *fp) | ||
| 1171 | { | ||
| 1172 | fprintf(fp, "# contains stat data\n"); | ||
| 1173 | } | ||
| 1174 | |||
| 1162 | static void print_pmu_mappings(struct perf_header *ph, int fd __maybe_unused, | 1175 | static void print_pmu_mappings(struct perf_header *ph, int fd __maybe_unused, |
| 1163 | FILE *fp) | 1176 | FILE *fp) |
| 1164 | { | 1177 | { |
| @@ -1948,6 +1961,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { | |||
| 1948 | FEAT_OPP(HEADER_PMU_MAPPINGS, pmu_mappings), | 1961 | FEAT_OPP(HEADER_PMU_MAPPINGS, pmu_mappings), |
| 1949 | FEAT_OPP(HEADER_GROUP_DESC, group_desc), | 1962 | FEAT_OPP(HEADER_GROUP_DESC, group_desc), |
| 1950 | FEAT_OPP(HEADER_AUXTRACE, auxtrace), | 1963 | FEAT_OPP(HEADER_AUXTRACE, auxtrace), |
| 1964 | FEAT_OPA(HEADER_STAT, stat), | ||
| 1951 | }; | 1965 | }; |
| 1952 | 1966 | ||
| 1953 | struct header_print_data { | 1967 | struct header_print_data { |
| @@ -2686,6 +2700,152 @@ int perf_event__synthesize_attr(struct perf_tool *tool, | |||
| 2686 | return err; | 2700 | return err; |
| 2687 | } | 2701 | } |
| 2688 | 2702 | ||
| 2703 | static struct event_update_event * | ||
| 2704 | event_update_event__new(size_t size, u64 type, u64 id) | ||
| 2705 | { | ||
| 2706 | struct event_update_event *ev; | ||
| 2707 | |||
| 2708 | size += sizeof(*ev); | ||
| 2709 | size = PERF_ALIGN(size, sizeof(u64)); | ||
| 2710 | |||
| 2711 | ev = zalloc(size); | ||
| 2712 | if (ev) { | ||
| 2713 | ev->header.type = PERF_RECORD_EVENT_UPDATE; | ||
| 2714 | ev->header.size = (u16)size; | ||
| 2715 | ev->type = type; | ||
| 2716 | ev->id = id; | ||
| 2717 | } | ||
| 2718 | return ev; | ||
| 2719 | } | ||
| 2720 | |||
| 2721 | int | ||
| 2722 | perf_event__synthesize_event_update_unit(struct perf_tool *tool, | ||
| 2723 | struct perf_evsel *evsel, | ||
| 2724 | perf_event__handler_t process) | ||
| 2725 | { | ||
| 2726 | struct event_update_event *ev; | ||
| 2727 | size_t size = strlen(evsel->unit); | ||
| 2728 | int err; | ||
| 2729 | |||
| 2730 | ev = event_update_event__new(size + 1, PERF_EVENT_UPDATE__UNIT, evsel->id[0]); | ||
| 2731 | if (ev == NULL) | ||
| 2732 | return -ENOMEM; | ||
| 2733 | |||
| 2734 | strncpy(ev->data, evsel->unit, size); | ||
| 2735 | err = process(tool, (union perf_event *)ev, NULL, NULL); | ||
| 2736 | free(ev); | ||
| 2737 | return err; | ||
| 2738 | } | ||
| 2739 | |||
| 2740 | int | ||
| 2741 | perf_event__synthesize_event_update_scale(struct perf_tool *tool, | ||
| 2742 | struct perf_evsel *evsel, | ||
| 2743 | perf_event__handler_t process) | ||
| 2744 | { | ||
| 2745 | struct event_update_event *ev; | ||
| 2746 | struct event_update_event_scale *ev_data; | ||
| 2747 | int err; | ||
| 2748 | |||
| 2749 | ev = event_update_event__new(sizeof(*ev_data), PERF_EVENT_UPDATE__SCALE, evsel->id[0]); | ||
| 2750 | if (ev == NULL) | ||
| 2751 | return -ENOMEM; | ||
| 2752 | |||
| 2753 | ev_data = (struct event_update_event_scale *) ev->data; | ||
| 2754 | ev_data->scale = evsel->scale; | ||
| 2755 | err = process(tool, (union perf_event*) ev, NULL, NULL); | ||
| 2756 | free(ev); | ||
| 2757 | return err; | ||
| 2758 | } | ||
| 2759 | |||
| 2760 | int | ||
| 2761 | perf_event__synthesize_event_update_name(struct perf_tool *tool, | ||
| 2762 | struct perf_evsel *evsel, | ||
| 2763 | perf_event__handler_t process) | ||
| 2764 | { | ||
| 2765 | struct event_update_event *ev; | ||
| 2766 | size_t len = strlen(evsel->name); | ||
| 2767 | int err; | ||
| 2768 | |||
| 2769 | ev = event_update_event__new(len + 1, PERF_EVENT_UPDATE__NAME, evsel->id[0]); | ||
| 2770 | if (ev == NULL) | ||
| 2771 | return -ENOMEM; | ||
| 2772 | |||
| 2773 | strncpy(ev->data, evsel->name, len); | ||
| 2774 | err = process(tool, (union perf_event*) ev, NULL, NULL); | ||
| 2775 | free(ev); | ||
| 2776 | return err; | ||
| 2777 | } | ||
| 2778 | |||
| 2779 | int | ||
| 2780 | perf_event__synthesize_event_update_cpus(struct perf_tool *tool, | ||
| 2781 | struct perf_evsel *evsel, | ||
| 2782 | perf_event__handler_t process) | ||
| 2783 | { | ||
| 2784 | size_t size = sizeof(struct event_update_event); | ||
| 2785 | struct event_update_event *ev; | ||
| 2786 | int max, err; | ||
| 2787 | u16 type; | ||
| 2788 | |||
| 2789 | if (!evsel->own_cpus) | ||
| 2790 | return 0; | ||
| 2791 | |||
| 2792 | ev = cpu_map_data__alloc(evsel->own_cpus, &size, &type, &max); | ||
| 2793 | if (!ev) | ||
| 2794 | return -ENOMEM; | ||
| 2795 | |||
| 2796 | ev->header.type = PERF_RECORD_EVENT_UPDATE; | ||
| 2797 | ev->header.size = (u16)size; | ||
| 2798 | ev->type = PERF_EVENT_UPDATE__CPUS; | ||
| 2799 | ev->id = evsel->id[0]; | ||
| 2800 | |||
| 2801 | cpu_map_data__synthesize((struct cpu_map_data *) ev->data, | ||
| 2802 | evsel->own_cpus, | ||
| 2803 | type, max); | ||
| 2804 | |||
| 2805 | err = process(tool, (union perf_event*) ev, NULL, NULL); | ||
| 2806 | free(ev); | ||
| 2807 | return err; | ||
| 2808 | } | ||
| 2809 | |||
| 2810 | size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp) | ||
| 2811 | { | ||
| 2812 | struct event_update_event *ev = &event->event_update; | ||
| 2813 | struct event_update_event_scale *ev_scale; | ||
| 2814 | struct event_update_event_cpus *ev_cpus; | ||
| 2815 | struct cpu_map *map; | ||
| 2816 | size_t ret; | ||
| 2817 | |||
| 2818 | ret = fprintf(fp, "\n... id: %" PRIu64 "\n", ev->id); | ||
| 2819 | |||
| 2820 | switch (ev->type) { | ||
| 2821 | case PERF_EVENT_UPDATE__SCALE: | ||
| 2822 | ev_scale = (struct event_update_event_scale *) ev->data; | ||
| 2823 | ret += fprintf(fp, "... scale: %f\n", ev_scale->scale); | ||
| 2824 | break; | ||
| 2825 | case PERF_EVENT_UPDATE__UNIT: | ||
| 2826 | ret += fprintf(fp, "... unit: %s\n", ev->data); | ||
| 2827 | break; | ||
| 2828 | case PERF_EVENT_UPDATE__NAME: | ||
| 2829 | ret += fprintf(fp, "... name: %s\n", ev->data); | ||
| 2830 | break; | ||
| 2831 | case PERF_EVENT_UPDATE__CPUS: | ||
| 2832 | ev_cpus = (struct event_update_event_cpus *) ev->data; | ||
| 2833 | ret += fprintf(fp, "... "); | ||
| 2834 | |||
| 2835 | map = cpu_map__new_data(&ev_cpus->cpus); | ||
| 2836 | if (map) | ||
| 2837 | ret += cpu_map__fprintf(map, fp); | ||
| 2838 | else | ||
| 2839 | ret += fprintf(fp, "failed to get cpus\n"); | ||
| 2840 | break; | ||
| 2841 | default: | ||
| 2842 | ret += fprintf(fp, "... unknown type\n"); | ||
| 2843 | break; | ||
| 2844 | } | ||
| 2845 | |||
| 2846 | return ret; | ||
| 2847 | } | ||
| 2848 | |||
| 2689 | int perf_event__synthesize_attrs(struct perf_tool *tool, | 2849 | int perf_event__synthesize_attrs(struct perf_tool *tool, |
| 2690 | struct perf_session *session, | 2850 | struct perf_session *session, |
| 2691 | perf_event__handler_t process) | 2851 | perf_event__handler_t process) |
| @@ -2745,6 +2905,51 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused, | |||
| 2745 | return 0; | 2905 | return 0; |
| 2746 | } | 2906 | } |
| 2747 | 2907 | ||
| 2908 | int perf_event__process_event_update(struct perf_tool *tool __maybe_unused, | ||
| 2909 | union perf_event *event, | ||
| 2910 | struct perf_evlist **pevlist) | ||
| 2911 | { | ||
| 2912 | struct event_update_event *ev = &event->event_update; | ||
| 2913 | struct event_update_event_scale *ev_scale; | ||
| 2914 | struct event_update_event_cpus *ev_cpus; | ||
| 2915 | struct perf_evlist *evlist; | ||
| 2916 | struct perf_evsel *evsel; | ||
| 2917 | struct cpu_map *map; | ||
| 2918 | |||
| 2919 | if (!pevlist || *pevlist == NULL) | ||
| 2920 | return -EINVAL; | ||
| 2921 | |||
| 2922 | evlist = *pevlist; | ||
| 2923 | |||
| 2924 | evsel = perf_evlist__id2evsel(evlist, ev->id); | ||
| 2925 | if (evsel == NULL) | ||
| 2926 | return -EINVAL; | ||
| 2927 | |||
| 2928 | switch (ev->type) { | ||
| 2929 | case PERF_EVENT_UPDATE__UNIT: | ||
| 2930 | evsel->unit = strdup(ev->data); | ||
| 2931 | break; | ||
| 2932 | case PERF_EVENT_UPDATE__NAME: | ||
| 2933 | evsel->name = strdup(ev->data); | ||
| 2934 | break; | ||
| 2935 | case PERF_EVENT_UPDATE__SCALE: | ||
| 2936 | ev_scale = (struct event_update_event_scale *) ev->data; | ||
| 2937 | evsel->scale = ev_scale->scale; | ||
| 2938 | case PERF_EVENT_UPDATE__CPUS: | ||
| 2939 | ev_cpus = (struct event_update_event_cpus *) ev->data; | ||
| 2940 | |||
| 2941 | map = cpu_map__new_data(&ev_cpus->cpus); | ||
| 2942 | if (map) | ||
| 2943 | evsel->own_cpus = map; | ||
| 2944 | else | ||
| 2945 | pr_err("failed to get event_update cpus\n"); | ||
| 2946 | default: | ||
| 2947 | break; | ||
| 2948 | } | ||
| 2949 | |||
| 2950 | return 0; | ||
| 2951 | } | ||
| 2952 | |||
| 2748 | int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd, | 2953 | int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd, |
| 2749 | struct perf_evlist *evlist, | 2954 | struct perf_evlist *evlist, |
| 2750 | perf_event__handler_t process) | 2955 | perf_event__handler_t process) |
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 05f27cb6b7e3..cff9892452ee 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
| @@ -31,6 +31,7 @@ enum { | |||
| 31 | HEADER_PMU_MAPPINGS, | 31 | HEADER_PMU_MAPPINGS, |
| 32 | HEADER_GROUP_DESC, | 32 | HEADER_GROUP_DESC, |
| 33 | HEADER_AUXTRACE, | 33 | HEADER_AUXTRACE, |
| 34 | HEADER_STAT, | ||
| 34 | HEADER_LAST_FEATURE, | 35 | HEADER_LAST_FEATURE, |
| 35 | HEADER_FEAT_BITS = 256, | 36 | HEADER_FEAT_BITS = 256, |
| 36 | }; | 37 | }; |
| @@ -105,8 +106,24 @@ int perf_event__synthesize_attr(struct perf_tool *tool, | |||
| 105 | int perf_event__synthesize_attrs(struct perf_tool *tool, | 106 | int perf_event__synthesize_attrs(struct perf_tool *tool, |
| 106 | struct perf_session *session, | 107 | struct perf_session *session, |
| 107 | perf_event__handler_t process); | 108 | perf_event__handler_t process); |
| 109 | int perf_event__synthesize_event_update_unit(struct perf_tool *tool, | ||
| 110 | struct perf_evsel *evsel, | ||
| 111 | perf_event__handler_t process); | ||
| 112 | int perf_event__synthesize_event_update_scale(struct perf_tool *tool, | ||
| 113 | struct perf_evsel *evsel, | ||
| 114 | perf_event__handler_t process); | ||
| 115 | int perf_event__synthesize_event_update_name(struct perf_tool *tool, | ||
| 116 | struct perf_evsel *evsel, | ||
| 117 | perf_event__handler_t process); | ||
| 118 | int perf_event__synthesize_event_update_cpus(struct perf_tool *tool, | ||
| 119 | struct perf_evsel *evsel, | ||
| 120 | perf_event__handler_t process); | ||
| 108 | int perf_event__process_attr(struct perf_tool *tool, union perf_event *event, | 121 | int perf_event__process_attr(struct perf_tool *tool, union perf_event *event, |
| 109 | struct perf_evlist **pevlist); | 122 | struct perf_evlist **pevlist); |
| 123 | int perf_event__process_event_update(struct perf_tool *tool __maybe_unused, | ||
| 124 | union perf_event *event, | ||
| 125 | struct perf_evlist **pevlist); | ||
| 126 | size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp); | ||
| 110 | 127 | ||
| 111 | int perf_event__synthesize_tracing_data(struct perf_tool *tool, | 128 | int perf_event__synthesize_tracing_data(struct perf_tool *tool, |
| 112 | int fd, struct perf_evlist *evlist, | 129 | int fd, struct perf_evlist *evlist, |
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c new file mode 100644 index 000000000000..dc1e41c9b054 --- /dev/null +++ b/tools/perf/util/help-unknown-cmd.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include <subcmd/help.h> | ||
| 3 | #include "../builtin.h" | ||
| 4 | #include "levenshtein.h" | ||
| 5 | |||
| 6 | static int autocorrect; | ||
| 7 | static struct cmdnames aliases; | ||
| 8 | |||
| 9 | static int perf_unknown_cmd_config(const char *var, const char *value, void *cb) | ||
| 10 | { | ||
| 11 | if (!strcmp(var, "help.autocorrect")) | ||
| 12 | autocorrect = perf_config_int(var,value); | ||
| 13 | /* Also use aliases for command lookup */ | ||
| 14 | if (!prefixcmp(var, "alias.")) | ||
| 15 | add_cmdname(&aliases, var + 6, strlen(var + 6)); | ||
| 16 | |||
| 17 | return perf_default_config(var, value, cb); | ||
| 18 | } | ||
| 19 | |||
| 20 | static int levenshtein_compare(const void *p1, const void *p2) | ||
| 21 | { | ||
| 22 | const struct cmdname *const *c1 = p1, *const *c2 = p2; | ||
| 23 | const char *s1 = (*c1)->name, *s2 = (*c2)->name; | ||
| 24 | int l1 = (*c1)->len; | ||
| 25 | int l2 = (*c2)->len; | ||
| 26 | return l1 != l2 ? l1 - l2 : strcmp(s1, s2); | ||
| 27 | } | ||
| 28 | |||
| 29 | static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) | ||
| 30 | { | ||
| 31 | unsigned int i; | ||
| 32 | |||
| 33 | ALLOC_GROW(cmds->names, cmds->cnt + old->cnt, cmds->alloc); | ||
| 34 | |||
| 35 | for (i = 0; i < old->cnt; i++) | ||
| 36 | cmds->names[cmds->cnt++] = old->names[i]; | ||
| 37 | zfree(&old->names); | ||
| 38 | old->cnt = 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | const char *help_unknown_cmd(const char *cmd) | ||
| 42 | { | ||
| 43 | unsigned int i, n = 0, best_similarity = 0; | ||
| 44 | struct cmdnames main_cmds, other_cmds; | ||
| 45 | |||
| 46 | memset(&main_cmds, 0, sizeof(main_cmds)); | ||
| 47 | memset(&other_cmds, 0, sizeof(main_cmds)); | ||
| 48 | memset(&aliases, 0, sizeof(aliases)); | ||
| 49 | |||
| 50 | perf_config(perf_unknown_cmd_config, NULL); | ||
| 51 | |||
| 52 | load_command_list("perf-", &main_cmds, &other_cmds); | ||
| 53 | |||
| 54 | add_cmd_list(&main_cmds, &aliases); | ||
| 55 | add_cmd_list(&main_cmds, &other_cmds); | ||
| 56 | qsort(main_cmds.names, main_cmds.cnt, | ||
| 57 | sizeof(main_cmds.names), cmdname_compare); | ||
| 58 | uniq(&main_cmds); | ||
| 59 | |||
| 60 | if (main_cmds.cnt) { | ||
| 61 | /* This reuses cmdname->len for similarity index */ | ||
| 62 | for (i = 0; i < main_cmds.cnt; ++i) | ||
| 63 | main_cmds.names[i]->len = | ||
| 64 | levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4); | ||
| 65 | |||
| 66 | qsort(main_cmds.names, main_cmds.cnt, | ||
| 67 | sizeof(*main_cmds.names), levenshtein_compare); | ||
| 68 | |||
| 69 | best_similarity = main_cmds.names[0]->len; | ||
| 70 | n = 1; | ||
| 71 | while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len) | ||
| 72 | ++n; | ||
| 73 | } | ||
| 74 | |||
| 75 | if (autocorrect && n == 1) { | ||
| 76 | const char *assumed = main_cmds.names[0]->name; | ||
| 77 | |||
| 78 | main_cmds.names[0] = NULL; | ||
| 79 | clean_cmdnames(&main_cmds); | ||
| 80 | fprintf(stderr, "WARNING: You called a perf program named '%s', " | ||
| 81 | "which does not exist.\n" | ||
| 82 | "Continuing under the assumption that you meant '%s'\n", | ||
| 83 | cmd, assumed); | ||
| 84 | if (autocorrect > 0) { | ||
| 85 | fprintf(stderr, "in %0.1f seconds automatically...\n", | ||
| 86 | (float)autocorrect/10.0); | ||
| 87 | poll(NULL, 0, autocorrect * 100); | ||
| 88 | } | ||
| 89 | return assumed; | ||
| 90 | } | ||
| 91 | |||
| 92 | fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd); | ||
| 93 | |||
| 94 | if (main_cmds.cnt && best_similarity < 6) { | ||
| 95 | fprintf(stderr, "\nDid you mean %s?\n", | ||
| 96 | n < 2 ? "this": "one of these"); | ||
| 97 | |||
| 98 | for (i = 0; i < n; i++) | ||
| 99 | fprintf(stderr, "\t%s\n", main_cmds.names[i]->name); | ||
| 100 | } | ||
| 101 | |||
| 102 | exit(1); | ||
| 103 | } | ||
diff --git a/tools/perf/util/help-unknown-cmd.h b/tools/perf/util/help-unknown-cmd.h new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/tools/perf/util/help-unknown-cmd.h | |||
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c deleted file mode 100644 index 86c37c472263..000000000000 --- a/tools/perf/util/help.c +++ /dev/null | |||
| @@ -1,339 +0,0 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include "../builtin.h" | ||
| 3 | #include "exec_cmd.h" | ||
| 4 | #include "levenshtein.h" | ||
| 5 | #include "help.h" | ||
| 6 | #include <termios.h> | ||
| 7 | |||
| 8 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) | ||
| 9 | { | ||
| 10 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); | ||
| 11 | |||
| 12 | ent->len = len; | ||
| 13 | memcpy(ent->name, name, len); | ||
| 14 | ent->name[len] = 0; | ||
| 15 | |||
| 16 | ALLOC_GROW(cmds->names, cmds->cnt + 1, cmds->alloc); | ||
| 17 | cmds->names[cmds->cnt++] = ent; | ||
| 18 | } | ||
| 19 | |||
| 20 | static void clean_cmdnames(struct cmdnames *cmds) | ||
| 21 | { | ||
| 22 | unsigned int i; | ||
| 23 | |||
| 24 | for (i = 0; i < cmds->cnt; ++i) | ||
| 25 | zfree(&cmds->names[i]); | ||
| 26 | zfree(&cmds->names); | ||
| 27 | cmds->cnt = 0; | ||
| 28 | cmds->alloc = 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | static int cmdname_compare(const void *a_, const void *b_) | ||
| 32 | { | ||
| 33 | struct cmdname *a = *(struct cmdname **)a_; | ||
| 34 | struct cmdname *b = *(struct cmdname **)b_; | ||
| 35 | return strcmp(a->name, b->name); | ||
| 36 | } | ||
| 37 | |||
| 38 | static void uniq(struct cmdnames *cmds) | ||
| 39 | { | ||
| 40 | unsigned int i, j; | ||
| 41 | |||
| 42 | if (!cmds->cnt) | ||
| 43 | return; | ||
| 44 | |||
| 45 | for (i = j = 1; i < cmds->cnt; i++) | ||
| 46 | if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) | ||
| 47 | cmds->names[j++] = cmds->names[i]; | ||
| 48 | |||
| 49 | cmds->cnt = j; | ||
| 50 | } | ||
| 51 | |||
| 52 | void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) | ||
| 53 | { | ||
| 54 | size_t ci, cj, ei; | ||
| 55 | int cmp; | ||
| 56 | |||
| 57 | ci = cj = ei = 0; | ||
| 58 | while (ci < cmds->cnt && ei < excludes->cnt) { | ||
| 59 | cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name); | ||
| 60 | if (cmp < 0) | ||
| 61 | cmds->names[cj++] = cmds->names[ci++]; | ||
| 62 | else if (cmp == 0) | ||
| 63 | ci++, ei++; | ||
| 64 | else if (cmp > 0) | ||
| 65 | ei++; | ||
| 66 | } | ||
| 67 | |||
| 68 | while (ci < cmds->cnt) | ||
| 69 | cmds->names[cj++] = cmds->names[ci++]; | ||
| 70 | |||
| 71 | cmds->cnt = cj; | ||
| 72 | } | ||
| 73 | |||
| 74 | static void pretty_print_string_list(struct cmdnames *cmds, int longest) | ||
| 75 | { | ||
| 76 | int cols = 1, rows; | ||
| 77 | int space = longest + 1; /* min 1 SP between words */ | ||
| 78 | struct winsize win; | ||
| 79 | int max_cols; | ||
| 80 | int i, j; | ||
| 81 | |||
| 82 | get_term_dimensions(&win); | ||
| 83 | max_cols = win.ws_col - 1; /* don't print *on* the edge */ | ||
| 84 | |||
| 85 | if (space < max_cols) | ||
| 86 | cols = max_cols / space; | ||
| 87 | rows = (cmds->cnt + cols - 1) / cols; | ||
| 88 | |||
| 89 | for (i = 0; i < rows; i++) { | ||
| 90 | printf(" "); | ||
| 91 | |||
| 92 | for (j = 0; j < cols; j++) { | ||
| 93 | unsigned int n = j * rows + i; | ||
| 94 | unsigned int size = space; | ||
| 95 | |||
| 96 | if (n >= cmds->cnt) | ||
| 97 | break; | ||
| 98 | if (j == cols-1 || n + rows >= cmds->cnt) | ||
| 99 | size = 1; | ||
| 100 | printf("%-*s", size, cmds->names[n]->name); | ||
| 101 | } | ||
| 102 | putchar('\n'); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | static int is_executable(const char *name) | ||
| 107 | { | ||
| 108 | struct stat st; | ||
| 109 | |||
| 110 | if (stat(name, &st) || /* stat, not lstat */ | ||
| 111 | !S_ISREG(st.st_mode)) | ||
| 112 | return 0; | ||
| 113 | |||
| 114 | return st.st_mode & S_IXUSR; | ||
| 115 | } | ||
| 116 | |||
| 117 | static void list_commands_in_dir(struct cmdnames *cmds, | ||
| 118 | const char *path, | ||
| 119 | const char *prefix) | ||
| 120 | { | ||
| 121 | int prefix_len; | ||
| 122 | DIR *dir = opendir(path); | ||
| 123 | struct dirent *de; | ||
| 124 | struct strbuf buf = STRBUF_INIT; | ||
| 125 | int len; | ||
| 126 | |||
| 127 | if (!dir) | ||
| 128 | return; | ||
| 129 | if (!prefix) | ||
| 130 | prefix = "perf-"; | ||
| 131 | prefix_len = strlen(prefix); | ||
| 132 | |||
| 133 | strbuf_addf(&buf, "%s/", path); | ||
| 134 | len = buf.len; | ||
| 135 | |||
| 136 | while ((de = readdir(dir)) != NULL) { | ||
| 137 | int entlen; | ||
| 138 | |||
| 139 | if (prefixcmp(de->d_name, prefix)) | ||
| 140 | continue; | ||
| 141 | |||
| 142 | strbuf_setlen(&buf, len); | ||
| 143 | strbuf_addstr(&buf, de->d_name); | ||
| 144 | if (!is_executable(buf.buf)) | ||
| 145 | continue; | ||
| 146 | |||
| 147 | entlen = strlen(de->d_name) - prefix_len; | ||
| 148 | if (has_extension(de->d_name, ".exe")) | ||
| 149 | entlen -= 4; | ||
| 150 | |||
| 151 | add_cmdname(cmds, de->d_name + prefix_len, entlen); | ||
| 152 | } | ||
| 153 | closedir(dir); | ||
| 154 | strbuf_release(&buf); | ||
| 155 | } | ||
| 156 | |||
| 157 | void load_command_list(const char *prefix, | ||
| 158 | struct cmdnames *main_cmds, | ||
| 159 | struct cmdnames *other_cmds) | ||
| 160 | { | ||
| 161 | const char *env_path = getenv("PATH"); | ||
| 162 | const char *exec_path = perf_exec_path(); | ||
| 163 | |||
| 164 | if (exec_path) { | ||
| 165 | list_commands_in_dir(main_cmds, exec_path, prefix); | ||
| 166 | qsort(main_cmds->names, main_cmds->cnt, | ||
| 167 | sizeof(*main_cmds->names), cmdname_compare); | ||
| 168 | uniq(main_cmds); | ||
| 169 | } | ||
| 170 | |||
| 171 | if (env_path) { | ||
| 172 | char *paths, *path, *colon; | ||
| 173 | path = paths = strdup(env_path); | ||
| 174 | while (1) { | ||
| 175 | if ((colon = strchr(path, PATH_SEP))) | ||
| 176 | *colon = 0; | ||
| 177 | if (!exec_path || strcmp(path, exec_path)) | ||
| 178 | list_commands_in_dir(other_cmds, path, prefix); | ||
| 179 | |||
| 180 | if (!colon) | ||
| 181 | break; | ||
| 182 | path = colon + 1; | ||
| 183 | } | ||
| 184 | free(paths); | ||
| 185 | |||
| 186 | qsort(other_cmds->names, other_cmds->cnt, | ||
| 187 | sizeof(*other_cmds->names), cmdname_compare); | ||
| 188 | uniq(other_cmds); | ||
| 189 | } | ||
| 190 | exclude_cmds(other_cmds, main_cmds); | ||
| 191 | } | ||
| 192 | |||
| 193 | void list_commands(const char *title, struct cmdnames *main_cmds, | ||
| 194 | struct cmdnames *other_cmds) | ||
| 195 | { | ||
| 196 | unsigned int i, longest = 0; | ||
| 197 | |||
| 198 | for (i = 0; i < main_cmds->cnt; i++) | ||
| 199 | if (longest < main_cmds->names[i]->len) | ||
| 200 | longest = main_cmds->names[i]->len; | ||
| 201 | for (i = 0; i < other_cmds->cnt; i++) | ||
| 202 | if (longest < other_cmds->names[i]->len) | ||
| 203 | longest = other_cmds->names[i]->len; | ||
| 204 | |||
| 205 | if (main_cmds->cnt) { | ||
| 206 | const char *exec_path = perf_exec_path(); | ||
| 207 | printf("available %s in '%s'\n", title, exec_path); | ||
| 208 | printf("----------------"); | ||
| 209 | mput_char('-', strlen(title) + strlen(exec_path)); | ||
| 210 | putchar('\n'); | ||
| 211 | pretty_print_string_list(main_cmds, longest); | ||
| 212 | putchar('\n'); | ||
| 213 | } | ||
| 214 | |||
| 215 | if (other_cmds->cnt) { | ||
| 216 | printf("%s available from elsewhere on your $PATH\n", title); | ||
| 217 | printf("---------------------------------------"); | ||
| 218 | mput_char('-', strlen(title)); | ||
| 219 | putchar('\n'); | ||
| 220 | pretty_print_string_list(other_cmds, longest); | ||
| 221 | putchar('\n'); | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | int is_in_cmdlist(struct cmdnames *c, const char *s) | ||
| 226 | { | ||
| 227 | unsigned int i; | ||
| 228 | |||
| 229 | for (i = 0; i < c->cnt; i++) | ||
| 230 | if (!strcmp(s, c->names[i]->name)) | ||
| 231 | return 1; | ||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | |||
| 235 | static int autocorrect; | ||
| 236 | static struct cmdnames aliases; | ||
| 237 | |||
| 238 | static int perf_unknown_cmd_config(const char *var, const char *value, void *cb) | ||
| 239 | { | ||
| 240 | if (!strcmp(var, "help.autocorrect")) | ||
| 241 | autocorrect = perf_config_int(var,value); | ||
| 242 | /* Also use aliases for command lookup */ | ||
| 243 | if (!prefixcmp(var, "alias.")) | ||
| 244 | add_cmdname(&aliases, var + 6, strlen(var + 6)); | ||
| 245 | |||
| 246 | return perf_default_config(var, value, cb); | ||
| 247 | } | ||
| 248 | |||
| 249 | static int levenshtein_compare(const void *p1, const void *p2) | ||
| 250 | { | ||
| 251 | const struct cmdname *const *c1 = p1, *const *c2 = p2; | ||
| 252 | const char *s1 = (*c1)->name, *s2 = (*c2)->name; | ||
| 253 | int l1 = (*c1)->len; | ||
| 254 | int l2 = (*c2)->len; | ||
| 255 | return l1 != l2 ? l1 - l2 : strcmp(s1, s2); | ||
| 256 | } | ||
| 257 | |||
| 258 | static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) | ||
| 259 | { | ||
| 260 | unsigned int i; | ||
| 261 | |||
| 262 | ALLOC_GROW(cmds->names, cmds->cnt + old->cnt, cmds->alloc); | ||
| 263 | |||
| 264 | for (i = 0; i < old->cnt; i++) | ||
| 265 | cmds->names[cmds->cnt++] = old->names[i]; | ||
| 266 | zfree(&old->names); | ||
| 267 | old->cnt = 0; | ||
| 268 | } | ||
| 269 | |||
| 270 | const char *help_unknown_cmd(const char *cmd) | ||
| 271 | { | ||
| 272 | unsigned int i, n = 0, best_similarity = 0; | ||
| 273 | struct cmdnames main_cmds, other_cmds; | ||
| 274 | |||
| 275 | memset(&main_cmds, 0, sizeof(main_cmds)); | ||
| 276 | memset(&other_cmds, 0, sizeof(main_cmds)); | ||
| 277 | memset(&aliases, 0, sizeof(aliases)); | ||
| 278 | |||
| 279 | perf_config(perf_unknown_cmd_config, NULL); | ||
| 280 | |||
| 281 | load_command_list("perf-", &main_cmds, &other_cmds); | ||
| 282 | |||
| 283 | add_cmd_list(&main_cmds, &aliases); | ||
| 284 | add_cmd_list(&main_cmds, &other_cmds); | ||
| 285 | qsort(main_cmds.names, main_cmds.cnt, | ||
| 286 | sizeof(main_cmds.names), cmdname_compare); | ||
| 287 | uniq(&main_cmds); | ||
| 288 | |||
| 289 | if (main_cmds.cnt) { | ||
| 290 | /* This reuses cmdname->len for similarity index */ | ||
| 291 | for (i = 0; i < main_cmds.cnt; ++i) | ||
| 292 | main_cmds.names[i]->len = | ||
| 293 | levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4); | ||
| 294 | |||
| 295 | qsort(main_cmds.names, main_cmds.cnt, | ||
| 296 | sizeof(*main_cmds.names), levenshtein_compare); | ||
| 297 | |||
| 298 | best_similarity = main_cmds.names[0]->len; | ||
| 299 | n = 1; | ||
| 300 | while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len) | ||
| 301 | ++n; | ||
| 302 | } | ||
| 303 | |||
| 304 | if (autocorrect && n == 1) { | ||
| 305 | const char *assumed = main_cmds.names[0]->name; | ||
| 306 | |||
| 307 | main_cmds.names[0] = NULL; | ||
| 308 | clean_cmdnames(&main_cmds); | ||
| 309 | fprintf(stderr, "WARNING: You called a perf program named '%s', " | ||
| 310 | "which does not exist.\n" | ||
| 311 | "Continuing under the assumption that you meant '%s'\n", | ||
| 312 | cmd, assumed); | ||
| 313 | if (autocorrect > 0) { | ||
| 314 | fprintf(stderr, "in %0.1f seconds automatically...\n", | ||
| 315 | (float)autocorrect/10.0); | ||
| 316 | poll(NULL, 0, autocorrect * 100); | ||
| 317 | } | ||
| 318 | return assumed; | ||
| 319 | } | ||
| 320 | |||
| 321 | fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd); | ||
| 322 | |||
| 323 | if (main_cmds.cnt && best_similarity < 6) { | ||
| 324 | fprintf(stderr, "\nDid you mean %s?\n", | ||
| 325 | n < 2 ? "this": "one of these"); | ||
| 326 | |||
| 327 | for (i = 0; i < n; i++) | ||
| 328 | fprintf(stderr, "\t%s\n", main_cmds.names[i]->name); | ||
| 329 | } | ||
| 330 | |||
| 331 | exit(1); | ||
| 332 | } | ||
| 333 | |||
| 334 | int cmd_version(int argc __maybe_unused, const char **argv __maybe_unused, | ||
| 335 | const char *prefix __maybe_unused) | ||
| 336 | { | ||
| 337 | printf("perf version %s\n", perf_version_string); | ||
| 338 | return 0; | ||
| 339 | } | ||
diff --git a/tools/perf/util/help.h b/tools/perf/util/help.h deleted file mode 100644 index 7f5c6dedd714..000000000000 --- a/tools/perf/util/help.h +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | #ifndef __PERF_HELP_H | ||
| 2 | #define __PERF_HELP_H | ||
| 3 | |||
| 4 | struct cmdnames { | ||
| 5 | size_t alloc; | ||
| 6 | size_t cnt; | ||
| 7 | struct cmdname { | ||
| 8 | size_t len; /* also used for similarity index in help.c */ | ||
| 9 | char name[FLEX_ARRAY]; | ||
| 10 | } **names; | ||
| 11 | }; | ||
| 12 | |||
| 13 | static inline void mput_char(char c, unsigned int num) | ||
| 14 | { | ||
| 15 | while(num--) | ||
| 16 | putchar(c); | ||
| 17 | } | ||
| 18 | |||
| 19 | void load_command_list(const char *prefix, | ||
| 20 | struct cmdnames *main_cmds, | ||
| 21 | struct cmdnames *other_cmds); | ||
| 22 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len); | ||
| 23 | /* Here we require that excludes is a sorted list. */ | ||
| 24 | void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes); | ||
| 25 | int is_in_cmdlist(struct cmdnames *c, const char *s); | ||
| 26 | void list_commands(const char *title, struct cmdnames *main_cmds, | ||
| 27 | struct cmdnames *other_cmds); | ||
| 28 | |||
| 29 | #endif /* __PERF_HELP_H */ | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 4fd37d6708cb..c226303e3da0 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
| @@ -254,6 +254,7 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) | |||
| 254 | he_stat__decay(&he->stat); | 254 | he_stat__decay(&he->stat); |
| 255 | if (symbol_conf.cumulate_callchain) | 255 | if (symbol_conf.cumulate_callchain) |
| 256 | he_stat__decay(he->stat_acc); | 256 | he_stat__decay(he->stat_acc); |
| 257 | decay_callchain(he->callchain); | ||
| 257 | 258 | ||
| 258 | diff = prev_period - he->stat.period; | 259 | diff = prev_period - he->stat.period; |
| 259 | 260 | ||
| @@ -270,6 +271,8 @@ static void hists__delete_entry(struct hists *hists, struct hist_entry *he) | |||
| 270 | 271 | ||
| 271 | if (sort__need_collapse) | 272 | if (sort__need_collapse) |
| 272 | rb_erase(&he->rb_node_in, &hists->entries_collapsed); | 273 | rb_erase(&he->rb_node_in, &hists->entries_collapsed); |
| 274 | else | ||
| 275 | rb_erase(&he->rb_node_in, hists->entries_in); | ||
| 273 | 276 | ||
| 274 | --hists->nr_entries; | 277 | --hists->nr_entries; |
| 275 | if (!he->filtered) | 278 | if (!he->filtered) |
| @@ -367,6 +370,25 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template, | |||
| 367 | if (symbol_conf.use_callchain) | 370 | if (symbol_conf.use_callchain) |
| 368 | callchain_init(he->callchain); | 371 | callchain_init(he->callchain); |
| 369 | 372 | ||
| 373 | if (he->raw_data) { | ||
| 374 | he->raw_data = memdup(he->raw_data, he->raw_size); | ||
| 375 | |||
| 376 | if (he->raw_data == NULL) { | ||
| 377 | map__put(he->ms.map); | ||
| 378 | if (he->branch_info) { | ||
| 379 | map__put(he->branch_info->from.map); | ||
| 380 | map__put(he->branch_info->to.map); | ||
| 381 | free(he->branch_info); | ||
| 382 | } | ||
| 383 | if (he->mem_info) { | ||
| 384 | map__put(he->mem_info->iaddr.map); | ||
| 385 | map__put(he->mem_info->daddr.map); | ||
| 386 | } | ||
| 387 | free(he->stat_acc); | ||
| 388 | free(he); | ||
| 389 | return NULL; | ||
| 390 | } | ||
| 391 | } | ||
| 370 | INIT_LIST_HEAD(&he->pairs.node); | 392 | INIT_LIST_HEAD(&he->pairs.node); |
| 371 | thread__get(he->thread); | 393 | thread__get(he->thread); |
| 372 | } | 394 | } |
| @@ -459,7 +481,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
| 459 | struct symbol *sym_parent, | 481 | struct symbol *sym_parent, |
| 460 | struct branch_info *bi, | 482 | struct branch_info *bi, |
| 461 | struct mem_info *mi, | 483 | struct mem_info *mi, |
| 462 | u64 period, u64 weight, u64 transaction, | 484 | struct perf_sample *sample, |
| 463 | bool sample_self) | 485 | bool sample_self) |
| 464 | { | 486 | { |
| 465 | struct hist_entry entry = { | 487 | struct hist_entry entry = { |
| @@ -476,15 +498,17 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
| 476 | .level = al->level, | 498 | .level = al->level, |
| 477 | .stat = { | 499 | .stat = { |
| 478 | .nr_events = 1, | 500 | .nr_events = 1, |
| 479 | .period = period, | 501 | .period = sample->period, |
| 480 | .weight = weight, | 502 | .weight = sample->weight, |
| 481 | }, | 503 | }, |
| 482 | .parent = sym_parent, | 504 | .parent = sym_parent, |
| 483 | .filtered = symbol__parent_filter(sym_parent) | al->filtered, | 505 | .filtered = symbol__parent_filter(sym_parent) | al->filtered, |
| 484 | .hists = hists, | 506 | .hists = hists, |
| 485 | .branch_info = bi, | 507 | .branch_info = bi, |
| 486 | .mem_info = mi, | 508 | .mem_info = mi, |
| 487 | .transaction = transaction, | 509 | .transaction = sample->transaction, |
| 510 | .raw_data = sample->raw_data, | ||
| 511 | .raw_size = sample->raw_size, | ||
| 488 | }; | 512 | }; |
| 489 | 513 | ||
| 490 | return hists__findnew_entry(hists, &entry, al, sample_self); | 514 | return hists__findnew_entry(hists, &entry, al, sample_self); |
| @@ -524,12 +548,13 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al | |||
| 524 | u64 cost; | 548 | u64 cost; |
| 525 | struct mem_info *mi = iter->priv; | 549 | struct mem_info *mi = iter->priv; |
| 526 | struct hists *hists = evsel__hists(iter->evsel); | 550 | struct hists *hists = evsel__hists(iter->evsel); |
| 551 | struct perf_sample *sample = iter->sample; | ||
| 527 | struct hist_entry *he; | 552 | struct hist_entry *he; |
| 528 | 553 | ||
| 529 | if (mi == NULL) | 554 | if (mi == NULL) |
| 530 | return -EINVAL; | 555 | return -EINVAL; |
| 531 | 556 | ||
| 532 | cost = iter->sample->weight; | 557 | cost = sample->weight; |
| 533 | if (!cost) | 558 | if (!cost) |
| 534 | cost = 1; | 559 | cost = 1; |
| 535 | 560 | ||
| @@ -540,8 +565,10 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al | |||
| 540 | * and this is indirectly achieved by passing period=weight here | 565 | * and this is indirectly achieved by passing period=weight here |
| 541 | * and the he_stat__add_period() function. | 566 | * and the he_stat__add_period() function. |
| 542 | */ | 567 | */ |
| 568 | sample->period = cost; | ||
| 569 | |||
| 543 | he = __hists__add_entry(hists, al, iter->parent, NULL, mi, | 570 | he = __hists__add_entry(hists, al, iter->parent, NULL, mi, |
| 544 | cost, cost, 0, true); | 571 | sample, true); |
| 545 | if (!he) | 572 | if (!he) |
| 546 | return -ENOMEM; | 573 | return -ENOMEM; |
| 547 | 574 | ||
| @@ -628,6 +655,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a | |||
| 628 | struct branch_info *bi; | 655 | struct branch_info *bi; |
| 629 | struct perf_evsel *evsel = iter->evsel; | 656 | struct perf_evsel *evsel = iter->evsel; |
| 630 | struct hists *hists = evsel__hists(evsel); | 657 | struct hists *hists = evsel__hists(evsel); |
| 658 | struct perf_sample *sample = iter->sample; | ||
| 631 | struct hist_entry *he = NULL; | 659 | struct hist_entry *he = NULL; |
| 632 | int i = iter->curr; | 660 | int i = iter->curr; |
| 633 | int err = 0; | 661 | int err = 0; |
| @@ -641,9 +669,11 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a | |||
| 641 | * The report shows the percentage of total branches captured | 669 | * The report shows the percentage of total branches captured |
| 642 | * and not events sampled. Thus we use a pseudo period of 1. | 670 | * and not events sampled. Thus we use a pseudo period of 1. |
| 643 | */ | 671 | */ |
| 672 | sample->period = 1; | ||
| 673 | sample->weight = bi->flags.cycles ? bi->flags.cycles : 1; | ||
| 674 | |||
| 644 | he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL, | 675 | he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL, |
| 645 | 1, bi->flags.cycles ? bi->flags.cycles : 1, | 676 | sample, true); |
| 646 | 0, true); | ||
| 647 | if (he == NULL) | 677 | if (he == NULL) |
| 648 | return -ENOMEM; | 678 | return -ENOMEM; |
| 649 | 679 | ||
| @@ -680,8 +710,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location | |||
| 680 | struct hist_entry *he; | 710 | struct hist_entry *he; |
| 681 | 711 | ||
| 682 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, | 712 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
| 683 | sample->period, sample->weight, | 713 | sample, true); |
| 684 | sample->transaction, true); | ||
| 685 | if (he == NULL) | 714 | if (he == NULL) |
| 686 | return -ENOMEM; | 715 | return -ENOMEM; |
| 687 | 716 | ||
| @@ -742,8 +771,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter, | |||
| 742 | int err = 0; | 771 | int err = 0; |
| 743 | 772 | ||
| 744 | he = __hists__add_entry(hists, al, iter->parent, NULL, NULL, | 773 | he = __hists__add_entry(hists, al, iter->parent, NULL, NULL, |
| 745 | sample->period, sample->weight, | 774 | sample, true); |
| 746 | sample->transaction, true); | ||
| 747 | if (he == NULL) | 775 | if (he == NULL) |
| 748 | return -ENOMEM; | 776 | return -ENOMEM; |
| 749 | 777 | ||
| @@ -795,6 +823,8 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, | |||
| 795 | .sym = al->sym, | 823 | .sym = al->sym, |
| 796 | }, | 824 | }, |
| 797 | .parent = iter->parent, | 825 | .parent = iter->parent, |
| 826 | .raw_data = sample->raw_data, | ||
| 827 | .raw_size = sample->raw_size, | ||
| 798 | }; | 828 | }; |
| 799 | int i; | 829 | int i; |
| 800 | struct callchain_cursor cursor; | 830 | struct callchain_cursor cursor; |
| @@ -816,8 +846,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, | |||
| 816 | } | 846 | } |
| 817 | 847 | ||
| 818 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, | 848 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
| 819 | sample->period, sample->weight, | 849 | sample, false); |
| 820 | sample->transaction, false); | ||
| 821 | if (he == NULL) | 850 | if (he == NULL) |
| 822 | return -ENOMEM; | 851 | return -ENOMEM; |
| 823 | 852 | ||
| @@ -924,9 +953,6 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | |||
| 924 | int64_t cmp = 0; | 953 | int64_t cmp = 0; |
| 925 | 954 | ||
| 926 | perf_hpp__for_each_sort_list(fmt) { | 955 | perf_hpp__for_each_sort_list(fmt) { |
| 927 | if (perf_hpp__should_skip(fmt)) | ||
| 928 | continue; | ||
| 929 | |||
| 930 | cmp = fmt->cmp(fmt, left, right); | 956 | cmp = fmt->cmp(fmt, left, right); |
| 931 | if (cmp) | 957 | if (cmp) |
| 932 | break; | 958 | break; |
| @@ -942,9 +968,6 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | |||
| 942 | int64_t cmp = 0; | 968 | int64_t cmp = 0; |
| 943 | 969 | ||
| 944 | perf_hpp__for_each_sort_list(fmt) { | 970 | perf_hpp__for_each_sort_list(fmt) { |
| 945 | if (perf_hpp__should_skip(fmt)) | ||
| 946 | continue; | ||
| 947 | |||
| 948 | cmp = fmt->collapse(fmt, left, right); | 971 | cmp = fmt->collapse(fmt, left, right); |
| 949 | if (cmp) | 972 | if (cmp) |
| 950 | break; | 973 | break; |
| @@ -975,6 +998,8 @@ void hist_entry__delete(struct hist_entry *he) | |||
| 975 | if (he->srcfile && he->srcfile[0]) | 998 | if (he->srcfile && he->srcfile[0]) |
| 976 | free(he->srcfile); | 999 | free(he->srcfile); |
| 977 | free_callchain(he->callchain); | 1000 | free_callchain(he->callchain); |
| 1001 | free(he->trace_output); | ||
| 1002 | free(he->raw_data); | ||
| 978 | free(he); | 1003 | free(he); |
| 979 | } | 1004 | } |
| 980 | 1005 | ||
| @@ -982,9 +1007,8 @@ void hist_entry__delete(struct hist_entry *he) | |||
| 982 | * collapse the histogram | 1007 | * collapse the histogram |
| 983 | */ | 1008 | */ |
| 984 | 1009 | ||
| 985 | static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, | 1010 | bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, |
| 986 | struct rb_root *root, | 1011 | struct rb_root *root, struct hist_entry *he) |
| 987 | struct hist_entry *he) | ||
| 988 | { | 1012 | { |
| 989 | struct rb_node **p = &root->rb_node; | 1013 | struct rb_node **p = &root->rb_node; |
| 990 | struct rb_node *parent = NULL; | 1014 | struct rb_node *parent = NULL; |
| @@ -1024,7 +1048,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, | |||
| 1024 | return true; | 1048 | return true; |
| 1025 | } | 1049 | } |
| 1026 | 1050 | ||
| 1027 | static struct rb_root *hists__get_rotate_entries_in(struct hists *hists) | 1051 | struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
| 1028 | { | 1052 | { |
| 1029 | struct rb_root *root; | 1053 | struct rb_root *root; |
| 1030 | 1054 | ||
| @@ -1088,7 +1112,7 @@ static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b) | |||
| 1088 | int64_t cmp = 0; | 1112 | int64_t cmp = 0; |
| 1089 | 1113 | ||
| 1090 | perf_hpp__for_each_sort_list(fmt) { | 1114 | perf_hpp__for_each_sort_list(fmt) { |
| 1091 | if (perf_hpp__should_skip(fmt)) | 1115 | if (perf_hpp__should_skip(fmt, a->hists)) |
| 1092 | continue; | 1116 | continue; |
| 1093 | 1117 | ||
| 1094 | cmp = fmt->sort(fmt, a, b); | 1118 | cmp = fmt->sort(fmt, a, b); |
| @@ -1559,10 +1583,8 @@ int perf_hist_config(const char *var, const char *value) | |||
| 1559 | return 0; | 1583 | return 0; |
| 1560 | } | 1584 | } |
| 1561 | 1585 | ||
| 1562 | static int hists_evsel__init(struct perf_evsel *evsel) | 1586 | int __hists__init(struct hists *hists) |
| 1563 | { | 1587 | { |
| 1564 | struct hists *hists = evsel__hists(evsel); | ||
| 1565 | |||
| 1566 | memset(hists, 0, sizeof(*hists)); | 1588 | memset(hists, 0, sizeof(*hists)); |
| 1567 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; | 1589 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; |
| 1568 | hists->entries_in = &hists->entries_in_array[0]; | 1590 | hists->entries_in = &hists->entries_in_array[0]; |
| @@ -1573,6 +1595,43 @@ static int hists_evsel__init(struct perf_evsel *evsel) | |||
| 1573 | return 0; | 1595 | return 0; |
| 1574 | } | 1596 | } |
| 1575 | 1597 | ||
| 1598 | static void hists__delete_remaining_entries(struct rb_root *root) | ||
| 1599 | { | ||
| 1600 | struct rb_node *node; | ||
| 1601 | struct hist_entry *he; | ||
| 1602 | |||
| 1603 | while (!RB_EMPTY_ROOT(root)) { | ||
| 1604 | node = rb_first(root); | ||
| 1605 | rb_erase(node, root); | ||
| 1606 | |||
| 1607 | he = rb_entry(node, struct hist_entry, rb_node_in); | ||
| 1608 | hist_entry__delete(he); | ||
| 1609 | } | ||
| 1610 | } | ||
| 1611 | |||
| 1612 | static void hists__delete_all_entries(struct hists *hists) | ||
| 1613 | { | ||
| 1614 | hists__delete_entries(hists); | ||
| 1615 | hists__delete_remaining_entries(&hists->entries_in_array[0]); | ||
| 1616 | hists__delete_remaining_entries(&hists->entries_in_array[1]); | ||
| 1617 | hists__delete_remaining_entries(&hists->entries_collapsed); | ||
| 1618 | } | ||
| 1619 | |||
| 1620 | static void hists_evsel__exit(struct perf_evsel *evsel) | ||
| 1621 | { | ||
| 1622 | struct hists *hists = evsel__hists(evsel); | ||
| 1623 | |||
| 1624 | hists__delete_all_entries(hists); | ||
| 1625 | } | ||
| 1626 | |||
| 1627 | static int hists_evsel__init(struct perf_evsel *evsel) | ||
| 1628 | { | ||
| 1629 | struct hists *hists = evsel__hists(evsel); | ||
| 1630 | |||
| 1631 | __hists__init(hists); | ||
| 1632 | return 0; | ||
| 1633 | } | ||
| 1634 | |||
| 1576 | /* | 1635 | /* |
| 1577 | * XXX We probably need a hists_evsel__exit() to free the hist_entries | 1636 | * XXX We probably need a hists_evsel__exit() to free the hist_entries |
| 1578 | * stored in the rbtree... | 1637 | * stored in the rbtree... |
| @@ -1581,7 +1640,8 @@ static int hists_evsel__init(struct perf_evsel *evsel) | |||
| 1581 | int hists__init(void) | 1640 | int hists__init(void) |
| 1582 | { | 1641 | { |
| 1583 | int err = perf_evsel__object_config(sizeof(struct hists_evsel), | 1642 | int err = perf_evsel__object_config(sizeof(struct hists_evsel), |
| 1584 | hists_evsel__init, NULL); | 1643 | hists_evsel__init, |
| 1644 | hists_evsel__exit); | ||
| 1585 | if (err) | 1645 | if (err) |
| 1586 | fputs("FATAL ERROR: Couldn't setup hists class\n", stderr); | 1646 | fputs("FATAL ERROR: Couldn't setup hists class\n", stderr); |
| 1587 | 1647 | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a48a2078d288..d4ec4822a103 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
| @@ -52,6 +52,7 @@ enum hist_column { | |||
| 52 | HISTC_MEM_IADDR_SYMBOL, | 52 | HISTC_MEM_IADDR_SYMBOL, |
| 53 | HISTC_TRANSACTION, | 53 | HISTC_TRANSACTION, |
| 54 | HISTC_CYCLES, | 54 | HISTC_CYCLES, |
| 55 | HISTC_TRACE, | ||
| 55 | HISTC_NR_COLS, /* Last entry */ | 56 | HISTC_NR_COLS, /* Last entry */ |
| 56 | }; | 57 | }; |
| 57 | 58 | ||
| @@ -114,8 +115,8 @@ struct hist_entry *__hists__add_entry(struct hists *hists, | |||
| 114 | struct addr_location *al, | 115 | struct addr_location *al, |
| 115 | struct symbol *parent, | 116 | struct symbol *parent, |
| 116 | struct branch_info *bi, | 117 | struct branch_info *bi, |
| 117 | struct mem_info *mi, u64 period, | 118 | struct mem_info *mi, |
| 118 | u64 weight, u64 transaction, | 119 | struct perf_sample *sample, |
| 119 | bool sample_self); | 120 | bool sample_self); |
| 120 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, | 121 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, |
| 121 | int max_stack_depth, void *arg); | 122 | int max_stack_depth, void *arg); |
| @@ -184,6 +185,11 @@ static inline struct hists *evsel__hists(struct perf_evsel *evsel) | |||
| 184 | } | 185 | } |
| 185 | 186 | ||
| 186 | int hists__init(void); | 187 | int hists__init(void); |
| 188 | int __hists__init(struct hists *hists); | ||
| 189 | |||
| 190 | struct rb_root *hists__get_rotate_entries_in(struct hists *hists); | ||
| 191 | bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, | ||
| 192 | struct rb_root *root, struct hist_entry *he); | ||
| 187 | 193 | ||
| 188 | struct perf_hpp { | 194 | struct perf_hpp { |
| 189 | char *buf; | 195 | char *buf; |
| @@ -261,10 +267,20 @@ void perf_hpp__append_sort_keys(void); | |||
| 261 | 267 | ||
| 262 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); | 268 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); |
| 263 | bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b); | 269 | bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b); |
| 270 | bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format); | ||
| 271 | bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists); | ||
| 264 | 272 | ||
| 265 | static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format) | 273 | static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format, |
| 274 | struct hists *hists) | ||
| 266 | { | 275 | { |
| 267 | return format->elide; | 276 | if (format->elide) |
| 277 | return true; | ||
| 278 | |||
| 279 | if (perf_hpp__is_dynamic_entry(format) && | ||
| 280 | !perf_hpp__defined_dynamic_entry(format, hists)) | ||
| 281 | return true; | ||
| 282 | |||
| 283 | return false; | ||
| 268 | } | 284 | } |
| 269 | 285 | ||
| 270 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); | 286 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); |
diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h deleted file mode 100644 index 40bd21488032..000000000000 --- a/tools/perf/util/include/linux/bitmap.h +++ /dev/null | |||
| @@ -1,66 +0,0 @@ | |||
| 1 | #ifndef _PERF_BITOPS_H | ||
| 2 | #define _PERF_BITOPS_H | ||
| 3 | |||
| 4 | #include <string.h> | ||
| 5 | #include <linux/bitops.h> | ||
| 6 | |||
| 7 | #define DECLARE_BITMAP(name,bits) \ | ||
| 8 | unsigned long name[BITS_TO_LONGS(bits)] | ||
| 9 | |||
| 10 | int __bitmap_weight(const unsigned long *bitmap, int bits); | ||
| 11 | void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, | ||
| 12 | const unsigned long *bitmap2, int bits); | ||
| 13 | |||
| 14 | #define BITMAP_LAST_WORD_MASK(nbits) \ | ||
| 15 | ( \ | ||
| 16 | ((nbits) % BITS_PER_LONG) ? \ | ||
| 17 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | ||
| 18 | ) | ||
| 19 | |||
| 20 | #define small_const_nbits(nbits) \ | ||
| 21 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | ||
| 22 | |||
| 23 | static inline void bitmap_zero(unsigned long *dst, int nbits) | ||
| 24 | { | ||
| 25 | if (small_const_nbits(nbits)) | ||
| 26 | *dst = 0UL; | ||
| 27 | else { | ||
| 28 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | ||
| 29 | memset(dst, 0, len); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | static inline int bitmap_weight(const unsigned long *src, int nbits) | ||
| 34 | { | ||
| 35 | if (small_const_nbits(nbits)) | ||
| 36 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); | ||
| 37 | return __bitmap_weight(src, nbits); | ||
| 38 | } | ||
| 39 | |||
| 40 | static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, | ||
| 41 | const unsigned long *src2, int nbits) | ||
| 42 | { | ||
| 43 | if (small_const_nbits(nbits)) | ||
| 44 | *dst = *src1 | *src2; | ||
| 45 | else | ||
| 46 | __bitmap_or(dst, src1, src2, nbits); | ||
| 47 | } | ||
| 48 | |||
| 49 | /** | ||
| 50 | * test_and_set_bit - Set a bit and return its old value | ||
| 51 | * @nr: Bit to set | ||
| 52 | * @addr: Address to count from | ||
| 53 | */ | ||
| 54 | static inline int test_and_set_bit(int nr, unsigned long *addr) | ||
| 55 | { | ||
| 56 | unsigned long mask = BIT_MASK(nr); | ||
| 57 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); | ||
| 58 | unsigned long old; | ||
| 59 | |||
| 60 | old = *p; | ||
| 61 | *p = old | mask; | ||
| 62 | |||
| 63 | return (old & mask) != 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | #endif /* _PERF_BITOPS_H */ | ||
diff --git a/tools/perf/util/include/linux/string.h b/tools/perf/util/include/linux/string.h deleted file mode 100644 index 6f19c548ecc0..000000000000 --- a/tools/perf/util/include/linux/string.h +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | void *memdup(const void *src, size_t len); | ||
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 97f963a3dcb9..81a2eb77ba7f 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c | |||
| @@ -1744,7 +1744,7 @@ static void intel_pt_free(struct perf_session *session) | |||
| 1744 | auxtrace_heap__free(&pt->heap); | 1744 | auxtrace_heap__free(&pt->heap); |
| 1745 | intel_pt_free_events(session); | 1745 | intel_pt_free_events(session); |
| 1746 | session->auxtrace = NULL; | 1746 | session->auxtrace = NULL; |
| 1747 | thread__delete(pt->unknown_thread); | 1747 | thread__put(pt->unknown_thread); |
| 1748 | free(pt); | 1748 | free(pt); |
| 1749 | } | 1749 | } |
| 1750 | 1750 | ||
| @@ -2153,7 +2153,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, | |||
| 2153 | return 0; | 2153 | return 0; |
| 2154 | 2154 | ||
| 2155 | err_delete_thread: | 2155 | err_delete_thread: |
| 2156 | thread__delete(pt->unknown_thread); | 2156 | thread__zput(pt->unknown_thread); |
| 2157 | err_free_queues: | 2157 | err_free_queues: |
| 2158 | intel_pt_log_disable(); | 2158 | intel_pt_log_disable(); |
| 2159 | auxtrace_queues__free(&pt->queues); | 2159 | auxtrace_queues__free(&pt->queues); |
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 5ef90be2a249..ad79297c76c8 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
| @@ -25,6 +25,7 @@ static void dsos__init(struct dsos *dsos) | |||
| 25 | 25 | ||
| 26 | int machine__init(struct machine *machine, const char *root_dir, pid_t pid) | 26 | int machine__init(struct machine *machine, const char *root_dir, pid_t pid) |
| 27 | { | 27 | { |
| 28 | memset(machine, 0, sizeof(*machine)); | ||
| 28 | map_groups__init(&machine->kmaps, machine); | 29 | map_groups__init(&machine->kmaps, machine); |
| 29 | RB_CLEAR_NODE(&machine->rb_node); | 30 | RB_CLEAR_NODE(&machine->rb_node); |
| 30 | dsos__init(&machine->dsos); | 31 | dsos__init(&machine->dsos); |
| @@ -44,6 +45,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) | |||
| 44 | machine->comm_exec = false; | 45 | machine->comm_exec = false; |
| 45 | machine->kernel_start = 0; | 46 | machine->kernel_start = 0; |
| 46 | 47 | ||
| 48 | memset(machine->vmlinux_maps, 0, sizeof(machine->vmlinux_maps)); | ||
| 49 | |||
| 47 | machine->root_dir = strdup(root_dir); | 50 | machine->root_dir = strdup(root_dir); |
| 48 | if (machine->root_dir == NULL) | 51 | if (machine->root_dir == NULL) |
| 49 | return -ENOMEM; | 52 | return -ENOMEM; |
| @@ -91,6 +94,7 @@ static void dsos__purge(struct dsos *dsos) | |||
| 91 | 94 | ||
| 92 | list_for_each_entry_safe(pos, n, &dsos->head, node) { | 95 | list_for_each_entry_safe(pos, n, &dsos->head, node) { |
| 93 | RB_CLEAR_NODE(&pos->rb_node); | 96 | RB_CLEAR_NODE(&pos->rb_node); |
| 97 | pos->root = NULL; | ||
| 94 | list_del_init(&pos->node); | 98 | list_del_init(&pos->node); |
| 95 | dso__put(pos); | 99 | dso__put(pos); |
| 96 | } | 100 | } |
| @@ -121,6 +125,7 @@ void machine__delete_threads(struct machine *machine) | |||
| 121 | 125 | ||
| 122 | void machine__exit(struct machine *machine) | 126 | void machine__exit(struct machine *machine) |
| 123 | { | 127 | { |
| 128 | machine__destroy_kernel_maps(machine); | ||
| 124 | map_groups__exit(&machine->kmaps); | 129 | map_groups__exit(&machine->kmaps); |
| 125 | dsos__exit(&machine->dsos); | 130 | dsos__exit(&machine->dsos); |
| 126 | machine__exit_vdso(machine); | 131 | machine__exit_vdso(machine); |
| @@ -347,13 +352,18 @@ static void machine__update_thread_pid(struct machine *machine, | |||
| 347 | } | 352 | } |
| 348 | 353 | ||
| 349 | th->mg = map_groups__get(leader->mg); | 354 | th->mg = map_groups__get(leader->mg); |
| 350 | 355 | out_put: | |
| 356 | thread__put(leader); | ||
| 351 | return; | 357 | return; |
| 352 | |||
| 353 | out_err: | 358 | out_err: |
| 354 | pr_err("Failed to join map groups for %d:%d\n", th->pid_, th->tid); | 359 | pr_err("Failed to join map groups for %d:%d\n", th->pid_, th->tid); |
| 360 | goto out_put; | ||
| 355 | } | 361 | } |
| 356 | 362 | ||
| 363 | /* | ||
| 364 | * Caller must eventually drop thread->refcnt returned with a successfull | ||
| 365 | * lookup/new thread inserted. | ||
| 366 | */ | ||
| 357 | static struct thread *____machine__findnew_thread(struct machine *machine, | 367 | static struct thread *____machine__findnew_thread(struct machine *machine, |
| 358 | pid_t pid, pid_t tid, | 368 | pid_t pid, pid_t tid, |
| 359 | bool create) | 369 | bool create) |
| @@ -371,7 +381,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine, | |||
| 371 | if (th != NULL) { | 381 | if (th != NULL) { |
| 372 | if (th->tid == tid) { | 382 | if (th->tid == tid) { |
| 373 | machine__update_thread_pid(machine, th, pid); | 383 | machine__update_thread_pid(machine, th, pid); |
| 374 | return th; | 384 | return thread__get(th); |
| 375 | } | 385 | } |
| 376 | 386 | ||
| 377 | machine->last_match = NULL; | 387 | machine->last_match = NULL; |
| @@ -384,7 +394,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine, | |||
| 384 | if (th->tid == tid) { | 394 | if (th->tid == tid) { |
| 385 | machine->last_match = th; | 395 | machine->last_match = th; |
| 386 | machine__update_thread_pid(machine, th, pid); | 396 | machine__update_thread_pid(machine, th, pid); |
| 387 | return th; | 397 | return thread__get(th); |
| 388 | } | 398 | } |
| 389 | 399 | ||
| 390 | if (tid < th->tid) | 400 | if (tid < th->tid) |
| @@ -412,7 +422,7 @@ static struct thread *____machine__findnew_thread(struct machine *machine, | |||
| 412 | if (thread__init_map_groups(th, machine)) { | 422 | if (thread__init_map_groups(th, machine)) { |
| 413 | rb_erase_init(&th->rb_node, &machine->threads); | 423 | rb_erase_init(&th->rb_node, &machine->threads); |
| 414 | RB_CLEAR_NODE(&th->rb_node); | 424 | RB_CLEAR_NODE(&th->rb_node); |
| 415 | thread__delete(th); | 425 | thread__put(th); |
| 416 | return NULL; | 426 | return NULL; |
| 417 | } | 427 | } |
| 418 | /* | 428 | /* |
| @@ -436,7 +446,7 @@ struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, | |||
| 436 | struct thread *th; | 446 | struct thread *th; |
| 437 | 447 | ||
| 438 | pthread_rwlock_wrlock(&machine->threads_lock); | 448 | pthread_rwlock_wrlock(&machine->threads_lock); |
| 439 | th = thread__get(__machine__findnew_thread(machine, pid, tid)); | 449 | th = __machine__findnew_thread(machine, pid, tid); |
| 440 | pthread_rwlock_unlock(&machine->threads_lock); | 450 | pthread_rwlock_unlock(&machine->threads_lock); |
| 441 | return th; | 451 | return th; |
| 442 | } | 452 | } |
| @@ -446,7 +456,7 @@ struct thread *machine__find_thread(struct machine *machine, pid_t pid, | |||
| 446 | { | 456 | { |
| 447 | struct thread *th; | 457 | struct thread *th; |
| 448 | pthread_rwlock_rdlock(&machine->threads_lock); | 458 | pthread_rwlock_rdlock(&machine->threads_lock); |
| 449 | th = thread__get(____machine__findnew_thread(machine, pid, tid, false)); | 459 | th = ____machine__findnew_thread(machine, pid, tid, false); |
| 450 | pthread_rwlock_unlock(&machine->threads_lock); | 460 | pthread_rwlock_unlock(&machine->threads_lock); |
| 451 | return th; | 461 | return th; |
| 452 | } | 462 | } |
| @@ -559,11 +569,29 @@ int machine__process_switch_event(struct machine *machine __maybe_unused, | |||
| 559 | return 0; | 569 | return 0; |
| 560 | } | 570 | } |
| 561 | 571 | ||
| 572 | static void dso__adjust_kmod_long_name(struct dso *dso, const char *filename) | ||
| 573 | { | ||
| 574 | const char *dup_filename; | ||
| 575 | |||
| 576 | if (!filename || !dso || !dso->long_name) | ||
| 577 | return; | ||
| 578 | if (dso->long_name[0] != '[') | ||
| 579 | return; | ||
| 580 | if (!strchr(filename, '/')) | ||
| 581 | return; | ||
| 582 | |||
| 583 | dup_filename = strdup(filename); | ||
| 584 | if (!dup_filename) | ||
| 585 | return; | ||
| 586 | |||
| 587 | dso__set_long_name(dso, dup_filename, true); | ||
| 588 | } | ||
| 589 | |||
| 562 | struct map *machine__findnew_module_map(struct machine *machine, u64 start, | 590 | struct map *machine__findnew_module_map(struct machine *machine, u64 start, |
| 563 | const char *filename) | 591 | const char *filename) |
| 564 | { | 592 | { |
| 565 | struct map *map = NULL; | 593 | struct map *map = NULL; |
| 566 | struct dso *dso; | 594 | struct dso *dso = NULL; |
| 567 | struct kmod_path m; | 595 | struct kmod_path m; |
| 568 | 596 | ||
| 569 | if (kmod_path__parse_name(&m, filename)) | 597 | if (kmod_path__parse_name(&m, filename)) |
| @@ -571,8 +599,15 @@ struct map *machine__findnew_module_map(struct machine *machine, u64 start, | |||
| 571 | 599 | ||
| 572 | map = map_groups__find_by_name(&machine->kmaps, MAP__FUNCTION, | 600 | map = map_groups__find_by_name(&machine->kmaps, MAP__FUNCTION, |
| 573 | m.name); | 601 | m.name); |
| 574 | if (map) | 602 | if (map) { |
| 603 | /* | ||
| 604 | * If the map's dso is an offline module, give dso__load() | ||
| 605 | * a chance to find the file path of that module by fixing | ||
| 606 | * long_name. | ||
| 607 | */ | ||
| 608 | dso__adjust_kmod_long_name(map->dso, filename); | ||
| 575 | goto out; | 609 | goto out; |
| 610 | } | ||
| 576 | 611 | ||
| 577 | dso = machine__findnew_module_dso(machine, &m, filename); | 612 | dso = machine__findnew_module_dso(machine, &m, filename); |
| 578 | if (dso == NULL) | 613 | if (dso == NULL) |
| @@ -584,7 +619,11 @@ struct map *machine__findnew_module_map(struct machine *machine, u64 start, | |||
| 584 | 619 | ||
| 585 | map_groups__insert(&machine->kmaps, map); | 620 | map_groups__insert(&machine->kmaps, map); |
| 586 | 621 | ||
| 622 | /* Put the map here because map_groups__insert alread got it */ | ||
| 623 | map__put(map); | ||
| 587 | out: | 624 | out: |
| 625 | /* put the dso here, corresponding to machine__findnew_module_dso */ | ||
| 626 | dso__put(dso); | ||
| 588 | free(m.name); | 627 | free(m.name); |
| 589 | return map; | 628 | return map; |
| 590 | } | 629 | } |
| @@ -739,6 +778,9 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel) | |||
| 739 | enum map_type type; | 778 | enum map_type type; |
| 740 | u64 start = machine__get_running_kernel_start(machine, NULL); | 779 | u64 start = machine__get_running_kernel_start(machine, NULL); |
| 741 | 780 | ||
| 781 | /* In case of renewal the kernel map, destroy previous one */ | ||
| 782 | machine__destroy_kernel_maps(machine); | ||
| 783 | |||
| 742 | for (type = 0; type < MAP__NR_TYPES; ++type) { | 784 | for (type = 0; type < MAP__NR_TYPES; ++type) { |
| 743 | struct kmap *kmap; | 785 | struct kmap *kmap; |
| 744 | struct map *map; | 786 | struct map *map; |
| @@ -787,6 +829,7 @@ void machine__destroy_kernel_maps(struct machine *machine) | |||
| 787 | kmap->ref_reloc_sym = NULL; | 829 | kmap->ref_reloc_sym = NULL; |
| 788 | } | 830 | } |
| 789 | 831 | ||
| 832 | map__put(machine->vmlinux_maps[type]); | ||
| 790 | machine->vmlinux_maps[type] = NULL; | 833 | machine->vmlinux_maps[type] = NULL; |
| 791 | } | 834 | } |
| 792 | } | 835 | } |
| @@ -1083,11 +1126,14 @@ int machine__create_kernel_maps(struct machine *machine) | |||
| 1083 | struct dso *kernel = machine__get_kernel(machine); | 1126 | struct dso *kernel = machine__get_kernel(machine); |
| 1084 | const char *name; | 1127 | const char *name; |
| 1085 | u64 addr = machine__get_running_kernel_start(machine, &name); | 1128 | u64 addr = machine__get_running_kernel_start(machine, &name); |
| 1086 | if (!addr) | 1129 | int ret; |
| 1130 | |||
| 1131 | if (!addr || kernel == NULL) | ||
| 1087 | return -1; | 1132 | return -1; |
| 1088 | 1133 | ||
| 1089 | if (kernel == NULL || | 1134 | ret = __machine__create_kernel_maps(machine, kernel); |
| 1090 | __machine__create_kernel_maps(machine, kernel) < 0) | 1135 | dso__put(kernel); |
| 1136 | if (ret < 0) | ||
| 1091 | return -1; | 1137 | return -1; |
| 1092 | 1138 | ||
| 1093 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) { | 1139 | if (symbol_conf.use_modules && machine__create_modules(machine) < 0) { |
| @@ -1608,6 +1654,8 @@ static int add_callchain_ip(struct thread *thread, | |||
| 1608 | } | 1654 | } |
| 1609 | } | 1655 | } |
| 1610 | 1656 | ||
| 1657 | if (symbol_conf.hide_unresolved && al.sym == NULL) | ||
| 1658 | return 0; | ||
| 1611 | return callchain_cursor_append(&callchain_cursor, al.addr, al.map, al.sym); | 1659 | return callchain_cursor_append(&callchain_cursor, al.addr, al.map, al.sym); |
| 1612 | } | 1660 | } |
| 1613 | 1661 | ||
| @@ -1862,6 +1910,9 @@ check_calls: | |||
| 1862 | static int unwind_entry(struct unwind_entry *entry, void *arg) | 1910 | static int unwind_entry(struct unwind_entry *entry, void *arg) |
| 1863 | { | 1911 | { |
| 1864 | struct callchain_cursor *cursor = arg; | 1912 | struct callchain_cursor *cursor = arg; |
| 1913 | |||
| 1914 | if (symbol_conf.hide_unresolved && entry->sym == NULL) | ||
| 1915 | return 0; | ||
| 1865 | return callchain_cursor_append(cursor, entry->ip, | 1916 | return callchain_cursor_append(cursor, entry->ip, |
| 1866 | entry->map, entry->sym); | 1917 | entry->map, entry->sym); |
| 1867 | } | 1918 | } |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index afc6b56cf749..171b6d10a04b 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
| @@ -26,8 +26,8 @@ const char *map_type__name[MAP__NR_TYPES] = { | |||
| 26 | static inline int is_anon_memory(const char *filename) | 26 | static inline int is_anon_memory(const char *filename) |
| 27 | { | 27 | { |
| 28 | return !strcmp(filename, "//anon") || | 28 | return !strcmp(filename, "//anon") || |
| 29 | !strcmp(filename, "/dev/zero (deleted)") || | 29 | !strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) || |
| 30 | !strcmp(filename, "/anon_hugepage (deleted)"); | 30 | !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage") - 1); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | static inline int is_no_dso_memory(const char *filename) | 33 | static inline int is_no_dso_memory(const char *filename) |
| @@ -691,6 +691,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp | |||
| 691 | __map_groups__insert(pos->groups, before); | 691 | __map_groups__insert(pos->groups, before); |
| 692 | if (verbose >= 2) | 692 | if (verbose >= 2) |
| 693 | map__fprintf(before, fp); | 693 | map__fprintf(before, fp); |
| 694 | map__put(before); | ||
| 694 | } | 695 | } |
| 695 | 696 | ||
| 696 | if (map->end < pos->end) { | 697 | if (map->end < pos->end) { |
| @@ -705,6 +706,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp | |||
| 705 | __map_groups__insert(pos->groups, after); | 706 | __map_groups__insert(pos->groups, after); |
| 706 | if (verbose >= 2) | 707 | if (verbose >= 2) |
| 707 | map__fprintf(after, fp); | 708 | map__fprintf(after, fp); |
| 709 | map__put(after); | ||
| 708 | } | 710 | } |
| 709 | put_map: | 711 | put_map: |
| 710 | map__put(pos); | 712 | map__put(pos); |
| @@ -742,6 +744,7 @@ int map_groups__clone(struct map_groups *mg, | |||
| 742 | if (new == NULL) | 744 | if (new == NULL) |
| 743 | goto out_unlock; | 745 | goto out_unlock; |
| 744 | map_groups__insert(mg, new); | 746 | map_groups__insert(mg, new); |
| 747 | map__put(new); | ||
| 745 | } | 748 | } |
| 746 | 749 | ||
| 747 | err = 0; | 750 | err = 0; |
diff --git a/tools/perf/util/pager.c b/tools/perf/util/pager.c deleted file mode 100644 index 53ef006a951c..000000000000 --- a/tools/perf/util/pager.c +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include "run-command.h" | ||
| 3 | #include "sigchain.h" | ||
| 4 | |||
| 5 | /* | ||
| 6 | * This is split up from the rest of git so that we can do | ||
| 7 | * something different on Windows. | ||
| 8 | */ | ||
| 9 | |||
| 10 | static int spawned_pager; | ||
| 11 | |||
| 12 | static void pager_preexec(void) | ||
| 13 | { | ||
| 14 | /* | ||
| 15 | * Work around bug in "less" by not starting it until we | ||
| 16 | * have real input | ||
| 17 | */ | ||
| 18 | fd_set in; | ||
| 19 | |||
| 20 | FD_ZERO(&in); | ||
| 21 | FD_SET(0, &in); | ||
| 22 | select(1, &in, NULL, &in, NULL); | ||
| 23 | |||
| 24 | setenv("LESS", "FRSX", 0); | ||
| 25 | } | ||
| 26 | |||
| 27 | static const char *pager_argv[] = { "sh", "-c", NULL, NULL }; | ||
| 28 | static struct child_process pager_process; | ||
| 29 | |||
| 30 | static void wait_for_pager(void) | ||
| 31 | { | ||
| 32 | fflush(stdout); | ||
| 33 | fflush(stderr); | ||
| 34 | /* signal EOF to pager */ | ||
| 35 | close(1); | ||
| 36 | close(2); | ||
| 37 | finish_command(&pager_process); | ||
| 38 | } | ||
| 39 | |||
| 40 | static void wait_for_pager_signal(int signo) | ||
| 41 | { | ||
| 42 | wait_for_pager(); | ||
| 43 | sigchain_pop(signo); | ||
| 44 | raise(signo); | ||
| 45 | } | ||
| 46 | |||
| 47 | void setup_pager(void) | ||
| 48 | { | ||
| 49 | const char *pager = getenv("PERF_PAGER"); | ||
| 50 | |||
| 51 | if (!isatty(1)) | ||
| 52 | return; | ||
| 53 | if (!pager) | ||
| 54 | pager = getenv("PAGER"); | ||
| 55 | if (!(pager || access("/usr/bin/pager", X_OK))) | ||
| 56 | pager = "/usr/bin/pager"; | ||
| 57 | if (!(pager || access("/usr/bin/less", X_OK))) | ||
| 58 | pager = "/usr/bin/less"; | ||
| 59 | if (!pager) | ||
| 60 | pager = "cat"; | ||
| 61 | if (!*pager || !strcmp(pager, "cat")) | ||
| 62 | return; | ||
| 63 | |||
| 64 | spawned_pager = 1; /* means we are emitting to terminal */ | ||
| 65 | |||
| 66 | /* spawn the pager */ | ||
| 67 | pager_argv[2] = pager; | ||
| 68 | pager_process.argv = pager_argv; | ||
| 69 | pager_process.in = -1; | ||
| 70 | pager_process.preexec_cb = pager_preexec; | ||
| 71 | |||
| 72 | if (start_command(&pager_process)) | ||
| 73 | return; | ||
| 74 | |||
| 75 | /* original process continues, but writes to the pipe */ | ||
| 76 | dup2(pager_process.in, 1); | ||
| 77 | if (isatty(2)) | ||
| 78 | dup2(pager_process.in, 2); | ||
| 79 | close(pager_process.in); | ||
| 80 | |||
| 81 | /* this makes sure that the parent terminates after the pager */ | ||
| 82 | sigchain_push_common(wait_for_pager_signal); | ||
| 83 | atexit(wait_for_pager); | ||
| 84 | } | ||
| 85 | |||
| 86 | int pager_in_use(void) | ||
| 87 | { | ||
| 88 | const char *env; | ||
| 89 | |||
| 90 | if (spawned_pager) | ||
| 91 | return 1; | ||
| 92 | |||
| 93 | env = getenv("PERF_PAGER_IN_USE"); | ||
| 94 | return env ? perf_config_bool("PERF_PAGER_IN_USE", env) : 0; | ||
| 95 | } | ||
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c index 355eecf6bf59..afc088dd7d20 100644 --- a/tools/perf/util/parse-branch-options.c +++ b/tools/perf/util/parse-branch-options.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "perf.h" | 1 | #include "perf.h" |
| 2 | #include "util/util.h" | 2 | #include "util/util.h" |
| 3 | #include "util/debug.h" | 3 | #include "util/debug.h" |
| 4 | #include "util/parse-options.h" | 4 | #include <subcmd/parse-options.h> |
| 5 | #include "util/parse-branch-options.h" | 5 | #include "util/parse-branch-options.h" |
| 6 | 6 | ||
| 7 | #define BRANCH_OPT(n, m) \ | 7 | #define BRANCH_OPT(n, m) \ |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index e48d9da75707..4f7b0efdde2f 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
| @@ -4,9 +4,9 @@ | |||
| 4 | #include "../perf.h" | 4 | #include "../perf.h" |
| 5 | #include "evlist.h" | 5 | #include "evlist.h" |
| 6 | #include "evsel.h" | 6 | #include "evsel.h" |
| 7 | #include "parse-options.h" | 7 | #include <subcmd/parse-options.h> |
| 8 | #include "parse-events.h" | 8 | #include "parse-events.h" |
| 9 | #include "exec_cmd.h" | 9 | #include <subcmd/exec-cmd.h> |
| 10 | #include "string.h" | 10 | #include "string.h" |
| 11 | #include "symbol.h" | 11 | #include "symbol.h" |
| 12 | #include "cache.h" | 12 | #include "cache.h" |
| @@ -124,6 +124,10 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { | |||
| 124 | .symbol = "dummy", | 124 | .symbol = "dummy", |
| 125 | .alias = "", | 125 | .alias = "", |
| 126 | }, | 126 | }, |
| 127 | [PERF_COUNT_SW_BPF_OUTPUT] = { | ||
| 128 | .symbol = "bpf-output", | ||
| 129 | .alias = "", | ||
| 130 | }, | ||
| 127 | }; | 131 | }; |
| 128 | 132 | ||
| 129 | #define __PERF_EVENT_FIELD(config, name) \ | 133 | #define __PERF_EVENT_FIELD(config, name) \ |
| @@ -1879,7 +1883,7 @@ restart: | |||
| 1879 | 1883 | ||
| 1880 | for (i = 0; i < max; i++, syms++) { | 1884 | for (i = 0; i < max; i++, syms++) { |
| 1881 | 1885 | ||
| 1882 | if (event_glob != NULL && | 1886 | if (event_glob != NULL && syms->symbol != NULL && |
| 1883 | !(strglobmatch(syms->symbol, event_glob) || | 1887 | !(strglobmatch(syms->symbol, event_glob) || |
| 1884 | (syms->alias && strglobmatch(syms->alias, event_glob)))) | 1888 | (syms->alias && strglobmatch(syms->alias, event_glob)))) |
| 1885 | continue; | 1889 | continue; |
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c deleted file mode 100644 index 9fca09296eb3..000000000000 --- a/tools/perf/util/parse-options.c +++ /dev/null | |||
| @@ -1,867 +0,0 @@ | |||
| 1 | #include "util.h" | ||
| 2 | #include "parse-options.h" | ||
| 3 | #include "cache.h" | ||
| 4 | #include "header.h" | ||
| 5 | #include <linux/string.h> | ||
| 6 | |||
| 7 | #define OPT_SHORT 1 | ||
| 8 | #define OPT_UNSET 2 | ||
| 9 | |||
| 10 | static struct strbuf error_buf = STRBUF_INIT; | ||
| 11 | |||
| 12 | static int opterror(const struct option *opt, const char *reason, int flags) | ||
| 13 | { | ||
| 14 | if (flags & OPT_SHORT) | ||
| 15 | return error("switch `%c' %s", opt->short_name, reason); | ||
| 16 | if (flags & OPT_UNSET) | ||
| 17 | return error("option `no-%s' %s", opt->long_name, reason); | ||
| 18 | return error("option `%s' %s", opt->long_name, reason); | ||
| 19 | } | ||
| 20 | |||
| 21 | static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, | ||
| 22 | int flags, const char **arg) | ||
| 23 | { | ||
| 24 | if (p->opt) { | ||
| 25 | *arg = p->opt; | ||
| 26 | p->opt = NULL; | ||
| 27 | } else if ((opt->flags & PARSE_OPT_LASTARG_DEFAULT) && (p->argc == 1 || | ||
| 28 | **(p->argv + 1) == '-')) { | ||
| 29 | *arg = (const char *)opt->defval; | ||
| 30 | } else if (p->argc > 1) { | ||
| 31 | p->argc--; | ||
| 32 | *arg = *++p->argv; | ||
| 33 | } else | ||
| 34 | return opterror(opt, "requires a value", flags); | ||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | static int get_value(struct parse_opt_ctx_t *p, | ||
| 39 | const struct option *opt, int flags) | ||
| 40 | { | ||
| 41 | const char *s, *arg = NULL; | ||
| 42 | const int unset = flags & OPT_UNSET; | ||
| 43 | int err; | ||
| 44 | |||
| 45 | if (unset && p->opt) | ||
| 46 | return opterror(opt, "takes no value", flags); | ||
| 47 | if (unset && (opt->flags & PARSE_OPT_NONEG)) | ||
| 48 | return opterror(opt, "isn't available", flags); | ||
| 49 | if (opt->flags & PARSE_OPT_DISABLED) | ||
| 50 | return opterror(opt, "is not usable", flags); | ||
| 51 | |||
| 52 | if (opt->flags & PARSE_OPT_EXCLUSIVE) { | ||
| 53 | if (p->excl_opt && p->excl_opt != opt) { | ||
| 54 | char msg[128]; | ||
| 55 | |||
| 56 | if (((flags & OPT_SHORT) && p->excl_opt->short_name) || | ||
| 57 | p->excl_opt->long_name == NULL) { | ||
| 58 | scnprintf(msg, sizeof(msg), "cannot be used with switch `%c'", | ||
| 59 | p->excl_opt->short_name); | ||
| 60 | } else { | ||
| 61 | scnprintf(msg, sizeof(msg), "cannot be used with %s", | ||
| 62 | p->excl_opt->long_name); | ||
| 63 | } | ||
| 64 | opterror(opt, msg, flags); | ||
| 65 | return -3; | ||
| 66 | } | ||
| 67 | p->excl_opt = opt; | ||
| 68 | } | ||
| 69 | if (!(flags & OPT_SHORT) && p->opt) { | ||
| 70 | switch (opt->type) { | ||
| 71 | case OPTION_CALLBACK: | ||
| 72 | if (!(opt->flags & PARSE_OPT_NOARG)) | ||
| 73 | break; | ||
| 74 | /* FALLTHROUGH */ | ||
| 75 | case OPTION_BOOLEAN: | ||
| 76 | case OPTION_INCR: | ||
| 77 | case OPTION_BIT: | ||
| 78 | case OPTION_SET_UINT: | ||
| 79 | case OPTION_SET_PTR: | ||
| 80 | return opterror(opt, "takes no value", flags); | ||
| 81 | case OPTION_END: | ||
| 82 | case OPTION_ARGUMENT: | ||
| 83 | case OPTION_GROUP: | ||
| 84 | case OPTION_STRING: | ||
| 85 | case OPTION_INTEGER: | ||
| 86 | case OPTION_UINTEGER: | ||
| 87 | case OPTION_LONG: | ||
| 88 | case OPTION_U64: | ||
| 89 | default: | ||
| 90 | break; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | switch (opt->type) { | ||
| 95 | case OPTION_BIT: | ||
| 96 | if (unset) | ||
| 97 | *(int *)opt->value &= ~opt->defval; | ||
| 98 | else | ||
| 99 | *(int *)opt->value |= opt->defval; | ||
| 100 | return 0; | ||
| 101 | |||
| 102 | case OPTION_BOOLEAN: | ||
| 103 | *(bool *)opt->value = unset ? false : true; | ||
| 104 | if (opt->set) | ||
| 105 | *(bool *)opt->set = true; | ||
| 106 | return 0; | ||
| 107 | |||
| 108 | case OPTION_INCR: | ||
| 109 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; | ||
| 110 | return 0; | ||
| 111 | |||
| 112 | case OPTION_SET_UINT: | ||
| 113 | *(unsigned int *)opt->value = unset ? 0 : opt->defval; | ||
| 114 | return 0; | ||
| 115 | |||
| 116 | case OPTION_SET_PTR: | ||
| 117 | *(void **)opt->value = unset ? NULL : (void *)opt->defval; | ||
| 118 | return 0; | ||
| 119 | |||
| 120 | case OPTION_STRING: | ||
| 121 | err = 0; | ||
| 122 | if (unset) | ||
| 123 | *(const char **)opt->value = NULL; | ||
| 124 | else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) | ||
| 125 | *(const char **)opt->value = (const char *)opt->defval; | ||
| 126 | else | ||
| 127 | err = get_arg(p, opt, flags, (const char **)opt->value); | ||
| 128 | |||
| 129 | /* PARSE_OPT_NOEMPTY: Allow NULL but disallow empty string. */ | ||
| 130 | if (opt->flags & PARSE_OPT_NOEMPTY) { | ||
| 131 | const char *val = *(const char **)opt->value; | ||
| 132 | |||
| 133 | if (!val) | ||
| 134 | return err; | ||
| 135 | |||
| 136 | /* Similar to unset if we are given an empty string. */ | ||
| 137 | if (val[0] == '\0') { | ||
| 138 | *(const char **)opt->value = NULL; | ||
| 139 | return 0; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | return err; | ||
| 144 | |||
| 145 | case OPTION_CALLBACK: | ||
| 146 | if (unset) | ||
| 147 | return (*opt->callback)(opt, NULL, 1) ? (-1) : 0; | ||
| 148 | if (opt->flags & PARSE_OPT_NOARG) | ||
| 149 | return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; | ||
| 150 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) | ||
| 151 | return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; | ||
| 152 | if (get_arg(p, opt, flags, &arg)) | ||
| 153 | return -1; | ||
| 154 | return (*opt->callback)(opt, arg, 0) ? (-1) : 0; | ||
| 155 | |||
| 156 | case OPTION_INTEGER: | ||
| 157 | if (unset) { | ||
| 158 | *(int *)opt->value = 0; | ||
| 159 | return 0; | ||
| 160 | } | ||
| 161 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
| 162 | *(int *)opt->value = opt->defval; | ||
| 163 | return 0; | ||
| 164 | } | ||
| 165 | if (get_arg(p, opt, flags, &arg)) | ||
| 166 | return -1; | ||
| 167 | *(int *)opt->value = strtol(arg, (char **)&s, 10); | ||
| 168 | if (*s) | ||
| 169 | return opterror(opt, "expects a numerical value", flags); | ||
| 170 | return 0; | ||
| 171 | |||
| 172 | case OPTION_UINTEGER: | ||
| 173 | if (unset) { | ||
| 174 | *(unsigned int *)opt->value = 0; | ||
| 175 | return 0; | ||
| 176 | } | ||
| 177 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
| 178 | *(unsigned int *)opt->value = opt->defval; | ||
| 179 | return 0; | ||
| 180 | } | ||
| 181 | if (get_arg(p, opt, flags, &arg)) | ||
| 182 | return -1; | ||
| 183 | *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); | ||
| 184 | if (*s) | ||
| 185 | return opterror(opt, "expects a numerical value", flags); | ||
| 186 | return 0; | ||
| 187 | |||
| 188 | case OPTION_LONG: | ||
| 189 | if (unset) { | ||
| 190 | *(long *)opt->value = 0; | ||
| 191 | return 0; | ||
| 192 | } | ||
| 193 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
| 194 | *(long *)opt->value = opt->defval; | ||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | if (get_arg(p, opt, flags, &arg)) | ||
| 198 | return -1; | ||
| 199 | *(long *)opt->value = strtol(arg, (char **)&s, 10); | ||
| 200 | if (*s) | ||
| 201 | return opterror(opt, "expects a numerical value", flags); | ||
| 202 | return 0; | ||
| 203 | |||
| 204 | case OPTION_U64: | ||
| 205 | if (unset) { | ||
| 206 | *(u64 *)opt->value = 0; | ||
| 207 | return 0; | ||
| 208 | } | ||
| 209 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
| 210 | *(u64 *)opt->value = opt->defval; | ||
| 211 | return 0; | ||
| 212 | } | ||
| 213 | if (get_arg(p, opt, flags, &arg)) | ||
| 214 | return -1; | ||
| 215 | *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); | ||
| 216 | if (*s) | ||
| 217 | return opterror(opt, "expects a numerical value", flags); | ||
| 218 | return 0; | ||
| 219 | |||
| 220 | case OPTION_END: | ||
| 221 | case OPTION_ARGUMENT: | ||
| 222 | case OPTION_GROUP: | ||
| 223 | default: | ||
| 224 | die("should not happen, someone must be hit on the forehead"); | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *options) | ||
| 229 | { | ||
| 230 | for (; options->type != OPTION_END; options++) { | ||
| 231 | if (options->short_name == *p->opt) { | ||
| 232 | p->opt = p->opt[1] ? p->opt + 1 : NULL; | ||
| 233 | return get_value(p, options, OPT_SHORT); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | return -2; | ||
| 237 | } | ||
| 238 | |||
| 239 | static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg, | ||
| 240 | const struct option *options) | ||
| 241 | { | ||
| 242 | const char *arg_end = strchr(arg, '='); | ||
| 243 | const struct option *abbrev_option = NULL, *ambiguous_option = NULL; | ||
| 244 | int abbrev_flags = 0, ambiguous_flags = 0; | ||
| 245 | |||
| 246 | if (!arg_end) | ||
| 247 | arg_end = arg + strlen(arg); | ||
| 248 | |||
| 249 | for (; options->type != OPTION_END; options++) { | ||
| 250 | const char *rest; | ||
| 251 | int flags = 0; | ||
| 252 | |||
| 253 | if (!options->long_name) | ||
| 254 | continue; | ||
| 255 | |||
| 256 | rest = skip_prefix(arg, options->long_name); | ||
| 257 | if (options->type == OPTION_ARGUMENT) { | ||
| 258 | if (!rest) | ||
| 259 | continue; | ||
| 260 | if (*rest == '=') | ||
| 261 | return opterror(options, "takes no value", flags); | ||
| 262 | if (*rest) | ||
| 263 | continue; | ||
| 264 | p->out[p->cpidx++] = arg - 2; | ||
| 265 | return 0; | ||
| 266 | } | ||
| 267 | if (!rest) { | ||
| 268 | if (!prefixcmp(options->long_name, "no-")) { | ||
| 269 | /* | ||
| 270 | * The long name itself starts with "no-", so | ||
| 271 | * accept the option without "no-" so that users | ||
| 272 | * do not have to enter "no-no-" to get the | ||
| 273 | * negation. | ||
| 274 | */ | ||
| 275 | rest = skip_prefix(arg, options->long_name + 3); | ||
| 276 | if (rest) { | ||
| 277 | flags |= OPT_UNSET; | ||
| 278 | goto match; | ||
| 279 | } | ||
| 280 | /* Abbreviated case */ | ||
| 281 | if (!prefixcmp(options->long_name + 3, arg)) { | ||
| 282 | flags |= OPT_UNSET; | ||
| 283 | goto is_abbreviated; | ||
| 284 | } | ||
| 285 | } | ||
| 286 | /* abbreviated? */ | ||
| 287 | if (!strncmp(options->long_name, arg, arg_end - arg)) { | ||
| 288 | is_abbreviated: | ||
| 289 | if (abbrev_option) { | ||
| 290 | /* | ||
| 291 | * If this is abbreviated, it is | ||
| 292 | * ambiguous. So when there is no | ||
| 293 | * exact match later, we need to | ||
| 294 | * error out. | ||
| 295 | */ | ||
| 296 | ambiguous_option = abbrev_option; | ||
| 297 | ambiguous_flags = abbrev_flags; | ||
| 298 | } | ||
| 299 | if (!(flags & OPT_UNSET) && *arg_end) | ||
| 300 | p->opt = arg_end + 1; | ||
| 301 | abbrev_option = options; | ||
| 302 | abbrev_flags = flags; | ||
| 303 | continue; | ||
| 304 | } | ||
| 305 | /* negated and abbreviated very much? */ | ||
| 306 | if (!prefixcmp("no-", arg)) { | ||
| 307 | flags |= OPT_UNSET; | ||
| 308 | goto is_abbreviated; | ||
| 309 | } | ||
| 310 | /* negated? */ | ||
| 311 | if (strncmp(arg, "no-", 3)) | ||
| 312 | continue; | ||
| 313 | flags |= OPT_UNSET; | ||
| 314 | rest = skip_prefix(arg + 3, options->long_name); | ||
| 315 | /* abbreviated and negated? */ | ||
| 316 | if (!rest && !prefixcmp(options->long_name, arg + 3)) | ||
| 317 | goto is_abbreviated; | ||
| 318 | if (!rest) | ||
| 319 | continue; | ||
| 320 | } | ||
| 321 | match: | ||
| 322 | if (*rest) { | ||
| 323 | if (*rest != '=') | ||
| 324 | continue; | ||
| 325 | p->opt = rest + 1; | ||
| 326 | } | ||
| 327 | return get_value(p, options, flags); | ||
| 328 | } | ||
| 329 | |||
| 330 | if (ambiguous_option) | ||
| 331 | return error("Ambiguous option: %s " | ||
| 332 | "(could be --%s%s or --%s%s)", | ||
| 333 | arg, | ||
| 334 | (ambiguous_flags & OPT_UNSET) ? "no-" : "", | ||
| 335 | ambiguous_option->long_name, | ||
| 336 | (abbrev_flags & OPT_UNSET) ? "no-" : "", | ||
| 337 | abbrev_option->long_name); | ||
| 338 | if (abbrev_option) | ||
| 339 | return get_value(p, abbrev_option, abbrev_flags); | ||
| 340 | return -2; | ||
| 341 | } | ||
| 342 | |||
| 343 | static void check_typos(const char *arg, const struct option *options) | ||
| 344 | { | ||
| 345 | if (strlen(arg) < 3) | ||
| 346 | return; | ||
| 347 | |||
| 348 | if (!prefixcmp(arg, "no-")) { | ||
| 349 | error ("did you mean `--%s` (with two dashes ?)", arg); | ||
| 350 | exit(129); | ||
| 351 | } | ||
| 352 | |||
| 353 | for (; options->type != OPTION_END; options++) { | ||
| 354 | if (!options->long_name) | ||
| 355 | continue; | ||
| 356 | if (!prefixcmp(options->long_name, arg)) { | ||
| 357 | error ("did you mean `--%s` (with two dashes ?)", arg); | ||
| 358 | exit(129); | ||
| 359 | } | ||
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 | void parse_options_start(struct parse_opt_ctx_t *ctx, | ||
| 364 | int argc, const char **argv, int flags) | ||
| 365 | { | ||
| 366 | memset(ctx, 0, sizeof(*ctx)); | ||
| 367 | ctx->argc = argc - 1; | ||
| 368 | ctx->argv = argv + 1; | ||
| 369 | ctx->out = argv; | ||
| 370 | ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); | ||
| 371 | ctx->flags = flags; | ||
| 372 | if ((flags & PARSE_OPT_KEEP_UNKNOWN) && | ||
| 373 | (flags & PARSE_OPT_STOP_AT_NON_OPTION)) | ||
| 374 | die("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together"); | ||
| 375 | } | ||
| 376 | |||
| 377 | static int usage_with_options_internal(const char * const *, | ||
| 378 | const struct option *, int, | ||
| 379 | struct parse_opt_ctx_t *); | ||
| 380 | |||
| 381 | int parse_options_step(struct parse_opt_ctx_t *ctx, | ||
| 382 | const struct option *options, | ||
| 383 | const char * const usagestr[]) | ||
| 384 | { | ||
| 385 | int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP); | ||
| 386 | int excl_short_opt = 1; | ||
| 387 | const char *arg; | ||
| 388 | |||
| 389 | /* we must reset ->opt, unknown short option leave it dangling */ | ||
| 390 | ctx->opt = NULL; | ||
| 391 | |||
| 392 | for (; ctx->argc; ctx->argc--, ctx->argv++) { | ||
| 393 | arg = ctx->argv[0]; | ||
| 394 | if (*arg != '-' || !arg[1]) { | ||
| 395 | if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) | ||
| 396 | break; | ||
| 397 | ctx->out[ctx->cpidx++] = ctx->argv[0]; | ||
| 398 | continue; | ||
| 399 | } | ||
| 400 | |||
| 401 | if (arg[1] != '-') { | ||
| 402 | ctx->opt = ++arg; | ||
| 403 | if (internal_help && *ctx->opt == 'h') { | ||
| 404 | return usage_with_options_internal(usagestr, options, 0, ctx); | ||
| 405 | } | ||
| 406 | switch (parse_short_opt(ctx, options)) { | ||
| 407 | case -1: | ||
| 408 | return parse_options_usage(usagestr, options, arg, 1); | ||
| 409 | case -2: | ||
| 410 | goto unknown; | ||
| 411 | case -3: | ||
| 412 | goto exclusive; | ||
| 413 | default: | ||
| 414 | break; | ||
| 415 | } | ||
| 416 | if (ctx->opt) | ||
| 417 | check_typos(arg, options); | ||
| 418 | while (ctx->opt) { | ||
| 419 | if (internal_help && *ctx->opt == 'h') | ||
| 420 | return usage_with_options_internal(usagestr, options, 0, ctx); | ||
| 421 | arg = ctx->opt; | ||
| 422 | switch (parse_short_opt(ctx, options)) { | ||
| 423 | case -1: | ||
| 424 | return parse_options_usage(usagestr, options, arg, 1); | ||
| 425 | case -2: | ||
| 426 | /* fake a short option thing to hide the fact that we may have | ||
| 427 | * started to parse aggregated stuff | ||
| 428 | * | ||
| 429 | * This is leaky, too bad. | ||
| 430 | */ | ||
| 431 | ctx->argv[0] = strdup(ctx->opt - 1); | ||
| 432 | *(char *)ctx->argv[0] = '-'; | ||
| 433 | goto unknown; | ||
| 434 | case -3: | ||
| 435 | goto exclusive; | ||
| 436 | default: | ||
| 437 | break; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | continue; | ||
| 441 | } | ||
| 442 | |||
| 443 | if (!arg[2]) { /* "--" */ | ||
| 444 | if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) { | ||
| 445 | ctx->argc--; | ||
| 446 | ctx->argv++; | ||
| 447 | } | ||
| 448 | break; | ||
| 449 | } | ||
| 450 | |||
| 451 | arg += 2; | ||
| 452 | if (internal_help && !strcmp(arg, "help-all")) | ||
| 453 | return usage_with_options_internal(usagestr, options, 1, ctx); | ||
| 454 | if (internal_help && !strcmp(arg, "help")) | ||
| 455 | return usage_with_options_internal(usagestr, options, 0, ctx); | ||
| 456 | if (!strcmp(arg, "list-opts")) | ||
| 457 | return PARSE_OPT_LIST_OPTS; | ||
| 458 | if (!strcmp(arg, "list-cmds")) | ||
| 459 | return PARSE_OPT_LIST_SUBCMDS; | ||
| 460 | switch (parse_long_opt(ctx, arg, options)) { | ||
| 461 | case -1: | ||
| 462 | return parse_options_usage(usagestr, options, arg, 0); | ||
| 463 | case -2: | ||
| 464 | goto unknown; | ||
| 465 | case -3: | ||
| 466 | excl_short_opt = 0; | ||
| 467 | goto exclusive; | ||
| 468 | default: | ||
| 469 | break; | ||
| 470 | } | ||
| 471 | continue; | ||
| 472 | unknown: | ||
| 473 | if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN)) | ||
| 474 | return PARSE_OPT_UNKNOWN; | ||
| 475 | ctx->out[ctx->cpidx++] = ctx->argv[0]; | ||
| 476 | ctx->opt = NULL; | ||
| 477 | } | ||
| 478 | return PARSE_OPT_DONE; | ||
| 479 | |||
| 480 | exclusive: | ||
| 481 | parse_options_usage(usagestr, options, arg, excl_short_opt); | ||
| 482 | if ((excl_short_opt && ctx->excl_opt->short_name) || | ||
| 483 | ctx->excl_opt->long_name == NULL) { | ||
| 484 | char opt = ctx->excl_opt->short_name; | ||
| 485 | parse_options_usage(NULL, options, &opt, 1); | ||
| 486 | } else { | ||
| 487 | parse_options_usage(NULL, options, ctx->excl_opt->long_name, 0); | ||
| 488 | } | ||
| 489 | return PARSE_OPT_HELP; | ||
| 490 | } | ||
| 491 | |||
| 492 | int parse_options_end(struct parse_opt_ctx_t *ctx) | ||
| 493 | { | ||
| 494 | memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out)); | ||
| 495 | ctx->out[ctx->cpidx + ctx->argc] = NULL; | ||
| 496 | return ctx->cpidx + ctx->argc; | ||
| 497 | } | ||
| 498 | |||
| 499 | int parse_options_subcommand(int argc, const char **argv, const struct option *options, | ||
| 500 | const char *const subcommands[], const char *usagestr[], int flags) | ||
| 501 | { | ||
| 502 | struct parse_opt_ctx_t ctx; | ||
| 503 | |||
| 504 | perf_env__set_cmdline(&perf_env, argc, argv); | ||
| 505 | |||
| 506 | /* build usage string if it's not provided */ | ||
| 507 | if (subcommands && !usagestr[0]) { | ||
| 508 | struct strbuf buf = STRBUF_INIT; | ||
| 509 | |||
| 510 | strbuf_addf(&buf, "perf %s [<options>] {", argv[0]); | ||
| 511 | for (int i = 0; subcommands[i]; i++) { | ||
| 512 | if (i) | ||
| 513 | strbuf_addstr(&buf, "|"); | ||
| 514 | strbuf_addstr(&buf, subcommands[i]); | ||
| 515 | } | ||
| 516 | strbuf_addstr(&buf, "}"); | ||
| 517 | |||
| 518 | usagestr[0] = strdup(buf.buf); | ||
| 519 | strbuf_release(&buf); | ||
| 520 | } | ||
| 521 | |||
| 522 | parse_options_start(&ctx, argc, argv, flags); | ||
| 523 | switch (parse_options_step(&ctx, options, usagestr)) { | ||
| 524 | case PARSE_OPT_HELP: | ||
| 525 | exit(129); | ||
| 526 | case PARSE_OPT_DONE: | ||
| 527 | break; | ||
| 528 | case PARSE_OPT_LIST_OPTS: | ||
| 529 | while (options->type != OPTION_END) { | ||
| 530 | if (options->long_name) | ||
| 531 | printf("--%s ", options->long_name); | ||
| 532 | options++; | ||
| 533 | } | ||
| 534 | putchar('\n'); | ||
| 535 | exit(130); | ||
| 536 | case PARSE_OPT_LIST_SUBCMDS: | ||
| 537 | if (subcommands) { | ||
| 538 | for (int i = 0; subcommands[i]; i++) | ||
| 539 | printf("%s ", subcommands[i]); | ||
| 540 | } | ||
| 541 | putchar('\n'); | ||
| 542 | exit(130); | ||
| 543 | default: /* PARSE_OPT_UNKNOWN */ | ||
| 544 | if (ctx.argv[0][1] == '-') { | ||
| 545 | strbuf_addf(&error_buf, "unknown option `%s'", | ||
| 546 | ctx.argv[0] + 2); | ||
| 547 | } else { | ||
| 548 | strbuf_addf(&error_buf, "unknown switch `%c'", | ||
| 549 | *ctx.opt); | ||
| 550 | } | ||
| 551 | usage_with_options(usagestr, options); | ||
| 552 | } | ||
| 553 | |||
| 554 | return parse_options_end(&ctx); | ||
| 555 | } | ||
| 556 | |||
| 557 | int parse_options(int argc, const char **argv, const struct option *options, | ||
| 558 | const char * const usagestr[], int flags) | ||
| 559 | { | ||
| 560 | return parse_options_subcommand(argc, argv, options, NULL, | ||
| 561 | (const char **) usagestr, flags); | ||
| 562 | } | ||
| 563 | |||
| 564 | #define USAGE_OPTS_WIDTH 24 | ||
| 565 | #define USAGE_GAP 2 | ||
| 566 | |||
| 567 | static void print_option_help(const struct option *opts, int full) | ||
| 568 | { | ||
| 569 | size_t pos; | ||
| 570 | int pad; | ||
| 571 | |||
| 572 | if (opts->type == OPTION_GROUP) { | ||
| 573 | fputc('\n', stderr); | ||
| 574 | if (*opts->help) | ||
| 575 | fprintf(stderr, "%s\n", opts->help); | ||
| 576 | return; | ||
| 577 | } | ||
| 578 | if (!full && (opts->flags & PARSE_OPT_HIDDEN)) | ||
| 579 | return; | ||
| 580 | if (opts->flags & PARSE_OPT_DISABLED) | ||
| 581 | return; | ||
| 582 | |||
| 583 | pos = fprintf(stderr, " "); | ||
| 584 | if (opts->short_name) | ||
| 585 | pos += fprintf(stderr, "-%c", opts->short_name); | ||
| 586 | else | ||
| 587 | pos += fprintf(stderr, " "); | ||
| 588 | |||
| 589 | if (opts->long_name && opts->short_name) | ||
| 590 | pos += fprintf(stderr, ", "); | ||
| 591 | if (opts->long_name) | ||
| 592 | pos += fprintf(stderr, "--%s", opts->long_name); | ||
| 593 | |||
| 594 | switch (opts->type) { | ||
| 595 | case OPTION_ARGUMENT: | ||
| 596 | break; | ||
| 597 | case OPTION_LONG: | ||
| 598 | case OPTION_U64: | ||
| 599 | case OPTION_INTEGER: | ||
| 600 | case OPTION_UINTEGER: | ||
| 601 | if (opts->flags & PARSE_OPT_OPTARG) | ||
| 602 | if (opts->long_name) | ||
| 603 | pos += fprintf(stderr, "[=<n>]"); | ||
| 604 | else | ||
| 605 | pos += fprintf(stderr, "[<n>]"); | ||
| 606 | else | ||
| 607 | pos += fprintf(stderr, " <n>"); | ||
| 608 | break; | ||
| 609 | case OPTION_CALLBACK: | ||
| 610 | if (opts->flags & PARSE_OPT_NOARG) | ||
| 611 | break; | ||
| 612 | /* FALLTHROUGH */ | ||
| 613 | case OPTION_STRING: | ||
| 614 | if (opts->argh) { | ||
| 615 | if (opts->flags & PARSE_OPT_OPTARG) | ||
| 616 | if (opts->long_name) | ||
| 617 | pos += fprintf(stderr, "[=<%s>]", opts->argh); | ||
| 618 | else | ||
| 619 | pos += fprintf(stderr, "[<%s>]", opts->argh); | ||
| 620 | else | ||
| 621 | pos += fprintf(stderr, " <%s>", opts->argh); | ||
| 622 | } else { | ||
| 623 | if (opts->flags & PARSE_OPT_OPTARG) | ||
| 624 | if (opts->long_name) | ||
| 625 | pos += fprintf(stderr, "[=...]"); | ||
| 626 | else | ||
| 627 | pos += fprintf(stderr, "[...]"); | ||
| 628 | else | ||
| 629 | pos += fprintf(stderr, " ..."); | ||
| 630 | } | ||
| 631 | break; | ||
| 632 | default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */ | ||
| 633 | case OPTION_END: | ||
| 634 | case OPTION_GROUP: | ||
| 635 | case OPTION_BIT: | ||
| 636 | case OPTION_BOOLEAN: | ||
| 637 | case OPTION_INCR: | ||
| 638 | case OPTION_SET_UINT: | ||
| 639 | case OPTION_SET_PTR: | ||
| 640 | break; | ||
| 641 | } | ||
| 642 | |||
| 643 | if (pos <= USAGE_OPTS_WIDTH) | ||
| 644 | pad = USAGE_OPTS_WIDTH - pos; | ||
| 645 | else { | ||
| 646 | fputc('\n', stderr); | ||
| 647 | pad = USAGE_OPTS_WIDTH; | ||
| 648 | } | ||
| 649 | fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help); | ||
| 650 | } | ||
| 651 | |||
| 652 | static int option__cmp(const void *va, const void *vb) | ||
| 653 | { | ||
| 654 | const struct option *a = va, *b = vb; | ||
| 655 | int sa = tolower(a->short_name), sb = tolower(b->short_name), ret; | ||
| 656 | |||
| 657 | if (sa == 0) | ||
| 658 | sa = 'z' + 1; | ||
| 659 | if (sb == 0) | ||
| 660 | sb = 'z' + 1; | ||
| 661 | |||
| 662 | ret = sa - sb; | ||
| 663 | |||
| 664 | if (ret == 0) { | ||
| 665 | const char *la = a->long_name ?: "", | ||
| 666 | *lb = b->long_name ?: ""; | ||
| 667 | ret = strcmp(la, lb); | ||
| 668 | } | ||
| 669 | |||
| 670 | return ret; | ||
| 671 | } | ||
| 672 | |||
| 673 | static struct option *options__order(const struct option *opts) | ||
| 674 | { | ||
| 675 | int nr_opts = 0; | ||
| 676 | const struct option *o = opts; | ||
| 677 | struct option *ordered; | ||
| 678 | |||
| 679 | for (o = opts; o->type != OPTION_END; o++) | ||
| 680 | ++nr_opts; | ||
| 681 | |||
| 682 | ordered = memdup(opts, sizeof(*o) * (nr_opts + 1)); | ||
| 683 | if (ordered == NULL) | ||
| 684 | goto out; | ||
| 685 | |||
| 686 | qsort(ordered, nr_opts, sizeof(*o), option__cmp); | ||
| 687 | out: | ||
| 688 | return ordered; | ||
| 689 | } | ||
| 690 | |||
| 691 | static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx) | ||
| 692 | { | ||
| 693 | int i; | ||
| 694 | |||
| 695 | for (i = 1; i < ctx->argc; ++i) { | ||
| 696 | const char *arg = ctx->argv[i]; | ||
| 697 | |||
| 698 | if (arg[0] != '-') { | ||
| 699 | if (arg[1] == '\0') { | ||
| 700 | if (arg[0] == opt->short_name) | ||
| 701 | return true; | ||
| 702 | continue; | ||
| 703 | } | ||
| 704 | |||
| 705 | if (opt->long_name && strcmp(opt->long_name, arg) == 0) | ||
| 706 | return true; | ||
| 707 | |||
| 708 | if (opt->help && strcasestr(opt->help, arg) != NULL) | ||
| 709 | return true; | ||
| 710 | |||
| 711 | continue; | ||
| 712 | } | ||
| 713 | |||
| 714 | if (arg[1] == opt->short_name || | ||
| 715 | (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0)) | ||
| 716 | return true; | ||
| 717 | } | ||
| 718 | |||
| 719 | return false; | ||
| 720 | } | ||
| 721 | |||
| 722 | int usage_with_options_internal(const char * const *usagestr, | ||
| 723 | const struct option *opts, int full, | ||
| 724 | struct parse_opt_ctx_t *ctx) | ||
| 725 | { | ||
| 726 | struct option *ordered; | ||
| 727 | |||
| 728 | if (!usagestr) | ||
| 729 | return PARSE_OPT_HELP; | ||
| 730 | |||
| 731 | setup_pager(); | ||
| 732 | |||
| 733 | if (strbuf_avail(&error_buf)) { | ||
| 734 | fprintf(stderr, " Error: %s\n", error_buf.buf); | ||
| 735 | strbuf_release(&error_buf); | ||
| 736 | } | ||
| 737 | |||
| 738 | fprintf(stderr, "\n Usage: %s\n", *usagestr++); | ||
| 739 | while (*usagestr && **usagestr) | ||
| 740 | fprintf(stderr, " or: %s\n", *usagestr++); | ||
| 741 | while (*usagestr) { | ||
| 742 | fprintf(stderr, "%s%s\n", | ||
| 743 | **usagestr ? " " : "", | ||
| 744 | *usagestr); | ||
| 745 | usagestr++; | ||
| 746 | } | ||
| 747 | |||
| 748 | if (opts->type != OPTION_GROUP) | ||
| 749 | fputc('\n', stderr); | ||
| 750 | |||
| 751 | ordered = options__order(opts); | ||
| 752 | if (ordered) | ||
| 753 | opts = ordered; | ||
| 754 | |||
| 755 | for ( ; opts->type != OPTION_END; opts++) { | ||
| 756 | if (ctx && ctx->argc > 1 && !option__in_argv(opts, ctx)) | ||
| 757 | continue; | ||
| 758 | print_option_help(opts, full); | ||
| 759 | } | ||
| 760 | |||
| 761 | fputc('\n', stderr); | ||
| 762 | |||
| 763 | free(ordered); | ||
| 764 | |||
| 765 | return PARSE_OPT_HELP; | ||
| 766 | } | ||
| 767 | |||
| 768 | void usage_with_options(const char * const *usagestr, | ||
| 769 | const struct option *opts) | ||
| 770 | { | ||
| 771 | exit_browser(false); | ||
| 772 | usage_with_options_internal(usagestr, opts, 0, NULL); | ||
| 773 | exit(129); | ||
| 774 | } | ||
| 775 | |||
| 776 | void usage_with_options_msg(const char * const *usagestr, | ||
| 777 | const struct option *opts, const char *fmt, ...) | ||
| 778 | { | ||
| 779 | va_list ap; | ||
| 780 | |||
| 781 | exit_browser(false); | ||
| 782 | |||
| 783 | va_start(ap, fmt); | ||
| 784 | strbuf_addv(&error_buf, fmt, ap); | ||
| 785 | va_end(ap); | ||
| 786 | |||
| 787 | usage_with_options_internal(usagestr, opts, 0, NULL); | ||
| 788 | exit(129); | ||
| 789 | } | ||
| 790 | |||
| 791 | int parse_options_usage(const char * const *usagestr, | ||
| 792 | const struct option *opts, | ||
| 793 | const char *optstr, bool short_opt) | ||
| 794 | { | ||
| 795 | if (!usagestr) | ||
| 796 | goto opt; | ||
| 797 | |||
| 798 | fprintf(stderr, "\n Usage: %s\n", *usagestr++); | ||
| 799 | while (*usagestr && **usagestr) | ||
| 800 | fprintf(stderr, " or: %s\n", *usagestr++); | ||
| 801 | while (*usagestr) { | ||
| 802 | fprintf(stderr, "%s%s\n", | ||
| 803 | **usagestr ? " " : "", | ||
| 804 | *usagestr); | ||
| 805 | usagestr++; | ||
| 806 | } | ||
| 807 | fputc('\n', stderr); | ||
| 808 | |||
| 809 | opt: | ||
| 810 | for ( ; opts->type != OPTION_END; opts++) { | ||
| 811 | if (short_opt) { | ||
| 812 | if (opts->short_name == *optstr) { | ||
| 813 | print_option_help(opts, 0); | ||
| 814 | break; | ||
| 815 | } | ||
| 816 | continue; | ||
| 817 | } | ||
| 818 | |||
| 819 | if (opts->long_name == NULL) | ||
| 820 | continue; | ||
| 821 | |||
| 822 | if (!prefixcmp(opts->long_name, optstr)) | ||
| 823 | print_option_help(opts, 0); | ||
| 824 | if (!prefixcmp("no-", optstr) && | ||
| 825 | !prefixcmp(opts->long_name, optstr + 3)) | ||
| 826 | print_option_help(opts, 0); | ||
| 827 | } | ||
| 828 | |||
| 829 | return PARSE_OPT_HELP; | ||
| 830 | } | ||
| 831 | |||
| 832 | |||
| 833 | int parse_opt_verbosity_cb(const struct option *opt, | ||
| 834 | const char *arg __maybe_unused, | ||
| 835 | int unset) | ||
| 836 | { | ||
| 837 | int *target = opt->value; | ||
| 838 | |||
| 839 | if (unset) | ||
| 840 | /* --no-quiet, --no-verbose */ | ||
| 841 | *target = 0; | ||
| 842 | else if (opt->short_name == 'v') { | ||
| 843 | if (*target >= 0) | ||
| 844 | (*target)++; | ||
| 845 | else | ||
| 846 | *target = 1; | ||
| 847 | } else { | ||
| 848 | if (*target <= 0) | ||
| 849 | (*target)--; | ||
| 850 | else | ||
| 851 | *target = -1; | ||
| 852 | } | ||
| 853 | return 0; | ||
| 854 | } | ||
| 855 | |||
| 856 | void set_option_flag(struct option *opts, int shortopt, const char *longopt, | ||
| 857 | int flag) | ||
| 858 | { | ||
| 859 | for (; opts->type != OPTION_END; opts++) { | ||
| 860 | if ((shortopt && opts->short_name == shortopt) || | ||
| 861 | (opts->long_name && longopt && | ||
| 862 | !strcmp(opts->long_name, longopt))) { | ||
| 863 | opts->flags |= flag; | ||
| 864 | break; | ||
| 865 | } | ||
| 866 | } | ||
| 867 | } | ||
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h deleted file mode 100644 index a8e407bc251e..000000000000 --- a/tools/perf/util/parse-options.h +++ /dev/null | |||
| @@ -1,229 +0,0 @@ | |||
| 1 | #ifndef __PERF_PARSE_OPTIONS_H | ||
| 2 | #define __PERF_PARSE_OPTIONS_H | ||
| 3 | |||
| 4 | #include <linux/kernel.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | |||
| 7 | enum parse_opt_type { | ||
| 8 | /* special types */ | ||
| 9 | OPTION_END, | ||
| 10 | OPTION_ARGUMENT, | ||
| 11 | OPTION_GROUP, | ||
| 12 | /* options with no arguments */ | ||
| 13 | OPTION_BIT, | ||
| 14 | OPTION_BOOLEAN, | ||
| 15 | OPTION_INCR, | ||
| 16 | OPTION_SET_UINT, | ||
| 17 | OPTION_SET_PTR, | ||
| 18 | /* options with arguments (usually) */ | ||
| 19 | OPTION_STRING, | ||
| 20 | OPTION_INTEGER, | ||
| 21 | OPTION_LONG, | ||
| 22 | OPTION_CALLBACK, | ||
| 23 | OPTION_U64, | ||
| 24 | OPTION_UINTEGER, | ||
| 25 | }; | ||
| 26 | |||
| 27 | enum parse_opt_flags { | ||
| 28 | PARSE_OPT_KEEP_DASHDASH = 1, | ||
| 29 | PARSE_OPT_STOP_AT_NON_OPTION = 2, | ||
| 30 | PARSE_OPT_KEEP_ARGV0 = 4, | ||
| 31 | PARSE_OPT_KEEP_UNKNOWN = 8, | ||
| 32 | PARSE_OPT_NO_INTERNAL_HELP = 16, | ||
| 33 | }; | ||
| 34 | |||
| 35 | enum parse_opt_option_flags { | ||
| 36 | PARSE_OPT_OPTARG = 1, | ||
| 37 | PARSE_OPT_NOARG = 2, | ||
| 38 | PARSE_OPT_NONEG = 4, | ||
| 39 | PARSE_OPT_HIDDEN = 8, | ||
| 40 | PARSE_OPT_LASTARG_DEFAULT = 16, | ||
| 41 | PARSE_OPT_DISABLED = 32, | ||
| 42 | PARSE_OPT_EXCLUSIVE = 64, | ||
| 43 | PARSE_OPT_NOEMPTY = 128, | ||
| 44 | }; | ||
| 45 | |||
| 46 | struct option; | ||
| 47 | typedef int parse_opt_cb(const struct option *, const char *arg, int unset); | ||
| 48 | |||
| 49 | /* | ||
| 50 | * `type`:: | ||
| 51 | * holds the type of the option, you must have an OPTION_END last in your | ||
| 52 | * array. | ||
| 53 | * | ||
| 54 | * `short_name`:: | ||
| 55 | * the character to use as a short option name, '\0' if none. | ||
| 56 | * | ||
| 57 | * `long_name`:: | ||
| 58 | * the long option name, without the leading dashes, NULL if none. | ||
| 59 | * | ||
| 60 | * `value`:: | ||
| 61 | * stores pointers to the values to be filled. | ||
| 62 | * | ||
| 63 | * `argh`:: | ||
| 64 | * token to explain the kind of argument this option wants. Keep it | ||
| 65 | * homogenous across the repository. | ||
| 66 | * | ||
| 67 | * `help`:: | ||
| 68 | * the short help associated to what the option does. | ||
| 69 | * Must never be NULL (except for OPTION_END). | ||
| 70 | * OPTION_GROUP uses this pointer to store the group header. | ||
| 71 | * | ||
| 72 | * `flags`:: | ||
| 73 | * mask of parse_opt_option_flags. | ||
| 74 | * PARSE_OPT_OPTARG: says that the argument is optionnal (not for BOOLEANs) | ||
| 75 | * PARSE_OPT_NOARG: says that this option takes no argument, for CALLBACKs | ||
| 76 | * PARSE_OPT_NONEG: says that this option cannot be negated | ||
| 77 | * PARSE_OPT_HIDDEN this option is skipped in the default usage, showed in | ||
| 78 | * the long one. | ||
| 79 | * | ||
| 80 | * `callback`:: | ||
| 81 | * pointer to the callback to use for OPTION_CALLBACK. | ||
| 82 | * | ||
| 83 | * `defval`:: | ||
| 84 | * default value to fill (*->value) with for PARSE_OPT_OPTARG. | ||
| 85 | * OPTION_{BIT,SET_UINT,SET_PTR} store the {mask,integer,pointer} to put in | ||
| 86 | * the value when met. | ||
| 87 | * CALLBACKS can use it like they want. | ||
| 88 | * | ||
| 89 | * `set`:: | ||
| 90 | * whether an option was set by the user | ||
| 91 | */ | ||
| 92 | struct option { | ||
| 93 | enum parse_opt_type type; | ||
| 94 | int short_name; | ||
| 95 | const char *long_name; | ||
| 96 | void *value; | ||
| 97 | const char *argh; | ||
| 98 | const char *help; | ||
| 99 | |||
| 100 | int flags; | ||
| 101 | parse_opt_cb *callback; | ||
| 102 | intptr_t defval; | ||
| 103 | bool *set; | ||
| 104 | void *data; | ||
| 105 | }; | ||
| 106 | |||
| 107 | #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) | ||
| 108 | |||
| 109 | #define OPT_END() { .type = OPTION_END } | ||
| 110 | #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } | ||
| 111 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } | ||
| 112 | #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) } | ||
| 113 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) } | ||
| 114 | #define OPT_BOOLEAN_FLAG(s, l, v, h, f) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h), .flags = (f) } | ||
| 115 | #define OPT_BOOLEAN_SET(s, l, v, os, h) \ | ||
| 116 | { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), \ | ||
| 117 | .value = check_vtype(v, bool *), .help = (h), \ | ||
| 118 | .set = check_vtype(os, bool *)} | ||
| 119 | #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } | ||
| 120 | #define OPT_SET_UINT(s, l, v, h, i) { .type = OPTION_SET_UINT, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h), .defval = (i) } | ||
| 121 | #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } | ||
| 122 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } | ||
| 123 | #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } | ||
| 124 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } | ||
| 125 | #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } | ||
| 126 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } | ||
| 127 | #define OPT_STRING_OPTARG(s, l, v, a, h, d) \ | ||
| 128 | { .type = OPTION_STRING, .short_name = (s), .long_name = (l), \ | ||
| 129 | .value = check_vtype(v, const char **), (a), .help = (h), \ | ||
| 130 | .flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d) } | ||
| 131 | #define OPT_STRING_NOEMPTY(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h), .flags = PARSE_OPT_NOEMPTY} | ||
| 132 | #define OPT_DATE(s, l, v, h) \ | ||
| 133 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } | ||
| 134 | #define OPT_CALLBACK(s, l, v, a, h, f) \ | ||
| 135 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) } | ||
| 136 | #define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \ | ||
| 137 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG } | ||
| 138 | #define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \ | ||
| 139 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d, .flags = PARSE_OPT_LASTARG_DEFAULT } | ||
| 140 | #define OPT_CALLBACK_DEFAULT_NOOPT(s, l, v, a, h, f, d) \ | ||
| 141 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l),\ | ||
| 142 | .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d,\ | ||
| 143 | .flags = PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NOARG} | ||
| 144 | #define OPT_CALLBACK_OPTARG(s, l, v, d, a, h, f) \ | ||
| 145 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), \ | ||
| 146 | .value = (v), (a), .help = (h), .callback = (f), \ | ||
| 147 | .flags = PARSE_OPT_OPTARG, .data = (d) } | ||
| 148 | |||
| 149 | /* parse_options() will filter out the processed options and leave the | ||
| 150 | * non-option argments in argv[]. | ||
| 151 | * Returns the number of arguments left in argv[]. | ||
| 152 | */ | ||
| 153 | extern int parse_options(int argc, const char **argv, | ||
| 154 | const struct option *options, | ||
| 155 | const char * const usagestr[], int flags); | ||
| 156 | |||
| 157 | extern int parse_options_subcommand(int argc, const char **argv, | ||
| 158 | const struct option *options, | ||
| 159 | const char *const subcommands[], | ||
| 160 | const char *usagestr[], int flags); | ||
| 161 | |||
| 162 | extern NORETURN void usage_with_options(const char * const *usagestr, | ||
| 163 | const struct option *options); | ||
| 164 | extern NORETURN __attribute__((format(printf,3,4))) | ||
| 165 | void usage_with_options_msg(const char * const *usagestr, | ||
| 166 | const struct option *options, | ||
| 167 | const char *fmt, ...); | ||
| 168 | |||
| 169 | /*----- incremantal advanced APIs -----*/ | ||
| 170 | |||
| 171 | enum { | ||
| 172 | PARSE_OPT_HELP = -1, | ||
| 173 | PARSE_OPT_DONE, | ||
| 174 | PARSE_OPT_LIST_OPTS, | ||
| 175 | PARSE_OPT_LIST_SUBCMDS, | ||
| 176 | PARSE_OPT_UNKNOWN, | ||
| 177 | }; | ||
| 178 | |||
| 179 | /* | ||
| 180 | * It's okay for the caller to consume argv/argc in the usual way. | ||
| 181 | * Other fields of that structure are private to parse-options and should not | ||
| 182 | * be modified in any way. | ||
| 183 | */ | ||
| 184 | struct parse_opt_ctx_t { | ||
| 185 | const char **argv; | ||
| 186 | const char **out; | ||
| 187 | int argc, cpidx; | ||
| 188 | const char *opt; | ||
| 189 | const struct option *excl_opt; | ||
| 190 | int flags; | ||
| 191 | }; | ||
| 192 | |||
| 193 | extern int parse_options_usage(const char * const *usagestr, | ||
| 194 | const struct option *opts, | ||
| 195 | const char *optstr, | ||
| 196 | bool short_opt); | ||
| 197 | |||
| 198 | extern void parse_options_start(struct parse_opt_ctx_t *ctx, | ||
| 199 | int argc, const char **argv, int flags); | ||
| 200 | |||
| 201 | extern int parse_options_step(struct parse_opt_ctx_t *ctx, | ||
| 202 | const struct option *options, | ||
| 203 | const char * const usagestr[]); | ||
| 204 | |||
| 205 | extern int parse_options_end(struct parse_opt_ctx_t *ctx); | ||
| 206 | |||
| 207 | |||
| 208 | /*----- some often used options -----*/ | ||
| 209 | extern int parse_opt_abbrev_cb(const struct option *, const char *, int); | ||
| 210 | extern int parse_opt_approxidate_cb(const struct option *, const char *, int); | ||
| 211 | extern int parse_opt_verbosity_cb(const struct option *, const char *, int); | ||
| 212 | |||
| 213 | #define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose") | ||
| 214 | #define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet") | ||
| 215 | #define OPT__VERBOSITY(var) \ | ||
| 216 | { OPTION_CALLBACK, 'v', "verbose", (var), NULL, "be more verbose", \ | ||
| 217 | PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \ | ||
| 218 | { OPTION_CALLBACK, 'q', "quiet", (var), NULL, "be more quiet", \ | ||
| 219 | PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 } | ||
| 220 | #define OPT__DRY_RUN(var) OPT_BOOLEAN('n', "dry-run", (var), "dry run") | ||
| 221 | #define OPT__ABBREV(var) \ | ||
| 222 | { OPTION_CALLBACK, 0, "abbrev", (var), "n", \ | ||
| 223 | "use <n> digits to display SHA-1s", \ | ||
| 224 | PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 } | ||
| 225 | |||
| 226 | extern const char *parse_options_fix_filename(const char *prefix, const char *file); | ||
| 227 | |||
| 228 | void set_option_flag(struct option *opts, int sopt, const char *lopt, int flag); | ||
| 229 | #endif /* __PERF_PARSE_OPTIONS_H */ | ||
diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c index 4f2c1c255d81..646ecf736aad 100644 --- a/tools/perf/util/parse-regs-options.c +++ b/tools/perf/util/parse-regs-options.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "perf.h" | 1 | #include "perf.h" |
| 2 | #include "util/util.h" | 2 | #include "util/util.h" |
| 3 | #include "util/debug.h" | 3 | #include "util/debug.h" |
| 4 | #include "util/parse-options.h" | 4 | #include <subcmd/parse-options.h> |
| 5 | #include "util/parse-regs-options.h" | 5 | #include "util/parse-regs-options.h" |
| 6 | 6 | ||
| 7 | int | 7 | int |
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 5d13cb45b317..3654d964e49d 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c | |||
| @@ -22,24 +22,6 @@ static const char *get_perf_dir(void) | |||
| 22 | return "."; | 22 | return "."; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | /* | ||
| 26 | * If libc has strlcpy() then that version will override this | ||
| 27 | * implementation: | ||
| 28 | */ | ||
| 29 | size_t __weak strlcpy(char *dest, const char *src, size_t size) | ||
| 30 | { | ||
| 31 | size_t ret = strlen(src); | ||
| 32 | |||
| 33 | if (size) { | ||
| 34 | size_t len = (ret >= size) ? size - 1 : ret; | ||
| 35 | |||
| 36 | memcpy(dest, src, len); | ||
| 37 | dest[len] = '\0'; | ||
| 38 | } | ||
| 39 | |||
| 40 | return ret; | ||
| 41 | } | ||
| 42 | |||
| 43 | static char *get_pathname(void) | 25 | static char *get_pathname(void) |
| 44 | { | 26 | { |
| 45 | static char pathname_array[4][PATH_MAX]; | 27 | static char pathname_array[4][PATH_MAX]; |
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index e4b173dec4b9..b597bcc8fc78 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
| @@ -220,6 +220,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, | |||
| 220 | alias->scale = 1.0; | 220 | alias->scale = 1.0; |
| 221 | alias->unit[0] = '\0'; | 221 | alias->unit[0] = '\0'; |
| 222 | alias->per_pkg = false; | 222 | alias->per_pkg = false; |
| 223 | alias->snapshot = false; | ||
| 223 | 224 | ||
| 224 | ret = parse_events_terms(&alias->terms, val); | 225 | ret = parse_events_terms(&alias->terms, val); |
| 225 | if (ret) { | 226 | if (ret) { |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 03875f9154e7..93996ec4bbe3 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
| @@ -2326,8 +2326,11 @@ static int get_new_event_name(char *buf, size_t len, const char *base, | |||
| 2326 | goto out; | 2326 | goto out; |
| 2327 | 2327 | ||
| 2328 | if (!allow_suffix) { | 2328 | if (!allow_suffix) { |
| 2329 | pr_warning("Error: event \"%s\" already exists. " | 2329 | pr_warning("Error: event \"%s\" already exists.\n" |
| 2330 | "(Use -f to force duplicates.)\n", buf); | 2330 | " Hint: Remove existing event by 'perf probe -d'\n" |
| 2331 | " or force duplicates by 'perf probe -f'\n" | ||
| 2332 | " or set 'force=yes' in BPF source.\n", | ||
| 2333 | buf); | ||
| 2331 | ret = -EEXIST; | 2334 | ret = -EEXIST; |
| 2332 | goto out; | 2335 | goto out; |
| 2333 | } | 2336 | } |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index bd8f03de5e40..2be10fb27172 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
| @@ -654,6 +654,7 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod, | |||
| 654 | static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) | 654 | static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) |
| 655 | { | 655 | { |
| 656 | Dwarf_Attribute fb_attr; | 656 | Dwarf_Attribute fb_attr; |
| 657 | Dwarf_Frame *frame = NULL; | ||
| 657 | size_t nops; | 658 | size_t nops; |
| 658 | int ret; | 659 | int ret; |
| 659 | 660 | ||
| @@ -686,11 +687,11 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) | |||
| 686 | #if _ELFUTILS_PREREQ(0, 142) | 687 | #if _ELFUTILS_PREREQ(0, 142) |
| 687 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && | 688 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && |
| 688 | pf->cfi != NULL) { | 689 | pf->cfi != NULL) { |
| 689 | Dwarf_Frame *frame; | ||
| 690 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || | 690 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || |
| 691 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { | 691 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { |
| 692 | pr_warning("Failed to get call frame on 0x%jx\n", | 692 | pr_warning("Failed to get call frame on 0x%jx\n", |
| 693 | (uintmax_t)pf->addr); | 693 | (uintmax_t)pf->addr); |
| 694 | free(frame); | ||
| 694 | return -ENOENT; | 695 | return -ENOENT; |
| 695 | } | 696 | } |
| 696 | #endif | 697 | #endif |
| @@ -699,7 +700,8 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct probe_finder *pf) | |||
| 699 | /* Call finder's callback handler */ | 700 | /* Call finder's callback handler */ |
| 700 | ret = pf->callback(sc_die, pf); | 701 | ret = pf->callback(sc_die, pf); |
| 701 | 702 | ||
| 702 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ | 703 | /* Since *pf->fb_ops can be a part of frame. we should free it here. */ |
| 704 | free(frame); | ||
| 703 | pf->fb_ops = NULL; | 705 | pf->fb_ops = NULL; |
| 704 | 706 | ||
| 705 | return ret; | 707 | return ret; |
| @@ -1183,7 +1185,7 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf) | |||
| 1183 | container_of(pf, struct trace_event_finder, pf); | 1185 | container_of(pf, struct trace_event_finder, pf); |
| 1184 | struct perf_probe_point *pp = &pf->pev->point; | 1186 | struct perf_probe_point *pp = &pf->pev->point; |
| 1185 | struct probe_trace_event *tev; | 1187 | struct probe_trace_event *tev; |
| 1186 | struct perf_probe_arg *args; | 1188 | struct perf_probe_arg *args = NULL; |
| 1187 | int ret, i; | 1189 | int ret, i; |
| 1188 | 1190 | ||
| 1189 | /* Check number of tevs */ | 1191 | /* Check number of tevs */ |
| @@ -1198,19 +1200,23 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf) | |||
| 1198 | ret = convert_to_trace_point(&pf->sp_die, tf->mod, pf->addr, | 1200 | ret = convert_to_trace_point(&pf->sp_die, tf->mod, pf->addr, |
| 1199 | pp->retprobe, pp->function, &tev->point); | 1201 | pp->retprobe, pp->function, &tev->point); |
| 1200 | if (ret < 0) | 1202 | if (ret < 0) |
| 1201 | return ret; | 1203 | goto end; |
| 1202 | 1204 | ||
| 1203 | tev->point.realname = strdup(dwarf_diename(sc_die)); | 1205 | tev->point.realname = strdup(dwarf_diename(sc_die)); |
| 1204 | if (!tev->point.realname) | 1206 | if (!tev->point.realname) { |
| 1205 | return -ENOMEM; | 1207 | ret = -ENOMEM; |
| 1208 | goto end; | ||
| 1209 | } | ||
| 1206 | 1210 | ||
| 1207 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, | 1211 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, |
| 1208 | tev->point.offset); | 1212 | tev->point.offset); |
| 1209 | 1213 | ||
| 1210 | /* Expand special probe argument if exist */ | 1214 | /* Expand special probe argument if exist */ |
| 1211 | args = zalloc(sizeof(struct perf_probe_arg) * MAX_PROBE_ARGS); | 1215 | args = zalloc(sizeof(struct perf_probe_arg) * MAX_PROBE_ARGS); |
| 1212 | if (args == NULL) | 1216 | if (args == NULL) { |
| 1213 | return -ENOMEM; | 1217 | ret = -ENOMEM; |
| 1218 | goto end; | ||
| 1219 | } | ||
| 1214 | 1220 | ||
| 1215 | ret = expand_probe_args(sc_die, pf, args); | 1221 | ret = expand_probe_args(sc_die, pf, args); |
| 1216 | if (ret < 0) | 1222 | if (ret < 0) |
| @@ -1234,6 +1240,10 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf) | |||
| 1234 | } | 1240 | } |
| 1235 | 1241 | ||
| 1236 | end: | 1242 | end: |
| 1243 | if (ret) { | ||
| 1244 | clear_probe_trace_event(tev); | ||
| 1245 | tf->ntevs--; | ||
| 1246 | } | ||
| 1237 | free(args); | 1247 | free(args); |
| 1238 | return ret; | 1248 | return ret; |
| 1239 | } | 1249 | } |
| @@ -1246,7 +1256,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, | |||
| 1246 | struct trace_event_finder tf = { | 1256 | struct trace_event_finder tf = { |
| 1247 | .pf = {.pev = pev, .callback = add_probe_trace_event}, | 1257 | .pf = {.pev = pev, .callback = add_probe_trace_event}, |
| 1248 | .max_tevs = probe_conf.max_probes, .mod = dbg->mod}; | 1258 | .max_tevs = probe_conf.max_probes, .mod = dbg->mod}; |
| 1249 | int ret; | 1259 | int ret, i; |
| 1250 | 1260 | ||
| 1251 | /* Allocate result tevs array */ | 1261 | /* Allocate result tevs array */ |
| 1252 | *tevs = zalloc(sizeof(struct probe_trace_event) * tf.max_tevs); | 1262 | *tevs = zalloc(sizeof(struct probe_trace_event) * tf.max_tevs); |
| @@ -1258,6 +1268,8 @@ int debuginfo__find_trace_events(struct debuginfo *dbg, | |||
| 1258 | 1268 | ||
| 1259 | ret = debuginfo__find_probes(dbg, &tf.pf); | 1269 | ret = debuginfo__find_probes(dbg, &tf.pf); |
| 1260 | if (ret < 0) { | 1270 | if (ret < 0) { |
| 1271 | for (i = 0; i < tf.ntevs; i++) | ||
| 1272 | clear_probe_trace_event(&tf.tevs[i]); | ||
| 1261 | zfree(tevs); | 1273 | zfree(tevs); |
| 1262 | return ret; | 1274 | return ret; |
| 1263 | } | 1275 | } |
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 51be28b1bca2..8162ba0e2e57 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
| @@ -10,6 +10,8 @@ util/ctype.c | |||
| 10 | util/evlist.c | 10 | util/evlist.c |
| 11 | util/evsel.c | 11 | util/evsel.c |
| 12 | util/cpumap.c | 12 | util/cpumap.c |
| 13 | ../lib/bitmap.c | ||
| 14 | ../lib/find_bit.c | ||
| 13 | ../lib/hweight.c | 15 | ../lib/hweight.c |
| 14 | util/thread_map.c | 16 | util/thread_map.c |
| 15 | util/util.c | 17 | util/util.c |
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c deleted file mode 100644 index 34622b53e733..000000000000 --- a/tools/perf/util/run-command.c +++ /dev/null | |||
| @@ -1,219 +0,0 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include "run-command.h" | ||
| 3 | #include "exec_cmd.h" | ||
| 4 | #include "debug.h" | ||
| 5 | |||
| 6 | static inline void close_pair(int fd[2]) | ||
| 7 | { | ||
| 8 | close(fd[0]); | ||
| 9 | close(fd[1]); | ||
| 10 | } | ||
| 11 | |||
| 12 | static inline void dup_devnull(int to) | ||
| 13 | { | ||
| 14 | int fd = open("/dev/null", O_RDWR); | ||
| 15 | dup2(fd, to); | ||
| 16 | close(fd); | ||
| 17 | } | ||
| 18 | |||
| 19 | int start_command(struct child_process *cmd) | ||
| 20 | { | ||
| 21 | int need_in, need_out, need_err; | ||
| 22 | int fdin[2], fdout[2], fderr[2]; | ||
| 23 | char sbuf[STRERR_BUFSIZE]; | ||
| 24 | |||
| 25 | /* | ||
| 26 | * In case of errors we must keep the promise to close FDs | ||
| 27 | * that have been passed in via ->in and ->out. | ||
| 28 | */ | ||
| 29 | |||
| 30 | need_in = !cmd->no_stdin && cmd->in < 0; | ||
| 31 | if (need_in) { | ||
| 32 | if (pipe(fdin) < 0) { | ||
| 33 | if (cmd->out > 0) | ||
| 34 | close(cmd->out); | ||
| 35 | return -ERR_RUN_COMMAND_PIPE; | ||
| 36 | } | ||
| 37 | cmd->in = fdin[1]; | ||
| 38 | } | ||
| 39 | |||
| 40 | need_out = !cmd->no_stdout | ||
| 41 | && !cmd->stdout_to_stderr | ||
| 42 | && cmd->out < 0; | ||
| 43 | if (need_out) { | ||
| 44 | if (pipe(fdout) < 0) { | ||
| 45 | if (need_in) | ||
| 46 | close_pair(fdin); | ||
| 47 | else if (cmd->in) | ||
| 48 | close(cmd->in); | ||
| 49 | return -ERR_RUN_COMMAND_PIPE; | ||
| 50 | } | ||
| 51 | cmd->out = fdout[0]; | ||
| 52 | } | ||
| 53 | |||
| 54 | need_err = !cmd->no_stderr && cmd->err < 0; | ||
| 55 | if (need_err) { | ||
| 56 | if (pipe(fderr) < 0) { | ||
| 57 | if (need_in) | ||
| 58 | close_pair(fdin); | ||
| 59 | else if (cmd->in) | ||
| 60 | close(cmd->in); | ||
| 61 | if (need_out) | ||
| 62 | close_pair(fdout); | ||
| 63 | else if (cmd->out) | ||
| 64 | close(cmd->out); | ||
| 65 | return -ERR_RUN_COMMAND_PIPE; | ||
| 66 | } | ||
| 67 | cmd->err = fderr[0]; | ||
| 68 | } | ||
| 69 | |||
| 70 | fflush(NULL); | ||
| 71 | cmd->pid = fork(); | ||
| 72 | if (!cmd->pid) { | ||
| 73 | if (cmd->no_stdin) | ||
| 74 | dup_devnull(0); | ||
| 75 | else if (need_in) { | ||
| 76 | dup2(fdin[0], 0); | ||
| 77 | close_pair(fdin); | ||
| 78 | } else if (cmd->in) { | ||
| 79 | dup2(cmd->in, 0); | ||
| 80 | close(cmd->in); | ||
| 81 | } | ||
| 82 | |||
| 83 | if (cmd->no_stderr) | ||
| 84 | dup_devnull(2); | ||
| 85 | else if (need_err) { | ||
| 86 | dup2(fderr[1], 2); | ||
| 87 | close_pair(fderr); | ||
| 88 | } | ||
| 89 | |||
| 90 | if (cmd->no_stdout) | ||
| 91 | dup_devnull(1); | ||
| 92 | else if (cmd->stdout_to_stderr) | ||
| 93 | dup2(2, 1); | ||
| 94 | else if (need_out) { | ||
| 95 | dup2(fdout[1], 1); | ||
| 96 | close_pair(fdout); | ||
| 97 | } else if (cmd->out > 1) { | ||
| 98 | dup2(cmd->out, 1); | ||
| 99 | close(cmd->out); | ||
| 100 | } | ||
| 101 | |||
| 102 | if (cmd->dir && chdir(cmd->dir)) | ||
| 103 | die("exec %s: cd to %s failed (%s)", cmd->argv[0], | ||
| 104 | cmd->dir, strerror_r(errno, sbuf, sizeof(sbuf))); | ||
| 105 | if (cmd->env) { | ||
| 106 | for (; *cmd->env; cmd->env++) { | ||
| 107 | if (strchr(*cmd->env, '=')) | ||
| 108 | putenv((char*)*cmd->env); | ||
| 109 | else | ||
| 110 | unsetenv(*cmd->env); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | if (cmd->preexec_cb) | ||
| 114 | cmd->preexec_cb(); | ||
| 115 | if (cmd->perf_cmd) { | ||
| 116 | execv_perf_cmd(cmd->argv); | ||
| 117 | } else { | ||
| 118 | execvp(cmd->argv[0], (char *const*) cmd->argv); | ||
| 119 | } | ||
| 120 | exit(127); | ||
| 121 | } | ||
| 122 | |||
| 123 | if (cmd->pid < 0) { | ||
| 124 | int err = errno; | ||
| 125 | if (need_in) | ||
| 126 | close_pair(fdin); | ||
| 127 | else if (cmd->in) | ||
| 128 | close(cmd->in); | ||
| 129 | if (need_out) | ||
| 130 | close_pair(fdout); | ||
| 131 | else if (cmd->out) | ||
| 132 | close(cmd->out); | ||
| 133 | if (need_err) | ||
| 134 | close_pair(fderr); | ||
| 135 | return err == ENOENT ? | ||
| 136 | -ERR_RUN_COMMAND_EXEC : | ||
| 137 | -ERR_RUN_COMMAND_FORK; | ||
| 138 | } | ||
| 139 | |||
| 140 | if (need_in) | ||
| 141 | close(fdin[0]); | ||
| 142 | else if (cmd->in) | ||
| 143 | close(cmd->in); | ||
| 144 | |||
| 145 | if (need_out) | ||
| 146 | close(fdout[1]); | ||
| 147 | else if (cmd->out) | ||
| 148 | close(cmd->out); | ||
| 149 | |||
| 150 | if (need_err) | ||
| 151 | close(fderr[1]); | ||
| 152 | |||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | |||
| 156 | static int wait_or_whine(pid_t pid) | ||
| 157 | { | ||
| 158 | char sbuf[STRERR_BUFSIZE]; | ||
| 159 | |||
| 160 | for (;;) { | ||
| 161 | int status, code; | ||
| 162 | pid_t waiting = waitpid(pid, &status, 0); | ||
| 163 | |||
| 164 | if (waiting < 0) { | ||
| 165 | if (errno == EINTR) | ||
| 166 | continue; | ||
| 167 | error("waitpid failed (%s)", | ||
| 168 | strerror_r(errno, sbuf, sizeof(sbuf))); | ||
| 169 | return -ERR_RUN_COMMAND_WAITPID; | ||
| 170 | } | ||
| 171 | if (waiting != pid) | ||
| 172 | return -ERR_RUN_COMMAND_WAITPID_WRONG_PID; | ||
| 173 | if (WIFSIGNALED(status)) | ||
| 174 | return -ERR_RUN_COMMAND_WAITPID_SIGNAL; | ||
| 175 | |||
| 176 | if (!WIFEXITED(status)) | ||
| 177 | return -ERR_RUN_COMMAND_WAITPID_NOEXIT; | ||
| 178 | code = WEXITSTATUS(status); | ||
| 179 | switch (code) { | ||
| 180 | case 127: | ||
| 181 | return -ERR_RUN_COMMAND_EXEC; | ||
| 182 | case 0: | ||
| 183 | return 0; | ||
| 184 | default: | ||
| 185 | return -code; | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | int finish_command(struct child_process *cmd) | ||
| 191 | { | ||
| 192 | return wait_or_whine(cmd->pid); | ||
| 193 | } | ||
| 194 | |||
| 195 | int run_command(struct child_process *cmd) | ||
| 196 | { | ||
| 197 | int code = start_command(cmd); | ||
| 198 | if (code) | ||
| 199 | return code; | ||
| 200 | return finish_command(cmd); | ||
| 201 | } | ||
| 202 | |||
| 203 | static void prepare_run_command_v_opt(struct child_process *cmd, | ||
| 204 | const char **argv, | ||
| 205 | int opt) | ||
| 206 | { | ||
| 207 | memset(cmd, 0, sizeof(*cmd)); | ||
| 208 | cmd->argv = argv; | ||
| 209 | cmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0; | ||
| 210 | cmd->perf_cmd = opt & RUN_PERF_CMD ? 1 : 0; | ||
| 211 | cmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0; | ||
| 212 | } | ||
| 213 | |||
| 214 | int run_command_v_opt(const char **argv, int opt) | ||
| 215 | { | ||
| 216 | struct child_process cmd; | ||
| 217 | prepare_run_command_v_opt(&cmd, argv, opt); | ||
| 218 | return run_command(&cmd); | ||
| 219 | } | ||
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h deleted file mode 100644 index 1ef264d5069c..000000000000 --- a/tools/perf/util/run-command.h +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | #ifndef __PERF_RUN_COMMAND_H | ||
| 2 | #define __PERF_RUN_COMMAND_H | ||
| 3 | |||
| 4 | enum { | ||
| 5 | ERR_RUN_COMMAND_FORK = 10000, | ||
| 6 | ERR_RUN_COMMAND_EXEC, | ||
| 7 | ERR_RUN_COMMAND_PIPE, | ||
| 8 | ERR_RUN_COMMAND_WAITPID, | ||
| 9 | ERR_RUN_COMMAND_WAITPID_WRONG_PID, | ||
| 10 | ERR_RUN_COMMAND_WAITPID_SIGNAL, | ||
| 11 | ERR_RUN_COMMAND_WAITPID_NOEXIT, | ||
| 12 | }; | ||
| 13 | #define IS_RUN_COMMAND_ERR(x) (-(x) >= ERR_RUN_COMMAND_FORK) | ||
| 14 | |||
| 15 | struct child_process { | ||
| 16 | const char **argv; | ||
| 17 | pid_t pid; | ||
| 18 | /* | ||
| 19 | * Using .in, .out, .err: | ||
| 20 | * - Specify 0 for no redirections (child inherits stdin, stdout, | ||
| 21 | * stderr from parent). | ||
| 22 | * - Specify -1 to have a pipe allocated as follows: | ||
| 23 | * .in: returns the writable pipe end; parent writes to it, | ||
| 24 | * the readable pipe end becomes child's stdin | ||
| 25 | * .out, .err: returns the readable pipe end; parent reads from | ||
| 26 | * it, the writable pipe end becomes child's stdout/stderr | ||
| 27 | * The caller of start_command() must close the returned FDs | ||
| 28 | * after it has completed reading from/writing to it! | ||
| 29 | * - Specify > 0 to set a channel to a particular FD as follows: | ||
| 30 | * .in: a readable FD, becomes child's stdin | ||
| 31 | * .out: a writable FD, becomes child's stdout/stderr | ||
| 32 | * .err > 0 not supported | ||
| 33 | * The specified FD is closed by start_command(), even in case | ||
| 34 | * of errors! | ||
| 35 | */ | ||
| 36 | int in; | ||
| 37 | int out; | ||
| 38 | int err; | ||
| 39 | const char *dir; | ||
| 40 | const char *const *env; | ||
| 41 | unsigned no_stdin:1; | ||
| 42 | unsigned no_stdout:1; | ||
| 43 | unsigned no_stderr:1; | ||
| 44 | unsigned perf_cmd:1; /* if this is to be perf sub-command */ | ||
| 45 | unsigned stdout_to_stderr:1; | ||
| 46 | void (*preexec_cb)(void); | ||
| 47 | }; | ||
| 48 | |||
| 49 | int start_command(struct child_process *); | ||
| 50 | int finish_command(struct child_process *); | ||
| 51 | int run_command(struct child_process *); | ||
| 52 | |||
| 53 | #define RUN_COMMAND_NO_STDIN 1 | ||
| 54 | #define RUN_PERF_CMD 2 /*If this is to be perf sub-command */ | ||
| 55 | #define RUN_COMMAND_STDOUT_TO_STDERR 4 | ||
| 56 | int run_command_v_opt(const char **argv, int opt); | ||
| 57 | |||
| 58 | #endif /* __PERF_RUN_COMMAND_H */ | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index a8e825fca42a..d72fafc1c800 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
| @@ -41,6 +41,9 @@ | |||
| 41 | #include "../thread-stack.h" | 41 | #include "../thread-stack.h" |
| 42 | #include "../trace-event.h" | 42 | #include "../trace-event.h" |
| 43 | #include "../machine.h" | 43 | #include "../machine.h" |
| 44 | #include "thread_map.h" | ||
| 45 | #include "cpumap.h" | ||
| 46 | #include "stat.h" | ||
| 44 | 47 | ||
| 45 | PyMODINIT_FUNC initperf_trace_context(void); | 48 | PyMODINIT_FUNC initperf_trace_context(void); |
| 46 | 49 | ||
| @@ -859,6 +862,104 @@ static void python_process_event(union perf_event *event, | |||
| 859 | } | 862 | } |
| 860 | } | 863 | } |
| 861 | 864 | ||
| 865 | static void get_handler_name(char *str, size_t size, | ||
| 866 | struct perf_evsel *evsel) | ||
| 867 | { | ||
| 868 | char *p = str; | ||
| 869 | |||
| 870 | scnprintf(str, size, "stat__%s", perf_evsel__name(evsel)); | ||
| 871 | |||
| 872 | while ((p = strchr(p, ':'))) { | ||
| 873 | *p = '_'; | ||
| 874 | p++; | ||
| 875 | } | ||
| 876 | } | ||
| 877 | |||
| 878 | static void | ||
| 879 | process_stat(struct perf_evsel *counter, int cpu, int thread, u64 tstamp, | ||
| 880 | struct perf_counts_values *count) | ||
| 881 | { | ||
| 882 | PyObject *handler, *t; | ||
| 883 | static char handler_name[256]; | ||
| 884 | int n = 0; | ||
| 885 | |||
| 886 | t = PyTuple_New(MAX_FIELDS); | ||
| 887 | if (!t) | ||
| 888 | Py_FatalError("couldn't create Python tuple"); | ||
| 889 | |||
| 890 | get_handler_name(handler_name, sizeof(handler_name), | ||
| 891 | counter); | ||
| 892 | |||
| 893 | handler = get_handler(handler_name); | ||
| 894 | if (!handler) { | ||
| 895 | pr_debug("can't find python handler %s\n", handler_name); | ||
| 896 | return; | ||
| 897 | } | ||
| 898 | |||
| 899 | PyTuple_SetItem(t, n++, PyInt_FromLong(cpu)); | ||
| 900 | PyTuple_SetItem(t, n++, PyInt_FromLong(thread)); | ||
| 901 | |||
| 902 | tuple_set_u64(t, n++, tstamp); | ||
| 903 | tuple_set_u64(t, n++, count->val); | ||
| 904 | tuple_set_u64(t, n++, count->ena); | ||
| 905 | tuple_set_u64(t, n++, count->run); | ||
| 906 | |||
| 907 | if (_PyTuple_Resize(&t, n) == -1) | ||
| 908 | Py_FatalError("error resizing Python tuple"); | ||
| 909 | |||
| 910 | call_object(handler, t, handler_name); | ||
| 911 | |||
| 912 | Py_DECREF(t); | ||
| 913 | } | ||
| 914 | |||
| 915 | static void python_process_stat(struct perf_stat_config *config, | ||
| 916 | struct perf_evsel *counter, u64 tstamp) | ||
| 917 | { | ||
| 918 | struct thread_map *threads = counter->threads; | ||
| 919 | struct cpu_map *cpus = counter->cpus; | ||
| 920 | int cpu, thread; | ||
| 921 | |||
| 922 | if (config->aggr_mode == AGGR_GLOBAL) { | ||
| 923 | process_stat(counter, -1, -1, tstamp, | ||
| 924 | &counter->counts->aggr); | ||
| 925 | return; | ||
| 926 | } | ||
| 927 | |||
| 928 | for (thread = 0; thread < threads->nr; thread++) { | ||
| 929 | for (cpu = 0; cpu < cpus->nr; cpu++) { | ||
| 930 | process_stat(counter, cpus->map[cpu], | ||
| 931 | thread_map__pid(threads, thread), tstamp, | ||
| 932 | perf_counts(counter->counts, cpu, thread)); | ||
| 933 | } | ||
| 934 | } | ||
| 935 | } | ||
| 936 | |||
| 937 | static void python_process_stat_interval(u64 tstamp) | ||
| 938 | { | ||
| 939 | PyObject *handler, *t; | ||
| 940 | static const char handler_name[] = "stat__interval"; | ||
| 941 | int n = 0; | ||
| 942 | |||
| 943 | t = PyTuple_New(MAX_FIELDS); | ||
| 944 | if (!t) | ||
| 945 | Py_FatalError("couldn't create Python tuple"); | ||
| 946 | |||
| 947 | handler = get_handler(handler_name); | ||
| 948 | if (!handler) { | ||
| 949 | pr_debug("can't find python handler %s\n", handler_name); | ||
| 950 | return; | ||
| 951 | } | ||
| 952 | |||
| 953 | tuple_set_u64(t, n++, tstamp); | ||
| 954 | |||
| 955 | if (_PyTuple_Resize(&t, n) == -1) | ||
| 956 | Py_FatalError("error resizing Python tuple"); | ||
| 957 | |||
| 958 | call_object(handler, t, handler_name); | ||
| 959 | |||
| 960 | Py_DECREF(t); | ||
| 961 | } | ||
| 962 | |||
| 862 | static int run_start_sub(void) | 963 | static int run_start_sub(void) |
| 863 | { | 964 | { |
| 864 | main_module = PyImport_AddModule("__main__"); | 965 | main_module = PyImport_AddModule("__main__"); |
| @@ -1201,10 +1302,12 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
| 1201 | } | 1302 | } |
| 1202 | 1303 | ||
| 1203 | struct scripting_ops python_scripting_ops = { | 1304 | struct scripting_ops python_scripting_ops = { |
| 1204 | .name = "Python", | 1305 | .name = "Python", |
| 1205 | .start_script = python_start_script, | 1306 | .start_script = python_start_script, |
| 1206 | .flush_script = python_flush_script, | 1307 | .flush_script = python_flush_script, |
| 1207 | .stop_script = python_stop_script, | 1308 | .stop_script = python_stop_script, |
| 1208 | .process_event = python_process_event, | 1309 | .process_event = python_process_event, |
| 1209 | .generate_script = python_generate_script, | 1310 | .process_stat = python_process_stat, |
| 1311 | .process_stat_interval = python_process_stat_interval, | ||
| 1312 | .generate_script = python_generate_script, | ||
| 1210 | }; | 1313 | }; |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index c35ffdd360fe..d5636ba94b20 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "asm/bug.h" | 17 | #include "asm/bug.h" |
| 18 | #include "auxtrace.h" | 18 | #include "auxtrace.h" |
| 19 | #include "thread-stack.h" | 19 | #include "thread-stack.h" |
| 20 | #include "stat.h" | ||
| 20 | 21 | ||
| 21 | static int perf_session__deliver_event(struct perf_session *session, | 22 | static int perf_session__deliver_event(struct perf_session *session, |
| 22 | union perf_event *event, | 23 | union perf_event *event, |
| @@ -36,6 +37,9 @@ static int perf_session__open(struct perf_session *session) | |||
| 36 | if (perf_data_file__is_pipe(file)) | 37 | if (perf_data_file__is_pipe(file)) |
| 37 | return 0; | 38 | return 0; |
| 38 | 39 | ||
| 40 | if (perf_header__has_feat(&session->header, HEADER_STAT)) | ||
| 41 | return 0; | ||
| 42 | |||
| 39 | if (!perf_evlist__valid_sample_type(session->evlist)) { | 43 | if (!perf_evlist__valid_sample_type(session->evlist)) { |
| 40 | pr_err("non matching sample_type\n"); | 44 | pr_err("non matching sample_type\n"); |
| 41 | return -1; | 45 | return -1; |
| @@ -205,6 +209,18 @@ static int process_event_synth_attr_stub(struct perf_tool *tool __maybe_unused, | |||
| 205 | return 0; | 209 | return 0; |
| 206 | } | 210 | } |
| 207 | 211 | ||
| 212 | static int process_event_synth_event_update_stub(struct perf_tool *tool __maybe_unused, | ||
| 213 | union perf_event *event __maybe_unused, | ||
| 214 | struct perf_evlist **pevlist | ||
| 215 | __maybe_unused) | ||
| 216 | { | ||
| 217 | if (dump_trace) | ||
| 218 | perf_event__fprintf_event_update(event, stdout); | ||
| 219 | |||
| 220 | dump_printf(": unhandled!\n"); | ||
| 221 | return 0; | ||
| 222 | } | ||
| 223 | |||
| 208 | static int process_event_sample_stub(struct perf_tool *tool __maybe_unused, | 224 | static int process_event_sample_stub(struct perf_tool *tool __maybe_unused, |
| 209 | union perf_event *event __maybe_unused, | 225 | union perf_event *event __maybe_unused, |
| 210 | struct perf_sample *sample __maybe_unused, | 226 | struct perf_sample *sample __maybe_unused, |
| @@ -296,6 +312,67 @@ int process_event_auxtrace_error_stub(struct perf_tool *tool __maybe_unused, | |||
| 296 | return 0; | 312 | return 0; |
| 297 | } | 313 | } |
| 298 | 314 | ||
| 315 | |||
| 316 | static | ||
| 317 | int process_event_thread_map_stub(struct perf_tool *tool __maybe_unused, | ||
| 318 | union perf_event *event __maybe_unused, | ||
| 319 | struct perf_session *session __maybe_unused) | ||
| 320 | { | ||
| 321 | if (dump_trace) | ||
| 322 | perf_event__fprintf_thread_map(event, stdout); | ||
| 323 | |||
| 324 | dump_printf(": unhandled!\n"); | ||
| 325 | return 0; | ||
| 326 | } | ||
| 327 | |||
| 328 | static | ||
| 329 | int process_event_cpu_map_stub(struct perf_tool *tool __maybe_unused, | ||
| 330 | union perf_event *event __maybe_unused, | ||
| 331 | struct perf_session *session __maybe_unused) | ||
| 332 | { | ||
| 333 | if (dump_trace) | ||
| 334 | perf_event__fprintf_cpu_map(event, stdout); | ||
| 335 | |||
| 336 | dump_printf(": unhandled!\n"); | ||
| 337 | return 0; | ||
| 338 | } | ||
| 339 | |||
| 340 | static | ||
| 341 | int process_event_stat_config_stub(struct perf_tool *tool __maybe_unused, | ||
| 342 | union perf_event *event __maybe_unused, | ||
| 343 | struct perf_session *session __maybe_unused) | ||
| 344 | { | ||
| 345 | if (dump_trace) | ||
| 346 | perf_event__fprintf_stat_config(event, stdout); | ||
| 347 | |||
| 348 | dump_printf(": unhandled!\n"); | ||
| 349 | return 0; | ||
| 350 | } | ||
| 351 | |||
| 352 | static int process_stat_stub(struct perf_tool *tool __maybe_unused, | ||
| 353 | union perf_event *event __maybe_unused, | ||
| 354 | struct perf_session *perf_session | ||
| 355 | __maybe_unused) | ||
| 356 | { | ||
| 357 | if (dump_trace) | ||
| 358 | perf_event__fprintf_stat(event, stdout); | ||
| 359 | |||
| 360 | dump_printf(": unhandled!\n"); | ||
| 361 | return 0; | ||
| 362 | } | ||
| 363 | |||
| 364 | static int process_stat_round_stub(struct perf_tool *tool __maybe_unused, | ||
| 365 | union perf_event *event __maybe_unused, | ||
| 366 | struct perf_session *perf_session | ||
| 367 | __maybe_unused) | ||
| 368 | { | ||
| 369 | if (dump_trace) | ||
| 370 | perf_event__fprintf_stat_round(event, stdout); | ||
| 371 | |||
| 372 | dump_printf(": unhandled!\n"); | ||
| 373 | return 0; | ||
| 374 | } | ||
| 375 | |||
| 299 | void perf_tool__fill_defaults(struct perf_tool *tool) | 376 | void perf_tool__fill_defaults(struct perf_tool *tool) |
| 300 | { | 377 | { |
| 301 | if (tool->sample == NULL) | 378 | if (tool->sample == NULL) |
| @@ -328,6 +405,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool) | |||
| 328 | tool->unthrottle = process_event_stub; | 405 | tool->unthrottle = process_event_stub; |
| 329 | if (tool->attr == NULL) | 406 | if (tool->attr == NULL) |
| 330 | tool->attr = process_event_synth_attr_stub; | 407 | tool->attr = process_event_synth_attr_stub; |
| 408 | if (tool->event_update == NULL) | ||
| 409 | tool->event_update = process_event_synth_event_update_stub; | ||
| 331 | if (tool->tracing_data == NULL) | 410 | if (tool->tracing_data == NULL) |
| 332 | tool->tracing_data = process_event_synth_tracing_data_stub; | 411 | tool->tracing_data = process_event_synth_tracing_data_stub; |
| 333 | if (tool->build_id == NULL) | 412 | if (tool->build_id == NULL) |
| @@ -346,6 +425,16 @@ void perf_tool__fill_defaults(struct perf_tool *tool) | |||
| 346 | tool->auxtrace = process_event_auxtrace_stub; | 425 | tool->auxtrace = process_event_auxtrace_stub; |
| 347 | if (tool->auxtrace_error == NULL) | 426 | if (tool->auxtrace_error == NULL) |
| 348 | tool->auxtrace_error = process_event_auxtrace_error_stub; | 427 | tool->auxtrace_error = process_event_auxtrace_error_stub; |
| 428 | if (tool->thread_map == NULL) | ||
| 429 | tool->thread_map = process_event_thread_map_stub; | ||
| 430 | if (tool->cpu_map == NULL) | ||
| 431 | tool->cpu_map = process_event_cpu_map_stub; | ||
| 432 | if (tool->stat_config == NULL) | ||
| 433 | tool->stat_config = process_event_stat_config_stub; | ||
| 434 | if (tool->stat == NULL) | ||
| 435 | tool->stat = process_stat_stub; | ||
| 436 | if (tool->stat_round == NULL) | ||
| 437 | tool->stat_round = process_stat_round_stub; | ||
| 349 | } | 438 | } |
| 350 | 439 | ||
| 351 | static void swap_sample_id_all(union perf_event *event, void *data) | 440 | static void swap_sample_id_all(union perf_event *event, void *data) |
| @@ -569,6 +658,13 @@ static void perf_event__hdr_attr_swap(union perf_event *event, | |||
| 569 | mem_bswap_64(event->attr.id, size); | 658 | mem_bswap_64(event->attr.id, size); |
| 570 | } | 659 | } |
| 571 | 660 | ||
| 661 | static void perf_event__event_update_swap(union perf_event *event, | ||
| 662 | bool sample_id_all __maybe_unused) | ||
| 663 | { | ||
| 664 | event->event_update.type = bswap_64(event->event_update.type); | ||
| 665 | event->event_update.id = bswap_64(event->event_update.id); | ||
| 666 | } | ||
| 667 | |||
| 572 | static void perf_event__event_type_swap(union perf_event *event, | 668 | static void perf_event__event_type_swap(union perf_event *event, |
| 573 | bool sample_id_all __maybe_unused) | 669 | bool sample_id_all __maybe_unused) |
| 574 | { | 670 | { |
| @@ -616,6 +712,81 @@ static void perf_event__auxtrace_error_swap(union perf_event *event, | |||
| 616 | event->auxtrace_error.ip = bswap_64(event->auxtrace_error.ip); | 712 | event->auxtrace_error.ip = bswap_64(event->auxtrace_error.ip); |
| 617 | } | 713 | } |
| 618 | 714 | ||
| 715 | static void perf_event__thread_map_swap(union perf_event *event, | ||
| 716 | bool sample_id_all __maybe_unused) | ||
| 717 | { | ||
| 718 | unsigned i; | ||
| 719 | |||
| 720 | event->thread_map.nr = bswap_64(event->thread_map.nr); | ||
| 721 | |||
| 722 | for (i = 0; i < event->thread_map.nr; i++) | ||
| 723 | event->thread_map.entries[i].pid = bswap_64(event->thread_map.entries[i].pid); | ||
| 724 | } | ||
| 725 | |||
| 726 | static void perf_event__cpu_map_swap(union perf_event *event, | ||
| 727 | bool sample_id_all __maybe_unused) | ||
| 728 | { | ||
| 729 | struct cpu_map_data *data = &event->cpu_map.data; | ||
| 730 | struct cpu_map_entries *cpus; | ||
| 731 | struct cpu_map_mask *mask; | ||
| 732 | unsigned i; | ||
| 733 | |||
| 734 | data->type = bswap_64(data->type); | ||
| 735 | |||
| 736 | switch (data->type) { | ||
| 737 | case PERF_CPU_MAP__CPUS: | ||
| 738 | cpus = (struct cpu_map_entries *)data->data; | ||
| 739 | |||
| 740 | cpus->nr = bswap_16(cpus->nr); | ||
| 741 | |||
| 742 | for (i = 0; i < cpus->nr; i++) | ||
| 743 | cpus->cpu[i] = bswap_16(cpus->cpu[i]); | ||
| 744 | break; | ||
| 745 | case PERF_CPU_MAP__MASK: | ||
| 746 | mask = (struct cpu_map_mask *) data->data; | ||
| 747 | |||
| 748 | mask->nr = bswap_16(mask->nr); | ||
| 749 | mask->long_size = bswap_16(mask->long_size); | ||
| 750 | |||
| 751 | switch (mask->long_size) { | ||
| 752 | case 4: mem_bswap_32(&mask->mask, mask->nr); break; | ||
| 753 | case 8: mem_bswap_64(&mask->mask, mask->nr); break; | ||
| 754 | default: | ||
| 755 | pr_err("cpu_map swap: unsupported long size\n"); | ||
| 756 | } | ||
| 757 | default: | ||
| 758 | break; | ||
| 759 | } | ||
| 760 | } | ||
| 761 | |||
| 762 | static void perf_event__stat_config_swap(union perf_event *event, | ||
| 763 | bool sample_id_all __maybe_unused) | ||
| 764 | { | ||
| 765 | u64 size; | ||
| 766 | |||
| 767 | size = event->stat_config.nr * sizeof(event->stat_config.data[0]); | ||
| 768 | size += 1; /* nr item itself */ | ||
| 769 | mem_bswap_64(&event->stat_config.nr, size); | ||
| 770 | } | ||
| 771 | |||
| 772 | static void perf_event__stat_swap(union perf_event *event, | ||
| 773 | bool sample_id_all __maybe_unused) | ||
| 774 | { | ||
| 775 | event->stat.id = bswap_64(event->stat.id); | ||
| 776 | event->stat.thread = bswap_32(event->stat.thread); | ||
| 777 | event->stat.cpu = bswap_32(event->stat.cpu); | ||
| 778 | event->stat.val = bswap_64(event->stat.val); | ||
| 779 | event->stat.ena = bswap_64(event->stat.ena); | ||
| 780 | event->stat.run = bswap_64(event->stat.run); | ||
| 781 | } | ||
| 782 | |||
| 783 | static void perf_event__stat_round_swap(union perf_event *event, | ||
| 784 | bool sample_id_all __maybe_unused) | ||
| 785 | { | ||
| 786 | event->stat_round.type = bswap_64(event->stat_round.type); | ||
| 787 | event->stat_round.time = bswap_64(event->stat_round.time); | ||
| 788 | } | ||
| 789 | |||
| 619 | typedef void (*perf_event__swap_op)(union perf_event *event, | 790 | typedef void (*perf_event__swap_op)(union perf_event *event, |
| 620 | bool sample_id_all); | 791 | bool sample_id_all); |
| 621 | 792 | ||
| @@ -643,6 +814,12 @@ static perf_event__swap_op perf_event__swap_ops[] = { | |||
| 643 | [PERF_RECORD_AUXTRACE_INFO] = perf_event__auxtrace_info_swap, | 814 | [PERF_RECORD_AUXTRACE_INFO] = perf_event__auxtrace_info_swap, |
| 644 | [PERF_RECORD_AUXTRACE] = perf_event__auxtrace_swap, | 815 | [PERF_RECORD_AUXTRACE] = perf_event__auxtrace_swap, |
| 645 | [PERF_RECORD_AUXTRACE_ERROR] = perf_event__auxtrace_error_swap, | 816 | [PERF_RECORD_AUXTRACE_ERROR] = perf_event__auxtrace_error_swap, |
| 817 | [PERF_RECORD_THREAD_MAP] = perf_event__thread_map_swap, | ||
| 818 | [PERF_RECORD_CPU_MAP] = perf_event__cpu_map_swap, | ||
| 819 | [PERF_RECORD_STAT_CONFIG] = perf_event__stat_config_swap, | ||
| 820 | [PERF_RECORD_STAT] = perf_event__stat_swap, | ||
| 821 | [PERF_RECORD_STAT_ROUND] = perf_event__stat_round_swap, | ||
| 822 | [PERF_RECORD_EVENT_UPDATE] = perf_event__event_update_swap, | ||
| 646 | [PERF_RECORD_HEADER_MAX] = NULL, | 823 | [PERF_RECORD_HEADER_MAX] = NULL, |
| 647 | }; | 824 | }; |
| 648 | 825 | ||
| @@ -1154,6 +1331,8 @@ static s64 perf_session__process_user_event(struct perf_session *session, | |||
| 1154 | perf_session__set_comm_exec(session); | 1331 | perf_session__set_comm_exec(session); |
| 1155 | } | 1332 | } |
| 1156 | return err; | 1333 | return err; |
| 1334 | case PERF_RECORD_EVENT_UPDATE: | ||
| 1335 | return tool->event_update(tool, event, &session->evlist); | ||
| 1157 | case PERF_RECORD_HEADER_EVENT_TYPE: | 1336 | case PERF_RECORD_HEADER_EVENT_TYPE: |
| 1158 | /* | 1337 | /* |
| 1159 | * Depreceated, but we need to handle it for sake | 1338 | * Depreceated, but we need to handle it for sake |
| @@ -1179,6 +1358,16 @@ static s64 perf_session__process_user_event(struct perf_session *session, | |||
| 1179 | case PERF_RECORD_AUXTRACE_ERROR: | 1358 | case PERF_RECORD_AUXTRACE_ERROR: |
| 1180 | perf_session__auxtrace_error_inc(session, event); | 1359 | perf_session__auxtrace_error_inc(session, event); |
| 1181 | return tool->auxtrace_error(tool, event, session); | 1360 | return tool->auxtrace_error(tool, event, session); |
| 1361 | case PERF_RECORD_THREAD_MAP: | ||
| 1362 | return tool->thread_map(tool, event, session); | ||
| 1363 | case PERF_RECORD_CPU_MAP: | ||
| 1364 | return tool->cpu_map(tool, event, session); | ||
| 1365 | case PERF_RECORD_STAT_CONFIG: | ||
| 1366 | return tool->stat_config(tool, event, session); | ||
| 1367 | case PERF_RECORD_STAT: | ||
| 1368 | return tool->stat(tool, event, session); | ||
| 1369 | case PERF_RECORD_STAT_ROUND: | ||
| 1370 | return tool->stat_round(tool, event, session); | ||
| 1182 | default: | 1371 | default: |
| 1183 | return -EINVAL; | 1372 | return -EINVAL; |
| 1184 | } | 1373 | } |
| @@ -1311,17 +1500,20 @@ struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) | |||
| 1311 | return machine__findnew_thread(&session->machines.host, -1, pid); | 1500 | return machine__findnew_thread(&session->machines.host, -1, pid); |
| 1312 | } | 1501 | } |
| 1313 | 1502 | ||
| 1314 | struct thread *perf_session__register_idle_thread(struct perf_session *session) | 1503 | int perf_session__register_idle_thread(struct perf_session *session) |
| 1315 | { | 1504 | { |
| 1316 | struct thread *thread; | 1505 | struct thread *thread; |
| 1506 | int err = 0; | ||
| 1317 | 1507 | ||
| 1318 | thread = machine__findnew_thread(&session->machines.host, 0, 0); | 1508 | thread = machine__findnew_thread(&session->machines.host, 0, 0); |
| 1319 | if (thread == NULL || thread__set_comm(thread, "swapper", 0)) { | 1509 | if (thread == NULL || thread__set_comm(thread, "swapper", 0)) { |
| 1320 | pr_err("problem inserting idle task.\n"); | 1510 | pr_err("problem inserting idle task.\n"); |
| 1321 | thread = NULL; | 1511 | err = -1; |
| 1322 | } | 1512 | } |
| 1323 | 1513 | ||
| 1324 | return thread; | 1514 | /* machine__findnew_thread() got the thread, so put it */ |
| 1515 | thread__put(thread); | ||
| 1516 | return err; | ||
| 1325 | } | 1517 | } |
| 1326 | 1518 | ||
| 1327 | static void perf_session__warn_about_errors(const struct perf_session *session) | 1519 | static void perf_session__warn_about_errors(const struct perf_session *session) |
| @@ -1676,7 +1868,7 @@ int perf_session__process_events(struct perf_session *session) | |||
| 1676 | u64 size = perf_data_file__size(session->file); | 1868 | u64 size = perf_data_file__size(session->file); |
| 1677 | int err; | 1869 | int err; |
| 1678 | 1870 | ||
| 1679 | if (perf_session__register_idle_thread(session) == NULL) | 1871 | if (perf_session__register_idle_thread(session) < 0) |
| 1680 | return -ENOMEM; | 1872 | return -ENOMEM; |
| 1681 | 1873 | ||
| 1682 | if (!perf_data_file__is_pipe(session->file)) | 1874 | if (!perf_data_file__is_pipe(session->file)) |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 3e900c0efc73..5f792e35d4c1 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
| @@ -89,7 +89,7 @@ struct machine *perf_session__findnew_machine(struct perf_session *session, pid_ | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | struct thread *perf_session__findnew(struct perf_session *session, pid_t pid); | 91 | struct thread *perf_session__findnew(struct perf_session *session, pid_t pid); |
| 92 | struct thread *perf_session__register_idle_thread(struct perf_session *session); | 92 | int perf_session__register_idle_thread(struct perf_session *session); |
| 93 | 93 | ||
| 94 | size_t perf_session__fprintf(struct perf_session *session, FILE *fp); | 94 | size_t perf_session__fprintf(struct perf_session *session, FILE *fp); |
| 95 | 95 | ||
diff --git a/tools/perf/util/sigchain.c b/tools/perf/util/sigchain.c deleted file mode 100644 index ba785e9b1841..000000000000 --- a/tools/perf/util/sigchain.c +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | #include "sigchain.h" | ||
| 2 | #include "cache.h" | ||
| 3 | |||
| 4 | #define SIGCHAIN_MAX_SIGNALS 32 | ||
| 5 | |||
| 6 | struct sigchain_signal { | ||
| 7 | sigchain_fun *old; | ||
| 8 | int n; | ||
| 9 | int alloc; | ||
| 10 | }; | ||
| 11 | static struct sigchain_signal signals[SIGCHAIN_MAX_SIGNALS]; | ||
| 12 | |||
| 13 | static void check_signum(int sig) | ||
| 14 | { | ||
| 15 | if (sig < 1 || sig >= SIGCHAIN_MAX_SIGNALS) | ||
| 16 | die("BUG: signal out of range: %d", sig); | ||
| 17 | } | ||
| 18 | |||
| 19 | static int sigchain_push(int sig, sigchain_fun f) | ||
| 20 | { | ||
| 21 | struct sigchain_signal *s = signals + sig; | ||
| 22 | check_signum(sig); | ||
| 23 | |||
| 24 | ALLOC_GROW(s->old, s->n + 1, s->alloc); | ||
| 25 | s->old[s->n] = signal(sig, f); | ||
| 26 | if (s->old[s->n] == SIG_ERR) | ||
| 27 | return -1; | ||
| 28 | s->n++; | ||
| 29 | return 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | int sigchain_pop(int sig) | ||
| 33 | { | ||
| 34 | struct sigchain_signal *s = signals + sig; | ||
| 35 | check_signum(sig); | ||
| 36 | if (s->n < 1) | ||
| 37 | return 0; | ||
| 38 | |||
| 39 | if (signal(sig, s->old[s->n - 1]) == SIG_ERR) | ||
| 40 | return -1; | ||
| 41 | s->n--; | ||
| 42 | return 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | void sigchain_push_common(sigchain_fun f) | ||
| 46 | { | ||
| 47 | sigchain_push(SIGINT, f); | ||
| 48 | sigchain_push(SIGHUP, f); | ||
| 49 | sigchain_push(SIGTERM, f); | ||
| 50 | sigchain_push(SIGQUIT, f); | ||
| 51 | sigchain_push(SIGPIPE, f); | ||
| 52 | } | ||
diff --git a/tools/perf/util/sigchain.h b/tools/perf/util/sigchain.h deleted file mode 100644 index 959d64eb5557..000000000000 --- a/tools/perf/util/sigchain.h +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | #ifndef __PERF_SIGCHAIN_H | ||
| 2 | #define __PERF_SIGCHAIN_H | ||
| 3 | |||
| 4 | typedef void (*sigchain_fun)(int); | ||
| 5 | |||
| 6 | int sigchain_pop(int sig); | ||
| 7 | |||
| 8 | void sigchain_push_common(sigchain_fun f); | ||
| 9 | |||
| 10 | #endif /* __PERF_SIGCHAIN_H */ | ||
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 2d8ccd4d9e1b..ec722346e6ff 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | #include "comm.h" | 4 | #include "comm.h" |
| 5 | #include "symbol.h" | 5 | #include "symbol.h" |
| 6 | #include "evsel.h" | 6 | #include "evsel.h" |
| 7 | #include "evlist.h" | ||
| 8 | #include <traceevent/event-parse.h> | ||
| 7 | 9 | ||
| 8 | regex_t parent_regex; | 10 | regex_t parent_regex; |
| 9 | const char default_parent_pattern[] = "^sys_|^do_page_fault"; | 11 | const char default_parent_pattern[] = "^sys_|^do_page_fault"; |
| @@ -13,6 +15,7 @@ const char default_branch_sort_order[] = "comm,dso_from,symbol_from,symbol_to,cy | |||
| 13 | const char default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked"; | 15 | const char default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked"; |
| 14 | const char default_top_sort_order[] = "dso,symbol"; | 16 | const char default_top_sort_order[] = "dso,symbol"; |
| 15 | const char default_diff_sort_order[] = "dso,symbol"; | 17 | const char default_diff_sort_order[] = "dso,symbol"; |
| 18 | const char default_tracepoint_sort_order[] = "trace"; | ||
| 16 | const char *sort_order; | 19 | const char *sort_order; |
| 17 | const char *field_order; | 20 | const char *field_order; |
| 18 | regex_t ignore_callees_regex; | 21 | regex_t ignore_callees_regex; |
| @@ -443,6 +446,70 @@ struct sort_entry sort_socket = { | |||
| 443 | .se_width_idx = HISTC_SOCKET, | 446 | .se_width_idx = HISTC_SOCKET, |
| 444 | }; | 447 | }; |
| 445 | 448 | ||
| 449 | /* --sort trace */ | ||
| 450 | |||
| 451 | static char *get_trace_output(struct hist_entry *he) | ||
| 452 | { | ||
| 453 | struct trace_seq seq; | ||
| 454 | struct perf_evsel *evsel; | ||
| 455 | struct pevent_record rec = { | ||
| 456 | .data = he->raw_data, | ||
| 457 | .size = he->raw_size, | ||
| 458 | }; | ||
| 459 | |||
| 460 | evsel = hists_to_evsel(he->hists); | ||
| 461 | |||
| 462 | trace_seq_init(&seq); | ||
| 463 | if (symbol_conf.raw_trace) { | ||
| 464 | pevent_print_fields(&seq, he->raw_data, he->raw_size, | ||
| 465 | evsel->tp_format); | ||
| 466 | } else { | ||
| 467 | pevent_event_info(&seq, evsel->tp_format, &rec); | ||
| 468 | } | ||
| 469 | return seq.buffer; | ||
| 470 | } | ||
| 471 | |||
| 472 | static int64_t | ||
| 473 | sort__trace_cmp(struct hist_entry *left, struct hist_entry *right) | ||
| 474 | { | ||
| 475 | struct perf_evsel *evsel; | ||
| 476 | |||
| 477 | evsel = hists_to_evsel(left->hists); | ||
| 478 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | ||
| 479 | return 0; | ||
| 480 | |||
| 481 | if (left->trace_output == NULL) | ||
| 482 | left->trace_output = get_trace_output(left); | ||
| 483 | if (right->trace_output == NULL) | ||
| 484 | right->trace_output = get_trace_output(right); | ||
| 485 | |||
| 486 | hists__new_col_len(left->hists, HISTC_TRACE, strlen(left->trace_output)); | ||
| 487 | hists__new_col_len(right->hists, HISTC_TRACE, strlen(right->trace_output)); | ||
| 488 | |||
| 489 | return strcmp(right->trace_output, left->trace_output); | ||
| 490 | } | ||
| 491 | |||
| 492 | static int hist_entry__trace_snprintf(struct hist_entry *he, char *bf, | ||
| 493 | size_t size, unsigned int width) | ||
| 494 | { | ||
| 495 | struct perf_evsel *evsel; | ||
| 496 | |||
| 497 | evsel = hists_to_evsel(he->hists); | ||
| 498 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | ||
| 499 | return scnprintf(bf, size, "%-*.*s", width, width, "N/A"); | ||
| 500 | |||
| 501 | if (he->trace_output == NULL) | ||
| 502 | he->trace_output = get_trace_output(he); | ||
| 503 | return repsep_snprintf(bf, size, "%-*.*s", width, width, he->trace_output); | ||
| 504 | } | ||
| 505 | |||
| 506 | struct sort_entry sort_trace = { | ||
| 507 | .se_header = "Trace output", | ||
| 508 | .se_cmp = sort__trace_cmp, | ||
| 509 | .se_snprintf = hist_entry__trace_snprintf, | ||
| 510 | .se_width_idx = HISTC_TRACE, | ||
| 511 | }; | ||
| 512 | |||
| 446 | /* sort keys for branch stacks */ | 513 | /* sort keys for branch stacks */ |
| 447 | 514 | ||
| 448 | static int64_t | 515 | static int64_t |
| @@ -1312,6 +1379,7 @@ static struct sort_dimension common_sort_dimensions[] = { | |||
| 1312 | DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight), | 1379 | DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight), |
| 1313 | DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight), | 1380 | DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight), |
| 1314 | DIM(SORT_TRANSACTION, "transaction", sort_transaction), | 1381 | DIM(SORT_TRANSACTION, "transaction", sort_transaction), |
| 1382 | DIM(SORT_TRACE, "trace", sort_trace), | ||
| 1315 | }; | 1383 | }; |
| 1316 | 1384 | ||
| 1317 | #undef DIM | 1385 | #undef DIM |
| @@ -1529,6 +1597,455 @@ static int __sort_dimension__add_hpp_output(struct sort_dimension *sd) | |||
| 1529 | return 0; | 1597 | return 0; |
| 1530 | } | 1598 | } |
| 1531 | 1599 | ||
| 1600 | struct hpp_dynamic_entry { | ||
| 1601 | struct perf_hpp_fmt hpp; | ||
| 1602 | struct perf_evsel *evsel; | ||
| 1603 | struct format_field *field; | ||
| 1604 | unsigned dynamic_len; | ||
| 1605 | bool raw_trace; | ||
| 1606 | }; | ||
| 1607 | |||
| 1608 | static int hde_width(struct hpp_dynamic_entry *hde) | ||
| 1609 | { | ||
| 1610 | if (!hde->hpp.len) { | ||
| 1611 | int len = hde->dynamic_len; | ||
| 1612 | int namelen = strlen(hde->field->name); | ||
| 1613 | int fieldlen = hde->field->size; | ||
| 1614 | |||
| 1615 | if (namelen > len) | ||
| 1616 | len = namelen; | ||
| 1617 | |||
| 1618 | if (!(hde->field->flags & FIELD_IS_STRING)) { | ||
| 1619 | /* length for print hex numbers */ | ||
| 1620 | fieldlen = hde->field->size * 2 + 2; | ||
| 1621 | } | ||
| 1622 | if (fieldlen > len) | ||
| 1623 | len = fieldlen; | ||
| 1624 | |||
| 1625 | hde->hpp.len = len; | ||
| 1626 | } | ||
| 1627 | return hde->hpp.len; | ||
| 1628 | } | ||
| 1629 | |||
| 1630 | static void update_dynamic_len(struct hpp_dynamic_entry *hde, | ||
| 1631 | struct hist_entry *he) | ||
| 1632 | { | ||
| 1633 | char *str, *pos; | ||
| 1634 | struct format_field *field = hde->field; | ||
| 1635 | size_t namelen; | ||
| 1636 | bool last = false; | ||
| 1637 | |||
| 1638 | if (hde->raw_trace) | ||
| 1639 | return; | ||
| 1640 | |||
| 1641 | /* parse pretty print result and update max length */ | ||
| 1642 | if (!he->trace_output) | ||
| 1643 | he->trace_output = get_trace_output(he); | ||
| 1644 | |||
| 1645 | namelen = strlen(field->name); | ||
| 1646 | str = he->trace_output; | ||
| 1647 | |||
| 1648 | while (str) { | ||
| 1649 | pos = strchr(str, ' '); | ||
| 1650 | if (pos == NULL) { | ||
| 1651 | last = true; | ||
| 1652 | pos = str + strlen(str); | ||
| 1653 | } | ||
| 1654 | |||
| 1655 | if (!strncmp(str, field->name, namelen)) { | ||
| 1656 | size_t len; | ||
| 1657 | |||
| 1658 | str += namelen + 1; | ||
| 1659 | len = pos - str; | ||
| 1660 | |||
| 1661 | if (len > hde->dynamic_len) | ||
| 1662 | hde->dynamic_len = len; | ||
| 1663 | break; | ||
| 1664 | } | ||
| 1665 | |||
| 1666 | if (last) | ||
| 1667 | str = NULL; | ||
| 1668 | else | ||
| 1669 | str = pos + 1; | ||
| 1670 | } | ||
| 1671 | } | ||
| 1672 | |||
| 1673 | static int __sort__hde_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, | ||
| 1674 | struct perf_evsel *evsel __maybe_unused) | ||
| 1675 | { | ||
| 1676 | struct hpp_dynamic_entry *hde; | ||
| 1677 | size_t len = fmt->user_len; | ||
| 1678 | |||
| 1679 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | ||
| 1680 | |||
| 1681 | if (!len) | ||
| 1682 | len = hde_width(hde); | ||
| 1683 | |||
| 1684 | return scnprintf(hpp->buf, hpp->size, "%*.*s", len, len, hde->field->name); | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | static int __sort__hde_width(struct perf_hpp_fmt *fmt, | ||
| 1688 | struct perf_hpp *hpp __maybe_unused, | ||
| 1689 | struct perf_evsel *evsel __maybe_unused) | ||
| 1690 | { | ||
| 1691 | struct hpp_dynamic_entry *hde; | ||
| 1692 | size_t len = fmt->user_len; | ||
| 1693 | |||
| 1694 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | ||
| 1695 | |||
| 1696 | if (!len) | ||
| 1697 | len = hde_width(hde); | ||
| 1698 | |||
| 1699 | return len; | ||
| 1700 | } | ||
| 1701 | |||
| 1702 | bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists) | ||
| 1703 | { | ||
| 1704 | struct hpp_dynamic_entry *hde; | ||
| 1705 | |||
| 1706 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | ||
| 1707 | |||
| 1708 | return hists_to_evsel(hists) == hde->evsel; | ||
| 1709 | } | ||
| 1710 | |||
| 1711 | static int __sort__hde_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, | ||
| 1712 | struct hist_entry *he) | ||
| 1713 | { | ||
| 1714 | struct hpp_dynamic_entry *hde; | ||
| 1715 | size_t len = fmt->user_len; | ||
| 1716 | char *str, *pos; | ||
| 1717 | struct format_field *field; | ||
| 1718 | size_t namelen; | ||
| 1719 | bool last = false; | ||
| 1720 | int ret; | ||
| 1721 | |||
| 1722 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | ||
| 1723 | |||
| 1724 | if (!len) | ||
| 1725 | len = hde_width(hde); | ||
| 1726 | |||
| 1727 | if (hde->raw_trace) | ||
| 1728 | goto raw_field; | ||
| 1729 | |||
| 1730 | field = hde->field; | ||
| 1731 | namelen = strlen(field->name); | ||
| 1732 | str = he->trace_output; | ||
| 1733 | |||
| 1734 | while (str) { | ||
| 1735 | pos = strchr(str, ' '); | ||
| 1736 | if (pos == NULL) { | ||
| 1737 | last = true; | ||
| 1738 | pos = str + strlen(str); | ||
| 1739 | } | ||
| 1740 | |||
| 1741 | if (!strncmp(str, field->name, namelen)) { | ||
| 1742 | str += namelen + 1; | ||
| 1743 | str = strndup(str, pos - str); | ||
| 1744 | |||
| 1745 | if (str == NULL) | ||
| 1746 | return scnprintf(hpp->buf, hpp->size, | ||
| 1747 | "%*.*s", len, len, "ERROR"); | ||
| 1748 | break; | ||
| 1749 | } | ||
| 1750 | |||
| 1751 | if (last) | ||
| 1752 | str = NULL; | ||
| 1753 | else | ||
| 1754 | str = pos + 1; | ||
| 1755 | } | ||
| 1756 | |||
| 1757 | if (str == NULL) { | ||
| 1758 | struct trace_seq seq; | ||
| 1759 | raw_field: | ||
| 1760 | trace_seq_init(&seq); | ||
| 1761 | pevent_print_field(&seq, he->raw_data, hde->field); | ||
| 1762 | str = seq.buffer; | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | ret = scnprintf(hpp->buf, hpp->size, "%*.*s", len, len, str); | ||
| 1766 | free(str); | ||
| 1767 | return ret; | ||
| 1768 | } | ||
| 1769 | |||
| 1770 | static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt, | ||
| 1771 | struct hist_entry *a, struct hist_entry *b) | ||
| 1772 | { | ||
| 1773 | struct hpp_dynamic_entry *hde; | ||
| 1774 | struct format_field *field; | ||
| 1775 | unsigned offset, size; | ||
| 1776 | |||
| 1777 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | ||
| 1778 | |||
| 1779 | field = hde->field; | ||
| 1780 | if (field->flags & FIELD_IS_DYNAMIC) { | ||
| 1781 | unsigned long long dyn; | ||
| 1782 | |||
| 1783 | pevent_read_number_field(field, a->raw_data, &dyn); | ||
| 1784 | offset = dyn & 0xffff; | ||
| 1785 | size = (dyn >> 16) & 0xffff; | ||
| 1786 | |||
| 1787 | /* record max width for output */ | ||
| 1788 | if (size > hde->dynamic_len) | ||
| 1789 | hde->dynamic_len = size; | ||
| 1790 | } else { | ||
| 1791 | offset = field->offset; | ||
| 1792 | size = field->size; | ||
| 1793 | |||
| 1794 | update_dynamic_len(hde, a); | ||
| 1795 | update_dynamic_len(hde, b); | ||
| 1796 | } | ||
| 1797 | |||
| 1798 | return memcmp(a->raw_data + offset, b->raw_data + offset, size); | ||
| 1799 | } | ||
| 1800 | |||
| 1801 | bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *fmt) | ||
| 1802 | { | ||
| 1803 | return fmt->cmp == __sort__hde_cmp; | ||
| 1804 | } | ||
| 1805 | |||
| 1806 | static struct hpp_dynamic_entry * | ||
| 1807 | __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field) | ||
| 1808 | { | ||
| 1809 | struct hpp_dynamic_entry *hde; | ||
| 1810 | |||
| 1811 | hde = malloc(sizeof(*hde)); | ||
| 1812 | if (hde == NULL) { | ||
| 1813 | pr_debug("Memory allocation failed\n"); | ||
| 1814 | return NULL; | ||
| 1815 | } | ||
| 1816 | |||
| 1817 | hde->evsel = evsel; | ||
| 1818 | hde->field = field; | ||
| 1819 | hde->dynamic_len = 0; | ||
| 1820 | |||
| 1821 | hde->hpp.name = field->name; | ||
| 1822 | hde->hpp.header = __sort__hde_header; | ||
| 1823 | hde->hpp.width = __sort__hde_width; | ||
| 1824 | hde->hpp.entry = __sort__hde_entry; | ||
| 1825 | hde->hpp.color = NULL; | ||
| 1826 | |||
| 1827 | hde->hpp.cmp = __sort__hde_cmp; | ||
| 1828 | hde->hpp.collapse = __sort__hde_cmp; | ||
| 1829 | hde->hpp.sort = __sort__hde_cmp; | ||
| 1830 | |||
| 1831 | INIT_LIST_HEAD(&hde->hpp.list); | ||
| 1832 | INIT_LIST_HEAD(&hde->hpp.sort_list); | ||
| 1833 | hde->hpp.elide = false; | ||
| 1834 | hde->hpp.len = 0; | ||
| 1835 | hde->hpp.user_len = 0; | ||
| 1836 | |||
| 1837 | return hde; | ||
| 1838 | } | ||
| 1839 | |||
| 1840 | static int parse_field_name(char *str, char **event, char **field, char **opt) | ||
| 1841 | { | ||
| 1842 | char *event_name, *field_name, *opt_name; | ||
| 1843 | |||
| 1844 | event_name = str; | ||
| 1845 | field_name = strchr(str, '.'); | ||
| 1846 | |||
| 1847 | if (field_name) { | ||
| 1848 | *field_name++ = '\0'; | ||
| 1849 | } else { | ||
| 1850 | event_name = NULL; | ||
| 1851 | field_name = str; | ||
| 1852 | } | ||
| 1853 | |||
| 1854 | opt_name = strchr(field_name, '/'); | ||
| 1855 | if (opt_name) | ||
| 1856 | *opt_name++ = '\0'; | ||
| 1857 | |||
| 1858 | *event = event_name; | ||
| 1859 | *field = field_name; | ||
| 1860 | *opt = opt_name; | ||
| 1861 | |||
| 1862 | return 0; | ||
| 1863 | } | ||
| 1864 | |||
| 1865 | /* find match evsel using a given event name. The event name can be: | ||
| 1866 | * 1. '%' + event index (e.g. '%1' for first event) | ||
| 1867 | * 2. full event name (e.g. sched:sched_switch) | ||
| 1868 | * 3. partial event name (should not contain ':') | ||
| 1869 | */ | ||
| 1870 | static struct perf_evsel *find_evsel(struct perf_evlist *evlist, char *event_name) | ||
| 1871 | { | ||
| 1872 | struct perf_evsel *evsel = NULL; | ||
| 1873 | struct perf_evsel *pos; | ||
| 1874 | bool full_name; | ||
| 1875 | |||
| 1876 | /* case 1 */ | ||
| 1877 | if (event_name[0] == '%') { | ||
| 1878 | int nr = strtol(event_name+1, NULL, 0); | ||
| 1879 | |||
| 1880 | if (nr > evlist->nr_entries) | ||
| 1881 | return NULL; | ||
| 1882 | |||
| 1883 | evsel = perf_evlist__first(evlist); | ||
| 1884 | while (--nr > 0) | ||
| 1885 | evsel = perf_evsel__next(evsel); | ||
| 1886 | |||
| 1887 | return evsel; | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | full_name = !!strchr(event_name, ':'); | ||
| 1891 | evlist__for_each(evlist, pos) { | ||
| 1892 | /* case 2 */ | ||
| 1893 | if (full_name && !strcmp(pos->name, event_name)) | ||
| 1894 | return pos; | ||
| 1895 | /* case 3 */ | ||
| 1896 | if (!full_name && strstr(pos->name, event_name)) { | ||
| 1897 | if (evsel) { | ||
| 1898 | pr_debug("'%s' event is ambiguous: it can be %s or %s\n", | ||
| 1899 | event_name, evsel->name, pos->name); | ||
| 1900 | return NULL; | ||
| 1901 | } | ||
| 1902 | evsel = pos; | ||
| 1903 | } | ||
| 1904 | } | ||
| 1905 | |||
| 1906 | return evsel; | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | static int __dynamic_dimension__add(struct perf_evsel *evsel, | ||
| 1910 | struct format_field *field, | ||
| 1911 | bool raw_trace) | ||
| 1912 | { | ||
| 1913 | struct hpp_dynamic_entry *hde; | ||
| 1914 | |||
| 1915 | hde = __alloc_dynamic_entry(evsel, field); | ||
| 1916 | if (hde == NULL) | ||
| 1917 | return -ENOMEM; | ||
| 1918 | |||
| 1919 | hde->raw_trace = raw_trace; | ||
| 1920 | |||
| 1921 | perf_hpp__register_sort_field(&hde->hpp); | ||
| 1922 | return 0; | ||
| 1923 | } | ||
| 1924 | |||
| 1925 | static int add_evsel_fields(struct perf_evsel *evsel, bool raw_trace) | ||
| 1926 | { | ||
| 1927 | int ret; | ||
| 1928 | struct format_field *field; | ||
| 1929 | |||
| 1930 | field = evsel->tp_format->format.fields; | ||
| 1931 | while (field) { | ||
| 1932 | ret = __dynamic_dimension__add(evsel, field, raw_trace); | ||
| 1933 | if (ret < 0) | ||
| 1934 | return ret; | ||
| 1935 | |||
| 1936 | field = field->next; | ||
| 1937 | } | ||
| 1938 | return 0; | ||
| 1939 | } | ||
| 1940 | |||
| 1941 | static int add_all_dynamic_fields(struct perf_evlist *evlist, bool raw_trace) | ||
| 1942 | { | ||
| 1943 | int ret; | ||
| 1944 | struct perf_evsel *evsel; | ||
| 1945 | |||
| 1946 | evlist__for_each(evlist, evsel) { | ||
| 1947 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | ||
| 1948 | continue; | ||
| 1949 | |||
| 1950 | ret = add_evsel_fields(evsel, raw_trace); | ||
| 1951 | if (ret < 0) | ||
| 1952 | return ret; | ||
| 1953 | } | ||
| 1954 | return 0; | ||
| 1955 | } | ||
| 1956 | |||
| 1957 | static int add_all_matching_fields(struct perf_evlist *evlist, | ||
| 1958 | char *field_name, bool raw_trace) | ||
| 1959 | { | ||
| 1960 | int ret = -ESRCH; | ||
| 1961 | struct perf_evsel *evsel; | ||
| 1962 | struct format_field *field; | ||
| 1963 | |||
| 1964 | evlist__for_each(evlist, evsel) { | ||
| 1965 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) | ||
| 1966 | continue; | ||
| 1967 | |||
| 1968 | field = pevent_find_any_field(evsel->tp_format, field_name); | ||
| 1969 | if (field == NULL) | ||
| 1970 | continue; | ||
| 1971 | |||
| 1972 | ret = __dynamic_dimension__add(evsel, field, raw_trace); | ||
| 1973 | if (ret < 0) | ||
| 1974 | break; | ||
| 1975 | } | ||
| 1976 | return ret; | ||
| 1977 | } | ||
| 1978 | |||
| 1979 | static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok) | ||
| 1980 | { | ||
| 1981 | char *str, *event_name, *field_name, *opt_name; | ||
| 1982 | struct perf_evsel *evsel; | ||
| 1983 | struct format_field *field; | ||
| 1984 | bool raw_trace = symbol_conf.raw_trace; | ||
| 1985 | int ret = 0; | ||
| 1986 | |||
| 1987 | if (evlist == NULL) | ||
| 1988 | return -ENOENT; | ||
| 1989 | |||
| 1990 | str = strdup(tok); | ||
| 1991 | if (str == NULL) | ||
| 1992 | return -ENOMEM; | ||
| 1993 | |||
| 1994 | if (parse_field_name(str, &event_name, &field_name, &opt_name) < 0) { | ||
| 1995 | ret = -EINVAL; | ||
| 1996 | goto out; | ||
| 1997 | } | ||
| 1998 | |||
| 1999 | if (opt_name) { | ||
| 2000 | if (strcmp(opt_name, "raw")) { | ||
| 2001 | pr_debug("unsupported field option %s\n", opt_name); | ||
| 2002 | ret = -EINVAL; | ||
| 2003 | goto out; | ||
| 2004 | } | ||
| 2005 | raw_trace = true; | ||
| 2006 | } | ||
| 2007 | |||
| 2008 | if (!strcmp(field_name, "trace_fields")) { | ||
| 2009 | ret = add_all_dynamic_fields(evlist, raw_trace); | ||
| 2010 | goto out; | ||
| 2011 | } | ||
| 2012 | |||
| 2013 | if (event_name == NULL) { | ||
| 2014 | ret = add_all_matching_fields(evlist, field_name, raw_trace); | ||
| 2015 | goto out; | ||
| 2016 | } | ||
| 2017 | |||
| 2018 | evsel = find_evsel(evlist, event_name); | ||
| 2019 | if (evsel == NULL) { | ||
| 2020 | pr_debug("Cannot find event: %s\n", event_name); | ||
| 2021 | ret = -ENOENT; | ||
| 2022 | goto out; | ||
| 2023 | } | ||
| 2024 | |||
| 2025 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { | ||
| 2026 | pr_debug("%s is not a tracepoint event\n", event_name); | ||
| 2027 | ret = -EINVAL; | ||
| 2028 | goto out; | ||
| 2029 | } | ||
| 2030 | |||
| 2031 | if (!strcmp(field_name, "*")) { | ||
| 2032 | ret = add_evsel_fields(evsel, raw_trace); | ||
| 2033 | } else { | ||
| 2034 | field = pevent_find_any_field(evsel->tp_format, field_name); | ||
| 2035 | if (field == NULL) { | ||
| 2036 | pr_debug("Cannot find event field for %s.%s\n", | ||
| 2037 | event_name, field_name); | ||
| 2038 | return -ENOENT; | ||
| 2039 | } | ||
| 2040 | |||
| 2041 | ret = __dynamic_dimension__add(evsel, field, raw_trace); | ||
| 2042 | } | ||
| 2043 | |||
| 2044 | out: | ||
| 2045 | free(str); | ||
| 2046 | return ret; | ||
| 2047 | } | ||
| 2048 | |||
| 1532 | static int __sort_dimension__add(struct sort_dimension *sd) | 2049 | static int __sort_dimension__add(struct sort_dimension *sd) |
| 1533 | { | 2050 | { |
| 1534 | if (sd->taken) | 2051 | if (sd->taken) |
| @@ -1583,7 +2100,8 @@ int hpp_dimension__add_output(unsigned col) | |||
| 1583 | return __hpp_dimension__add_output(&hpp_sort_dimensions[col]); | 2100 | return __hpp_dimension__add_output(&hpp_sort_dimensions[col]); |
| 1584 | } | 2101 | } |
| 1585 | 2102 | ||
| 1586 | int sort_dimension__add(const char *tok) | 2103 | static int sort_dimension__add(const char *tok, |
| 2104 | struct perf_evlist *evlist __maybe_unused) | ||
| 1587 | { | 2105 | { |
| 1588 | unsigned int i; | 2106 | unsigned int i; |
| 1589 | 2107 | ||
| @@ -1664,10 +2182,13 @@ int sort_dimension__add(const char *tok) | |||
| 1664 | return 0; | 2182 | return 0; |
| 1665 | } | 2183 | } |
| 1666 | 2184 | ||
| 2185 | if (!add_dynamic_entry(evlist, tok)) | ||
| 2186 | return 0; | ||
| 2187 | |||
| 1667 | return -ESRCH; | 2188 | return -ESRCH; |
| 1668 | } | 2189 | } |
| 1669 | 2190 | ||
| 1670 | static const char *get_default_sort_order(void) | 2191 | static const char *get_default_sort_order(struct perf_evlist *evlist) |
| 1671 | { | 2192 | { |
| 1672 | const char *default_sort_orders[] = { | 2193 | const char *default_sort_orders[] = { |
| 1673 | default_sort_order, | 2194 | default_sort_order, |
| @@ -1675,14 +2196,33 @@ static const char *get_default_sort_order(void) | |||
| 1675 | default_mem_sort_order, | 2196 | default_mem_sort_order, |
| 1676 | default_top_sort_order, | 2197 | default_top_sort_order, |
| 1677 | default_diff_sort_order, | 2198 | default_diff_sort_order, |
| 2199 | default_tracepoint_sort_order, | ||
| 1678 | }; | 2200 | }; |
| 2201 | bool use_trace = true; | ||
| 2202 | struct perf_evsel *evsel; | ||
| 1679 | 2203 | ||
| 1680 | BUG_ON(sort__mode >= ARRAY_SIZE(default_sort_orders)); | 2204 | BUG_ON(sort__mode >= ARRAY_SIZE(default_sort_orders)); |
| 1681 | 2205 | ||
| 2206 | if (evlist == NULL) | ||
| 2207 | goto out_no_evlist; | ||
| 2208 | |||
| 2209 | evlist__for_each(evlist, evsel) { | ||
| 2210 | if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { | ||
| 2211 | use_trace = false; | ||
| 2212 | break; | ||
| 2213 | } | ||
| 2214 | } | ||
| 2215 | |||
| 2216 | if (use_trace) { | ||
| 2217 | sort__mode = SORT_MODE__TRACEPOINT; | ||
| 2218 | if (symbol_conf.raw_trace) | ||
| 2219 | return "trace_fields"; | ||
| 2220 | } | ||
| 2221 | out_no_evlist: | ||
| 1682 | return default_sort_orders[sort__mode]; | 2222 | return default_sort_orders[sort__mode]; |
| 1683 | } | 2223 | } |
| 1684 | 2224 | ||
| 1685 | static int setup_sort_order(void) | 2225 | static int setup_sort_order(struct perf_evlist *evlist) |
| 1686 | { | 2226 | { |
| 1687 | char *new_sort_order; | 2227 | char *new_sort_order; |
| 1688 | 2228 | ||
| @@ -1703,7 +2243,7 @@ static int setup_sort_order(void) | |||
| 1703 | * because it's checked over the rest of the code. | 2243 | * because it's checked over the rest of the code. |
| 1704 | */ | 2244 | */ |
| 1705 | if (asprintf(&new_sort_order, "%s,%s", | 2245 | if (asprintf(&new_sort_order, "%s,%s", |
| 1706 | get_default_sort_order(), sort_order + 1) < 0) { | 2246 | get_default_sort_order(evlist), sort_order + 1) < 0) { |
| 1707 | error("Not enough memory to set up --sort"); | 2247 | error("Not enough memory to set up --sort"); |
| 1708 | return -ENOMEM; | 2248 | return -ENOMEM; |
| 1709 | } | 2249 | } |
| @@ -1712,13 +2252,41 @@ static int setup_sort_order(void) | |||
| 1712 | return 0; | 2252 | return 0; |
| 1713 | } | 2253 | } |
| 1714 | 2254 | ||
| 1715 | static int __setup_sorting(void) | 2255 | /* |
| 2256 | * Adds 'pre,' prefix into 'str' is 'pre' is | ||
| 2257 | * not already part of 'str'. | ||
| 2258 | */ | ||
| 2259 | static char *prefix_if_not_in(const char *pre, char *str) | ||
| 2260 | { | ||
| 2261 | char *n; | ||
| 2262 | |||
| 2263 | if (!str || strstr(str, pre)) | ||
| 2264 | return str; | ||
| 2265 | |||
| 2266 | if (asprintf(&n, "%s,%s", pre, str) < 0) | ||
| 2267 | return NULL; | ||
| 2268 | |||
| 2269 | free(str); | ||
| 2270 | return n; | ||
| 2271 | } | ||
| 2272 | |||
| 2273 | static char *setup_overhead(char *keys) | ||
| 2274 | { | ||
| 2275 | keys = prefix_if_not_in("overhead", keys); | ||
| 2276 | |||
| 2277 | if (symbol_conf.cumulate_callchain) | ||
| 2278 | keys = prefix_if_not_in("overhead_children", keys); | ||
| 2279 | |||
| 2280 | return keys; | ||
| 2281 | } | ||
| 2282 | |||
| 2283 | static int __setup_sorting(struct perf_evlist *evlist) | ||
| 1716 | { | 2284 | { |
| 1717 | char *tmp, *tok, *str; | 2285 | char *tmp, *tok, *str; |
| 1718 | const char *sort_keys; | 2286 | const char *sort_keys; |
| 1719 | int ret = 0; | 2287 | int ret = 0; |
| 1720 | 2288 | ||
| 1721 | ret = setup_sort_order(); | 2289 | ret = setup_sort_order(evlist); |
| 1722 | if (ret) | 2290 | if (ret) |
| 1723 | return ret; | 2291 | return ret; |
| 1724 | 2292 | ||
| @@ -1732,7 +2300,7 @@ static int __setup_sorting(void) | |||
| 1732 | return 0; | 2300 | return 0; |
| 1733 | } | 2301 | } |
| 1734 | 2302 | ||
| 1735 | sort_keys = get_default_sort_order(); | 2303 | sort_keys = get_default_sort_order(evlist); |
| 1736 | } | 2304 | } |
| 1737 | 2305 | ||
| 1738 | str = strdup(sort_keys); | 2306 | str = strdup(sort_keys); |
| @@ -1741,9 +2309,20 @@ static int __setup_sorting(void) | |||
| 1741 | return -ENOMEM; | 2309 | return -ENOMEM; |
| 1742 | } | 2310 | } |
| 1743 | 2311 | ||
| 2312 | /* | ||
| 2313 | * Prepend overhead fields for backward compatibility. | ||
| 2314 | */ | ||
| 2315 | if (!is_strict_order(field_order)) { | ||
| 2316 | str = setup_overhead(str); | ||
| 2317 | if (str == NULL) { | ||
| 2318 | error("Not enough memory to setup overhead keys"); | ||
| 2319 | return -ENOMEM; | ||
| 2320 | } | ||
| 2321 | } | ||
| 2322 | |||
| 1744 | for (tok = strtok_r(str, ", ", &tmp); | 2323 | for (tok = strtok_r(str, ", ", &tmp); |
| 1745 | tok; tok = strtok_r(NULL, ", ", &tmp)) { | 2324 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
| 1746 | ret = sort_dimension__add(tok); | 2325 | ret = sort_dimension__add(tok, evlist); |
| 1747 | if (ret == -EINVAL) { | 2326 | if (ret == -EINVAL) { |
| 1748 | error("Invalid --sort key: `%s'", tok); | 2327 | error("Invalid --sort key: `%s'", tok); |
| 1749 | break; | 2328 | break; |
| @@ -1954,16 +2533,16 @@ out: | |||
| 1954 | return ret; | 2533 | return ret; |
| 1955 | } | 2534 | } |
| 1956 | 2535 | ||
| 1957 | int setup_sorting(void) | 2536 | int setup_sorting(struct perf_evlist *evlist) |
| 1958 | { | 2537 | { |
| 1959 | int err; | 2538 | int err; |
| 1960 | 2539 | ||
| 1961 | err = __setup_sorting(); | 2540 | err = __setup_sorting(evlist); |
| 1962 | if (err < 0) | 2541 | if (err < 0) |
| 1963 | return err; | 2542 | return err; |
| 1964 | 2543 | ||
| 1965 | if (parent_pattern != default_parent_pattern) { | 2544 | if (parent_pattern != default_parent_pattern) { |
| 1966 | err = sort_dimension__add("parent"); | 2545 | err = sort_dimension__add("parent", evlist); |
| 1967 | if (err < 0) | 2546 | if (err < 0) |
| 1968 | return err; | 2547 | return err; |
| 1969 | } | 2548 | } |
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 31228851e397..687bbb124428 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
| @@ -18,7 +18,7 @@ | |||
| 18 | #include "debug.h" | 18 | #include "debug.h" |
| 19 | #include "header.h" | 19 | #include "header.h" |
| 20 | 20 | ||
| 21 | #include "parse-options.h" | 21 | #include <subcmd/parse-options.h> |
| 22 | #include "parse-events.h" | 22 | #include "parse-events.h" |
| 23 | #include "hist.h" | 23 | #include "hist.h" |
| 24 | #include "thread.h" | 24 | #include "thread.h" |
| @@ -122,6 +122,9 @@ struct hist_entry { | |||
| 122 | struct branch_info *branch_info; | 122 | struct branch_info *branch_info; |
| 123 | struct hists *hists; | 123 | struct hists *hists; |
| 124 | struct mem_info *mem_info; | 124 | struct mem_info *mem_info; |
| 125 | void *raw_data; | ||
| 126 | u32 raw_size; | ||
| 127 | void *trace_output; | ||
| 125 | struct callchain_root callchain[0]; /* must be last member */ | 128 | struct callchain_root callchain[0]; /* must be last member */ |
| 126 | }; | 129 | }; |
| 127 | 130 | ||
| @@ -164,6 +167,7 @@ enum sort_mode { | |||
| 164 | SORT_MODE__MEMORY, | 167 | SORT_MODE__MEMORY, |
| 165 | SORT_MODE__TOP, | 168 | SORT_MODE__TOP, |
| 166 | SORT_MODE__DIFF, | 169 | SORT_MODE__DIFF, |
| 170 | SORT_MODE__TRACEPOINT, | ||
| 167 | }; | 171 | }; |
| 168 | 172 | ||
| 169 | enum sort_type { | 173 | enum sort_type { |
| @@ -180,6 +184,7 @@ enum sort_type { | |||
| 180 | SORT_LOCAL_WEIGHT, | 184 | SORT_LOCAL_WEIGHT, |
| 181 | SORT_GLOBAL_WEIGHT, | 185 | SORT_GLOBAL_WEIGHT, |
| 182 | SORT_TRANSACTION, | 186 | SORT_TRANSACTION, |
| 187 | SORT_TRACE, | ||
| 183 | 188 | ||
| 184 | /* branch stack specific sort keys */ | 189 | /* branch stack specific sort keys */ |
| 185 | __SORT_BRANCH_STACK, | 190 | __SORT_BRANCH_STACK, |
| @@ -209,8 +214,6 @@ enum sort_type { | |||
| 209 | */ | 214 | */ |
| 210 | 215 | ||
| 211 | struct sort_entry { | 216 | struct sort_entry { |
| 212 | struct list_head list; | ||
| 213 | |||
| 214 | const char *se_header; | 217 | const char *se_header; |
| 215 | 218 | ||
| 216 | int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); | 219 | int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); |
| @@ -224,10 +227,11 @@ struct sort_entry { | |||
| 224 | extern struct sort_entry sort_thread; | 227 | extern struct sort_entry sort_thread; |
| 225 | extern struct list_head hist_entry__sort_list; | 228 | extern struct list_head hist_entry__sort_list; |
| 226 | 229 | ||
| 227 | int setup_sorting(void); | 230 | struct perf_evlist; |
| 231 | struct pevent; | ||
| 232 | int setup_sorting(struct perf_evlist *evlist); | ||
| 228 | int setup_output_field(void); | 233 | int setup_output_field(void); |
| 229 | void reset_output_field(void); | 234 | void reset_output_field(void); |
| 230 | extern int sort_dimension__add(const char *); | ||
| 231 | void sort__setup_elide(FILE *fp); | 235 | void sort__setup_elide(FILE *fp); |
| 232 | void perf_hpp__set_elide(int idx, bool elide); | 236 | void perf_hpp__set_elide(int idx, bool elide); |
| 233 | 237 | ||
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 2d9d8306dbd3..2f901d15e063 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c | |||
| @@ -341,3 +341,65 @@ int perf_stat_process_counter(struct perf_stat_config *config, | |||
| 341 | 341 | ||
| 342 | return 0; | 342 | return 0; |
| 343 | } | 343 | } |
| 344 | |||
| 345 | int perf_event__process_stat_event(struct perf_tool *tool __maybe_unused, | ||
| 346 | union perf_event *event, | ||
| 347 | struct perf_session *session) | ||
| 348 | { | ||
| 349 | struct perf_counts_values count; | ||
| 350 | struct stat_event *st = &event->stat; | ||
| 351 | struct perf_evsel *counter; | ||
| 352 | |||
| 353 | count.val = st->val; | ||
| 354 | count.ena = st->ena; | ||
| 355 | count.run = st->run; | ||
| 356 | |||
| 357 | counter = perf_evlist__id2evsel(session->evlist, st->id); | ||
| 358 | if (!counter) { | ||
| 359 | pr_err("Failed to resolve counter for stat event.\n"); | ||
| 360 | return -EINVAL; | ||
| 361 | } | ||
| 362 | |||
| 363 | *perf_counts(counter->counts, st->cpu, st->thread) = count; | ||
| 364 | counter->supported = true; | ||
| 365 | return 0; | ||
| 366 | } | ||
| 367 | |||
| 368 | size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp) | ||
| 369 | { | ||
| 370 | struct stat_event *st = (struct stat_event *) event; | ||
| 371 | size_t ret; | ||
| 372 | |||
| 373 | ret = fprintf(fp, "\n... id %" PRIu64 ", cpu %d, thread %d\n", | ||
| 374 | st->id, st->cpu, st->thread); | ||
| 375 | ret += fprintf(fp, "... value %" PRIu64 ", enabled %" PRIu64 ", running %" PRIu64 "\n", | ||
| 376 | st->val, st->ena, st->run); | ||
| 377 | |||
| 378 | return ret; | ||
| 379 | } | ||
| 380 | |||
| 381 | size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp) | ||
| 382 | { | ||
| 383 | struct stat_round_event *rd = (struct stat_round_event *)event; | ||
| 384 | size_t ret; | ||
| 385 | |||
| 386 | ret = fprintf(fp, "\n... time %" PRIu64 ", type %s\n", rd->time, | ||
| 387 | rd->type == PERF_STAT_ROUND_TYPE__FINAL ? "FINAL" : "INTERVAL"); | ||
| 388 | |||
| 389 | return ret; | ||
| 390 | } | ||
| 391 | |||
| 392 | size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp) | ||
| 393 | { | ||
| 394 | struct perf_stat_config sc; | ||
| 395 | size_t ret; | ||
| 396 | |||
| 397 | perf_event__read_stat_config(&sc, &event->stat_config); | ||
| 398 | |||
| 399 | ret = fprintf(fp, "\n"); | ||
| 400 | ret += fprintf(fp, "... aggr_mode %d\n", sc.aggr_mode); | ||
| 401 | ret += fprintf(fp, "... scale %d\n", sc.scale); | ||
| 402 | ret += fprintf(fp, "... interval %u\n", sc.interval); | ||
| 403 | |||
| 404 | return ret; | ||
| 405 | } | ||
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index da1d11c4f8c1..086f4e128d63 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h | |||
| @@ -90,4 +90,14 @@ void perf_evlist__reset_stats(struct perf_evlist *evlist); | |||
| 90 | 90 | ||
| 91 | int perf_stat_process_counter(struct perf_stat_config *config, | 91 | int perf_stat_process_counter(struct perf_stat_config *config, |
| 92 | struct perf_evsel *counter); | 92 | struct perf_evsel *counter); |
| 93 | struct perf_tool; | ||
| 94 | union perf_event; | ||
| 95 | struct perf_session; | ||
| 96 | int perf_event__process_stat_event(struct perf_tool *tool, | ||
| 97 | union perf_event *event, | ||
| 98 | struct perf_session *session); | ||
| 99 | |||
| 100 | size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); | ||
| 101 | size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); | ||
| 102 | size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); | ||
| 93 | #endif | 103 | #endif |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index fc8781de62db..7f7e072be746 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
| @@ -342,22 +342,6 @@ char *rtrim(char *s) | |||
| 342 | return s; | 342 | return s; |
| 343 | } | 343 | } |
| 344 | 344 | ||
| 345 | /** | ||
| 346 | * memdup - duplicate region of memory | ||
| 347 | * @src: memory region to duplicate | ||
| 348 | * @len: memory region length | ||
| 349 | */ | ||
| 350 | void *memdup(const void *src, size_t len) | ||
| 351 | { | ||
| 352 | void *p; | ||
| 353 | |||
| 354 | p = malloc(len); | ||
| 355 | if (p) | ||
| 356 | memcpy(p, src, len); | ||
| 357 | |||
| 358 | return p; | ||
| 359 | } | ||
| 360 | |||
| 361 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) | 345 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) |
| 362 | { | 346 | { |
| 363 | /* | 347 | /* |
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c index bdf98f6f27bb..0d3dfcb919b4 100644 --- a/tools/perf/util/strlist.c +++ b/tools/perf/util/strlist.c | |||
| @@ -126,6 +126,11 @@ static int strlist__parse_list_entry(struct strlist *slist, const char *s, | |||
| 126 | err = strlist__load(slist, subst); | 126 | err = strlist__load(slist, subst); |
| 127 | goto out; | 127 | goto out; |
| 128 | } | 128 | } |
| 129 | |||
| 130 | if (slist->file_only) { | ||
| 131 | err = -ENOENT; | ||
| 132 | goto out; | ||
| 133 | } | ||
| 129 | } | 134 | } |
| 130 | 135 | ||
| 131 | err = strlist__add(slist, s); | 136 | err = strlist__add(slist, s); |
| @@ -157,11 +162,13 @@ struct strlist *strlist__new(const char *list, const struct strlist_config *conf | |||
| 157 | 162 | ||
| 158 | if (slist != NULL) { | 163 | if (slist != NULL) { |
| 159 | bool dupstr = true; | 164 | bool dupstr = true; |
| 165 | bool file_only = false; | ||
| 160 | const char *dirname = NULL; | 166 | const char *dirname = NULL; |
| 161 | 167 | ||
| 162 | if (config) { | 168 | if (config) { |
| 163 | dupstr = !config->dont_dupstr; | 169 | dupstr = !config->dont_dupstr; |
| 164 | dirname = config->dirname; | 170 | dirname = config->dirname; |
| 171 | file_only = config->file_only; | ||
| 165 | } | 172 | } |
| 166 | 173 | ||
| 167 | rblist__init(&slist->rblist); | 174 | rblist__init(&slist->rblist); |
| @@ -170,6 +177,7 @@ struct strlist *strlist__new(const char *list, const struct strlist_config *conf | |||
| 170 | slist->rblist.node_delete = strlist__node_delete; | 177 | slist->rblist.node_delete = strlist__node_delete; |
| 171 | 178 | ||
| 172 | slist->dupstr = dupstr; | 179 | slist->dupstr = dupstr; |
| 180 | slist->file_only = file_only; | ||
| 173 | 181 | ||
| 174 | if (list && strlist__parse_list(slist, list, dirname) != 0) | 182 | if (list && strlist__parse_list(slist, list, dirname) != 0) |
| 175 | goto out_error; | 183 | goto out_error; |
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h index 297565aa7535..ca990029e243 100644 --- a/tools/perf/util/strlist.h +++ b/tools/perf/util/strlist.h | |||
| @@ -13,11 +13,18 @@ struct str_node { | |||
| 13 | 13 | ||
| 14 | struct strlist { | 14 | struct strlist { |
| 15 | struct rblist rblist; | 15 | struct rblist rblist; |
| 16 | bool dupstr; | 16 | bool dupstr; |
| 17 | bool file_only; | ||
| 17 | }; | 18 | }; |
| 18 | 19 | ||
| 20 | /* | ||
| 21 | * @file_only: When dirname is present, only consider entries as filenames, | ||
| 22 | * that should not be added to the list if dirname/entry is not | ||
| 23 | * found | ||
| 24 | */ | ||
| 19 | struct strlist_config { | 25 | struct strlist_config { |
| 20 | bool dont_dupstr; | 26 | bool dont_dupstr; |
| 27 | bool file_only; | ||
| 21 | const char *dirname; | 28 | const char *dirname; |
| 22 | }; | 29 | }; |
| 23 | 30 | ||
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 475d88d0a1c9..562b8ebeae5b 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c | |||
| @@ -1026,8 +1026,8 @@ int dso__load_sym(struct dso *dso, struct map *map, | |||
| 1026 | curr_dso->long_name_len = dso->long_name_len; | 1026 | curr_dso->long_name_len = dso->long_name_len; |
| 1027 | curr_map = map__new2(start, curr_dso, | 1027 | curr_map = map__new2(start, curr_dso, |
| 1028 | map->type); | 1028 | map->type); |
| 1029 | dso__put(curr_dso); | ||
| 1029 | if (curr_map == NULL) { | 1030 | if (curr_map == NULL) { |
| 1030 | dso__put(curr_dso); | ||
| 1031 | goto out_elf_end; | 1031 | goto out_elf_end; |
| 1032 | } | 1032 | } |
| 1033 | if (adjust_kernel_syms) { | 1033 | if (adjust_kernel_syms) { |
| @@ -1042,7 +1042,14 @@ int dso__load_sym(struct dso *dso, struct map *map, | |||
| 1042 | } | 1042 | } |
| 1043 | curr_dso->symtab_type = dso->symtab_type; | 1043 | curr_dso->symtab_type = dso->symtab_type; |
| 1044 | map_groups__insert(kmaps, curr_map); | 1044 | map_groups__insert(kmaps, curr_map); |
| 1045 | /* | ||
| 1046 | * Add it before we drop the referece to curr_map, | ||
| 1047 | * i.e. while we still are sure to have a reference | ||
| 1048 | * to this DSO via curr_map->dso. | ||
| 1049 | */ | ||
| 1045 | dsos__add(&map->groups->machine->dsos, curr_dso); | 1050 | dsos__add(&map->groups->machine->dsos, curr_dso); |
| 1051 | /* kmaps already got it */ | ||
| 1052 | map__put(curr_map); | ||
| 1046 | dso__set_loaded(curr_dso, map->type); | 1053 | dso__set_loaded(curr_dso, map->type); |
| 1047 | } else | 1054 | } else |
| 1048 | curr_dso = curr_map->dso; | 1055 | curr_dso = curr_map->dso; |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index b4cc7662677e..3b2de6eb3376 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
| @@ -39,6 +39,7 @@ struct symbol_conf symbol_conf = { | |||
| 39 | .cumulate_callchain = true, | 39 | .cumulate_callchain = true, |
| 40 | .show_hist_headers = true, | 40 | .show_hist_headers = true, |
| 41 | .symfs = "", | 41 | .symfs = "", |
| 42 | .event_group = true, | ||
| 42 | }; | 43 | }; |
| 43 | 44 | ||
| 44 | static enum dso_binary_type binary_type_symtab[] = { | 45 | static enum dso_binary_type binary_type_symtab[] = { |
| @@ -654,19 +655,24 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map, | |||
| 654 | struct map_groups *kmaps = map__kmaps(map); | 655 | struct map_groups *kmaps = map__kmaps(map); |
| 655 | struct map *curr_map; | 656 | struct map *curr_map; |
| 656 | struct symbol *pos; | 657 | struct symbol *pos; |
| 657 | int count = 0, moved = 0; | 658 | int count = 0; |
| 659 | struct rb_root old_root = dso->symbols[map->type]; | ||
| 658 | struct rb_root *root = &dso->symbols[map->type]; | 660 | struct rb_root *root = &dso->symbols[map->type]; |
| 659 | struct rb_node *next = rb_first(root); | 661 | struct rb_node *next = rb_first(root); |
| 660 | 662 | ||
| 661 | if (!kmaps) | 663 | if (!kmaps) |
| 662 | return -1; | 664 | return -1; |
| 663 | 665 | ||
| 666 | *root = RB_ROOT; | ||
| 667 | |||
| 664 | while (next) { | 668 | while (next) { |
| 665 | char *module; | 669 | char *module; |
| 666 | 670 | ||
| 667 | pos = rb_entry(next, struct symbol, rb_node); | 671 | pos = rb_entry(next, struct symbol, rb_node); |
| 668 | next = rb_next(&pos->rb_node); | 672 | next = rb_next(&pos->rb_node); |
| 669 | 673 | ||
| 674 | rb_erase_init(&pos->rb_node, &old_root); | ||
| 675 | |||
| 670 | module = strchr(pos->name, '\t'); | 676 | module = strchr(pos->name, '\t'); |
| 671 | if (module) | 677 | if (module) |
| 672 | *module = '\0'; | 678 | *module = '\0'; |
| @@ -674,28 +680,21 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map, | |||
| 674 | curr_map = map_groups__find(kmaps, map->type, pos->start); | 680 | curr_map = map_groups__find(kmaps, map->type, pos->start); |
| 675 | 681 | ||
| 676 | if (!curr_map || (filter && filter(curr_map, pos))) { | 682 | if (!curr_map || (filter && filter(curr_map, pos))) { |
| 677 | rb_erase_init(&pos->rb_node, root); | ||
| 678 | symbol__delete(pos); | 683 | symbol__delete(pos); |
| 679 | } else { | 684 | continue; |
| 680 | pos->start -= curr_map->start - curr_map->pgoff; | ||
| 681 | if (pos->end) | ||
| 682 | pos->end -= curr_map->start - curr_map->pgoff; | ||
| 683 | if (curr_map->dso != map->dso) { | ||
| 684 | rb_erase_init(&pos->rb_node, root); | ||
| 685 | symbols__insert( | ||
| 686 | &curr_map->dso->symbols[curr_map->type], | ||
| 687 | pos); | ||
| 688 | ++moved; | ||
| 689 | } else { | ||
| 690 | ++count; | ||
| 691 | } | ||
| 692 | } | 685 | } |
| 686 | |||
| 687 | pos->start -= curr_map->start - curr_map->pgoff; | ||
| 688 | if (pos->end) | ||
| 689 | pos->end -= curr_map->start - curr_map->pgoff; | ||
| 690 | symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); | ||
| 691 | ++count; | ||
| 693 | } | 692 | } |
| 694 | 693 | ||
| 695 | /* Symbols have been adjusted */ | 694 | /* Symbols have been adjusted */ |
| 696 | dso->adjust_symbols = 1; | 695 | dso->adjust_symbols = 1; |
| 697 | 696 | ||
| 698 | return count + moved; | 697 | return count; |
| 699 | } | 698 | } |
| 700 | 699 | ||
| 701 | /* | 700 | /* |
| @@ -1438,9 +1437,9 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) | |||
| 1438 | if (lstat(dso->name, &st) < 0) | 1437 | if (lstat(dso->name, &st) < 0) |
| 1439 | goto out; | 1438 | goto out; |
| 1440 | 1439 | ||
| 1441 | if (st.st_uid && (st.st_uid != geteuid())) { | 1440 | if (!symbol_conf.force && st.st_uid && (st.st_uid != geteuid())) { |
| 1442 | pr_warning("File %s not owned by current user or root, " | 1441 | pr_warning("File %s not owned by current user or root, " |
| 1443 | "ignoring it.\n", dso->name); | 1442 | "ignoring it (use -f to override).\n", dso->name); |
| 1444 | goto out; | 1443 | goto out; |
| 1445 | } | 1444 | } |
| 1446 | 1445 | ||
| @@ -1862,24 +1861,44 @@ static void vmlinux_path__exit(void) | |||
| 1862 | zfree(&vmlinux_path); | 1861 | zfree(&vmlinux_path); |
| 1863 | } | 1862 | } |
| 1864 | 1863 | ||
| 1864 | static const char * const vmlinux_paths[] = { | ||
| 1865 | "vmlinux", | ||
| 1866 | "/boot/vmlinux" | ||
| 1867 | }; | ||
| 1868 | |||
| 1869 | static const char * const vmlinux_paths_upd[] = { | ||
| 1870 | "/boot/vmlinux-%s", | ||
| 1871 | "/usr/lib/debug/boot/vmlinux-%s", | ||
| 1872 | "/lib/modules/%s/build/vmlinux", | ||
| 1873 | "/usr/lib/debug/lib/modules/%s/vmlinux", | ||
| 1874 | "/usr/lib/debug/boot/vmlinux-%s.debug" | ||
| 1875 | }; | ||
| 1876 | |||
| 1877 | static int vmlinux_path__add(const char *new_entry) | ||
| 1878 | { | ||
| 1879 | vmlinux_path[vmlinux_path__nr_entries] = strdup(new_entry); | ||
| 1880 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | ||
| 1881 | return -1; | ||
| 1882 | ++vmlinux_path__nr_entries; | ||
| 1883 | |||
| 1884 | return 0; | ||
| 1885 | } | ||
| 1886 | |||
| 1865 | static int vmlinux_path__init(struct perf_env *env) | 1887 | static int vmlinux_path__init(struct perf_env *env) |
| 1866 | { | 1888 | { |
| 1867 | struct utsname uts; | 1889 | struct utsname uts; |
| 1868 | char bf[PATH_MAX]; | 1890 | char bf[PATH_MAX]; |
| 1869 | char *kernel_version; | 1891 | char *kernel_version; |
| 1892 | unsigned int i; | ||
| 1870 | 1893 | ||
| 1871 | vmlinux_path = malloc(sizeof(char *) * 6); | 1894 | vmlinux_path = malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) + |
| 1895 | ARRAY_SIZE(vmlinux_paths_upd))); | ||
| 1872 | if (vmlinux_path == NULL) | 1896 | if (vmlinux_path == NULL) |
| 1873 | return -1; | 1897 | return -1; |
| 1874 | 1898 | ||
| 1875 | vmlinux_path[vmlinux_path__nr_entries] = strdup("vmlinux"); | 1899 | for (i = 0; i < ARRAY_SIZE(vmlinux_paths); i++) |
| 1876 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | 1900 | if (vmlinux_path__add(vmlinux_paths[i]) < 0) |
| 1877 | goto out_fail; | 1901 | goto out_fail; |
| 1878 | ++vmlinux_path__nr_entries; | ||
| 1879 | vmlinux_path[vmlinux_path__nr_entries] = strdup("/boot/vmlinux"); | ||
| 1880 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | ||
| 1881 | goto out_fail; | ||
| 1882 | ++vmlinux_path__nr_entries; | ||
| 1883 | 1902 | ||
| 1884 | /* only try kernel version if no symfs was given */ | 1903 | /* only try kernel version if no symfs was given */ |
| 1885 | if (symbol_conf.symfs[0] != 0) | 1904 | if (symbol_conf.symfs[0] != 0) |
| @@ -1894,28 +1913,11 @@ static int vmlinux_path__init(struct perf_env *env) | |||
| 1894 | kernel_version = uts.release; | 1913 | kernel_version = uts.release; |
| 1895 | } | 1914 | } |
| 1896 | 1915 | ||
| 1897 | snprintf(bf, sizeof(bf), "/boot/vmlinux-%s", kernel_version); | 1916 | for (i = 0; i < ARRAY_SIZE(vmlinux_paths_upd); i++) { |
| 1898 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); | 1917 | snprintf(bf, sizeof(bf), vmlinux_paths_upd[i], kernel_version); |
| 1899 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | 1918 | if (vmlinux_path__add(bf) < 0) |
| 1900 | goto out_fail; | 1919 | goto out_fail; |
| 1901 | ++vmlinux_path__nr_entries; | 1920 | } |
| 1902 | snprintf(bf, sizeof(bf), "/usr/lib/debug/boot/vmlinux-%s", | ||
| 1903 | kernel_version); | ||
| 1904 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); | ||
| 1905 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | ||
| 1906 | goto out_fail; | ||
| 1907 | ++vmlinux_path__nr_entries; | ||
| 1908 | snprintf(bf, sizeof(bf), "/lib/modules/%s/build/vmlinux", kernel_version); | ||
| 1909 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); | ||
| 1910 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | ||
| 1911 | goto out_fail; | ||
| 1912 | ++vmlinux_path__nr_entries; | ||
| 1913 | snprintf(bf, sizeof(bf), "/usr/lib/debug/lib/modules/%s/vmlinux", | ||
| 1914 | kernel_version); | ||
| 1915 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); | ||
| 1916 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) | ||
| 1917 | goto out_fail; | ||
| 1918 | ++vmlinux_path__nr_entries; | ||
| 1919 | 1921 | ||
| 1920 | return 0; | 1922 | return 0; |
| 1921 | 1923 | ||
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 40073c60b83d..ccd1caa40e11 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
| @@ -84,6 +84,7 @@ struct symbol_conf { | |||
| 84 | unsigned short priv_size; | 84 | unsigned short priv_size; |
| 85 | unsigned short nr_events; | 85 | unsigned short nr_events; |
| 86 | bool try_vmlinux_path, | 86 | bool try_vmlinux_path, |
| 87 | force, | ||
| 87 | ignore_vmlinux, | 88 | ignore_vmlinux, |
| 88 | ignore_vmlinux_buildid, | 89 | ignore_vmlinux_buildid, |
| 89 | show_kernel_path, | 90 | show_kernel_path, |
| @@ -107,7 +108,9 @@ struct symbol_conf { | |||
| 107 | show_hist_headers, | 108 | show_hist_headers, |
| 108 | branch_callstack, | 109 | branch_callstack, |
| 109 | has_filter, | 110 | has_filter, |
| 110 | show_ref_callgraph; | 111 | show_ref_callgraph, |
| 112 | hide_unresolved, | ||
| 113 | raw_trace; | ||
| 111 | const char *vmlinux_name, | 114 | const char *vmlinux_name, |
| 112 | *kallsyms_name, | 115 | *kallsyms_name, |
| 113 | *source_prefix, | 116 | *source_prefix, |
diff --git a/tools/perf/util/term.c b/tools/perf/util/term.c new file mode 100644 index 000000000000..90b47d8aa19c --- /dev/null +++ b/tools/perf/util/term.c | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #include "util.h" | ||
| 2 | |||
| 3 | void get_term_dimensions(struct winsize *ws) | ||
| 4 | { | ||
| 5 | char *s = getenv("LINES"); | ||
| 6 | |||
| 7 | if (s != NULL) { | ||
| 8 | ws->ws_row = atoi(s); | ||
| 9 | s = getenv("COLUMNS"); | ||
| 10 | if (s != NULL) { | ||
| 11 | ws->ws_col = atoi(s); | ||
| 12 | if (ws->ws_row && ws->ws_col) | ||
| 13 | return; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | #ifdef TIOCGWINSZ | ||
| 17 | if (ioctl(1, TIOCGWINSZ, ws) == 0 && | ||
| 18 | ws->ws_row && ws->ws_col) | ||
| 19 | return; | ||
| 20 | #endif | ||
| 21 | ws->ws_row = 25; | ||
| 22 | ws->ws_col = 80; | ||
| 23 | } | ||
| 24 | |||
| 25 | void set_term_quiet_input(struct termios *old) | ||
| 26 | { | ||
| 27 | struct termios tc; | ||
| 28 | |||
| 29 | tcgetattr(0, old); | ||
| 30 | tc = *old; | ||
| 31 | tc.c_lflag &= ~(ICANON | ECHO); | ||
| 32 | tc.c_cc[VMIN] = 0; | ||
| 33 | tc.c_cc[VTIME] = 0; | ||
| 34 | tcsetattr(0, TCSANOW, &tc); | ||
| 35 | } | ||
diff --git a/tools/perf/util/term.h b/tools/perf/util/term.h new file mode 100644 index 000000000000..2c06a61846a1 --- /dev/null +++ b/tools/perf/util/term.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef __PERF_TERM_H | ||
| 2 | #define __PERF_TERM_H | ||
| 3 | |||
| 4 | struct termios; | ||
| 5 | struct winsize; | ||
| 6 | |||
| 7 | void get_term_dimensions(struct winsize *ws); | ||
| 8 | void set_term_quiet_input(struct termios *old); | ||
| 9 | |||
| 10 | #endif /* __PERF_TERM_H */ | ||
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 0a9ae8014729..dfd00c6dad6e 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
| @@ -19,8 +19,10 @@ int thread__init_map_groups(struct thread *thread, struct machine *machine) | |||
| 19 | thread->mg = map_groups__new(machine); | 19 | thread->mg = map_groups__new(machine); |
| 20 | } else { | 20 | } else { |
| 21 | leader = __machine__findnew_thread(machine, pid, pid); | 21 | leader = __machine__findnew_thread(machine, pid, pid); |
| 22 | if (leader) | 22 | if (leader) { |
| 23 | thread->mg = map_groups__get(leader->mg); | 23 | thread->mg = map_groups__get(leader->mg); |
| 24 | thread__put(leader); | ||
| 25 | } | ||
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | return thread->mg ? 0 : -1; | 28 | return thread->mg ? 0 : -1; |
| @@ -53,7 +55,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) | |||
| 53 | goto err_thread; | 55 | goto err_thread; |
| 54 | 56 | ||
| 55 | list_add(&comm->list, &thread->comm_list); | 57 | list_add(&comm->list, &thread->comm_list); |
| 56 | atomic_set(&thread->refcnt, 0); | 58 | atomic_set(&thread->refcnt, 1); |
| 57 | RB_CLEAR_NODE(&thread->rb_node); | 59 | RB_CLEAR_NODE(&thread->rb_node); |
| 58 | } | 60 | } |
| 59 | 61 | ||
| @@ -95,6 +97,10 @@ struct thread *thread__get(struct thread *thread) | |||
| 95 | void thread__put(struct thread *thread) | 97 | void thread__put(struct thread *thread) |
| 96 | { | 98 | { |
| 97 | if (thread && atomic_dec_and_test(&thread->refcnt)) { | 99 | if (thread && atomic_dec_and_test(&thread->refcnt)) { |
| 100 | /* | ||
| 101 | * Remove it from the dead_threads list, as last reference | ||
| 102 | * is gone. | ||
| 103 | */ | ||
| 98 | list_del_init(&thread->node); | 104 | list_del_init(&thread->node); |
| 99 | thread__delete(thread); | 105 | thread__delete(thread); |
| 100 | } | 106 | } |
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 6ec3c5ca438f..08afc6909953 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "thread_map.h" | 13 | #include "thread_map.h" |
| 14 | #include "util.h" | 14 | #include "util.h" |
| 15 | #include "debug.h" | 15 | #include "debug.h" |
| 16 | #include "event.h" | ||
| 16 | 17 | ||
| 17 | /* Skip "." and ".." directories */ | 18 | /* Skip "." and ".." directories */ |
| 18 | static int filter(const struct dirent *dir) | 19 | static int filter(const struct dirent *dir) |
| @@ -304,6 +305,7 @@ out: | |||
| 304 | 305 | ||
| 305 | out_free_threads: | 306 | out_free_threads: |
| 306 | zfree(&threads); | 307 | zfree(&threads); |
| 308 | strlist__delete(slist); | ||
| 307 | goto out; | 309 | goto out; |
| 308 | } | 310 | } |
| 309 | 311 | ||
| @@ -408,3 +410,29 @@ void thread_map__read_comms(struct thread_map *threads) | |||
| 408 | for (i = 0; i < threads->nr; ++i) | 410 | for (i = 0; i < threads->nr; ++i) |
| 409 | comm_init(threads, i); | 411 | comm_init(threads, i); |
| 410 | } | 412 | } |
| 413 | |||
| 414 | static void thread_map__copy_event(struct thread_map *threads, | ||
| 415 | struct thread_map_event *event) | ||
| 416 | { | ||
| 417 | unsigned i; | ||
| 418 | |||
| 419 | threads->nr = (int) event->nr; | ||
| 420 | |||
| 421 | for (i = 0; i < event->nr; i++) { | ||
| 422 | thread_map__set_pid(threads, i, (pid_t) event->entries[i].pid); | ||
| 423 | threads->map[i].comm = strndup(event->entries[i].comm, 16); | ||
| 424 | } | ||
| 425 | |||
| 426 | atomic_set(&threads->refcnt, 1); | ||
| 427 | } | ||
| 428 | |||
| 429 | struct thread_map *thread_map__new_event(struct thread_map_event *event) | ||
| 430 | { | ||
| 431 | struct thread_map *threads; | ||
| 432 | |||
| 433 | threads = thread_map__alloc(event->nr); | ||
| 434 | if (threads) | ||
| 435 | thread_map__copy_event(threads, event); | ||
| 436 | |||
| 437 | return threads; | ||
| 438 | } | ||
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h index af679d8a50f8..85e4c7c4fbde 100644 --- a/tools/perf/util/thread_map.h +++ b/tools/perf/util/thread_map.h | |||
| @@ -16,11 +16,14 @@ struct thread_map { | |||
| 16 | struct thread_map_data map[]; | 16 | struct thread_map_data map[]; |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | struct thread_map_event; | ||
| 20 | |||
| 19 | struct thread_map *thread_map__new_dummy(void); | 21 | struct thread_map *thread_map__new_dummy(void); |
| 20 | struct thread_map *thread_map__new_by_pid(pid_t pid); | 22 | struct thread_map *thread_map__new_by_pid(pid_t pid); |
| 21 | struct thread_map *thread_map__new_by_tid(pid_t tid); | 23 | struct thread_map *thread_map__new_by_tid(pid_t tid); |
| 22 | struct thread_map *thread_map__new_by_uid(uid_t uid); | 24 | struct thread_map *thread_map__new_by_uid(uid_t uid); |
| 23 | struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid); | 25 | struct thread_map *thread_map__new(pid_t pid, pid_t tid, uid_t uid); |
| 26 | struct thread_map *thread_map__new_event(struct thread_map_event *event); | ||
| 24 | 27 | ||
| 25 | struct thread_map *thread_map__get(struct thread_map *map); | 28 | struct thread_map *thread_map__get(struct thread_map *map); |
| 26 | void thread_map__put(struct thread_map *map); | 29 | void thread_map__put(struct thread_map *map); |
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h index cab8cc24831b..55de4cffcd4e 100644 --- a/tools/perf/util/tool.h +++ b/tools/perf/util/tool.h | |||
| @@ -50,12 +50,18 @@ struct perf_tool { | |||
| 50 | throttle, | 50 | throttle, |
| 51 | unthrottle; | 51 | unthrottle; |
| 52 | event_attr_op attr; | 52 | event_attr_op attr; |
| 53 | event_attr_op event_update; | ||
| 53 | event_op2 tracing_data; | 54 | event_op2 tracing_data; |
| 54 | event_oe finished_round; | 55 | event_oe finished_round; |
| 55 | event_op2 build_id, | 56 | event_op2 build_id, |
| 56 | id_index, | 57 | id_index, |
| 57 | auxtrace_info, | 58 | auxtrace_info, |
| 58 | auxtrace_error; | 59 | auxtrace_error, |
| 60 | thread_map, | ||
| 61 | cpu_map, | ||
| 62 | stat_config, | ||
| 63 | stat, | ||
| 64 | stat_round; | ||
| 59 | event_op3 auxtrace; | 65 | event_op3 auxtrace; |
| 60 | bool ordered_events; | 66 | bool ordered_events; |
| 61 | bool ordering_requires_timestamps; | 67 | bool ordering_requires_timestamps; |
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index 8ff7d620d942..33b52eaa39db 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
| @@ -209,7 +209,7 @@ static const struct flag flags[] = { | |||
| 209 | { "NET_TX_SOFTIRQ", 2 }, | 209 | { "NET_TX_SOFTIRQ", 2 }, |
| 210 | { "NET_RX_SOFTIRQ", 3 }, | 210 | { "NET_RX_SOFTIRQ", 3 }, |
| 211 | { "BLOCK_SOFTIRQ", 4 }, | 211 | { "BLOCK_SOFTIRQ", 4 }, |
| 212 | { "BLOCK_IOPOLL_SOFTIRQ", 5 }, | 212 | { "IRQ_POLL_SOFTIRQ", 5 }, |
| 213 | { "TASKLET_SOFTIRQ", 6 }, | 213 | { "TASKLET_SOFTIRQ", 6 }, |
| 214 | { "SCHED_SOFTIRQ", 7 }, | 214 | { "SCHED_SOFTIRQ", 7 }, |
| 215 | { "HRTIMER_SOFTIRQ", 8 }, | 215 | { "HRTIMER_SOFTIRQ", 8 }, |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index b85ee55cca0c..bce5b1dac268 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
| @@ -65,6 +65,7 @@ int tracing_data_put(struct tracing_data *tdata); | |||
| 65 | struct addr_location; | 65 | struct addr_location; |
| 66 | 66 | ||
| 67 | struct perf_session; | 67 | struct perf_session; |
| 68 | struct perf_stat_config; | ||
| 68 | 69 | ||
| 69 | struct scripting_ops { | 70 | struct scripting_ops { |
| 70 | const char *name; | 71 | const char *name; |
| @@ -75,6 +76,9 @@ struct scripting_ops { | |||
| 75 | struct perf_sample *sample, | 76 | struct perf_sample *sample, |
| 76 | struct perf_evsel *evsel, | 77 | struct perf_evsel *evsel, |
| 77 | struct addr_location *al); | 78 | struct addr_location *al); |
| 79 | void (*process_stat)(struct perf_stat_config *config, | ||
| 80 | struct perf_evsel *evsel, u64 tstamp); | ||
| 81 | void (*process_stat_interval)(u64 tstamp); | ||
| 78 | int (*generate_script) (struct pevent *pevent, const char *outfile); | 82 | int (*generate_script) (struct pevent *pevent, const char *outfile); |
| 79 | }; | 83 | }; |
| 80 | 84 | ||
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 2dcfe9a7c8d0..cf5e250bc78e 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
| 12 | #include "event.h" | 12 | #include "event.h" |
| 13 | #include "perf_regs.h" | 13 | #include "perf_regs.h" |
| 14 | #include "callchain.h" | ||
| 14 | 15 | ||
| 15 | static char *debuginfo_path; | 16 | static char *debuginfo_path; |
| 16 | 17 | ||
| @@ -52,25 +53,28 @@ static int report_module(u64 ip, struct unwind_info *ui) | |||
| 52 | return __report_module(&al, ip, ui); | 53 | return __report_module(&al, ip, ui); |
| 53 | } | 54 | } |
| 54 | 55 | ||
| 56 | /* | ||
| 57 | * Store all entries within entries array, | ||
| 58 | * we will process it after we finish unwind. | ||
| 59 | */ | ||
| 55 | static int entry(u64 ip, struct unwind_info *ui) | 60 | static int entry(u64 ip, struct unwind_info *ui) |
| 56 | 61 | ||
| 57 | { | 62 | { |
| 58 | struct unwind_entry e; | 63 | struct unwind_entry *e = &ui->entries[ui->idx++]; |
| 59 | struct addr_location al; | 64 | struct addr_location al; |
| 60 | 65 | ||
| 61 | if (__report_module(&al, ip, ui)) | 66 | if (__report_module(&al, ip, ui)) |
| 62 | return -1; | 67 | return -1; |
| 63 | 68 | ||
| 64 | e.ip = ip; | 69 | e->ip = ip; |
| 65 | e.map = al.map; | 70 | e->map = al.map; |
| 66 | e.sym = al.sym; | 71 | e->sym = al.sym; |
| 67 | 72 | ||
| 68 | pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n", | 73 | pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n", |
| 69 | al.sym ? al.sym->name : "''", | 74 | al.sym ? al.sym->name : "''", |
| 70 | ip, | 75 | ip, |
| 71 | al.map ? al.map->map_ip(al.map, ip) : (u64) 0); | 76 | al.map ? al.map->map_ip(al.map, ip) : (u64) 0); |
| 72 | 77 | return 0; | |
| 73 | return ui->cb(&e, ui->arg); | ||
| 74 | } | 78 | } |
| 75 | 79 | ||
| 76 | static pid_t next_thread(Dwfl *dwfl, void *arg, void **thread_argp) | 80 | static pid_t next_thread(Dwfl *dwfl, void *arg, void **thread_argp) |
| @@ -92,6 +96,16 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr, | |||
| 92 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 96 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, |
| 93 | MAP__FUNCTION, addr, &al); | 97 | MAP__FUNCTION, addr, &al); |
| 94 | if (!al.map) { | 98 | if (!al.map) { |
| 99 | /* | ||
| 100 | * We've seen cases (softice) where DWARF unwinder went | ||
| 101 | * through non executable mmaps, which we need to lookup | ||
| 102 | * in MAP__VARIABLE tree. | ||
| 103 | */ | ||
| 104 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | ||
| 105 | MAP__VARIABLE, addr, &al); | ||
| 106 | } | ||
| 107 | |||
| 108 | if (!al.map) { | ||
| 95 | pr_debug("unwind: no map for %lx\n", (unsigned long)addr); | 109 | pr_debug("unwind: no map for %lx\n", (unsigned long)addr); |
| 96 | return -1; | 110 | return -1; |
| 97 | } | 111 | } |
| @@ -168,7 +182,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | |||
| 168 | struct perf_sample *data, | 182 | struct perf_sample *data, |
| 169 | int max_stack) | 183 | int max_stack) |
| 170 | { | 184 | { |
| 171 | struct unwind_info ui = { | 185 | struct unwind_info *ui, ui_buf = { |
| 172 | .sample = data, | 186 | .sample = data, |
| 173 | .thread = thread, | 187 | .thread = thread, |
| 174 | .machine = thread->mg->machine, | 188 | .machine = thread->mg->machine, |
| @@ -177,35 +191,54 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | |||
| 177 | .max_stack = max_stack, | 191 | .max_stack = max_stack, |
| 178 | }; | 192 | }; |
| 179 | Dwarf_Word ip; | 193 | Dwarf_Word ip; |
| 180 | int err = -EINVAL; | 194 | int err = -EINVAL, i; |
| 181 | 195 | ||
| 182 | if (!data->user_regs.regs) | 196 | if (!data->user_regs.regs) |
| 183 | return -EINVAL; | 197 | return -EINVAL; |
| 184 | 198 | ||
| 185 | ui.dwfl = dwfl_begin(&offline_callbacks); | 199 | ui = zalloc(sizeof(ui_buf) + sizeof(ui_buf.entries[0]) * max_stack); |
| 186 | if (!ui.dwfl) | 200 | if (!ui) |
| 201 | return -ENOMEM; | ||
| 202 | |||
| 203 | *ui = ui_buf; | ||
| 204 | |||
| 205 | ui->dwfl = dwfl_begin(&offline_callbacks); | ||
| 206 | if (!ui->dwfl) | ||
| 187 | goto out; | 207 | goto out; |
| 188 | 208 | ||
| 189 | err = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP); | 209 | err = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP); |
| 190 | if (err) | 210 | if (err) |
| 191 | goto out; | 211 | goto out; |
| 192 | 212 | ||
| 193 | err = report_module(ip, &ui); | 213 | err = report_module(ip, ui); |
| 194 | if (err) | 214 | if (err) |
| 195 | goto out; | 215 | goto out; |
| 196 | 216 | ||
| 197 | if (!dwfl_attach_state(ui.dwfl, EM_NONE, thread->tid, &callbacks, &ui)) | 217 | if (!dwfl_attach_state(ui->dwfl, EM_NONE, thread->tid, &callbacks, ui)) |
| 198 | goto out; | 218 | goto out; |
| 199 | 219 | ||
| 200 | err = dwfl_getthread_frames(ui.dwfl, thread->tid, frame_callback, &ui); | 220 | err = dwfl_getthread_frames(ui->dwfl, thread->tid, frame_callback, ui); |
| 201 | 221 | ||
| 202 | if (err && !ui.max_stack) | 222 | if (err && !ui->max_stack) |
| 203 | err = 0; | 223 | err = 0; |
| 204 | 224 | ||
| 225 | /* | ||
| 226 | * Display what we got based on the order setup. | ||
| 227 | */ | ||
| 228 | for (i = 0; i < ui->idx && !err; i++) { | ||
| 229 | int j = i; | ||
| 230 | |||
| 231 | if (callchain_param.order == ORDER_CALLER) | ||
| 232 | j = ui->idx - i - 1; | ||
| 233 | |||
| 234 | err = ui->entries[j].ip ? ui->cb(&ui->entries[j], ui->arg) : 0; | ||
| 235 | } | ||
| 236 | |||
| 205 | out: | 237 | out: |
| 206 | if (err) | 238 | if (err) |
| 207 | pr_debug("unwind: failed with '%s'\n", dwfl_errmsg(-1)); | 239 | pr_debug("unwind: failed with '%s'\n", dwfl_errmsg(-1)); |
| 208 | 240 | ||
| 209 | dwfl_end(ui.dwfl); | 241 | dwfl_end(ui->dwfl); |
| 242 | free(ui); | ||
| 210 | return 0; | 243 | return 0; |
| 211 | } | 244 | } |
diff --git a/tools/perf/util/unwind-libdw.h b/tools/perf/util/unwind-libdw.h index 417a1426f3ad..58328669ed16 100644 --- a/tools/perf/util/unwind-libdw.h +++ b/tools/perf/util/unwind-libdw.h | |||
| @@ -16,6 +16,8 @@ struct unwind_info { | |||
| 16 | unwind_entry_cb_t cb; | 16 | unwind_entry_cb_t cb; |
| 17 | void *arg; | 17 | void *arg; |
| 18 | int max_stack; | 18 | int max_stack; |
| 19 | int idx; | ||
| 20 | struct unwind_entry entries[]; | ||
| 19 | }; | 21 | }; |
| 20 | 22 | ||
| 21 | #endif /* __PERF_UNWIND_LIBDW_H */ | 23 | #endif /* __PERF_UNWIND_LIBDW_H */ |
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c index c83832b555e5..ee7e372297e5 100644 --- a/tools/perf/util/unwind-libunwind.c +++ b/tools/perf/util/unwind-libunwind.c | |||
| @@ -319,6 +319,15 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui) | |||
| 319 | 319 | ||
| 320 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 320 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, |
| 321 | MAP__FUNCTION, ip, &al); | 321 | MAP__FUNCTION, ip, &al); |
| 322 | if (!al.map) { | ||
| 323 | /* | ||
| 324 | * We've seen cases (softice) where DWARF unwinder went | ||
| 325 | * through non executable mmaps, which we need to lookup | ||
| 326 | * in MAP__VARIABLE tree. | ||
| 327 | */ | ||
| 328 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | ||
| 329 | MAP__VARIABLE, ip, &al); | ||
| 330 | } | ||
| 322 | return al.map; | 331 | return al.map; |
| 323 | } | 332 | } |
| 324 | 333 | ||
| @@ -416,20 +425,19 @@ get_proc_name(unw_addr_space_t __maybe_unused as, | |||
| 416 | static int access_dso_mem(struct unwind_info *ui, unw_word_t addr, | 425 | static int access_dso_mem(struct unwind_info *ui, unw_word_t addr, |
| 417 | unw_word_t *data) | 426 | unw_word_t *data) |
| 418 | { | 427 | { |
| 419 | struct addr_location al; | 428 | struct map *map; |
| 420 | ssize_t size; | 429 | ssize_t size; |
| 421 | 430 | ||
| 422 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 431 | map = find_map(addr, ui); |
| 423 | MAP__FUNCTION, addr, &al); | 432 | if (!map) { |
| 424 | if (!al.map) { | ||
| 425 | pr_debug("unwind: no map for %lx\n", (unsigned long)addr); | 433 | pr_debug("unwind: no map for %lx\n", (unsigned long)addr); |
| 426 | return -1; | 434 | return -1; |
| 427 | } | 435 | } |
| 428 | 436 | ||
| 429 | if (!al.map->dso) | 437 | if (!map->dso) |
| 430 | return -1; | 438 | return -1; |
| 431 | 439 | ||
| 432 | size = dso__data_read_addr(al.map->dso, al.map, ui->machine, | 440 | size = dso__data_read_addr(map->dso, map, ui->machine, |
| 433 | addr, (u8 *) data, sizeof(*data)); | 441 | addr, (u8 *) data, sizeof(*data)); |
| 434 | 442 | ||
| 435 | return !(size == sizeof(*data)); | 443 | return !(size == sizeof(*data)); |
| @@ -614,23 +622,48 @@ void unwind__finish_access(struct thread *thread) | |||
| 614 | static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, | 622 | static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, |
| 615 | void *arg, int max_stack) | 623 | void *arg, int max_stack) |
| 616 | { | 624 | { |
| 625 | u64 val; | ||
| 626 | unw_word_t ips[max_stack]; | ||
| 617 | unw_addr_space_t addr_space; | 627 | unw_addr_space_t addr_space; |
| 618 | unw_cursor_t c; | 628 | unw_cursor_t c; |
| 619 | int ret; | 629 | int ret, i = 0; |
| 620 | |||
| 621 | addr_space = thread__priv(ui->thread); | ||
| 622 | if (addr_space == NULL) | ||
| 623 | return -1; | ||
| 624 | 630 | ||
| 625 | ret = unw_init_remote(&c, addr_space, ui); | 631 | ret = perf_reg_value(&val, &ui->sample->user_regs, PERF_REG_IP); |
| 626 | if (ret) | 632 | if (ret) |
| 627 | display_error(ret); | 633 | return ret; |
| 628 | 634 | ||
| 629 | while (!ret && (unw_step(&c) > 0) && max_stack--) { | 635 | ips[i++] = (unw_word_t) val; |
| 630 | unw_word_t ip; | ||
| 631 | 636 | ||
| 632 | unw_get_reg(&c, UNW_REG_IP, &ip); | 637 | /* |
| 633 | ret = ip ? entry(ip, ui->thread, cb, arg) : 0; | 638 | * If we need more than one entry, do the DWARF |
| 639 | * unwind itself. | ||
| 640 | */ | ||
| 641 | if (max_stack - 1 > 0) { | ||
| 642 | addr_space = thread__priv(ui->thread); | ||
| 643 | if (addr_space == NULL) | ||
| 644 | return -1; | ||
| 645 | |||
| 646 | ret = unw_init_remote(&c, addr_space, ui); | ||
| 647 | if (ret) | ||
| 648 | display_error(ret); | ||
| 649 | |||
| 650 | while (!ret && (unw_step(&c) > 0) && i < max_stack) { | ||
| 651 | unw_get_reg(&c, UNW_REG_IP, &ips[i]); | ||
| 652 | ++i; | ||
| 653 | } | ||
| 654 | |||
| 655 | max_stack = i; | ||
| 656 | } | ||
| 657 | |||
| 658 | /* | ||
| 659 | * Display what we got based on the order setup. | ||
| 660 | */ | ||
| 661 | for (i = 0; i < max_stack && !ret; i++) { | ||
| 662 | int j = i; | ||
| 663 | |||
| 664 | if (callchain_param.order == ORDER_CALLER) | ||
| 665 | j = max_stack - i - 1; | ||
| 666 | ret = ips[j] ? entry(ips[j], ui->thread, cb, arg) : 0; | ||
| 634 | } | 667 | } |
| 635 | 668 | ||
| 636 | return ret; | 669 | return ret; |
| @@ -640,24 +673,17 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg, | |||
| 640 | struct thread *thread, | 673 | struct thread *thread, |
| 641 | struct perf_sample *data, int max_stack) | 674 | struct perf_sample *data, int max_stack) |
| 642 | { | 675 | { |
| 643 | u64 ip; | ||
| 644 | struct unwind_info ui = { | 676 | struct unwind_info ui = { |
| 645 | .sample = data, | 677 | .sample = data, |
| 646 | .thread = thread, | 678 | .thread = thread, |
| 647 | .machine = thread->mg->machine, | 679 | .machine = thread->mg->machine, |
| 648 | }; | 680 | }; |
| 649 | int ret; | ||
| 650 | 681 | ||
| 651 | if (!data->user_regs.regs) | 682 | if (!data->user_regs.regs) |
| 652 | return -EINVAL; | 683 | return -EINVAL; |
| 653 | 684 | ||
| 654 | ret = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP); | 685 | if (max_stack <= 0) |
| 655 | if (ret) | 686 | return -EINVAL; |
| 656 | return ret; | ||
| 657 | |||
| 658 | ret = entry(ip, thread, cb, arg); | ||
| 659 | if (ret) | ||
| 660 | return -ENOMEM; | ||
| 661 | 687 | ||
| 662 | return --max_stack > 0 ? get_entries(&ui, cb, arg, max_stack) : 0; | 688 | return get_entries(&ui, cb, arg, max_stack); |
| 663 | } | 689 | } |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 47b1e36c7ea0..ead9509835d2 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
| @@ -16,12 +16,14 @@ | |||
| 16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
| 17 | #include <unistd.h> | 17 | #include <unistd.h> |
| 18 | #include "callchain.h" | 18 | #include "callchain.h" |
| 19 | #include "strlist.h" | ||
| 19 | 20 | ||
| 20 | struct callchain_param callchain_param = { | 21 | struct callchain_param callchain_param = { |
| 21 | .mode = CHAIN_GRAPH_ABS, | 22 | .mode = CHAIN_GRAPH_ABS, |
| 22 | .min_percent = 0.5, | 23 | .min_percent = 0.5, |
| 23 | .order = ORDER_CALLEE, | 24 | .order = ORDER_CALLEE, |
| 24 | .key = CCKEY_FUNCTION | 25 | .key = CCKEY_FUNCTION, |
| 26 | .value = CCVAL_PERCENT, | ||
| 25 | }; | 27 | }; |
| 26 | 28 | ||
| 27 | /* | 29 | /* |
| @@ -351,41 +353,8 @@ void sighandler_dump_stack(int sig) | |||
| 351 | { | 353 | { |
| 352 | psignal(sig, "perf"); | 354 | psignal(sig, "perf"); |
| 353 | dump_stack(); | 355 | dump_stack(); |
| 354 | exit(sig); | 356 | signal(sig, SIG_DFL); |
| 355 | } | 357 | raise(sig); |
| 356 | |||
| 357 | void get_term_dimensions(struct winsize *ws) | ||
| 358 | { | ||
| 359 | char *s = getenv("LINES"); | ||
| 360 | |||
| 361 | if (s != NULL) { | ||
| 362 | ws->ws_row = atoi(s); | ||
| 363 | s = getenv("COLUMNS"); | ||
| 364 | if (s != NULL) { | ||
| 365 | ws->ws_col = atoi(s); | ||
| 366 | if (ws->ws_row && ws->ws_col) | ||
| 367 | return; | ||
| 368 | } | ||
| 369 | } | ||
| 370 | #ifdef TIOCGWINSZ | ||
| 371 | if (ioctl(1, TIOCGWINSZ, ws) == 0 && | ||
| 372 | ws->ws_row && ws->ws_col) | ||
| 373 | return; | ||
| 374 | #endif | ||
| 375 | ws->ws_row = 25; | ||
| 376 | ws->ws_col = 80; | ||
| 377 | } | ||
| 378 | |||
| 379 | void set_term_quiet_input(struct termios *old) | ||
| 380 | { | ||
| 381 | struct termios tc; | ||
| 382 | |||
| 383 | tcgetattr(0, old); | ||
| 384 | tc = *old; | ||
| 385 | tc.c_lflag &= ~(ICANON | ECHO); | ||
| 386 | tc.c_cc[VMIN] = 0; | ||
| 387 | tc.c_cc[VTIME] = 0; | ||
| 388 | tcsetattr(0, TCSANOW, &tc); | ||
| 389 | } | 358 | } |
| 390 | 359 | ||
| 391 | int parse_nsec_time(const char *str, u64 *ptime) | 360 | int parse_nsec_time(const char *str, u64 *ptime) |
| @@ -695,3 +664,30 @@ fetch_kernel_version(unsigned int *puint, char *str, | |||
| 695 | *puint = (version << 16) + (patchlevel << 8) + sublevel; | 664 | *puint = (version << 16) + (patchlevel << 8) + sublevel; |
| 696 | return 0; | 665 | return 0; |
| 697 | } | 666 | } |
| 667 | |||
| 668 | const char *perf_tip(const char *dirpath) | ||
| 669 | { | ||
| 670 | struct strlist *tips; | ||
| 671 | struct str_node *node; | ||
| 672 | char *tip = NULL; | ||
| 673 | struct strlist_config conf = { | ||
| 674 | .dirname = dirpath, | ||
| 675 | .file_only = true, | ||
| 676 | }; | ||
| 677 | |||
| 678 | tips = strlist__new("tips.txt", &conf); | ||
| 679 | if (tips == NULL) | ||
| 680 | return errno == ENOENT ? NULL : "Tip: get more memory! ;-p"; | ||
| 681 | |||
| 682 | if (strlist__nr_entries(tips) == 0) | ||
| 683 | goto out; | ||
| 684 | |||
| 685 | node = strlist__entry(tips, random() % strlist__nr_entries(tips)); | ||
| 686 | if (asprintf(&tip, "Tip: %s", node->s) < 0) | ||
| 687 | tip = (char *)"Tip: get more memory! ;-)"; | ||
| 688 | |||
| 689 | out: | ||
| 690 | strlist__delete(tips); | ||
| 691 | |||
| 692 | return tip; | ||
| 693 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index dcc659017976..fe915e616f9b 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | #include <stdlib.h> | 53 | #include <stdlib.h> |
| 54 | #include <stdarg.h> | 54 | #include <stdarg.h> |
| 55 | #include <string.h> | 55 | #include <string.h> |
| 56 | #include <term.h> | ||
| 56 | #include <errno.h> | 57 | #include <errno.h> |
| 57 | #include <limits.h> | 58 | #include <limits.h> |
| 58 | #include <sys/param.h> | 59 | #include <sys/param.h> |
| @@ -150,12 +151,6 @@ extern void set_warning_routine(void (*routine)(const char *err, va_list params) | |||
| 150 | extern int prefixcmp(const char *str, const char *prefix); | 151 | extern int prefixcmp(const char *str, const char *prefix); |
| 151 | extern void set_buildid_dir(const char *dir); | 152 | extern void set_buildid_dir(const char *dir); |
| 152 | 153 | ||
| 153 | static inline const char *skip_prefix(const char *str, const char *prefix) | ||
| 154 | { | ||
| 155 | size_t len = strlen(prefix); | ||
| 156 | return strncmp(str, prefix, len) ? NULL : str + len; | ||
| 157 | } | ||
| 158 | |||
| 159 | #ifdef __GLIBC_PREREQ | 154 | #ifdef __GLIBC_PREREQ |
| 160 | #if __GLIBC_PREREQ(2, 1) | 155 | #if __GLIBC_PREREQ(2, 1) |
| 161 | #define HAVE_STRCHRNUL | 156 | #define HAVE_STRCHRNUL |
| @@ -186,14 +181,6 @@ static inline void *zalloc(size_t size) | |||
| 186 | 181 | ||
| 187 | #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) | 182 | #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) |
| 188 | 183 | ||
| 189 | static inline int has_extension(const char *filename, const char *ext) | ||
| 190 | { | ||
| 191 | size_t len = strlen(filename); | ||
| 192 | size_t extlen = strlen(ext); | ||
| 193 | |||
| 194 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); | ||
| 195 | } | ||
| 196 | |||
| 197 | /* Sane ctype - no locale, and works with signed chars */ | 184 | /* Sane ctype - no locale, and works with signed chars */ |
| 198 | #undef isascii | 185 | #undef isascii |
| 199 | #undef isspace | 186 | #undef isspace |
| @@ -282,9 +269,6 @@ void sighandler_dump_stack(int sig); | |||
| 282 | extern unsigned int page_size; | 269 | extern unsigned int page_size; |
| 283 | extern int cacheline_size; | 270 | extern int cacheline_size; |
| 284 | 271 | ||
| 285 | void get_term_dimensions(struct winsize *ws); | ||
| 286 | void set_term_quiet_input(struct termios *old); | ||
| 287 | |||
| 288 | struct parse_tag { | 272 | struct parse_tag { |
| 289 | char tag; | 273 | char tag; |
| 290 | int mult; | 274 | int mult; |
| @@ -358,4 +342,6 @@ int fetch_kernel_version(unsigned int *puint, | |||
| 358 | #define KVER_FMT "%d.%d.%d" | 342 | #define KVER_FMT "%d.%d.%d" |
| 359 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) | 343 | #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) |
| 360 | 344 | ||
| 345 | const char *perf_tip(const char *dirpath); | ||
| 346 | |||
| 361 | #endif /* GIT_COMPAT_UTIL_H */ | 347 | #endif /* GIT_COMPAT_UTIL_H */ |
