kernel-shark: Do not truncate multi-line events
PATCH 1/1 kernel-shark: Do not truncate multi-line events
From: "Steven Rostedt (Google)" <[email protected]>
Some events have more than one line. The libkshark-tepdata.c get_info function did a string search for the first occurrence of '\n' and set it to '\0', with the comment of removing trailing newlines. Unfortunately, it removed more than the trailing newline and removed most of the event. This is particularly true with stack traces.
Instead, use the trace_seq.len to check the last written character, and if that is a newline, remove it.
--- src/libkshark-tepdata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/libkshark-tepdata.c +3 -3
@@ -816,7 +816,7 @@ static char *get_info_str(struct kshark_data_stream *stream,struct tep_record *record, struct tep_event *event) { - char *pos, *buffer; + char *buffer;if (!init_thread_seq () || !record || !event)return NULL ;
@@ -829,8 +829,8 @@ static char *get_info_str(struct kshark_data_stream *stream,* The event info string contains a trailing newline. * Remove this newline. */ -if ((pos =strchr (seq.buffer,'\n' )) !=NULL ) - *pos ='\0' ; +if (seq.buffer[seq.len -1 ] =='\n' ) + seq.buffer[seq.len -1 ] ='\0' ;if (asprintf (&buffer,"%s" , seq.buffer) <=0 )return NULL ;
Signature · 1 line
2.35.1
Quoted 11 lines · Steven Rostedt
From: "Steven Rostedt (Google)" <[email protected]>
Some events have more than one line. The
libkshark-tepdata.cget_infofunction did a string search for the first occurrence of '\n' and set it to '\0', with the comment of removing trailing newlines. Unfortunately, it removed more than the trailing newline and removed most of the event. This is particularly true with stack traces.Instead, use the trace_seq.len to check the last written character, and if that is a newline, remove it.
Hi Steven,
Sorry for the delay of my replay.
This patch looks good to me. I am going to apply it.
Thanks!
Y.
Quoted 30 lines
Fixes 836ce858246b7 ("kernel-shark: Add stream interface for trace-cmd data")Signed-off-by Steven Rostedt (Google) <[email protected]>--- src/libkshark-tepdata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)src/libkshark-tepdata.c +3
-3@@ -816,7 +816,7 @@ static char *get_info_str(struct kshark_data_stream *stream,struct tep_record *record, struct tep_event *event) { - char *pos, *buffer; + char *buffer;if (!init_thread_seq () || !record || !event)return NULL ;@@ -829,8 +829,8 @@ static char *get_info_str(struct kshark_data_stream *stream,* The event info string contains a trailing newline. * Remove this newline. */ -if ((pos =strchr (seq.buffer,'\n' )) !=NULL ) - *pos ='\0' ; +if (seq.buffer[seq.len -1 ] =='\n' ) + seq.buffer[seq.len -1 ] ='\0' ;if (asprintf (&buffer,"%s" , seq.buffer) <=0 )return NULL ;
Quoted 1 line · On Tue, 20 Dec 2022 18:33:44 +0200 Yordan Karadzhov <[email protected]> wrote:
Sorry for the delay of my replay.
No problem. It's that time of year ;-)
Quoted 1 line
This patch looks good to me. I am going to apply it.
Great! Thanks for continuing to maintain KernelShark!
-- Steve