summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAkos PASZTORY <akos.pasztory@gmail.com>2011-12-03 15:42:56 +0000
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-12-05 11:05:01 +0100
commit749d16e7ac7dab3641d23eeead752335e23854f4 (patch)
tree8d95ea8bbae20abcfae42c3927a016cb727559fb /src
parent01166acb9da9ea2aea40349c44d78764f8e2f3cd (diff)
downloadlatrace-749d16e7ac7dab3641d23eeead752335e23854f4.tar.gz
latrace-749d16e7ac7dab3641d23eeead752335e23854f4.tar.xz
latrace-749d16e7ac7dab3641d23eeead752335e23854f4.zip
stats: bugfix: use timersub() and timeradd()
tv_sub() had a bug: if 'a' represented the same time as 'b' then it added extra 1000000 usecs.
Diffstat (limited to 'src')
-rw-r--r--src/stats.c41
1 files changed, 5 insertions, 36 deletions
diff --git a/src/stats.c b/src/stats.c
index b1c8dda..d5c5351 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -31,37 +31,6 @@
struct timeval tv_program_start;
struct timeval tv_program_stop;
-/* res = a - b*/
-static int tv_sub(struct timeval *res, struct timeval *a, struct timeval *b)
-{
- res->tv_sec = a->tv_sec - b->tv_sec;
-
- if (a->tv_usec > b->tv_usec)
- res->tv_usec = a->tv_usec - b->tv_usec;
- else {
- res->tv_usec = a->tv_usec + (1000000 - b->tv_usec);
- if (res->tv_sec)
- res->tv_sec--;
- }
-
- return 0;
-}
-
-/* res = a + b*/
-static int tv_add(struct timeval *res, struct timeval *a, struct timeval *b)
-{
- struct timeval tv;
- tv.tv_sec = a->tv_sec + b->tv_sec;
- tv.tv_usec = a->tv_usec + b->tv_usec;
- if (tv.tv_usec > 1000000) {
- tv.tv_usec -= 1000000;
- tv.tv_sec++;
- }
-
- *res = tv;
- return 0;
-}
-
int lt_stats_alloc(struct lt_config_app *cfg, struct lt_thread *t)
{
int i;
@@ -186,8 +155,8 @@ int lt_stats_sym(struct lt_config_app *cfg, struct lt_thread *t,
if (FIFO_MSG_TYPE_EXIT == m->h.type) {
struct timeval tv;
- tv_sub(&tv, &m->h.tv, &sym->tv_cur);
- tv_add(&sym->tv_all, &sym->tv_all, &tv);
+ timersub(&m->h.tv, &sym->tv_cur, &tv);
+ timeradd(&sym->tv_all, &tv, &sym->tv_all);
}
return 0;
@@ -248,7 +217,7 @@ static int lt_stats_show_thread(struct lt_config_app *cfg, struct lt_thread *t)
for(i = 0; i < t->sym_cnt; i++) {
struct lt_stats_sym *sym = t->sym_array[i];
- tv_add(&tv_thread_accu, &tv_thread_accu, &sym->tv_all);
+ timeradd(&sym->tv_all, &tv_thread_accu, &tv_thread_accu);
}
time_global = tv_thread_accu.tv_sec * 1000000 + tv_thread_accu.tv_usec;
@@ -270,7 +239,7 @@ static int lt_stats_show_thread(struct lt_config_app *cfg, struct lt_thread *t)
PRINT_VERBOSE(cfg, 1, "%s\n", "printing");
- tv_sub(&tv_thread_real, &t->tv_stop, &t->tv_start);
+ timersub(&t->tv_stop, &t->tv_start, &tv_thread_real);
printf("\nThread %d (runtime %u.%06u sec)\n",
t->tid, (u_int) tv_thread_real.tv_sec, (u_int) tv_thread_real.tv_usec);
printf("%3s %-6s %10s %10s %10s %-30s\n",
@@ -311,7 +280,7 @@ int lt_stats_show(struct lt_config_app *cfg)
struct lt_thread *t;
struct timeval tv_program_real;
- tv_sub(&tv_program_real, &tv_program_stop, &tv_program_start);
+ timersub(&tv_program_stop, &tv_program_start, &tv_program_real);
printf("\n--------------------------------------------------------------------------\n");
printf("Statistics for [%s] total runtime: %u.%06u sec\n",