XIOS  1.0
Xml I/O Server
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Amis Macros
timer.cpp
Aller à la documentation de ce fichier.
1 #include "timer.hpp"
2 #include "mpi.hpp"
3 #include <string>
4 #include <map>
5 #include <iostream>
6 #include <sstream>
7 #include "tracer.hpp"
8 
9 namespace xios
10 {
11  std::map<std::string,CTimer> CTimer::allTimer;
12 
13  CTimer::CTimer(const std::string& name_) : name(name_)
14  {
15  reset();
16  }
17 
18  double CTimer::getTime(void)
19  {
20  return MPI_Wtime();
21  }
22 
23  void CTimer::suspend(void)
24  {
25  if (!suspended)
26  {
27  traceEnd(name);
29  }
30  suspended = true;
31  }
32 
33  void CTimer::resume(void)
34  {
35  if (suspended)
36  {
37  lastTime = getTime();
39  }
40  suspended = false;
41  }
42 
43  void CTimer::reset(void)
44  {
45  cumulatedTime = 0.;
46  suspended = true;
47  }
48 
50  {
51  return cumulatedTime;
52  }
53 
54  CTimer& CTimer::get(const std::string name)
55  {
56  std::map<std::string,CTimer>::iterator it = allTimer.find(name);
57  if (it == allTimer.end())
58  it = allTimer.insert(std::make_pair(name, CTimer(name))).first;
59  return it->second;
60  }
61 
63  {
64  std::ostringstream strOut ;
65  for(std::map<std::string,CTimer>::iterator it=allTimer.begin();it!=allTimer.end();++it)
66  strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ;
67  return strOut.str() ;
68  }
69 }
void traceEnd(const string &name)
Definition: tracer.cpp:75
bool suspended
Definition: timer.hpp:14
double getCumulatedTime(void)
Definition: timer.cpp:49
void suspend(void)
Definition: timer.cpp:23
#define xios(arg)
static double getTime(void)
Definition: timer.cpp:18
void traceBegin(const string &name)
Definition: tracer.cpp:50
double lastTime
Definition: timer.hpp:13
void resume(void)
Definition: timer.cpp:33
static std::map< std::string, CTimer > allTimer
Definition: timer.hpp:22
static CTimer & get(std::string name)
Definition: timer.cpp:54
double cumulatedTime
Definition: timer.hpp:12
CTimer(const std::string &name)
Definition: timer.cpp:13
static std::string getAllCumulatedTime(void)
Definition: timer.cpp:62
std::string name
Definition: timer.hpp:15
void reset(void)
Definition: timer.cpp:43