mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Maguire <alan.maguire@oracle.com>
To: Howard Chu <howardchu95@gmail.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Kan Liang <kan.liang@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org
Subject: Re: perf trace: substruct BTF based pretty printing
Date: Mon, 23 Sep 2024 18:47:54 +0100	[thread overview]
Message-ID: <8ad3ada6-f719-43ca-bf16-0095be555302@oracle.com> (raw)
In-Reply-To: <CAH0uvoj_2An0QQgCSenZiK8XubS=amyrxhAWK7ragAFfi+Hnqg@mail.gmail.com>

On 23/09/2024 18:42, Howard Chu wrote:
> Hello,
> 
> On Wed, Sep 11, 2024 at 6:29 PM Howard Chu <howardchu95@gmail.com> wrote:
>>
>> Hello Arnaldo,
>>
>> On Wed, Sep 11, 2024 at 1:25 PM Arnaldo Carvalho de Melo
>> <acme@kernel.org> wrote:
>>>
>>> Hi Howard,
>>>
>>>         Not really a requirement on you to do work, just a some notes to
>>> add to our discussion/experiment on using BTF to pretty print syscall
>>> (and tracepoints/whatever) arguments:
>>>
>>> root@number:~# perf trace -e setitimer -p 5444 |& head -5
>>>      0.000 ( 0.017 ms): Xwayland/5444 setitimer(value: (struct __kernel_old_itimerval){})                   = 0
>>>      0.050 ( 0.004 ms): Xwayland/5444 setitimer(value: (struct __kernel_old_itimerval){})                   = 0
>>>      0.142 ( 0.005 ms): Xwayland/5444 setitimer(value: (struct __kernel_old_itimerval){})                   = 0
>>>      0.174 ( 0.004 ms): Xwayland/5444 setitimer(value: (struct __kernel_old_itimerval){})                   = 0
>>>      0.293 ( 0.004 ms): Xwayland/5444 setitimer(value: (struct __kernel_old_itimerval){})                   = 0
> 
> First of all I bypass the from_user check to make perf trace use BTF
> output instead of just printing an address:
> 
>         for (i = 0, field = sc->args; field; ++i, field = field->next) {
>                 // XXX We're only collecting pointer payloads _from_ user space
>                 /*if (!sc->arg_fmt[i].from_user)*/
>                         /*continue;*/
> 
> Got the bad output:
> 
>    500.218 ( 0.015 ms): a.out/112335 setitimer(value: (struct
> __kernel_old_itimerval){})                   = 0
> 
> But after switching on emit_zeroes from btf_dump_type_data_opts:
> 
> dump_data_opts.compact   = true;
> dump_data_opts.skip_names = !arg->trace->show_arg_names;
> dump_data_opts.emit_zeroes = true; // this
> 
> My output is good:
> 
>  96058.828 ( 0.010 ms): a.out/104347 setitimer(value: (struct
> __kernel_old_itimerval){.it_interval = (struct
> __kernel_old_timeval){.tv_sec = (__kernel_long_t)0,.tv_usec =
> (__kernel_long_t)500000,},.it_value = (struct
> __kernel_old_timeval){.tv_sec = (__kernel_long_t)0,.tv_usec =
> (__kernel_long_t)500000,},}) = 0
> 
> So I think this is btf_dump's problem... Because most of the time we
> want to omit the zeroes, but that will have the side effect of not
> being able to print the whole output. I'll figure something out.
>

One thing we could think about is if there's a way for BTF data dump to
better represent the fact that a structure is all 0s; currently we will
show "{}" since we skip emitting zeroed data, but maybe - at the
toplevel only - "{ 0 }" would be more expressive? Thanks!

Alan

> Thanks,
> Howard
>>
>> First glance, yes this is a substruct, but we should be able to
>> collect those substruct data in BPF, since it is substruct, not
>> substruct pointer. It seems to be the same -p problem we discussed
>> here:
>>
>> Before:
>> ```
>> perf $ perf trace -e open -p 3792392
>>          ? (         ):  ... [continued]: open())
>>                        = -1 ENOENT (No such file or directory)
>>          ? (         ):  ... [continued]: open())
>>                        = -1 ENOENT (No such file or directory)
>> ```
>>
>> We can see there's no output.
>>
>> After:
>> ```
>> perf $ perf trace -e open -p 3792392
>>      0.000 ( 0.123 ms): a.out/3792392 open(filename: "DINGZHEN",
>> flags: WRONLY)                             = -1 ENOENT (No such file
>> or directory)
>>   1000.398 ( 0.116 ms): a.out/3792392 open(filename: "DINGZHEN",
>> flags: WRONLY)                             = -1 ENOENT (No such file
>> or directory)
>> ```
>>
>> I will test and fix it later.
>>
>> Thanks,
>> Howard
>>
>>> root@number:~# strace -e setitimer -p 5444 |& head -5
>>> strace: Process 5444 attached
>>> setitimer(ITIMER_REAL, {it_interval={tv_sec=0, tv_usec=5000}, it_value={tv_sec=0, tv_usec=5000}}, NULL) = 0
>>> setitimer(ITIMER_REAL, {it_interval={tv_sec=0, tv_usec=0}, it_value={tv_sec=0, tv_usec=0}}, NULL) = 0
>>> setitimer(ITIMER_REAL, {it_interval={tv_sec=0, tv_usec=5000}, it_value={tv_sec=0, tv_usec=5000}}, NULL) = 0
>>> setitimer(ITIMER_REAL, {it_interval={tv_sec=0, tv_usec=0}, it_value={tv_sec=0, tv_usec=0}}, NULL) = 0
>>> root@number:~#
>>> root@number:~#
>>> root@number:~# grep -w value /sys/kernel/tracing/events/syscalls/sys_enter_rseq/format
>>> root@number:~# grep -w value /sys/kernel/tracing/events/syscalls/sys_enter_setitimer/format
>>>         field:struct __kernel_old_itimerval * value;    offset:24;      size:8; signed:0;
>>> print fmt: "which: 0x%08lx, value: 0x%08lx, ovalue: 0x%08lx", ((unsigned long)(REC->which)), ((unsigned long)(REC->value)), ((unsigned long)(REC->ovalue))
>>> root@number:~# pahole __kernel_old_itimerval
>>> struct __kernel_old_itimerval {
>>>         struct __kernel_old_timeval it_interval;         /*     0    16 */
>>>         struct __kernel_old_timeval it_value;            /*    16    16 */
>>>
>>>         /* size: 32, cachelines: 1, members: 2 */
>>>         /* last cacheline: 32 bytes */
>>> };
>>>
>>> root@number:~# pahole -E __kernel_old_itimerval
>>> struct __kernel_old_itimerval {
>>>         struct __kernel_old_timeval {
>>>                 /* typedef __kernel_long_t */ long int           tv_sec;                 /*     0     8 */
>>>                 /* typedef __kernel_long_t */ long int           tv_usec;                /*     8     8 */
>>>         } it_interval; /*     0    16 */
>>>         struct __kernel_old_timeval {
>>>                 /* typedef __kernel_long_t */ long int           tv_sec;                 /*    16     8 */
>>>                 /* typedef __kernel_long_t */ long int           tv_usec;                /*    24     8 */
>>>         } it_value; /*    16    16 */
>>>
>>>         /* size: 32, cachelines: 1, members: 2 */
>>>         /* last cacheline: 32 bytes */
>>> };
>>>
>>> root@number:~#


  reply	other threads:[~2024-09-23 17:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 20:25 Arnaldo Carvalho de Melo
2024-09-12  1:29 ` Howard Chu
2024-09-23 17:42   ` Howard Chu
2024-09-23 17:47     ` Alan Maguire [this message]
2024-09-23 18:17       ` Howard Chu

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=8ad3ada6-f719-43ca-bf16-0095be555302@oracle.com \
    --to=alan.maguire@oracle.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=howardchu95@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.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

all inboxes | Powered by JetHome®