diff options
author | Wolf Bergenheim <ext-wolf.2.bergenheim@nokia.com> | 2010-09-14 14:28:37 +0300 |
---|---|---|
committer | Wolf Bergenheim <ext-wolf.2.bergenheim@nokia.com> | 2010-09-14 14:28:37 +0300 |
commit | e1491cbe83ad2b59ae8be0519e029d937fbc7f59 (patch) | |
tree | 36ff4097a714c40ce7dd4c2896b74276fe2c4d50 | |
parent | 1acec5d9ba420845a8077d2adba9678ead90bfef (diff) |
Added operation timing
-rw-r--r-- | client/Makefile.am | 6 | ||||
-rw-r--r-- | client/time-stat.c | 34 | ||||
-rw-r--r-- | client/time-stat.h | 16 |
3 files changed, 53 insertions, 3 deletions
diff --git a/client/Makefile.am b/client/Makefile.am index aa108cd..ffcd987 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -1,9 +1,9 @@ bin_PROGRAMS = resource-client -resource_client_SOURCES = client.c -resource_client_CFLAGS = -I$(top_srcdir)/src @DBUS_CFLAGS@ -g3 -O0 +resource_client_SOURCES = client.c time-stat.c time-stat.h +resource_client_CFLAGS = -I$(top_srcdir)/src @DBUS_CFLAGS@ -g3 -O0 -std=c99 -D_POSIX_C_SOURCE=199309L -D_GNU_SOURCE if DEBUG resource_client_CFLAGS += -D__DEBUG__ endif -resource_client_LDADD = $(top_builddir)/src/libresource.la @DBUS_LIBS@ +resource_client_LDADD = $(top_builddir)/src/libresource.la @DBUS_LIBS@ -lm -lrt diff --git a/client/time-stat.c b/client/time-stat.c new file mode 100644 index 0000000..c18daa5 --- /dev/null +++ b/client/time-stat.c @@ -0,0 +1,34 @@ +#include <math.h> +#include "time-stat.h" + +static struct timespec start_time; + +int start_timer(void) +{ + int r; + r = clock_gettime(CLOCK_REALTIME, &start_time); + + if (r == 0) + return 1; + else + return 0; +} + +long int stop_timer(void) +{ + struct timespec end_time; + int r; + double milliseconds = 0.0; + + r = clock_gettime(CLOCK_REALTIME, &end_time); + + if (r == 0) { + milliseconds = 1000.0 * (end_time.tv_sec - start_time.tv_sec) + + (end_time.tv_nsec - start_time.tv_nsec) / 1000000.0; + } + start_time.tv_sec = 0; + start_time.tv_nsec = 0; + + return lround(milliseconds); +} + diff --git a/client/time-stat.h b/client/time-stat.h new file mode 100644 index 0000000..e32a4cb --- /dev/null +++ b/client/time-stat.h @@ -0,0 +1,16 @@ +#ifndef TIME_STAT_H +#define TIME_STAT_H +#include <time.h> + +#ifdef __cplusplus +extern "C" { +#endif +int start_timer(void); + +long int stop_timer(void); +#ifdef __cplusplus +} +#endif + +#endif + |