trace/ftrace: move snprintf+write from tracepoints to ftrace.c
This simplifies the Python code and reduces the size of the tracepoints. Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20250929154938.594389-6-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
6f94ad27f0
commit
02d4a4a674
4 changed files with 24 additions and 32 deletions
|
|
@ -28,18 +28,10 @@ def generate_h(event, group):
|
||||||
if len(event.args) > 0:
|
if len(event.args) > 0:
|
||||||
argnames = ", " + argnames
|
argnames = ", " + argnames
|
||||||
|
|
||||||
out(' {',
|
out(' if (trace_event_get_state(%(event_id)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"',
|
'#line %(event_lineno)d "%(event_filename)s"',
|
||||||
' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
|
' ftrace_write("%(name)s " %(fmt)s "\\n" %(argnames)s);',
|
||||||
' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
|
|
||||||
'#line %(out_next_lineno)d "%(out_filename)s"',
|
'#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,
|
name=event.name,
|
||||||
args=event.args,
|
args=event.args,
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,10 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE;
|
||||||
|
|
||||||
static inline void trace_test_blah(void *context, const char *filename)
|
static inline void trace_test_blah(void *context, const char *filename)
|
||||||
{
|
{
|
||||||
{
|
if (trace_event_get_state(TRACE_TEST_BLAH)) {
|
||||||
char ftrace_buf[MAX_TRACE_STRLEN];
|
|
||||||
int unused __attribute__ ((unused));
|
|
||||||
int trlen;
|
|
||||||
if (trace_event_get_state(TRACE_TEST_BLAH)) {
|
|
||||||
#line 4 "trace-events"
|
#line 4 "trace-events"
|
||||||
trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,
|
ftrace_write("test_blah " "Blah context=%p filename=%s" "\n" , context, filename);
|
||||||
"test_blah " "Blah context=%p filename=%s" "\n" , context, filename);
|
#line 28 "ftrace.h"
|
||||||
#line 33 "ftrace.h"
|
|
||||||
trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
|
|
||||||
unused = write(trace_marker_fd, ftrace_buf, trlen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,18 +34,10 @@ static inline void trace_test_blah(void *context, const char *filename)
|
||||||
|
|
||||||
static inline void trace_test_wibble(void *context, int value)
|
static inline void trace_test_wibble(void *context, int value)
|
||||||
{
|
{
|
||||||
{
|
if (trace_event_get_state(TRACE_TEST_WIBBLE)) {
|
||||||
char ftrace_buf[MAX_TRACE_STRLEN];
|
|
||||||
int unused __attribute__ ((unused));
|
|
||||||
int trlen;
|
|
||||||
if (trace_event_get_state(TRACE_TEST_WIBBLE)) {
|
|
||||||
#line 5 "trace-events"
|
#line 5 "trace-events"
|
||||||
trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,
|
ftrace_write("test_wibble " "Wibble context=%p value=%d" "\n" , context, value);
|
||||||
"test_wibble " "Wibble context=%p value=%d" "\n" , context, value);
|
#line 41 "ftrace.h"
|
||||||
#line 54 "ftrace.h"
|
|
||||||
trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
|
|
||||||
unused = write(trace_marker_fd, ftrace_buf, trlen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
|
#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,21 @@ static int find_mount(char *mount_point, const char *fstype)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ftrace_write(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char ftrace_buf[MAX_TRACE_STRLEN];
|
||||||
|
int unused __attribute__ ((unused));
|
||||||
|
int trlen;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
trlen = vsnprintf(ftrace_buf, MAX_TRACE_STRLEN, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
|
||||||
|
unused = write(trace_marker_fd, ftrace_buf, trlen);
|
||||||
|
}
|
||||||
|
|
||||||
bool ftrace_init(void)
|
bool ftrace_init(void)
|
||||||
{
|
{
|
||||||
char mount_point[PATH_MAX];
|
char mount_point[PATH_MAX];
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,6 @@
|
||||||
extern int trace_marker_fd;
|
extern int trace_marker_fd;
|
||||||
|
|
||||||
bool ftrace_init(void);
|
bool ftrace_init(void);
|
||||||
|
G_GNUC_PRINTF(1, 2) void ftrace_write(const char *fmt, ...);
|
||||||
|
|
||||||
#endif /* TRACE_FTRACE_H */
|
#endif /* TRACE_FTRACE_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue