source: XIOS/trunk/src/timer.cpp @ 652

Last change on this file since 652 was 652, checked in by rlacroix, 8 years ago

Timer: Avoid using heap allocations.

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1#include "timer.hpp"
2#include "mpi.hpp"
3#include <string>
4#include <map>
5#include "tracer.hpp"
6
7namespace xios
8{
9  std::map<std::string,CTimer> CTimer::allTimer;
10 
11  CTimer::CTimer(const std::string& name_) : name(name_) 
12  { 
13    reset();
14  }
15
16  double CTimer::getTime(void)
17  {
18    return MPI_Wtime();
19  }
20 
21  void CTimer::suspend(void)
22  {
23    if (!suspended) 
24    {
25      traceEnd(name);
26      cumulatedTime += getTime() - lastTime;
27    }
28    suspended = true;
29  }
30 
31  void CTimer::resume(void)
32  {
33    if (suspended) 
34    {
35      lastTime = getTime();
36      traceBegin(name);
37    }
38    suspended = false;
39  }
40 
41  void CTimer::reset(void)
42  {
43    cumulatedTime = 0.;
44    suspended = true;
45  }
46 
47  double CTimer::getCumulatedTime(void)
48  {
49    return cumulatedTime;
50  }
51 
52  CTimer& CTimer::get(const std::string name)
53  {
54    std::map<std::string,CTimer>::iterator it = allTimer.find(name);
55    if (it == allTimer.end())
56      it = allTimer.insert(std::make_pair(name, CTimer(name))).first;
57    return it->second;
58  }
59}
Note: See TracBrowser for help on using the repository browser.