diff mbox series

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

Message ID 20190325001425.29483-16-jniethe5@gmail.com
State Superseded
Headers show
Series Improve usability of skiboot traces | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (b392d785eb49630b9f00fef8d17944ed82b2c1fe)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco fail Signed-off-by missing

Commit Message

Jordan Niethe March 25, 2019, 12:14 a.m. UTC
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(-)

Comments

Oliver O'Halloran March 25, 2019, 2:22 a.m. UTC | #1
On Mon, Mar 25, 2019 at 11:19 AM Jordan Niethe <jniethe5@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@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot
diff mbox series

Patch

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);
+	} while (follow);
 
 	return 0;
 }