Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Mar 2012 08:18:44 GMT
From:      Vitaly Magerya <vmagerya@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/165654: [patch] make /usr/sbin/pmcannotate work on amd64
Message-ID:  <201203030818.q238IinM006934@red.freebsd.org>
Resent-Message-ID: <201203030820.q238K9M8019298@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         165654
>Category:       bin
>Synopsis:       [patch] make /usr/sbin/pmcannotate work on amd64
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 03 08:20:09 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Vitaly Magerya
>Release:        FreeBSD 8.2-RELEASE amd64
>Organization:
>Environment:
>Description:
pmcannotate does not print out source code or assembly code on my
system. This seems to be caused by isasminline function at line 116
fail to recognize objdump source dump output: it expects the second
character of assembly line to be a hex number, while at least on
amd64 objdump seems to ident asm lines by two spaces.
>How-To-Repeat:
Create a simple C program:

  cat > test.c <<EOF
  int main() {
    int i;
    for (i = 1000000; i >= 0; i--);
    return i;
  }
  EOF

Compile it with debug info:
  cc -g -o test test.c

Load hwpmc module (if not already):
  kldload hwpmc

Collect statistics:
  pmcstat -O test.log -P instructions ./test

Now pmcannotate should show C source annotated with profile statistics:
  pmcannotate test.log test

.. or the same, but with disassembly:
  pmcannotate -a test.log test

In both cases I see output like this:
  [...]
  Profile trace for function: main() [81.48%]

  Profile trace for function: get_pv_entry() [3.70%]
  [...]

While I'd like to see something like this:
  [...]
  Profile trace for function: main() [81.48%]
           |   400530: 55                      push   %rbp
           |   400531: 48 89 e5                mov    %rsp,%rbp
           |   400534: c7 45 fc 40 42 0f 00    movl   $0xf4240,-4(%rbp)
           |   40053b: eb 04                   jmp    400541 <main+0x11>
   59.09%  |   40053d: 83 6d fc 01             subl   $0x1,-4(%rbp)
   22.73%  |   400541: 83 7d fc 00             cmpl   $0x0,-4(%rbp)
   18.18%  |   400545: 79 f6                   jns    40053d <main+0xd>
           |   400547: 8b 45 fc                mov    -4(%rbp),%eax
           |   40054a: c9                      leaveq
           |   40054b: c3                      retq
           |   40054c: 90                      nop

  Profile trace for function: get_pv_entry() [3.70%]
  [...]

Or like this (for C source annotation):
  [...]
  Profile trace for function: main() [81.48%]
          |   int main() {
  100.00% |     int i;
          |     for (i = 1000000; i >= 0; i--);
          |     return i;
          |   }
  [...]

(It annotates the wrong line when no-op lines are encountered; still 
better than no output).
>Fix:
Just remove the test for second character being a hex number. The 
sscanf call on the next line will check that anyway, but it will
skip any amount of spaces too.

Note that I only tested this on amd64.
I don't know how i386 is affected.

Patch attached with submission follows:

--- pmcannotate.c.orig	2012-03-03 09:16:30.000000000 +0200
+++ pmcannotate.c	2012-03-03 09:18:32.000000000 +0200
@@ -118,8 +118,6 @@
 	void *ptr;
 	int nbytes;
 
-	if (isxdigit(str[1]) == 0)
-		return (0);
 	if (sscanf(str, " %p%n", &ptr, &nbytes) != 1)
 		return (0);
 	if (str[nbytes] != ':' || isspace(str[nbytes + 1]) == 0)


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203030818.q238IinM006934>