2 * Sherlock Library -- Poor Man's Profiler
4 * (c) 2001 Martin Mares <mj@ucw.cz>
8 #include "lib/profile.h"
12 #ifdef CONFIG_PROFILE_TOD
22 prof_switch(prof_t *o, prof_t *n)
25 gettimeofday(&tv, NULL);
28 n->start_sec = tv.tv_sec;
29 n->start_usec = tv.tv_usec;
33 o->sec += tv.tv_sec - o->start_sec;
34 o->usec += tv.tv_usec - o->start_usec;
40 else while (o->usec >= 1000000)
49 prof_format(char *buf, prof_t *c)
51 return sprintf(buf, "%d.%06d", c->sec, c->usec);
55 #ifdef CONFIG_PROFILE_TSC
63 prof_format(char *buf, prof_t *c)
65 return sprintf(buf, "%Ld", c->ticks);
69 #ifdef CONFIG_PROFILE_KTSC
72 static int self_prof_fd = -1;
79 self_prof_fd = open("/proc/self/profile", O_RDONLY, 0);
81 die("Unable to open /proc/self/profile: %m");
88 prof_switch(prof_t *o, prof_t *n)
93 int l = pread(self_prof_fd, buf, sizeof(buf)-1, 0);
94 ASSERT(l > 0 && l < (int)sizeof(buf)-1);
96 l = sscanf(buf, "%Ld%Ld", &u, &s);
114 prof_format(char *buf, prof_t *c)
116 return sprintf(buf, "%Ld+%Ld", c->ticks_user, c->ticks_sys);