From b2165c26d73fd3ba8fc1cf33745b5732ea25e47f Mon Sep 17 00:00:00 2001 From: startx2017 Date: Mon, 9 Oct 2017 08:10:06 -0400 Subject: added a tool to measure time spent in various functions --- src/lib/common.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/lib') diff --git a/src/lib/common.c b/src/lib/common.c index b44563733..3d7fc5ffa 100644 --- a/src/lib/common.c +++ b/src/lib/common.c @@ -282,3 +282,42 @@ int pid_hidepid(void) { fclose(fp); return 0; } + +//************************** +// time trace based on getticks function +//************************** +static int tt_not_implemented = 0; // not implemented for the current architecture +static unsigned long long tt_1ms = 0; +static unsigned long long tt = 0; // start time + +void timetrace_start(void) { + if (tt_not_implemented) + return; + unsigned long long t1 = getticks(); + if (t1 == 0) { + tt_not_implemented = 1; + return; + } + + if (tt_1ms == 0) { + usleep(1000); // sleep 1 ms + unsigned long long t2 = getticks(); + tt_1ms = t2 - t1; + if (tt_1ms == 0) { + tt_not_implemented = 1; + return; + } + } + + tt = getticks(); +} + +float timetrace_end(void) { + if (tt_not_implemented) + return 0; + + unsigned long long delta = getticks() - tt; + assert(tt_1ms); + + return (float) delta / (float) tt_1ms; +} -- cgit v1.2.3-54-g00ecf