aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorJordan Niethe <jniethe5@gmail.com>2019-04-02 10:43:27 +1100
committerStewart Smith <stewart@linux.ibm.com>2019-05-20 14:27:51 +1000
commite0ed7e9985b49a3c9a2eac4c713aee1d441d5f47 (patch)
treefc031b3baa90b77a544c08e65da74ffd3468384d /external
parenta5038b4ccaf28d1152fdc64203c78410025a750a (diff)
downloadskiboot-e0ed7e9985b49a3c9a2eac4c713aee1d441d5f47.zip
skiboot-e0ed7e9985b49a3c9a2eac4c713aee1d441d5f47.tar.gz
skiboot-e0ed7e9985b49a3c9a2eac4c713aee1d441d5f47.tar.bz2
external/trace: Add follow option to dump_trace
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. Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
Diffstat (limited to 'external')
-rw-r--r--external/trace/dump_trace.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/external/trace/dump_trace.c b/external/trace/dump_trace.c
index cb68794..502adcd 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;
}