linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tstoyanov@vmware.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH 1/5 v2] trace-cmd: Move extract trace_clock into trace-input.c
Date: Fri, 20 Sep 2019 16:08:02 +0000	[thread overview]
Message-ID: <CACqStoe8VoxnAHwT6tB1x3=pyYAx-MZKjfxDS12hHfxPk+VzDg@mail.gmail.com> (raw)
In-Reply-To: <20190920111005.45ba39a6@gandalf.local.home>

On Fri, Sep 20, 2019 at 6:10 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
>
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
>
> Move the extracting of the trace_clock logic into trace-input.c from
> trace-util.c, and store it locally in the tracecmd_input handler. This will
> allow us to remove the trace_clock logic from event_parse.c as it doesn't
> belong there.
>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> Changes since v1:
>
>  - Initialized clock to NULL in case scanf failed (Tzvetomir Stoyanov)
>
>  include/trace-cmd/trace-cmd.h |  3 ++-
>  lib/trace-cmd/trace-input.c   | 33 +++++++++++++++++++++++++++++++--
>  lib/trace-cmd/trace-util.c    | 27 ---------------------------
>  3 files changed, 33 insertions(+), 30 deletions(-)
>
> diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
> index 7a9fbc5f..2d4c6e8f 100644
> --- a/include/trace-cmd/trace-cmd.h
> +++ b/include/trace-cmd/trace-cmd.h
> @@ -18,7 +18,6 @@
>  #define TRACECMD_PTR2ERR(ptr)  ((unisgned long)(ptr) & ~TRACECMD_ERR_MSK)
>
>  void tracecmd_parse_cmdlines(struct tep_handle *pevent, char *file, int size);
> -void tracecmd_parse_trace_clock(struct tep_handle *pevent, char *file, int size);
>  void tracecmd_parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
>  void tracecmd_parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
>
> @@ -127,6 +126,8 @@ void tracecmd_set_flag(struct tracecmd_input *handle, int flag);
>  void tracecmd_clear_flag(struct tracecmd_input *handle, int flag);
>  unsigned long tracecmd_get_flags(struct tracecmd_input *handle);
>
> +void tracecmd_parse_trace_clock(struct tracecmd_input *handle, char *file, int size);
> +
>  int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus);
>
>  int tracecmd_buffer_instances(struct tracecmd_input *handle);
> diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
> index 8cceb31c..f469118a 100644
> --- a/lib/trace-cmd/trace-input.c
> +++ b/lib/trace-cmd/trace-input.c
> @@ -95,6 +95,7 @@ struct tracecmd_input {
>         char *                  cpustats;
>         char *                  uname;
>         char *                  version;
> +       char *                  trace_clock;
>         struct input_buffer_instance    *buffers;
>         int                     parsing_failures;
>
> @@ -2571,6 +2572,33 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle)
>         return 0;
>  }
>
> +static void extract_trace_clock(struct tracecmd_input *handle, char *line)
> +{
> +       char *clock = NULL;
> +       char *next = NULL;
> +       char *data;
> +
> +       data = strtok_r(line, "[]", &next);
> +       sscanf(data, "%ms", &clock);
> +       /* TODO: report if it fails to allocate */
> +       handle->trace_clock = clock;
> +}
> +
> +void tracecmd_parse_trace_clock(struct tracecmd_input *handle,
> +                               char *file, int size __maybe_unused)
> +{
> +       char *line;
> +       char *next = NULL;
> +
> +       line = strtok_r(file, " ", &next);
> +       while (line) {
> +               /* current trace_clock is shown as "[local]". */
> +               if (*line == '[')
> +                       return extract_trace_clock(handle, line);
> +               line = strtok_r(NULL, " ", &next);
> +       }
> +}
> +
>  static int read_and_parse_trace_clock(struct tracecmd_input *handle,
>                                                         struct tep_handle *pevent)
>  {
> @@ -2580,7 +2608,7 @@ static int read_and_parse_trace_clock(struct tracecmd_input *handle,
>         if (read_data_and_size(handle, &trace_clock, &size) < 0)
>                 return -1;
>         trace_clock[size] = 0;
> -       tracecmd_parse_trace_clock(pevent, trace_clock, size);
> +       tracecmd_parse_trace_clock(handle, trace_clock, size);
>         free(trace_clock);
>         return 0;
>  }
> @@ -2618,7 +2646,7 @@ int tracecmd_init_data(struct tracecmd_input *handle)
>                 if (read_and_parse_trace_clock(handle, pevent) < 0) {
>                         char clock[] = "[local]";
>                         warning("File has trace_clock bug, using local clock");
> -                       tracecmd_parse_trace_clock(pevent, clock, 8);
> +                       tracecmd_parse_trace_clock(handle, clock, 8);
>                 }
>         }
>
> @@ -3011,6 +3039,7 @@ void tracecmd_close(struct tracecmd_input *handle)
>         free(handle->cpustats);
>         free(handle->cpu_data);
>         free(handle->uname);
> +       free(handle->trace_clock);
>         close(handle->fd);
>
>         tracecmd_free_hooks(handle->hooks);
> diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
> index c153e4b7..8aa3b6cd 100644
> --- a/lib/trace-cmd/trace-util.c
> +++ b/lib/trace-cmd/trace-util.c
> @@ -73,33 +73,6 @@ void tracecmd_parse_cmdlines(struct tep_handle *pevent,
>         }
>  }
>
> -static void extract_trace_clock(struct tep_handle *pevent, char *line)
> -{
> -       char *data;
> -       char *clock;
> -       char *next = NULL;
> -
> -       data = strtok_r(line, "[]", &next);
> -       sscanf(data, "%ms", &clock);
> -       tep_register_trace_clock(pevent, clock);
> -       free(clock);
> -}
> -
> -void tracecmd_parse_trace_clock(struct tep_handle *pevent,
> -                               char *file, int size __maybe_unused)
> -{
> -       char *line;
> -       char *next = NULL;
> -
> -       line = strtok_r(file, " ", &next);
> -       while (line) {
> -               /* current trace_clock is shown as "[local]". */
> -               if (*line == '[')
> -                       return extract_trace_clock(pevent, line);
> -               line = strtok_r(NULL, " ", &next);
> -       }
> -}
> -
>  void tracecmd_parse_proc_kallsyms(struct tep_handle *pevent,
>                          char *file, unsigned int size __maybe_unused)
>  {
> --
> 2.20.1
>

Looks good, thanks Steven.

Reviewed-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>


-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

  reply	other threads:[~2019-09-20 16:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18  2:03 [PATCH 0/5] trace-cmd: Update for the new trace_print_event() logic Steven Rostedt
2019-09-18  2:03 ` [PATCH 1/5] trace-cmd: Move extract trace_clock into trace-input.c Steven Rostedt
2019-09-20 14:55   ` Tzvetomir Stoyanov
2019-09-20 15:02     ` Steven Rostedt
2019-09-20 15:10     ` [PATCH 1/5 v2] " Steven Rostedt
2019-09-20 16:08       ` Tzvetomir Stoyanov [this message]
2019-09-20 16:11         ` Steven Rostedt
2019-09-18  2:03 ` [PATCH 2/5] trace-cmd: Separate out time diff code in trace_show_data() Steven Rostedt
2019-09-20 15:08   ` Tzvetomir Stoyanov
2019-09-18  2:03 ` [PATCH 3/5] trace-cmd: Add check for trace_clock using usecs into tracecmd_parse_trace_clock() Steven Rostedt
2019-09-20 15:10   ` Tzvetomir Stoyanov
2019-09-18  2:03 ` [PATCH 4/5] libtraceevent, perf tools: Changes in tep_print_event_* APIs Steven Rostedt
2019-09-19 22:50   ` Steven Rostedt
2019-09-19 22:53     ` [PATCH 4/5 v2] " Steven Rostedt
2019-09-20 16:06     ` [PATCH 4/5] " Tzvetomir Stoyanov
2019-09-19 22:52   ` Steven Rostedt
2019-09-18  2:03 ` [PATCH 5/5] tools/lib/traceevent: Round up in tep_print_event() time precision Steven Rostedt
2019-09-20 15:18   ` Tzvetomir Stoyanov

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='CACqStoe8VoxnAHwT6tB1x3=pyYAx-MZKjfxDS12hHfxPk+VzDg@mail.gmail.com' \
    --to=tstoyanov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).