X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fprofile.c;h=83ff77c2dc7c4c9bc6a003e7c21aaa7134dcd0bb;hb=90afcc18dbf7cb6c682e1efb994007f03e304422;hp=dea6b93240a36c0beda8b6737f4f756360c64e04;hpb=fb391b2b22680fc3e18bfb5fecdb3c56ae3b6d2a;p=libucw.git diff --git a/lib/profile.c b/lib/profile.c index dea6b932..83ff77c2 100644 --- a/lib/profile.c +++ b/lib/profile.c @@ -1,7 +1,10 @@ /* - * Sherlock Library -- Poor Man's Profiler + * UCW Library -- Poor Man's Profiler * * (c) 2001 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #include "lib/lib.h" @@ -9,17 +12,18 @@ #include -#ifdef CONFIG_PROFILE_TOD +/* PROFILE_TOD */ + #include void -prof_init(prof_t *c) +prof_tod_init(struct prof_tod *c) { c->sec = c->usec = 0; } void -prof_switch(prof_t *o, prof_t *n) +prof_tod_switch(struct prof_tod *o, struct prof_tod *n) { struct timeval tv; gettimeofday(&tv, NULL); @@ -35,44 +39,50 @@ prof_switch(prof_t *o, prof_t *n) if (o->usec < 0) { o->usec += 1000000; - o->sec++; + o->sec--; } else while (o->usec >= 1000000) { o->usec -= 1000000; - o->sec--; + o->sec++; } } } int -prof_format(char *buf, prof_t *c) +prof_tod_format(char *buf, struct prof_tod *c) { return sprintf(buf, "%d.%06d", c->sec, c->usec); } -#endif -#ifdef CONFIG_PROFILE_TSC +/* PROFILE_TSC */ + +#ifdef CPU_I386 + void -prof_init(prof_t *c) +prof_tsc_init(struct prof_tsc *c) { c->ticks = 0; } int -prof_format(char *buf, prof_t *c) +prof_tsc_format(char *buf, struct prof_tsc *c) { - return sprintf(buf, "%Ld", c->ticks); + return sprintf(buf, "%lld", c->ticks); } + #endif -#ifdef CONFIG_PROFILE_KTSC +/* PROFILE_KTSC */ + +#ifdef CONFIG_LINUX + #include #include static int self_prof_fd = -1; void -prof_init(prof_t *c) +prof_ktsc_init(struct prof_ktsc *c) { if (self_prof_fd < 0) { @@ -85,15 +95,15 @@ prof_init(prof_t *c) } void -prof_switch(prof_t *o, prof_t *n) +prof_ktsc_switch(struct prof_ktsc *o, struct prof_ktsc *n) { - u64 u, s; + unsigned long long u, s; byte buf[256]; int l = pread(self_prof_fd, buf, sizeof(buf)-1, 0); ASSERT(l > 0 && l < (int)sizeof(buf)-1); buf[l] = 0; - l = sscanf(buf, "%Ld%Ld", &u, &s); + l = sscanf(buf, "%lld%lld", &u, &s); ASSERT(l == 2); if (n) @@ -111,8 +121,9 @@ prof_switch(prof_t *o, prof_t *n) } int -prof_format(char *buf, prof_t *c) +prof_ktsc_format(char *buf, struct prof_ktsc *c) { - return sprintf(buf, "%Ld+%Ld", c->ticks_user, c->ticks_sys); + return sprintf(buf, "%lld+%lld", (long long) c->ticks_user, (long long) c->ticks_sys); } + #endif