diff options
author | netblue30 <netblue30@yahoo.com> | 2017-05-09 09:59:00 -0400 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2017-05-09 09:59:00 -0400 |
commit | 97e789c90b5ab45ffa3237dd2bd5da6158375f7a (patch) | |
tree | 9fcc9905992b38cf9c38b46d48ee743d4b40d7eb | |
parent | merge #1100 from zackw: support for Xpra extra params in firejail config file (diff) | |
download | firejail-97e789c90b5ab45ffa3237dd2bd5da6158375f7a.tar.gz firejail-97e789c90b5ab45ffa3237dd2bd5da6158375f7a.tar.zst firejail-97e789c90b5ab45ffa3237dd2bd5da6158375f7a.zip |
measure start time
-rw-r--r-- | src/firejail/firejail.h | 1 | ||||
-rw-r--r-- | src/firejail/main.c | 15 | ||||
-rw-r--r-- | src/firejail/sandbox.c | 20 | ||||
-rw-r--r-- | src/include/common.h | 11 |
4 files changed, 36 insertions, 11 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 6b1786a93..fba4c4fe2 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -354,6 +354,7 @@ extern int login_shell; | |||
354 | extern int parent_to_child_fds[2]; | 354 | extern int parent_to_child_fds[2]; |
355 | extern int child_to_parent_fds[2]; | 355 | extern int child_to_parent_fds[2]; |
356 | extern pid_t sandbox_pid; | 356 | extern pid_t sandbox_pid; |
357 | extern unsigned long long start_timestamp; | ||
357 | 358 | ||
358 | #define MAX_ARGS 128 // maximum number of command arguments (argc) | 359 | #define MAX_ARGS 128 // maximum number of command arguments (argc) |
359 | extern char *fullargv[MAX_ARGS]; | 360 | extern char *fullargv[MAX_ARGS]; |
diff --git a/src/firejail/main.c b/src/firejail/main.c index 4357ddaa4..9e5c31c32 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -37,15 +37,6 @@ | |||
37 | #include <net/if.h> | 37 | #include <net/if.h> |
38 | #include <sys/utsname.h> | 38 | #include <sys/utsname.h> |
39 | 39 | ||
40 | #if 0 | ||
41 | #include <sys/times.h> | ||
42 | { | ||
43 | struct tms tm; | ||
44 | clock_t systick = times(&tm); | ||
45 | printf("time %s:%d %u\n", __FILE__, __LINE__, (uint32_t) systick); | ||
46 | } | ||
47 | #endif | ||
48 | |||
49 | uid_t firejail_uid = 0; | 40 | uid_t firejail_uid = 0; |
50 | gid_t firejail_gid = 0; | 41 | gid_t firejail_gid = 0; |
51 | 42 | ||
@@ -127,6 +118,7 @@ char *fullargv[MAX_ARGS]; // expanded argv for restricted shell | |||
127 | int fullargc = 0; | 118 | int fullargc = 0; |
128 | static pid_t child = 0; | 119 | static pid_t child = 0; |
129 | pid_t sandbox_pid; | 120 | pid_t sandbox_pid; |
121 | unsigned long long start_timestamp; | ||
130 | 122 | ||
131 | static void set_name_file(pid_t pid); | 123 | static void set_name_file(pid_t pid); |
132 | static void delete_name_file(pid_t pid); | 124 | static void delete_name_file(pid_t pid); |
@@ -826,6 +818,11 @@ int main(int argc, char **argv) { | |||
826 | char *custom_profile_dir = NULL; // custom profile directory | 818 | char *custom_profile_dir = NULL; // custom profile directory |
827 | int arg_noprofile = 0; // use default.profile if none other found/specified | 819 | int arg_noprofile = 0; // use default.profile if none other found/specified |
828 | 820 | ||
821 | |||
822 | // get starting timestamp | ||
823 | start_timestamp = getticks(); | ||
824 | |||
825 | |||
829 | // build /run/firejail directory structure | 826 | // build /run/firejail directory structure |
830 | preproc_build_firejail_dir(); | 827 | preproc_build_firejail_dir(); |
831 | 828 | ||
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c index e6deddac5..9ecb1c8cc 100644 --- a/src/firejail/sandbox.c +++ b/src/firejail/sandbox.c | |||
@@ -274,6 +274,22 @@ void start_audit(void) { | |||
274 | exit(1); | 274 | exit(1); |
275 | } | 275 | } |
276 | 276 | ||
277 | static void print_time(void) { | ||
278 | if (start_timestamp) { | ||
279 | unsigned long long end_timestamp = getticks(); | ||
280 | // measure 1 ms | ||
281 | usleep(1000); | ||
282 | unsigned long long onems = getticks() - end_timestamp; | ||
283 | if (onems) { | ||
284 | printf("Child process initialized in %.02f ms\n", | ||
285 | (float) (end_timestamp - start_timestamp) / (float) onems); | ||
286 | return; | ||
287 | } | ||
288 | } | ||
289 | |||
290 | printf("Child process initialized\n"); | ||
291 | } | ||
292 | |||
277 | void start_application(void) { | 293 | void start_application(void) { |
278 | //if (setsid() == -1) | 294 | //if (setsid() == -1) |
279 | //errExit("setsid"); | 295 | //errExit("setsid"); |
@@ -315,7 +331,7 @@ void start_application(void) { | |||
315 | } | 331 | } |
316 | 332 | ||
317 | if (!arg_command && !arg_quiet) | 333 | if (!arg_command && !arg_quiet) |
318 | printf("Child process initialized\n"); | 334 | print_time(); |
319 | 335 | ||
320 | #ifdef HAVE_GCOV | 336 | #ifdef HAVE_GCOV |
321 | __gcov_dump(); | 337 | __gcov_dump(); |
@@ -366,7 +382,7 @@ void start_application(void) { | |||
366 | } | 382 | } |
367 | 383 | ||
368 | if (!arg_command && !arg_quiet) | 384 | if (!arg_command && !arg_quiet) |
369 | printf("Child process initialized\n"); | 385 | print_time(); |
370 | #ifdef HAVE_GCOV | 386 | #ifdef HAVE_GCOV |
371 | __gcov_dump(); | 387 | __gcov_dump(); |
372 | #endif | 388 | #endif |
diff --git a/src/include/common.h b/src/include/common.h index fc4059334..59b7f6213 100644 --- a/src/include/common.h +++ b/src/include/common.h | |||
@@ -109,6 +109,17 @@ static inline int mac_not_zero(const unsigned char mac[6]) { | |||
109 | return 0; | 109 | return 0; |
110 | } | 110 | } |
111 | 111 | ||
112 | // rtdsc timestamp on x86-64/amd64 processors | ||
113 | static inline unsigned long long getticks(void) { | ||
114 | #if defined(__x86_64__) | ||
115 | unsigned a, d; | ||
116 | asm volatile("rdtsc" : "=a" (a), "=d" (d)); | ||
117 | return ((unsigned long long)a) | (((unsigned long long)d) << 32); | ||
118 | #else | ||
119 | return 0; // not implemented | ||
120 | #endif | ||
121 | } | ||
122 | |||
112 | int join_namespace(pid_t pid, char *type); | 123 | int join_namespace(pid_t pid, char *type); |
113 | int name2pid(const char *name, pid_t *pid); | 124 | int name2pid(const char *name, pid_t *pid); |
114 | char *pid_proc_comm(const pid_t pid); | 125 | char *pid_proc_comm(const pid_t pid); |