From: Adam Dickmeiss Date: Mon, 11 Dec 2006 09:50:36 +0000 (+0000) Subject: Added a utility for doing timings. X-Git-Tag: ZEBRA.2.0.8~40 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=761702c17906c9c71a0c42e7abaa18e578aec012 Added a utility for doing timings. --- diff --git a/include/idzebra/util.h b/include/idzebra/util.h index d8f314c..f64c1af 100644 --- a/include/idzebra/util.h +++ b/include/idzebra/util.h @@ -1,4 +1,4 @@ -/* $Id: util.h,v 1.11 2006-11-21 22:17:49 adam Exp $ +/* $Id: util.h,v 1.12 2006-12-11 09:50:36 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -99,6 +99,23 @@ YAZ_EXPORT void zebra_zint_decode(const char **src, zint *pos); YAZ_EXPORT void zebra_exit(const char *msg); +typedef struct zebra_timing *zebra_timing_t; + +YAZ_EXPORT +zebra_timing_t zebra_timing_create(void); +YAZ_EXPORT +void zebra_timing_start(zebra_timing_t t); +YAZ_EXPORT +void zebra_timing_stop(zebra_timing_t t); +YAZ_EXPORT +double zebra_timing_get_real(zebra_timing_t t); +YAZ_EXPORT +double zebra_timing_get_user(zebra_timing_t t); +YAZ_EXPORT +double zebra_timing_get_sys(zebra_timing_t t); +YAZ_EXPORT +void zebra_timing_destroy(zebra_timing_t *tp); + YAZ_END_CDECL #define CAST_ZINT_TO_INT(x) (int)(x) diff --git a/util/Makefile.am b/util/Makefile.am index a336959..b04241a 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.29 2006-11-21 14:32:38 adam Exp $ +## $Id: Makefile.am,v 1.30 2006-12-11 09:50:36 adam Exp $ noinst_LTLIBRARIES = libidzebra-util.la @@ -17,7 +17,7 @@ LDADD = libidzebra-util.la $(YAZLALIB) libidzebra_util_la_SOURCES = zint.c res.c charmap.c zebramap.c passwddb.c \ zebra-lock.c dirent.c xpath.c atoi_zn.c snippet.c flock.c attrfind.c \ - exit.c it_key.c su_codec.c + exit.c it_key.c su_codec.c timing.c tstpass_SOURCES = tstpass.c diff --git a/util/timing.c b/util/timing.c new file mode 100644 index 0000000..9c39c4d --- /dev/null +++ b/util/timing.c @@ -0,0 +1,111 @@ +/* $Id: timing.c,v 1.1 2006-12-11 09:50:36 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include + +#if HAVE_SYS_TIMES_H +#include +#endif +#if HAVE_SYS_TIME_H +#include +#endif + +#include +#include + +struct zebra_timing { + struct tms tms1, tms2; + struct timeval start_time, end_time; + double real_sec, user_sec, sys_sec; +}; + +zebra_timing_t zebra_timing_create(void) +{ + zebra_timing_t t = xmalloc(sizeof(*t)); + zebra_timing_start(t); + return t; +} + +void zebra_timing_start(zebra_timing_t t) +{ +#if HAVE_SYS_TIMES_H +#if HAVE_SYS_TIME_H + times(&t->tms1); + gettimeofday(&t->start_time, 0); +#endif +#endif + t->real_sec = -1.0; + t->user_sec = -1.0; + t->sys_sec = -1.0; +} + +void zebra_timing_stop(zebra_timing_t t) +{ + t->real_sec = 0.0; + t->user_sec = 0.0; + t->sys_sec = 0.0; +#if HAVE_SYS_TIMES_H +#if HAVE_SYS_TIME_H + gettimeofday(&t->end_time, 0); + times(&t->tms2); + + t->real_sec = ((t->end_time.tv_sec - t->start_time.tv_sec) * 1000000.0 + + t->end_time.tv_usec - t->start_time.tv_usec) / 1000000; + + t->user_sec = (double) (t->tms2.tms_utime - t->tms1.tms_utime)/100; + t->sys_sec = (double) (t->tms2.tms_stime - t->tms1.tms_stime)/100; +#endif +#endif +} + +double zebra_timing_get_real(zebra_timing_t t) +{ + return t->real_sec; +} + +double zebra_timing_get_user(zebra_timing_t t) +{ + return t->user_sec; +} + +double zebra_timing_get_sys(zebra_timing_t t) +{ + return t->sys_sec; +} + +void zebra_timing_destroy(zebra_timing_t *tp) +{ + if (*tp) + { + xfree(*tp); + *tp = 0; + } +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +