libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_timer.h

Go to the documentation of this file.
00001 /* 00002 * Copyright 2005 Tiian 00003 * {In real life Tiian is Christian Ferrari} 00004 * This file is part of "libjf" package. 00005 * 00006 * "libjf" is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * "libjf" is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with ; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 #ifndef JF_TIMER_H 00021 #define JF_TIMER_H 00022 00023 00024 00025 #include <jf/jf_config.h> 00026 00027 00028 00029 #ifdef HAVE_UNISTD_H 00030 # include <unistd.h> 00031 #endif /* HAVE_UNISTD_H */ 00032 #ifdef HAVE_SYS_TIME_H 00033 # include <sys/time.h> 00034 #endif /* HAVE_SYS_TIMES_H */ 00035 #ifdef HAVE_SYS_TIMES_H 00036 # include <sys/times.h> 00037 #endif /* HAVE_SYS_TIMES_H */ 00038 00039 00040 00041 /* save old JF_TRACE_MODULE and set a new value */ 00042 #ifdef JF_TRACE_MODULE 00043 # define JF_TRACE_MODULE_SAVE JF_TRACE_MODULE 00044 # undef JF_TRACE_MODULE 00045 #else 00046 # undef JF_TRACE_MODULE_SAVE 00047 #endif /* JF_TRACE_MODULE */ 00048 #define JF_TRACE_MODULE JF_TRACE_MOD_LIB_TIMER 00049 00050 00051 00052 #if defined(SIZEOF_CLOCK_T) && defined(HAVE_TIMES) && defined(HAVE_SYSCONF) && defined(HAVE_GETTIMEOFDAY) 00053 # define JF_TIMER_AVAILABLE 00054 # define JF_FEATURE_TIMER_ACTIVE "yes" 00055 #else 00056 # define JF_FEATURE_TIMER_ACTIVE "no" 00057 #endif /* if defined(SIZEOF_CLOCK_T) && defined(HAVE_TIMES) */ 00058 00059 00060 00061 #ifdef __cplusplus 00062 extern "C" { 00063 #endif /* __cplusplus */ 00064 00065 00066 00071 extern const char *jf_feature_timer; 00072 00073 00074 00080 typedef struct { 00084 int started; 00085 # ifdef JF_TIMER_AVAILABLE 00086 00089 long ticks_per_sec; 00093 clock_t base_usr_time; 00097 clock_t base_sys_time; 00101 clock_t usr_time; 00105 clock_t sys_time; 00109 struct timezone tz; 00113 struct timeval base_ela_time; 00117 struct timeval ela_time; 00118 # endif /* JF_TIMER_AVAILABLE */ 00119 } jf_timer_t; 00120 00121 00122 00129 int jf_timer_reset(jf_timer_t *t); 00130 00131 00132 00138 int jf_timer_start(jf_timer_t *t); 00139 00140 00141 00147 int jf_timer_stop(jf_timer_t *t); 00148 00149 00150 00151 # ifdef JF_TIMER_AVAILABLE 00152 00157 static double inline jf_timer_get_usr_time(const jf_timer_t *t) { 00158 return (double)t->usr_time / (double)t->ticks_per_sec; 00159 } 00160 # else 00161 # define jf_timer_get_usr_time(t) (0.0) 00162 # endif /* JF_TIMER_AVAILABLE */ 00163 00164 00165 00166 # ifdef JF_TIMER_AVAILABLE 00167 00172 static double inline jf_timer_get_sys_time(const jf_timer_t *t) { 00173 return (double)t->sys_time / (double)t->ticks_per_sec; 00174 } 00175 # else 00176 # define jf_timer_get_usr_time(t) (0.0) 00177 # endif /* JF_TIMER_AVAILABLE */ 00178 00179 00180 00181 # ifdef JF_TIMER_AVAILABLE 00182 00187 static double inline jf_timer_get_ela_time(const jf_timer_t *t) { 00188 return (double)t->ela_time.tv_sec + 00189 ((double)t->ela_time.tv_usec / (double)1000000); 00190 } 00191 # else 00192 # define jf_timer_get_usr_time(t) (0.0) 00193 # endif /* JF_TIMER_AVAILABLE */ 00194 00195 00196 00197 #ifdef __cplusplus 00198 } 00199 #endif /* __cplusplus */ 00200 00201 00202 00203 /* restore old value of JF_TRACE_MODULE */ 00204 #ifdef JF_TRACE_MODULE_SAVE 00205 # undef JF_TRACE_MODULE 00206 # define JF_TRACE_MODULE JF_TRACE_MODULE_SAVE 00207 # undef JF_TRACE_MODULE_SAVE 00208 #endif /* JF_TRACE_MODULE_SAVE */ 00209 00210 00211 00212 #endif /* JF_TIMER_H */

Copyright 2005 © Tiian