1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3 * Copyright (c) 1999-2001 Carnegie Mellon University. All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * This work was supported in part by funding from the Defense Advanced
19 * Research Projects Agency and the National Science Foundation of the
20 * United States of America, and the CMU Sphinx Speech Consortium.
22 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * ====================================================================
38 * profile.h -- For timing and event counting.
40 * **********************************************
41 * CMU ARPA Speech Project
43 * Copyright (c) 1999 Carnegie Mellon University.
44 * ALL RIGHTS RESERVED.
45 * **********************************************
49 * Revision 1.10 2005/06/22 03:10:59 arthchan2003
50 * 1, Fixed doxygen documentation, 2, Added keyword.
52 * Revision 1.5 2005/06/15 04:21:47 archan
53 * 1, Fixed doxygen-documentation, 2, Add keyword such that changes will be logged into a file.
55 * Revision 1.4 2005/04/25 19:22:48 archan
56 * Refactor out the code of rescoring from lexical tree. Potentially we want to turn off the rescoring if we need.
58 * Revision 1.3 2005/03/30 01:22:48 archan
59 * Fixed mistakes in last updates. Add
62 * 11-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
65 * 19-Jun-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
66 * Created from earlier Sphinx-3 version.
70 #ifndef _LIBUTIL_PROFILE_H_
71 #define _LIBUTIL_PROFILE_H_
77 } /* Fool Emacs into not indenting things. */
81 * \brief Implementation of profiling, include counting , timing, cpu clock checking
83 * Currently, function host_endian is also in this function. It is
89 /* Win32/WinCE DLL gunk */
90 #include <sphinxbase/sphinxbase_export.h>
91 #include <sphinxbase/prim_type.h>
97 * Generic event counter for profiling. User is responsible for allocating an array
98 * of the desired number. There should be a sentinel with name = NULL.
101 char *name; /**< Counter print name; NULL
102 terminates array of counters
103 Used by pctr_print_all */
104 int32 count; /**< Counter value */
108 * operations of pctr_t
112 * Initialize a counter
113 * @return an initialized counter
117 char *name /**< The name of the counter */
125 void pctr_reset (pctr_t *ctr /**< A pointer of a counter */
132 void pctr_print(FILE *fp, /**< A file pointer */
133 pctr_t *ctr /**< A pointer of a counter */
137 * Increment a counter
140 void pctr_increment (pctr_t *ctr, /**< A pointer of a counter */
141 int32 inc /**< The increment of the counter */
148 void pctr_free(pctr_t* ctr /**< A pointer of a counter */
154 * Generic timer structures and functions for coarse-grained performance measurements
155 * using standard system calls.
158 const char *name; /**< Timer print name; NULL terminates an array of timers.
159 Used by ptmr_print_all */
160 float64 t_cpu; /**< CPU time accumulated since most recent reset op */
161 float64 t_elapsed; /**< Elapsed time accumulated since most recent reset */
162 float64 t_tot_cpu; /**< Total CPU time since creation */
163 float64 t_tot_elapsed; /**< Total elapsed time since creation */
164 float64 start_cpu; /**< ---- FOR INTERNAL USE ONLY ---- */
165 float64 start_elapsed; /**< ---- FOR INTERNAL USE ONLY ---- */
170 /** Start timing using tmr */
172 void ptmr_start (ptmr_t *tmr /**< The timer*/
175 /** Stop timing and accumulate tmr->{t_cpu, t_elapsed, t_tot_cpu, t_tot_elapsed} */
177 void ptmr_stop (ptmr_t *tmr /**< The timer*/
180 /** Reset tmr->{t_cpu, t_elapsed} to 0.0 */
182 void ptmr_reset (ptmr_t *tmr /**< The timer*/
185 /** Reset tmr->{t_cpu, t_elapsed, t_tot_cpu, t_tot_elapsed} to 0.0
188 void ptmr_init (ptmr_t *tmr /**< The timer*/
193 * Reset t_cpu, t_elapsed of all timer modules in array tmr[] to 0.0.
194 * The array should be terminated with a sentinel with .name = NULL.
197 void ptmr_reset_all (ptmr_t *tmr /**< The timer*/
201 * Print t_cpu for all timer modules in tmr[], normalized by norm (i.e., t_cpu/norm).
202 * The array should be terminated with a sentinel with .name = NULL.
205 void ptmr_print_all (FILE *fp, /**< The file pointer */
206 ptmr_t *tmr, /**< The timer*/
212 * Return the processor clock speed (in MHz); only available on some machines (Alphas).
213 * The dummy argument can be any integer value.
216 int32 host_pclk (int32 dummy);
220 * Check the native byte-ordering of the machine by writing a magic
221 * number to a temporary file and reading it back. * Return value:
222 * 0 if BIG-ENDIAN, 1 if LITTLE-ENDIAN, -1 if error.
225 int32 host_endian ( void );