linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: HOUSSEN Franck <fghoussen@gmail.com>
Cc: peterz@infradead.org, mingo@redhat.com,
	alexander.shishkin@linux.intel.com, namhyung@kernel.org,
	jolsa@kernel.org, penberg@kernel.org,
	linux-perf-users@vger.kernel.org
Subject: Re: can not trace function (main) with perf-probe
Date: Mon, 14 Nov 2016 11:55:36 -0300	[thread overview]
Message-ID: <20161114145536.GA24331@kernel.org> (raw)
In-Reply-To: <CABvthirHujJiKsYc_1Fq=sy9SoYzg0h9XyYGxe-LRf10YdXn8g@mail.gmail.com>

Em Sun, Nov 13, 2016 at 12:10:05PM +0100, HOUSSEN Franck escreveu:
> I can not trace the main function (hello world) with perf-probe.

You should send this to a list, like I'm doing now, not in private, I suggest
linux-perf-users@vger.kernel.org, info about it:

http://vger.kernel.org/vger-lists.html#linux-perf-users
 
> perf-report reports:
> # Overhead  Trace output
> # ........  ............
> #
>    100.00%  (563a994a56b
> Instead of the expected:
> # Overhead  Trace output
> # ........  ............
> #
>    100.00%  main

So, trying this:

[root@jouet c]# cat hello.c
#include <stdio.h>

int main(void)
{
	printf("hello, world\n");
	return 0;
}
[root@jouet c]# make hello
cc     hello.c   -o hello
[root@jouet c]# perf probe -x ./hello main
Added new event:
  probe_hello:main     (on main in /home/acme/c/hello)

You can now use it in all perf tools, such as:

	perf record -e probe_hello:main -aR sleep 1

[root@jouet c]# perf record -e probe_hello:main ./hello
hello, world
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.021 MB perf.data (1 samples) ]
[root@jouet c]# perf report --no-header --stdio
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 1  of event 'probe_hello:main'
# Event count (approx.): 1
#
# Overhead  Trace output
# ........  ............
#
   100.00%  (400526)


#
# (Tip: Create an archive with symtabs to analyse on other machine: perf archive)
#
[root@jouet c]# 


Reproduced, this ends up showing just the trace fields for this tracepoint:

[root@jouet c]# perf evlist --trace
probe_hello:main: trace_fields: __probe_ip
[root@jouet c]# perf script
           hello 26213 [003] 174431.417607: probe_hello:main: (400526)
[root@jouet c]# 

If we instead ask for dso,sym, as it is done for non-tracepoint events, we'd get:

[root@jouet c]# perf report --no-header --stdio -s dso,sym
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 1  of event 'probe_hello:main'
# Event count (approx.): 1
#
# Overhead  Shared Object  Symbol  
# ........  .............  ........
#
   100.00%  hello          [.] main

You can get both with:

[root@jouet c]# perf report --no-header --stdio -s dso,sym,trace
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 1  of event 'probe_hello:main'
# Event count (approx.): 1
#
# Overhead  Shared Object  Symbol    Trace output
# ........  .............  ........  ............
#
   100.00%  hello          [.] main  (400526)


[root@jouet c]#

Please look at the --sort/-s docs for further information:

[root@jouet c]# perf report -h -s

 Usage: perf report [<options>]

    -s, --sort <key[,key2...]>
                          sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ... Please refer the man page for the complete list.

[root@jouet c]# 

Some other example:

[root@jouet c]# perf report --no-header --stdio -s dso,sym,pid,cpu
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 1  of event 'probe_hello:main'
# Event count (approx.): 1
#
# Overhead  Shared Object  Symbol        Pid:Command  CPU
# ........  .............  ........  ...............  ...
#
   100.00%  hello          [.] main    26213:hello    003


[root@jouet c]#

- Arnaldo

 
> I use perf record/report with other events and I get some reports with
> expected symbols (= name of functions instead of their memory
> address).
> 
> Did I miss something when using perf-probe or perf-record / perf-report ?
> 
> Franck
> 
> /tmp> more main.cpp
> #include <unistd.h> // sleep
> int main(void) { sleep(10); return 0; }
> 
> /tmp> gcc -g main.cpp -o main
> 
> /tmp> sudo perf probe --exec ./main --add main
> Added new event:
>   probe_main:main      (on main in /tmp/main)
>   You can now use it in all perf tools, such as:
>     perf record -e probe_main:main -aR sleep 1
> 
> /tmp> sudo perf record -e probe_main:main ./main
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.017 MB perf.data (1 samples) ]
> 
> /tmp> sudo perf report --stdio
> # To display the perf.data header info, please use
> --header/--header-only options.
> #
> #
> # Total Lost Samples: 0
> #
> # Samples: 1  of event 'probe_main:main'
> # Event count (approx.): 1
> #
> # Overhead  Trace output
> # ........  ............
> #
>    100.00%  (563a994a56b
> #
> # (Tip: List events using substring match: perf list <keyword>)
> #
> 
> ~> lsb_release -a
> No LSB modules are available.
> Distributor ID: Debian
> Description:  Debian GNU/Linux testing (stretch)
> Release:  testing
> Codename: stretch
> 
> ~> cat /proc/sys/kernel/perf_event_paranoid
> -1
> 
> ~> cat /proc/sys/kernel/kptr_restrict
> 0
> 
> ~> gcc --version
> gcc (Debian 6.2.0-10) 6.2.0 20161027
> 
> ~> perf --version
> perf version 4.7.8
> 
> ~> uname -a
> Linux yoda 4.7.0-1-amd64 #1 SMP Debian 4.7.8-1 (2016-10-19) x86_64 GNU/Linux

           reply	other threads:[~2016-11-14 14:55 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CABvthirHujJiKsYc_1Fq=sy9SoYzg0h9XyYGxe-LRf10YdXn8g@mail.gmail.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161114145536.GA24331@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=fghoussen@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=penberg@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).