source: Sophya/trunk/SophyaLib/SysTools/timing.c@ 2624

Last change on this file since 2624 was 2624, checked in by cmv, 21 years ago

rustine pour le calcul des temps CPU en overflow cmv 30/09/04

File size: 2.7 KB
Line 
1/* Fonction d'impression de temps de calcul et de temps passe */
2/* R.Ansari Juin 93 */
3
4/*
5++
6 Module Temps CPU, passé (C)
7 Lib LibsUtil
8 include timing.h
9
10 Fonctions permettant d'imprimer le temps CPU consommé et le temps
11 passé.
12--
13*/
14
15/*
16++
17 void InitTim()
18 Initialisation des chronomètres
19 void PrtTim(char *comm)
20 Imprime le temps CPU, et le temps passé depuis
21 le dernier appel à "PrtTim()" avec le commentaire
22 "comm". Imprime aussi le cumul du temps CPU et du
23 temps passé depuis l'appel à "InitTim()".
24--
25*/
26
27#include <stdlib.h>
28#include <stdio.h>
29#include <string.h>
30#include <time.h>
31
32#include "timing.h"
33
34static clock_t CPUT0=0, CPUT=0;
35static time_t ELT0=0, ELT=0;
36/*------- modifs Christophe 30/09/04
37On somme nous memes les temps partiels pour avoir une autre
38mesure du temps CPU total. En effet, pour des jobs longs
39clock()-CPUT0 depasse la possibilite de stockage d'un entier
4032 bits car clock() renvoit des microsecondes.
41Par exemple pour un job de 20h = 72e+9 micro-secondes > 2^32
42(Ca ne marche plus pour des jobs > 2146 sec ~= 2^32 microsec)
43Seul un entier 64 bits pourrait donner un resultat correct
44mais il n'existe pas sur toutes les plateformes.
45-------*/
46static double tcalt_sum = 0.;
47
48/* Nouvelle-Fonction */
49/*!
50 \ingroup SysTools
51 Initializes CPU and elapsed time timer (C function).
52 The values of the CPU and elapsed time can then be printed
53 using \b PrtTim()
54*/
55void InitTim(void)
56{
57CPUT0 = CPUT = clock();
58ELT0 = ELT = time(NULL);
59tcalt_sum = 0.;
60return;
61}
62
63/* Nouvelle-Fonction */
64/*!
65 \ingroup SysTools
66 Prints the values of the CPU and elapsed time, since call to \b InitTim().
67*/
68void PrtTim(const char * Comm)
69{
70double tcal,tcalt;
71clock_t cput;
72time_t elt;
73unsigned long etm,etmt;
74
75cput = clock();
76tcalt = ( (double)(cput) - (double)(CPUT0) ) / (double)(CLOCKS_PER_SEC);
77tcal = ( (double)(cput) - (double)(CPUT) ) / (double)(CLOCKS_PER_SEC);
78
79elt = time(NULL);
80etm = elt - ELT;
81etmt = elt - ELT0;
82/*------- modifs Christophe 30/09/04
83- tcalt_sum en 1/100 ieme de seconde:
84 On imprime des Secondes que l'on somme N fois
85 -> on se donne une precision a 1/100 de Seconde
86- Au moment ou clock()>2^32 tcal devient negatif
87 ==> On ne somme donc pas tcal et on TRICHE en sommant "etm"
88 (pour etre vrai il faut que le process ait 100% du CPU !)
89-------*/
90if(tcal>0.) tcalt_sum += tcal*100.; else tcalt_sum += (double)etm*100.;
91
92printf("%s CPUTime: Total= %g (Sum~= %.1f) (Partial= %g) Sec. \n",
93 Comm, tcalt, tcalt_sum/100., tcal);
94printf("ElapsedTime(hh:mm:ss): Total= %02d:%02d:%02d ",
95 etmt/3600, (etmt%3600)/60, etmt%60);
96printf(" (Partial= %02d:%02d:%02d)\n",
97 etm/3600, (etm%3600)/60, etm%60);
98
99ELT = elt;
100CPUT = cput;
101return;
102}
Note: See TracBrowser for help on using the repository browser.