Commit b5b3ca16 authored by Mark Fasheh's avatar Mark Fasheh

Add a trivial wrapper around gettimeofday() for measuring function call

times.
Signed-off-by: 's avatarMark Fasheh <mfasheh@suse.de>
parent 4d65cee2
......@@ -25,6 +25,7 @@
#include <ctype.h>
#include <inttypes.h>
#include <execinfo.h>
#include <sys/time.h>
#include "debug.h"
#include "util.h"
......@@ -131,3 +132,23 @@ void print_stack_trace(void)
printf("%s\n", messages[i]);
free(messages);
}
void record_start(struct elapsed_time *e, const char *name)
{
e->name = name;
gettimeofday(&e->start, NULL);
}
static void record_end(struct elapsed_time *e)
{
gettimeofday(&e->end, NULL);
e->elapsed = (e->end.tv_sec - e->start.tv_sec) +
((e->end.tv_usec - e->start.tv_usec) / 1000000.0F);
}
void record_end_print(struct elapsed_time *e)
{
record_end(e);
printf("%s took %fs\n", e->name, e->elapsed);
}
......@@ -21,4 +21,14 @@ int pretty_size_snprintf(uint64_t size, char *str, size_t str_bytes);
_str; \
})
/* Trivial wrapper around gettimeofday */
struct elapsed_time {
struct timeval start;
struct timeval end;
const char *name;
double elapsed;
};
void record_start(struct elapsed_time *e, const char *name);
void record_end_print(struct elapsed_time *e);
#endif /* __UTIL_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment