[Skiboot] [PATCH v2 16/16] external/trace: Add follow option to dump_trace
Jordan Niethe
jniethe5 at gmail.com
Tue Apr 2 10:43:27 AEDT 2019
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 '-f' option to allow dump_trace to operate
similarly.
Tail also provides a '-s' (sleep time) option that
accompanies '-f'. This controls how often new input will be polled. Add
a '-s' option that will make dump_trace sleep for N milliseconds before
checking for new input.
---
v2: add -s option that controls sleep time.
Signed-off-by: Jordan Niethe <jniethe5 at gmail.com>
---
external/trace/dump_trace.c | 56 ++++++++++++++++++++++++++++++++-----
1 file changed, 49 insertions(+), 7 deletions(-)
diff --git a/external/trace/dump_trace.c b/external/trace/dump_trace.c
index cb687941aa6b..502adcd30447 100644
--- a/external/trace/dump_trace.c
+++ b/external/trace/dump_trace.c
@@ -27,6 +27,7 @@
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
+#include <errno.h>
#include "../../ccan/endian/endian.h"
#include "../../ccan/short_types/short_types.h"
@@ -40,6 +41,9 @@ struct trace_entry {
struct list_node link;
};
+static int follow;
+static long poll_msecs;
+
static void *ezalloc(size_t size)
{
void *p;
@@ -243,19 +247,53 @@ static void display_traces(struct trace_reader *trs, int count)
heap_free(h);
}
+
+/* Can't poll for 0 msec, so use 0 to signify failure */
+static long get_mseconds(char *s)
+{
+ char *end;
+ long ms;
+
+ errno = 0;
+ ms = strtol(s, &end, 10);
+ if (errno || *end || ms < 0)
+ return 0;
+ return ms;
+}
+
+static void usage(void)
+{
+ errx(1, "Usage: dump_trace [-f [-s msecs]] file...");
+}
+
int main(int argc, char *argv[])
{
struct trace_reader *trs;
struct trace_info *ti;
struct stat sb;
- int fd, i;
+ int fd, opt, i;
+ poll_msecs = 1000;
+ while ((opt = getopt(argc, argv, "fs:")) != -1) {
+ switch (opt) {
+ case 'f':
+ follow++;
+ break;
+ case 's':
+ poll_msecs = get_mseconds(optarg);
+ if (follow && poll_msecs)
+ break;
+ /* fallthru */
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
- if (argc < 2)
- errx(1, "Usage: dump_trace file...");
+ if (argc < 1)
+ usage();
- argc--;
- argv++;
trs = ezalloc(sizeof(struct trace_reader) * argc);
for (i = 0; i < argc; i++) {
@@ -274,8 +312,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)
+ usleep(poll_msecs * 1000);
+ } while (follow);
return 0;
}
--
2.20.1
More information about the Skiboot
mailing list