diff options
author | startx2017 <vradu.startx@yandex.com> | 2017-10-09 08:10:06 -0400 |
---|---|---|
committer | startx2017 <vradu.startx@yandex.com> | 2017-10-09 08:10:06 -0400 |
commit | b2165c26d73fd3ba8fc1cf33745b5732ea25e47f (patch) | |
tree | 269398955bb4860025d551180487ff40636b1646 /src/lib | |
parent | fix xed.profile (diff) | |
download | firejail-b2165c26d73fd3ba8fc1cf33745b5732ea25e47f.tar.gz firejail-b2165c26d73fd3ba8fc1cf33745b5732ea25e47f.tar.zst firejail-b2165c26d73fd3ba8fc1cf33745b5732ea25e47f.zip |
added a tool to measure time spent in various functions
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/common.c | 39 |
1 files changed, 39 insertions, 0 deletions
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) { | |||
282 | fclose(fp); | 282 | fclose(fp); |
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | |||
286 | //************************** | ||
287 | // time trace based on getticks function | ||
288 | //************************** | ||
289 | static int tt_not_implemented = 0; // not implemented for the current architecture | ||
290 | static unsigned long long tt_1ms = 0; | ||
291 | static unsigned long long tt = 0; // start time | ||
292 | |||
293 | void timetrace_start(void) { | ||
294 | if (tt_not_implemented) | ||
295 | return; | ||
296 | unsigned long long t1 = getticks(); | ||
297 | if (t1 == 0) { | ||
298 | tt_not_implemented = 1; | ||
299 | return; | ||
300 | } | ||
301 | |||
302 | if (tt_1ms == 0) { | ||
303 | usleep(1000); // sleep 1 ms | ||
304 | unsigned long long t2 = getticks(); | ||
305 | tt_1ms = t2 - t1; | ||
306 | if (tt_1ms == 0) { | ||
307 | tt_not_implemented = 1; | ||
308 | return; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | tt = getticks(); | ||
313 | } | ||
314 | |||
315 | float timetrace_end(void) { | ||
316 | if (tt_not_implemented) | ||
317 | return 0; | ||
318 | |||
319 | unsigned long long delta = getticks() - tt; | ||
320 | assert(tt_1ms); | ||
321 | |||
322 | return (float) delta / (float) tt_1ms; | ||
323 | } | ||