aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/firejail/main.c3
-rw-r--r--src/firejail/sandbox.c15
-rw-r--r--src/include/common.h15
-rw-r--r--src/lib/common.c55
4 files changed, 33 insertions, 55 deletions
diff --git a/src/firejail/main.c b/src/firejail/main.c
index 676d04895..53300fe2d 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -161,7 +161,6 @@ int fullargc = 0;
161static pid_t child = 0; 161static pid_t child = 0;
162pid_t sandbox_pid; 162pid_t sandbox_pid;
163mode_t orig_umask = 022; 163mode_t orig_umask = 022;
164unsigned long long start_timestamp;
165 164
166static void clear_atexit(void) { 165static void clear_atexit(void) {
167 EUID_ROOT(); 166 EUID_ROOT();
@@ -1026,7 +1025,7 @@ int main(int argc, char **argv, char **envp) {
1026 init_cfg(argc, argv); 1025 init_cfg(argc, argv);
1027 1026
1028 // get starting timestamp, process --quiet 1027 // get starting timestamp, process --quiet
1029 start_timestamp = getticks(); 1028 timetrace_start();
1030 char *env_quiet = getenv("FIREJAIL_QUIET"); 1029 char *env_quiet = getenv("FIREJAIL_QUIET");
1031 if (check_arg(argc, argv, "--quiet", 1) || (env_quiet && strcmp(env_quiet, "yes") == 0)) 1030 if (check_arg(argc, argv, "--quiet", 1) || (env_quiet && strcmp(env_quiet, "yes") == 0))
1032 arg_quiet = 1; 1031 arg_quiet = 1;
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index 41951f38f..5c7b5e556 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -400,19 +400,8 @@ static int monitor_application(pid_t app_pid) {
400} 400}
401 401
402static void print_time(void) { 402static void print_time(void) {
403 if (start_timestamp) { 403 float delta = timetrace_end();
404 unsigned long long end_timestamp = getticks(); 404 fmessage("Child process initialized in %.02f ms\n", delta);
405 // measure 1 ms
406 usleep(1000);
407 unsigned long long onems = getticks() - end_timestamp;
408 if (onems) {
409 fmessage("Child process initialized in %.02f ms\n",
410 (float) (end_timestamp - start_timestamp) / (float) onems);
411 return;
412 }
413 }
414
415 fmessage("Child process initialized\n");
416} 405}
417 406
418 407
diff --git a/src/include/common.h b/src/include/common.h
index 2fa61cc91..5df51c5a9 100644
--- a/src/include/common.h
+++ b/src/include/common.h
@@ -118,21 +118,6 @@ static inline int mac_not_zero(const unsigned char mac[6]) {
118 return 0; 118 return 0;
119} 119}
120 120
121// rtdsc timestamp on x86-64/amd64 processors
122static inline unsigned long long getticks(void) {
123#if defined(__x86_64__)
124 unsigned a, d;
125 asm volatile("rdtsc" : "=a" (a), "=d" (d));
126 return ((unsigned long long)a) | (((unsigned long long)d) << 32);
127#elif defined(__i386__)
128 unsigned long long ret;
129 __asm__ __volatile__("rdtsc" : "=A" (ret));
130 return ret;
131#else
132 return 0; // not implemented
133#endif
134}
135
136void timetrace_start(void); 121void timetrace_start(void);
137float timetrace_end(void); 122float timetrace_end(void);
138int join_namespace(pid_t pid, char *type); 123int join_namespace(pid_t pid, char *type);
diff --git a/src/lib/common.c b/src/lib/common.c
index 872772ec7..823442835 100644
--- a/src/lib/common.c
+++ b/src/lib/common.c
@@ -30,6 +30,7 @@
30#include <signal.h> 30#include <signal.h>
31#include <dirent.h> 31#include <dirent.h>
32#include <string.h> 32#include <string.h>
33#include <time.h>
33#include "../include/common.h" 34#include "../include/common.h"
34#define BUFLEN 4096 35#define BUFLEN 4096
35 36
@@ -290,38 +291,42 @@ int pid_hidepid(void) {
290//************************** 291//**************************
291// time trace based on getticks function 292// time trace based on getticks function
292//************************** 293//**************************
293static int tt_not_implemented = 0; // not implemented for the current architecture 294typedef struct list_entry_t {
294static unsigned long long tt_1ms = 0; 295 struct list_entry_t *next;
295static unsigned long long tt = 0; // start time 296 struct timespec ts;
297} ListEntry;
296 298
297void timetrace_start(void) { 299static ListEntry *ts_list = NULL;
298 if (tt_not_implemented)
299 return;
300 unsigned long long t1 = getticks();
301 if (t1 == 0) {
302 tt_not_implemented = 1;
303 return;
304 }
305 300
306 if (tt_1ms == 0) { 301static inline float msdelta(struct timespec *start, struct timespec *end) {
307 usleep(1000); // sleep 1 ms 302 unsigned sec = end->tv_sec - start->tv_sec;
308 unsigned long long t2 = getticks(); 303 long nsec = end->tv_nsec - start->tv_nsec;
309 tt_1ms = t2 - t1; 304 return (float) sec * 1000 + (float) nsec / 1000000;
310 if (tt_1ms == 0) { 305}
311 tt_not_implemented = 1;
312 return;
313 }
314 }
315 306
316 tt = getticks(); 307void timetrace_start(void) {
308 ListEntry *t = malloc(sizeof(ListEntry));
309 if (!t)
310 errExit("malloc");
311 memset(t, 0, sizeof(ListEntry));
312 clock_gettime(CLOCK_MONOTONIC, &t->ts);
313
314 // add it to the list
315 t->next = ts_list;
316 ts_list = t;
317} 317}
318 318
319float timetrace_end(void) { 319float timetrace_end(void) {
320 if (tt_not_implemented) 320 if (!ts_list)
321 return 0; 321 return 0;
322 322
323 unsigned long long delta = getticks() - tt; 323 // remove start time from the list
324 assert(tt_1ms); 324 ListEntry *t = ts_list;
325 ts_list = t->next;
325 326
326 return (float) delta / (float) tt_1ms; 327 struct timespec end;
328 clock_gettime(CLOCK_MONOTONIC, &end);
329 float rv = msdelta(&t->ts, &end);
330 free(t);
331 return rv;
327} 332}