Browse Source

sleep: floating point argument

master
Denis Tereshkin 6 months ago
parent
commit
9db186fda1
  1. 26
      src/ftracetool.c
  2. 5
      src/ftracetool.scm

26
src/ftracetool.c

@ -9,6 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <chibi/eval.h> #include <chibi/eval.h>
@ -34,6 +35,7 @@ struct ftt_mapping
struct ftt_mapping *next; struct ftt_mapping *next;
}; };
static double g_wait_sec = 0;
static int g_max_lines = 0; static int g_max_lines = 0;
static struct ftt_mapping *gs_mappings; 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) static sexp sexp_sleep_stub(sexp ctx, sexp self, sexp_sint_t n, sexp arg0)
{ {
struct timespec ts;
sexp res; sexp res;
if (!sexp_numberp(arg0)) if (!sexp_flonump(arg0))
return sexp_type_exception(ctx, self, SEXP_NUMBER, arg0); return sexp_type_exception(ctx, self, SEXP_FLONUM, arg0);
sleep(sexp_uint_value(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; return res;
} }
@ -579,7 +585,7 @@ static int register_sleep(sexp ctx)
if (sexp_opcodep(op)) if (sexp_opcodep(op))
{ {
sexp_opcode_return_type(op) = sexp_make_fixnum(SEXP_NULL); 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); sexp_gc_release1(ctx);
@ -719,7 +725,7 @@ int main(int argc, char **argv)
char filename[NAME_MAX] = {}; char filename[NAME_MAX] = {};
bool execute_script = false; bool execute_script = false;
bool show_symbols_in_file = 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) switch (opt)
{ {
@ -750,6 +756,16 @@ int main(int argc, char **argv)
g_max_lines = atoi(optarg); g_max_lines = atoi(optarg);
break; break;
} }
case 'w':
{
char *end = NULL;
const double wait_sec = strtod(optarg, &end);
if (end != optarg)
{
g_wait_sec = wait_sec;
}
break;
}
case 'm': case 'm':
{ {
struct ftt_mapping *const mapping = parse_mapping(optarg); struct ftt_mapping *const mapping = parse_mapping(optarg);

5
src/ftracetool.scm

@ -65,7 +65,7 @@
(case-lambda (case-lambda
(() (()
(display "Do waiting\n") (display "Do waiting\n")
(sleep 1)) (sleep 1.0))
((probe . rest) ((probe . rest)
(let ((token ((probe-install-handler probe)))) (let ((token ((probe-install-handler probe))))
(guard (x (guard (x
@ -238,6 +238,9 @@
(display "0") (display "0")
(newline))) (newline)))
(let ((events (read-trace-events-from-file "/sys/kernel/tracing/trace" max-lines))) (let ((events (read-trace-events-from-file "/sys/kernel/tracing/trace" max-lines)))
(display "Processing entries: ")
(display (length events))
(newline)
(for-each (for-each
(lambda (event) (lambda (event)
(let ((probe (find-subprobe (trace-event-probe-id event) subprobes))) (let ((probe (find-subprobe (trace-event-probe-id event) subprobes)))

Loading…
Cancel
Save