From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751530AbdK1FbH (ORCPT ); Tue, 28 Nov 2017 00:31:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:34110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750850AbdK1FbF (ORCPT ); Tue, 28 Nov 2017 00:31:05 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AC6D21909 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org Date: Tue, 28 Nov 2017 14:31:00 +0900 From: Masami Hiramatsu To: Andi Kleen Cc: acme@kernel.org, jolsa@kernel.org, mhiramat@kernel.org, adrian.hunter@intel.com, linux-kernel@vger.kernel.org Subject: Re: Implement dwarf variable/type resolving for perf script Message-Id: <20171128143100.e23ce8a6a592bbb1b51cda19@kernel.org> In-Reply-To: <20171128002321.2878-1-andi@firstfloor.org> References: <20171128002321.2878-1-andi@firstfloor.org> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andi, On Mon, 27 Nov 2017 16:23:09 -0800 Andi Kleen wrote: > This patchkit extends perf script to query dwarf information for variable > names or types/structure fields accessed from code. Very interesting! so it is a kind of revert query interface. > > The dwarf resolution is all on top of Masami's perf probe dwarf code. > > It supports multiple use cases: > - When we sample registers it can use the dwarf information to resolve > the registers to names. > - When we sample any instruction the instruction can be decoded and > we can determine the type/struct field to make an estimate of the > memory access patterns in data structures. > - When we sample the new PTWRITE instruction the logged value from > the PT log can be associated with a variable. > - Various cleanups and fixes to make the one above all possible. OK, I'll review that. Thanks! > > It is all implemented with new output formats in perf script: > iregval (map register values to names) and insnvar (decode instruction > and map back memory operand to dwarf operation) > > There are some limitations, it cannot decode everything, and is > somewhat slow, but it's already quite useful for typical code > > > % perf record -Idi,si ./targ > % perf script -F +iregvals > ... > targ 8584 169763.761843: 2091795 cycles:ppp: 40041a main (targ) > targ 8584 169763.762520: 1913932 cycles:ppp: 400534 f1 (targ) { b = 0x2, int } { a = 0x1, int } > targ 8584 169763.763141: 1638913 cycles:ppp: 400523 f2 (targ) { b = 0x1, int } { a = 0x2, int } > targ 8584 169763.763672: 1516522 cycles:ppp: 400522 f2 (targ) { b = 0x1, int } { a = 0x2, int } > targ 8584 169763.764165: 1335501 cycles:ppp: 400523 f2 (targ) { b = 0x1, int } { a = 0x2, int } > targ 8584 169763.764598: 1253289 cycles:ppp: 400522 f2 (targ) { b = 0x2, int } { a = 0x1, int } > targ 8584 169763.765005: 1135131 cycles:ppp: 400534 f1 (targ) { b = 0x2, int } { a = 0x1, int } > targ 8584 169763.765373: 1080325 cycles:ppp: 400522 f2 (targ) { b = 0x2, int } { a = 0x1, int } > targ 8584 169763.765724: 1036999 cycles:ppp: 400522 f2 (targ) { b = 0x1, int } { a = 0x2, int } > targ 8584 169763.766061: 971213 cycles:ppp: 400534 f1 (targ) { b = 0x2, int } { a = 0x1, int } > > > % perf record -e intel_pt//u -a sleep 1 > % perf script --itrace=i0ns -F insnvar,insn,ip,sym -f 2>&1 | xed -F insn: -A -64 | less > ... > 4f7e61 xyarray__max_y pushq %rbp > 4f7e62 xyarray__max_y mov %rsp, %rbp > 4f7e65 xyarray__max_y sub $0x20, %rsp > 4f7e69 xyarray__max_y movq %rdi, -0x18(%rbp) { -24(xy), struct xyarray* } > 4f7e6d xyarray__max_y movq %fs:0x28, %rax > 4f7e76 xyarray__max_y movq %rax, -0x8(%rbp) { -8(xy), struct xyarray* } > 4f7e7a xyarray__max_y xor %eax, %eax > 4f7e7c xyarray__max_y movq -0x18(%rbp), %rax { -24(xy), struct xyarray* } > 4f7e80 xyarray__max_y movq 0x20(%rax), %rax > 4f7e84 xyarray__max_y movq -0x8(%rbp), %rdx { -8(xy), struct xyarray* } > 4f7e88 xyarray__max_y xorq %fs:0x28, %rdx > 4f7e91 xyarray__max_y jz 0x7 > 4f7e98 xyarray__max_y leaveq > 4f7e99 xyarray__max_y retq > > In this example we now know that this function accesses two fields in struct xyarray * > > Available from > > git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc perf/var-resolve-2 > > v1: Initial post -- Masami Hiramatsu