Changeset 3274 in Sophya for trunk/SophyaLib/SysTools/ctimer.cc


Ignore:
Timestamp:
Jul 6, 2007, 2:54:12 PM (18 years ago)
Author:
ansari
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/ctimer.cc

    r2615 r3274  
    11//
    2 // $Id: ctimer.cc,v 1.6 2004-09-10 09:54:57 cmv Exp $
     2// $Id: ctimer.cc,v 1.7 2007-07-06 12:54:12 ansari Exp $
    33//
    44
     
    2323//      courante comme message. Le temps écoulé sera affiché à la sortie
    2424//      de la function.
    25 //      * SPLITTIME affiche le temps partiel du compteur crée par TIMEF
    26 //      * TIMEN(nom) permet de donner un autre nom que le nom de la fonction.
    2725//--
    2826
    2927
    30 //++
    31 // Titre        Constructeurs
    32 //--
    33 
    34 //++
    35 // Timer::Timer(const char* name)
    36 //      Crée un objet qui mémorise l'heure et le temps CPU du process courant.
    37 //      Le destructeur affiche les temps écoulé et CPU utilisé.
    38 //--
    3928
    4029/*!
     
    4534  measuring the CPU and elapsed time in functions. The constructor
    4635  keeps the start time (and CPU time) and an optional message.
    47   The \b Split method displays the partial time, and destructor
     36  The \b Split updates partial times and optionaly displays partial and
     37  total CPU and elapsed time.
     38  The destructor calls Split() if the object has been created with prfg=true.
    4839  displays the total CPU and elapsed time since timer creation.
    4940  The macro \b  TIMEF create a timer object with the function name.
    50   The macro \b  SPLITTIME calls the split methode for the timer created
    51   by TIMEF. A named timer can be created using the macro \b TIMEN(nom)
     41  The elapsed and CPU time are displayed at the end of the bloc or function.
    5242*/
    5343
    54 /*! Constructor with the specification of a optional name or message */
    55 Timer::Timer(const char* name)
    56 : timerName(name)
     44/*!
     45  \brief Constructor with the specification of a optional name or message
     46  and default print flag.
     47  if \b prfg==true , a call to Split() causes the display of partial and
     48  total CPU and elapsed time.
     49*/
     50Timer::Timer(const char* name, bool prfg)
     51  : timerName(name) , defprtflg(prfg)
    5752{
    5853  cpu0 = cpuSplit = clock();
    5954  elapse0 = elapseSplit = time(0);
     55  cpuSecT = cpuSecP = 0.;
     56  elapSecT = elapSecP = 0;
    6057}
    6158
    62 //++
    63 // Titre        Méthodes
    64 //--
     59//! The destructor call Split() if the object has been created with prtflag=true.
     60Timer::~Timer()
     61{
     62  if (defprtflg) Split();
     63}
    6564
    66 //++
    67 // Timer::Split(const char* comm)
    68 //      Affiche le temps partiel.
    69 //--
    7065
    71 /*! Method which displays the partial CPU and elapsed time
     66/*! This method updates the CPU and elapsed time.
     67    If the prfg==true or the constructor prfg==true, it also displays (prints)
     68    the partial CPU and elapsed time
    7269    An optional message can be passed to be used instead of the
    7370    timer name
    7471*/
    75 void Timer::Split(const char* comm)
     72void Timer::Split(const char* comm, bool prfg)
    7673{
    7774  time_t elapse = time(0);
    7875  clock_t cpu   = clock();
    7976
    80   float cpuSecT = ((float)cpu - (float)cpu0) / (float)(CLOCKS_PER_SEC);
    81   float cpuSecP = ((float)cpu - (float)cpuSplit) / (float)(CLOCKS_PER_SEC);
     77  cpuSecT = ((float)cpu - (float)cpu0) / (float)(CLOCKS_PER_SEC);
     78  cpuSecP = ((float)cpu - (float)cpuSplit) / (float)(CLOCKS_PER_SEC);
    8279 
    83   int etm  = elapse - elapseSplit;
    84   int etmt = elapse - elapse0;
     80  elapSecP  = elapse - elapseSplit;
     81  elapSecT = elapse - elapse0;
     82
     83
     84  //  cumlcpu += (double)cpuSecP;
     85  //  cumulelapse += (int_8)etm;
     86
     87  elapseSplit = elapse;
     88  cpuSplit    = cpu;
     89
     90  if ( !defprtflg && !prfg )  return;
    8591
    8692  cout << "***Timing " << (comm ? comm : timerName.c_str()) << endl;
     
    9096// autres C++ que GNU), on fait un cout << chaine.
    9197
     98  int etm  = elapSecP;
     99  int etmt = elapSecT;
    92100  char out[200];
    93101  sprintf(out,"CPU     Time: Total= %g (Partial= %g) Sec.",
     
    100108
    101109  cout << out << endl;
    102 
    103   elapseSplit = elapse;
    104   cpuSplit    = cpu;
    105110}
    106111
    107 Timer::~Timer()
    108 {
    109   Split();
    110 }
Note: See TracChangeset for help on using the changeset viewer.