[PATCH 1/3] trace/syslog: seperate cold paths of tracing functions

Tanish Desai posted 3 patches 5 months, 2 weeks ago
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Mads Ynddal <mads@ynddal.dk>
[PATCH 1/3] trace/syslog: seperate cold paths of tracing functions
Posted by Tanish Desai 5 months, 2 weeks ago
inline: move hot paths from .c to .h for better performance
Moved frequently used hot paths from the .c file to the .h file to enable inlining
and improve performance. This approach is inspired by past QEMU optimizations,
where performance-critical code was inlined based on profiling results.

Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
---
 scripts/tracetool/backend/syslog.py | 36 +++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
index 012970f6cc..52b8ff65ea 100644
--- a/scripts/tracetool/backend/syslog.py
+++ b/scripts/tracetool/backend/syslog.py
@@ -21,8 +21,12 @@
 
 
 def generate_h_begin(events, group):
-    out('#include <syslog.h>',
-        '')
+    out('#include <syslog.h>')
+    for event in events:
+        out('void _syslog_%(api)s(%(args)s);',
+            api=event.api(),
+            args=event.args)
+    out('')
 
 
 def generate_h(event, group):
@@ -37,17 +41,35 @@ def generate_h(event, group):
         cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
     out('    if (%(cond)s) {',
-        '#line %(event_lineno)d "%(event_filename)s"',
-        '        syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
-        '#line %(out_next_lineno)d "%(out_filename)s"',
+            '       _syslog_%(api)s(%(args)s);',
         '    }',
         cond=cond,
         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=", ".join(event.args.names()))
+
+
+def generate_c(event, group):
+        argnames = ", ".join(event.args.names())
+        if len(event.args) > 0:
+            argnames = ", " + argnames
+        out('void _syslog_%(api)s(%(args)s){',
+        '   #line %(event_lineno)d "%(event_filename)s"',
+        '            syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
+        '   #line %(out_next_lineno)d "%(out_filename)s"',
+        '}',
+        '',
+        event_lineno=event.lineno,
+        event_filename=os.path.relpath(event.filename),
+        name=event.name,
+        fmt=event.fmt.rstrip("\n"),
+        argnames=argnames,
+        api=event.api(),
+        args=event.args)    
 
 def generate_h_backend_dstate(event, group):
     out('    trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
-- 
2.34.1
Re: [PATCH 1/3] trace/syslog: seperate cold paths of tracing functions
Posted by Stefan Hajnoczi 5 months, 2 weeks ago
On Sun, Jun 01, 2025 at 06:12:29PM +0000, Tanish Desai wrote:
> inline: move hot paths from .c to .h for better performance
> Moved frequently used hot paths from the .c file to the .h file to enable inlining
> and improve performance. This approach is inspired by past QEMU optimizations,
> where performance-critical code was inlined based on profiling results.
> 
> Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
> ---
>  scripts/tracetool/backend/syslog.py | 36 +++++++++++++++++++++++------
>  1 file changed, 29 insertions(+), 7 deletions(-)

This commit description doesn't match what the patch does.

What is the purpose of creating a _syslog_trace_foo() function in the .c
file instead of calling syslog() directly from the .h file?

> 
> diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
> index 012970f6cc..52b8ff65ea 100644
> --- a/scripts/tracetool/backend/syslog.py
> +++ b/scripts/tracetool/backend/syslog.py
> @@ -21,8 +21,12 @@
>  
>  
>  def generate_h_begin(events, group):
> -    out('#include <syslog.h>',
> -        '')
> +    out('#include <syslog.h>')
> +    for event in events:
> +        out('void _syslog_%(api)s(%(args)s);',
> +            api=event.api(),
> +            args=event.args)
> +    out('')
>  
>  
>  def generate_h(event, group):
> @@ -37,17 +41,35 @@ def generate_h(event, group):
>          cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
>  
>      out('    if (%(cond)s) {',
> -        '#line %(event_lineno)d "%(event_filename)s"',
> -        '        syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
> -        '#line %(out_next_lineno)d "%(out_filename)s"',
> +            '       _syslog_%(api)s(%(args)s);',
>          '    }',
>          cond=cond,
>          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=", ".join(event.args.names()))
> +
> +
> +def generate_c(event, group):
> +        argnames = ", ".join(event.args.names())
> +        if len(event.args) > 0:
> +            argnames = ", " + argnames
> +        out('void _syslog_%(api)s(%(args)s){',
> +        '   #line %(event_lineno)d "%(event_filename)s"',
> +        '            syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
> +        '   #line %(out_next_lineno)d "%(out_filename)s"',
> +        '}',
> +        '',
> +        event_lineno=event.lineno,
> +        event_filename=os.path.relpath(event.filename),
> +        name=event.name,
> +        fmt=event.fmt.rstrip("\n"),
> +        argnames=argnames,
> +        api=event.api(),
> +        args=event.args)    
>  
>  def generate_h_backend_dstate(event, group):
>      out('    trace_event_get_state_dynamic_by_id(%(event_id)s) || \\',
> -- 
> 2.34.1
>