Last change
on this file since 2698 was
2687,
checked in by jderouillat, 2 months ago
|
Merge dev/XIOS_NOTIFICATIONS_MANAGER into trunk
|
-
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.6 KB
|
Line | |
---|
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_, bool trace) : name(name_), num_(0) |
---|
14 | { |
---|
15 | isTracing_=trace ; |
---|
16 | reset(); |
---|
17 | } |
---|
18 | |
---|
19 | double CTimer::getTime(void) |
---|
20 | { |
---|
21 | return MPI_Wtime(); |
---|
22 | } |
---|
23 | |
---|
24 | void CTimer::suspend(void) |
---|
25 | { |
---|
26 | if (!suspended) |
---|
27 | { |
---|
28 | if (isTracing_) traceEnd(name); |
---|
29 | cumulatedTime += getTime() - lastTime; |
---|
30 | } |
---|
31 | suspended = true; |
---|
32 | } |
---|
33 | |
---|
34 | void CTimer::resume(void) |
---|
35 | { |
---|
36 | if (suspended) |
---|
37 | { |
---|
38 | num_++ ; |
---|
39 | lastTime = getTime(); |
---|
40 | if (isTracing_) traceBegin(name); |
---|
41 | } |
---|
42 | suspended = false; |
---|
43 | } |
---|
44 | |
---|
45 | void CTimer::reset(void) |
---|
46 | { |
---|
47 | num_= 0 ; |
---|
48 | cumulatedTime = 0.; |
---|
49 | suspended = true; |
---|
50 | } |
---|
51 | |
---|
52 | double CTimer::getCumulatedTime(void) |
---|
53 | { |
---|
54 | return cumulatedTime; |
---|
55 | } |
---|
56 | |
---|
57 | double CTimer::getNumCall(void) |
---|
58 | { |
---|
59 | return num_; |
---|
60 | } |
---|
61 | |
---|
62 | double CTimer::getAverageTime(void) |
---|
63 | { |
---|
64 | if (num_==0) return 0. ; |
---|
65 | else return cumulatedTime/num_; |
---|
66 | } |
---|
67 | |
---|
68 | CTimer& CTimer::get(const std::string name, bool trace) |
---|
69 | { |
---|
70 | std::map<std::string,CTimer>::iterator it = allTimer.find(name); |
---|
71 | if (it == allTimer.end()) |
---|
72 | it = allTimer.insert(std::make_pair(name, CTimer(name,trace))).first; |
---|
73 | return it->second; |
---|
74 | } |
---|
75 | |
---|
76 | string CTimer::getAllCumulatedTime(void) |
---|
77 | { |
---|
78 | std::ostringstream strOut ; |
---|
79 | for(std::map<std::string,CTimer>::iterator it=allTimer.begin();it!=allTimer.end();++it) |
---|
80 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
---|
81 | return strOut.str() ; |
---|
82 | } |
---|
83 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.