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 | |
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
-rw-r--r-- | src/include/common.h | 2 | ||||
-rw-r--r-- | src/lib/common.c | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/include/common.h b/src/include/common.h index 4c517e427..80f55803d 100644 --- a/src/include/common.h +++ b/src/include/common.h | |||
@@ -124,6 +124,8 @@ static inline unsigned long long getticks(void) { | |||
124 | #endif | 124 | #endif |
125 | } | 125 | } |
126 | 126 | ||
127 | void timetrace_start(void); | ||
128 | float timetrace_end(void); | ||
127 | int join_namespace(pid_t pid, char *type); | 129 | int join_namespace(pid_t pid, char *type); |
128 | int name2pid(const char *name, pid_t *pid); | 130 | int name2pid(const char *name, pid_t *pid); |
129 | char *pid_proc_comm(const pid_t pid); | 131 | char *pid_proc_comm(const pid_t pid); |
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 | } | ||