diff --git a/src/ftracetool.c b/src/ftracetool.c index d91bdfe..81e5a60 100644 --- a/src/ftracetool.c +++ b/src/ftracetool.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ struct ftt_mapping struct ftt_mapping *next; }; +static double g_wait_sec = 0; static int g_max_lines = 0; static struct ftt_mapping *gs_mappings; @@ -318,10 +320,14 @@ static sexp display_exception(sexp ctx, sexp self, sexp_sint_t n, sexp arg0) static sexp sexp_sleep_stub(sexp ctx, sexp self, sexp_sint_t n, sexp arg0) { + struct timespec ts; sexp res; - if (!sexp_numberp(arg0)) - return sexp_type_exception(ctx, self, SEXP_NUMBER, arg0); - sleep(sexp_uint_value(arg0)); + if (!sexp_flonump(arg0)) + return sexp_type_exception(ctx, self, SEXP_FLONUM, arg0); + float sleep_sec = sexp_flonum_value(arg0); + ts.tv_sec = sleep_sec; + ts.tv_nsec = (sleep_sec - ts.tv_sec) * 1e9; + nanosleep(&ts, NULL); return res; } @@ -579,7 +585,7 @@ static int register_sleep(sexp ctx) if (sexp_opcodep(op)) { sexp_opcode_return_type(op) = sexp_make_fixnum(SEXP_NULL); - sexp_opcode_arg1_type(op) = sexp_make_fixnum(SEXP_NUMBER); + sexp_opcode_arg1_type(op) = sexp_make_fixnum(SEXP_FLONUM); } sexp_gc_release1(ctx); @@ -719,7 +725,7 @@ int main(int argc, char **argv) char filename[NAME_MAX] = {}; bool execute_script = false; bool show_symbols_in_file = false; - while ((opt = getopt(argc, argv, "vhs:e:m:")) != -1) + while ((opt = getopt(argc, argv, "vhs:e:m:l:")) != -1) { switch (opt) { @@ -750,6 +756,16 @@ int main(int argc, char **argv) g_max_lines = atoi(optarg); break; } + case 'w': + { + char *end = NULL; + const double wait_sec = strtod(optarg, &end); + if (end != optarg) + { + g_wait_sec = wait_sec; + } + break; + } case 'm': { struct ftt_mapping *const mapping = parse_mapping(optarg); diff --git a/src/ftracetool.scm b/src/ftracetool.scm index b73e76e..85e17d1 100644 --- a/src/ftracetool.scm +++ b/src/ftracetool.scm @@ -65,7 +65,7 @@ (case-lambda (() (display "Do waiting\n") - (sleep 1)) + (sleep 1.0)) ((probe . rest) (let ((token ((probe-install-handler probe)))) (guard (x @@ -238,6 +238,9 @@ (display "0") (newline))) (let ((events (read-trace-events-from-file "/sys/kernel/tracing/trace" max-lines))) + (display "Processing entries: ") + (display (length events)) + (newline) (for-each (lambda (event) (let ((probe (find-subprobe (trace-event-probe-id event) subprobes)))