Message ID | 20221214154404.5897fc23@gandalf.local.home (mailing list archive) |
---|---|
State | Accepted |
Commit | 3146d0b3d873546461163df2701ee1068e27ee04 |
Headers | show |
Series | kernel-shark: Do not truncate multi-line events | expand |
On 12/14/22 22:44, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" <rostedt@goodmis.org> > > 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. > Hi Steven, Sorry for the delay of my replay. This patch looks good to me. I am going to apply it. Thanks! Y. > Fixes: 836ce858246b7 ("kernel-shark: Add stream interface for trace-cmd data") > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> > --- > src/libkshark-tepdata.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c > index 08aca0989a59..58be934f7d20 100644 > --- a/src/libkshark-tepdata.c > +++ b/src/libkshark-tepdata.c > @@ -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;
On Tue, 20 Dec 2022 18:33:44 +0200 Yordan Karadzhov <y.karadz@gmail.com> wrote: > Sorry for the delay of my replay. No problem. It's that time of year ;-) > This patch looks good to me. I am going to apply it. Great! Thanks for continuing to maintain KernelShark! -- Steve
diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c index 08aca0989a59..58be934f7d20 100644 --- a/src/libkshark-tepdata.c +++ b/src/libkshark-tepdata.c @@ -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;