dnl $Id$ dnl dnl Copyright 1989-2016 MINES ParisTech dnl dnl This file is part of PIPS. dnl dnl PIPS is free software: you can redistribute it and/or modify it dnl under the terms of the GNU General Public License as published by dnl the Free Software Foundation, either version 3 of the License, or dnl any later version. dnl dnl PIPS is distributed in the hope that it will be useful, but WITHOUT ANY dnl WARRANTY; without even the implied warranty of MERCHANTABILITY or dnl FITNESS FOR A PARTICULAR PURPOSE. dnl dnl See the GNU General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License dnl along with PIPS. If not, see . dnl /* a set a timer functions written in C and * called from a Fortran subroutine. * * Fabien Coelho, 1993-1994-1995-1996 */ #include #include #include /******************************************************************** TIME */ /* functions to measure wall clock time and be called by the rt. * there is a static stack of ten timer starts, thus imbrication is possible. * going too far would result in an abort. */ #include #define MAX_COMMENT_LENGTH 63 /* static stack of timings... */ #define TIMER_STACK_SIZE 10 static struct timeval initial[TIMER_STACK_SIZE]; static int timer_index=0; /* static stack of cumulated timings */ #define C_TIMER_STACK_SIZE 10 typedef struct { struct timeval initial; long t_seconds; long t_micros; } c_timer; static c_timer cumulated_timer[C_TIMER_STACK_SIZE]; static int identity_array[C_TIMER_STACK_SIZE]; /* gettimeofday is not declared anywhere! (on sunos at least) */ /* extern int gettimeofday(struct timeval *, struct timezone *); */ /* to print the micros with leading and trailing 0s if needed. * ??? static buffer... I could not find any way to do that with formats. */ static char * print_micros(long micros) { static char buffer[7]; int i; sprintf(buffer, "%6ld", micros); for (i=0; i<6; i++) if (buffer[i]==' ') buffer[i]='0' ; return buffer; } /* Initialize informations about timer identity */ void FUNCTION(init_timer) ARGS(`') /* `' */ { int i; for(i=0;i */ /* is just a TAG which allows to identify the timer */ void FUNCTION(hpfcctimeon) ARGS(`timer') /* `' */ int timer; { int rank; rank = identify_timer(timer); /* push current time */ if (gettimeofday(&cumulated_timer[rank].initial, (struct timezone *) NULL)) fprintf(stderr, "gettimeofday error\n"); } /* Stop cumulated timer */ void FUNCTION(hpfcctimeoff) ARGS(`timer') /* `' */ int timer; { struct timeval current; long seconds, micros; int rank; rank = identify_timer(timer); /* get current time, and compute the delta. */ if (gettimeofday(¤t, (struct timezone *) NULL)) fprintf(stderr, "gettimeofday error\n"); seconds = current.tv_sec-cumulated_timer[rank].initial.tv_sec; micros = current.tv_usec-cumulated_timer[rank].initial.tv_usec; if (micros<0) micros+=1000000, seconds--; /* cumulate with earlier results */ cumulated_timer[rank].t_seconds += seconds; cumulated_timer[rank].t_micros += micros; if (cumulated_timer[rank].t_micros>=1000000) cumulated_timer[rank].t_micros -= 1000000, cumulated_timer[rank].t_seconds++; } /* Print cumulated value for that timer */ void FUNCTION(hpfcprintctime) ARGS(`timer, STRING_ARG(comment)') /* `' */ int timer; STRING_ARG_DECL(comment); { char buffer[ MAX_COMMENT_LENGTH + 1 ]; int i,rank; rank = identify_timer(timer); /* copy the comment in the buffer to ensure there is a NULL at the end. */ for (i=0; i0); timer_index--; /* copy the comment in the buffer to ensure there is a NULL at the end. */ for (i=0; i