source: Sophya/trunk/SophyaLib/SysTools/ctimer.h@ 3383

Last change on this file since 3383 was 3274, checked in by ansari, 18 years ago

Ajout methodes d'acces au temps CPU et elapsed ds la classe Timer , Reza 05/07/2007

File size: 2.1 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2//
3// $Id: ctimer.h,v 1.5 2007-07-06 12:54:12 ansari Exp $
4//
5
6
7#ifndef CTIMER_SEEN
8#define CTIMER_SEEN
9
10#include "machdefs.h"
11#include <sys/types.h>
12#include <time.h>
13#include <iostream>
14#include <stdio.h>
15#include <string>
16
17// <summary> Permet de chronometrer des fonctions. </summary>
18// Class Timer qui memorise l'heure de sa creation, et le temps CPU.
19// A la fin du bloc ou de la procedure, l'objet est detruit,
20// et son destructeur affiche le temps ecoule.
21
22namespace SOPHYA {
23
24//! Simple chronometer class
25class Timer {
26public:
27 // L'objet memorise le temps CPU et l'heure, et le nom donne
28 Timer(const char* name=0, bool prfg=true);
29
30 // Le destructeur appelle split sans parametre.
31 virtual ~Timer();
32
33 // Affiche le temps ecoule total/partiel, avec le nom eventuel.
34 // Si pas de parametre affiche le nom donne a la creation.
35 void Split(const char* comm=0, bool prfg=false);
36
37 // Sert a eviter que GNU ne pretende qu'on utilise pas l'objet...
38 /*! To avoid not used object compiler warnings */
39 void Nop() {}
40
41 /*! \brief Return the total elapsed time (number of seconds),
42 between the object creation and the last call to Split().
43 */
44 inline int_8 TotalElapsedTime() { return elapSecT ; }
45 /*! \brief Return the partial elapsed time (number of seconds).
46 between the last two calls to Split().
47 */
48 inline int_8 PartialElapsedTime() { return elapSecP ; }
49
50 /*! \brief Return the total CPU time in seconds,
51 between the object creation and the last call to Split().
52 */
53 inline float TotalCPUTime() { return cpuSecT; }
54 /*! \brief Return the partial CPU time in seconds,
55 between the last two calls to Split().
56 */
57 inline float PartialCPUTime() { return cpuSecP; }
58
59private:
60 clock_t cpu0, cpuSplit;
61 time_t elapse0, elapseSplit;
62 float cpuSecT, cpuSecP; // Total and partial CPU time
63 int_8 elapSecT, elapSecP; // Total and partial elapsed time
64 string timerName;
65 bool defprtflg;
66};
67
68} // namespace SOPHYA
69
70#define TIMEF Timer timer(__PRETTY_FUNCTION__); timer.Nop();
71
72#endif // CTIMER_SEEN
Note: See TracBrowser for help on using the repository browser.