1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/***************************************************************/
/*** Measuring processor time ***/
/***************************************************************/
#ifndef _TIMING_H
#define _TIMING_H
#include "psyco.h"
#include "Python/pyver.h"
#define TIMING_WITH_TICK_COUNTER 1 /* requires Python 2.2.2 */
#define TIMING_WITH_PROCESSOR_INSN 2 /* processor-specific timers */
#define TIMING_WITH_CLOCK 3 /* requires the clock() function */
/* does clock() return an absolute time, or per-process CPU time ?
Let's try to guess. */
#ifdef MS_WINDOWS
# define CLOCK_IS_PER_PROCESS 0 /* at least on Win9x -- don't know on NT */
#else
# define CLOCK_IS_PER_PROCESS 1 /* by default -- only tested under Linux */
#endif
/* Selection of the timing method */
#if HAVE_PYTHON_SUPPORT
# define TIMING_WITH TIMING_WITH_TICK_COUNTER
#elif defined(HAVE_CLOCK) && CLOCK_IS_PER_PROCESS
# define TIMING_WITH TIMING_WITH_CLOCK
#else
# define TIMING_WITH TIMING_WITH_PROCESSOR_INSN
#endif
#define measure_is_zero(m) ((m) == (time_measure_t) 0)
/* Check that the processor has dedicated timers */
#if TIMING_WITH == TIMING_WITH_PROCESSOR_INSN
# include <itiming.h>
# ifndef CURRENT_TIME_READER
# undef TIMING_WITH /* no processor support */
# define TIMING_WITH TIMING_WITH_CLOCK
# endif
#endif
/***************************************************************/
#if TIMING_WITH == TIMING_WITH_TICK_COUNTER
/***************************************************************/
#define MEASURE_ALL_THREADS 1
typedef int time_measure_t;
PSY_INLINE time_measure_t get_measure(PyThreadState* tstate)
{
int result = tstate->tick_counter;
tstate->tick_counter = 0;
return result;
}
/***************************************************************/
#else /* no tick_counter */
/***************************************************************/
/* without tick_counter, it is hard to tell the threads apart. */
#define MEASURE_ALL_THREADS 0
#if TIMING_WITH == TIMING_WITH_CLOCK
# ifndef HAVE_CLOCK
# error "no timing method available, sorry"
# endif
# include <time.h>
# define CURRENT_TIME_READER clock
# define time_measure_t clock_t
#endif
/* 'tstate' parameter ignored */
PSY_INLINE time_measure_t get_measure(PyThreadState* tstate)
{
static time_measure_t prevtime = (time_measure_t) 0;
time_measure_t curtime = CURRENT_TIME_READER();
time_measure_t result = curtime - prevtime;
prevtime = curtime;
return result;
}
/***************************************************************/
#endif /* tick_counter */
/***************************************************************/
#endif /* _TIMING_H */
|