71 #if defined(_WIN32) && !defined(__SYMBIAN32__)
76 #elif defined(HAVE_UNISTD_H)
78 # include <sys/time.h>
79 # include <sys/resource.h>
83 #pragma warning (disable: 4996)
90 #if defined(_WIN32_WCE) || defined(_WIN32_WP)
91 DWORD unlink(
const char *filename)
97 len = mbstowcs(NULL, filename, 0);
98 wfilename =
ckd_calloc(len+1,
sizeof(*wfilename));
99 mbstowcs(wfilename, filename, len);
100 rv = DeleteFileW(wfilename);
137 fprintf(fp,
"[%d %s]", ctr->
count, ctr->
name);
151 #if defined(_WIN32) && !defined(GNUWINCE) && !defined(__SYMBIAN32__)
153 #define TM_LOWSCALE 1e-7
154 #define TM_HIGHSCALE (4294967296.0 * TM_LOWSCALE);
157 make_sec(FILETIME * tm)
161 dt = tm->dwLowDateTime * TM_LOWSCALE;
162 dt += tm->dwHighDateTime * TM_HIGHSCALE;
170 make_sec(
struct timeval *s)
172 return (s->tv_sec + s->tv_usec * 0.000001);
181 #if (! defined(_WIN32)) || defined(GNUWINCE) || defined(__SYMBIAN32__)
182 struct timeval e_start;
184 #if (! defined(_HPUX_SOURCE)) && (! defined(__SYMBIAN32__))
188 getrusage(RUSAGE_SELF, &start);
189 tm->
start_cpu = make_sec(&start.ru_utime) + make_sec(&start.ru_stime);
192 gettimeofday(&e_start, 0);
194 #elif defined(_WIN32_WP)
197 #elif defined(_WIN32_WCE)
203 FILETIME t_create, t_exit, kst, ust;
206 pid = GetCurrentProcess();
207 GetProcessTimes(pid, &t_create, &t_exit, &kst, &ust);
208 tm->
start_cpu = make_sec(&ust) + make_sec(&kst);
218 float64 dt_cpu, dt_elapsed;
220 #if (! defined(_WIN32)) || defined(GNUWINCE) || defined(__SYMBIAN32__)
221 struct timeval e_stop;
223 #if (! defined(_HPUX_SOURCE)) && (! defined(__SYMBIAN32__))
227 getrusage(RUSAGE_SELF, &stop);
229 make_sec(&stop.ru_utime) + make_sec(&stop.ru_stime) -
235 gettimeofday(&e_stop, 0);
237 #elif defined(_WIN32_WP)
238 dt_cpu = GetTickCount64() / 1000 - tm->
start_cpu;
240 #elif defined(_WIN32_WCE)
242 dt_cpu = GetTickCount() / 1000 - tm->
start_cpu;
246 FILETIME t_create, t_exit, kst, ust;
249 pid = GetCurrentProcess();
250 GetProcessTimes(pid, &t_create, &t_exit, &kst, &ust);
251 dt_cpu = make_sec(&ust) + make_sec(&kst) - tm->
start_cpu;
252 dt_elapsed = ((float64) clock() / CLOCKS_PER_SEC) - tm->
start_elapsed;
284 for (; tm->
name; tm++)
294 for (; tm->
name; tm++)
295 fprintf(fp,
" %6.2fx %s", tm->
t_cpu * norm, tm->
name);
304 int32 BYTE_ORDER_MAGIC;
309 file =
"/tmp/__EnDiAn_TeSt__";
311 if ((fp = fopen(file,
"wb")) == NULL) {
312 E_ERROR(
"Failed to open file '%s' for writing", file);
316 BYTE_ORDER_MAGIC = (int32) 0x11223344;
318 k = (int32) BYTE_ORDER_MAGIC;
319 if (fwrite(&k,
sizeof(int32), 1, fp) != 1) {
320 E_ERROR(
"Failed to write to file '%s'\n", file);
327 if ((fp = fopen(file,
"rb")) == NULL) {
332 if (fread(buf, 1,
sizeof(int32), fp) !=
sizeof(int32)) {
333 E_ERROR(
"Failed to read from file '%s'\n", file);
342 endian = (buf[0] == (BYTE_ORDER_MAGIC & 0x000000ff)) ? 1 : 0;
#define E_ERROR_SYSTEM(...)
Print error text; Call perror("");.
SPHINXBASE_EXPORT void ptmr_reset_all(ptmr_t *tmr)
Reset t_cpu, t_elapsed of all timer modules in array tmr[] to 0.0.
SPHINXBASE_EXPORT pctr_t * pctr_new(char *name)
operations of pctr_t
int32 count
Counter value.
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
SPHINXBASE_EXPORT void ptmr_start(ptmr_t *tmr)
Start timing using tmr.
#define E_ERROR(...)
Print error message to error log.
Sphinx's memory allocation/deallocation routines.
float64 t_tot_elapsed
Total elapsed time since creation.
Generic timer structures and functions for coarse-grained performance measurements using standard sys...
float64 start_elapsed
-— FOR INTERNAL USE ONLY -—
#define ckd_salloc(ptr)
Macro for ckd_salloc
float64 start_cpu
-— FOR INTERNAL USE ONLY -—
const char * name
Timer print name; NULL terminates an array of timers.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
SPHINXBASE_EXPORT void pctr_free(pctr_t *ctr)
Free the counter.
SPHINXBASE_EXPORT void pctr_print(FILE *fp, pctr_t *ctr)
Print a counter.
float64 t_cpu
CPU time accumulated since most recent reset op.
float64 t_tot_cpu
Total CPU time since creation.
SPHINXBASE_EXPORT void ptmr_print_all(FILE *fp, ptmr_t *tmr, float64 norm)
Print t_cpu for all timer modules in tmr[], normalized by norm (i.e., t_cpu/norm).
SPHINXBASE_EXPORT void pctr_increment(pctr_t *ctr, int32 inc)
Increment a counter.
SPHINXBASE_EXPORT void pctr_reset(pctr_t *ctr)
Reset a counter.
SPHINXBASE_EXPORT void ptmr_init(ptmr_t *tmr)
Reset tmr->{t_cpu, t_elapsed, t_tot_cpu, t_tot_elapsed} to 0.0.
Implementation of logging routines.
SPHINXBASE_EXPORT void ptmr_stop(ptmr_t *tmr)
Stop timing and accumulate tmr->{t_cpu, t_elapsed, t_tot_cpu, t_tot_elapsed}.
float64 t_elapsed
Elapsed time accumulated since most recent reset.
Implementation of profiling, include counting , timing, cpu clock checking.
SPHINXBASE_EXPORT void ptmr_reset(ptmr_t *tmr)
Reset tmr->{t_cpu, t_elapsed} to 0.0.
char * name
Counter print name; NULL terminates array of counters Used by pctr_print_all.
Generic event counter for profiling.