[Skiboot] [PATCH 15/15] external/trace: Add 'follow' option to dump_trace

Oliver oohall at gmail.com
Mon Mar 25 13:22:30 AEDT 2019


On Mon, Mar 25, 2019 at 11:19 AM Jordan Niethe <jniethe5 at gmail.com> wrote:
>
> When monitoring traces, an option like the tail command's '-f' (follow)
> is very useful. This option continues to append to the output as more
> data arrives. Add an option to allow dump_trace to operate similarly.
> ---
>  external/trace/dump_trace.c | 29 ++++++++++++++++++++++-------
>  1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/external/trace/dump_trace.c b/external/trace/dump_trace.c
> index f29da62fbabc..05cdab99846a 100644
> --- a/external/trace/dump_trace.c
> +++ b/external/trace/dump_trace.c
> @@ -40,6 +40,8 @@ struct trace_entry {
>         struct list_node link;
>  };
>
> +static int follow;
> +
>  static void *ezalloc(size_t size)
>  {
>         void *p;
> @@ -248,14 +250,23 @@ int main(int argc, char *argv[])
>  {
>         struct trace_reader *trs;
>         struct trace_info *ti;
> -       int fd, i;
> +       int fd, opt, i;
>
> +       while ((opt = getopt(argc, argv, "f")) != -1) {
> +               switch (opt) {
> +               case 'f':
> +                       follow++;
> +                       break;
> +               default:
> +                       errx(1, "Unknown option: %c", optopt);
> +               }
> +       }
> +       argc -= optind;
> +       argv += optind;
>
> -       if (argc < 2)
> -               errx(1, "Usage: dump_trace file...");
> +       if (argc < 1)
> +               errx(1, "Usage: dump_trace [-f] file...");
>
> -       argc--;
> -       argv++;
>         trs = ezalloc(sizeof(struct trace_reader) * argc);
>
>         for (i =  0; i < argc; i++) {
> @@ -272,8 +283,12 @@ int main(int argc, char *argv[])
>                 list_head_init(&trs[i].traces);
>         }
>
> -       load_traces(trs, argc);
> -       display_traces(trs, argc);
> +       do {
> +               load_traces(trs, argc);
> +               display_traces(trs, argc);
> +               if (follow)
> +                       sleep(1);

I'd make the sleep duration also command line parameter. Using
usleep() instead to allow a faster polling time would also be a good
idea since 1s is a bit long.

> +       } while (follow);
>
>         return 0;
>  }
> --
> 2.20.1
>
> _______________________________________________
> Skiboot mailing list
> Skiboot at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot


More information about the Skiboot mailing list