perf-report show value of CPU register

2019-05-24 23:16发布

问题:

I follow this document and using perf record with --intr-regs=ax,bx,r15, trying to log additional CPU register information with PEBS record.

But how do I view those info from perf.data? The original command is perf report, and it only shows a few fields such as overhead, command, shared object and symbol.

Is there any way to show CPU regs' value?

回答1:

Try perf script data dumping command with the iregs field: perf script -F ip,sym,iregs. All fields -F are documented with source code of tools/perf/builtin-script.c - struct output_option .. all_output_options, and iregs is still here (also OPT_CALLBACK('F', "fields" ... in same file). There is also perf-script.txt documentation - https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/perf-script.txt#L115

-F::
--fields::
    Comma separated list of fields to print. Options are:
    comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
    srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
    callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw,
    to indicate to which event type the field list applies.

There were commits into linux kernel git which mention flag --intr-regs. Start from option implementation:

https://github.com/torvalds/linux/search?utf8=%E2%9C%93&q=intr-regs&type=

tools/perf/builtin-record.c OPT_CALLBACK_OPTARG('I', "intr-regs", &record.opts.sample_intr_regs, NULL, "any register",

Then search for 'sample_intr_regs' in commits: https://github.com/torvalds/linux/search?q=sample_intr_regs&type=Commits

Several commits were about kernel part and perf_attr debug print. But this has example of intr-regs printing (Sep 1, 2015) https://github.com/torvalds/linux/commit/532026612455a4a6fd27c1b2e7111263f63218a2

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: - Add ability to specify to select which registers to record, to reduce the size of perf.data files, and also allow printing the registers in 'perf script': (Stephane Eranian)

  # perf record --intr-regs=AX,SP usleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.016 MB perf.data (8 samples) ]
  # perf script -F ip,sym,iregs | tail -5
   ffffffff8105f42a native_write_msr_safe   AX:0xf    SP:0xffff8802629c3c00
   ffffffff8105f42a native_write_msr_safe   AX:0xf    SP:0xffff8802629c3c00
   ffffffff81761ac0 _raw_spin_lock   AX:0xffff8801bfcf8020    SP:0xffff8802629c3ce8
   ffffffff81202bf8 __vma_adjust_trans_huge   AX:0x7ffc75200000    SP:0xffff8802629c3b30
   ffffffff8122b089 dput   AX:0x101    SP:0xffff8802629c3c78
  #


回答2:

I find a way to achieve it by using perf report -D, and then find the registers' name which you need for record by record (but this seems to be very inefficient..).

Or someone else can provide a more streamlined approach?