From: Stefan Hajnoczi <stefanha@redhat.com>
To: Tanish Desai <tanishdesai37@gmail.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, Mads Ynddal <mads@ynddal.dk>
Subject: Re: [PATCH 2/3] trace/ftrace: seperate cold paths of tracing functions
Date: Mon, 2 Jun 2025 18:24:34 -0400 [thread overview]
Message-ID: <20250602222434.GB320269@fedora> (raw)
In-Reply-To: <20250601181231.3461-3-tanishdesai37@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3747 bytes --]
On Sun, Jun 01, 2025 at 06:12:30PM +0000, Tanish Desai wrote:
> Moved rarely used (cold) code from the header file to the C file to avoid
> unnecessary inlining and reduce binary size.
How much of a binary size reduction do you measure? Most trace events
are only called once, so the difference in code size is likely to be
small.
> This improves code organization
> and follows good practices for managing cold paths.
It's easier to understand the code generator and the generated code when
each trace event is implemented as a single function in the header file.
Splitting the trace event up adds complexity. I don't think this is a
step in the right direction.
>
> Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
> ---
> scripts/tracetool/backend/ftrace.py | 44 +++++++++++++++++++++--------
> 1 file changed, 32 insertions(+), 12 deletions(-)
>
> diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py
> index baed2ae61c..c9717d7b42 100644
> --- a/scripts/tracetool/backend/ftrace.py
> +++ b/scripts/tracetool/backend/ftrace.py
> @@ -23,6 +23,10 @@
> def generate_h_begin(events, group):
> out('#include "trace/ftrace.h"',
> '')
> + for event in events:
> + out('void _ftrace_%(api)s(%(args)s);',
> + api=event.api(),
> + args=event.args)
>
>
> def generate_h(event, group):
> @@ -30,26 +34,42 @@ def generate_h(event, group):
> if len(event.args) > 0:
> argnames = ", " + argnames
>
> - out(' {',
> + out(' if (trace_event_get_state(%(event_id)s)) {',
> + ' _ftrace_%(api)s(%(args)s);',
> + ' }',
> + name=event.name,
> + args=", ".join(event.args.names()),
> + event_id="TRACE_" + event.name.upper(),
> + event_lineno=event.lineno,
> + event_filename=os.path.relpath(event.filename),
> + fmt=event.fmt.rstrip("\n"),
> + argnames=argnames,
> + api=event.api()
> + )
> +
> +
> +def generate_c(event, group):
> + argnames = ", ".join(event.args.names())
> + if len(event.args) > 0:
> + argnames = ", " + argnames
> + out('void _ftrace_%(api)s(%(args)s){',
> ' char ftrace_buf[MAX_TRACE_STRLEN];',
> ' int unused __attribute__ ((unused));',
> ' int trlen;',
> - ' if (trace_event_get_state(%(event_id)s)) {',
> '#line %(event_lineno)d "%(event_filename)s"',
> - ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
> - ' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
> + ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
> '#line %(out_next_lineno)d "%(out_filename)s"',
> - ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
> - ' unused = write(trace_marker_fd, ftrace_buf, trlen);',
> - ' }',
> - ' }',
> - name=event.name,
> - args=event.args,
> - event_id="TRACE_" + event.name.upper(),
> + ' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
> + ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
> + ' unused = write(trace_marker_fd, ftrace_buf, trlen);',
> + '}',
> event_lineno=event.lineno,
> event_filename=os.path.relpath(event.filename),
> + name=event.name,
> fmt=event.fmt.rstrip("\n"),
> - argnames=argnames)
> + argnames=argnames,
> + api=event.api(),
> + args=event.args)
>
>
> def generate_h_backend_dstate(event, group):
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2025-06-02 22:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-01 18:12 [PATCH 0/3] trace: seperate cold path of trace Tanish Desai
2025-06-01 18:12 ` [PATCH 1/3] trace/syslog: seperate cold paths of tracing functions Tanish Desai
2025-06-02 22:01 ` Stefan Hajnoczi
2025-06-05 3:02 ` Tanish Desai
2025-06-01 18:12 ` [PATCH 2/3] trace/ftrace: " Tanish Desai
2025-06-02 22:24 ` Stefan Hajnoczi [this message]
2025-06-05 13:57 ` Paolo Bonzini
2025-06-05 18:37 ` Stefan Hajnoczi
2025-06-05 18:49 ` Paolo Bonzini
2025-06-05 19:20 ` Daniel P. Berrangé
2025-06-05 21:24 ` Paolo Bonzini
2025-06-09 18:27 ` Stefan Hajnoczi
2025-06-09 18:50 ` Paolo Bonzini
2025-06-01 18:12 ` [PATCH 3/3] trace/log: seperate cold path " Tanish Desai
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=20250602222434.GB320269@fedora \
--to=stefanha@redhat.com \
--cc=mads@ynddal.dk \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tanishdesai37@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.