Last change
on this file since 2362 was
2019,
checked in by yushan, 4 years ago
|
Graph intermedia commit to a tmp branch
|
-
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.4 KB
|
Rev | Line | |
---|
[347] | 1 | #include "timer.hpp" |
---|
[382] | 2 | #include "mpi.hpp" |
---|
[347] | 3 | #include <string> |
---|
| 4 | #include <map> |
---|
[1158] | 5 | #include <iostream> |
---|
| 6 | #include <sstream> |
---|
[347] | 7 | #include "tracer.hpp" |
---|
| 8 | |
---|
| 9 | namespace xios |
---|
| 10 | { |
---|
[652] | 11 | std::map<std::string,CTimer> CTimer::allTimer; |
---|
[347] | 12 | |
---|
[2019] | 13 | CTimer::CTimer(const std::string& name_, bool trace) : name(name_) |
---|
[347] | 14 | { |
---|
[2019] | 15 | isTracing_=trace ; |
---|
[652] | 16 | reset(); |
---|
[347] | 17 | } |
---|
| 18 | |
---|
| 19 | double CTimer::getTime(void) |
---|
| 20 | { |
---|
| 21 | return MPI_Wtime(); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | void CTimer::suspend(void) |
---|
| 25 | { |
---|
| 26 | if (!suspended) |
---|
| 27 | { |
---|
[2019] | 28 | if (isTracing_) traceEnd(name); |
---|
[652] | 29 | cumulatedTime += getTime() - lastTime; |
---|
[347] | 30 | } |
---|
[652] | 31 | suspended = true; |
---|
[347] | 32 | } |
---|
| 33 | |
---|
| 34 | void CTimer::resume(void) |
---|
| 35 | { |
---|
| 36 | if (suspended) |
---|
| 37 | { |
---|
[652] | 38 | lastTime = getTime(); |
---|
[2019] | 39 | if (isTracing_) traceBegin(name); |
---|
[347] | 40 | } |
---|
[652] | 41 | suspended = false; |
---|
[347] | 42 | } |
---|
| 43 | |
---|
| 44 | void CTimer::reset(void) |
---|
| 45 | { |
---|
[652] | 46 | cumulatedTime = 0.; |
---|
| 47 | suspended = true; |
---|
[347] | 48 | } |
---|
| 49 | |
---|
| 50 | double CTimer::getCumulatedTime(void) |
---|
| 51 | { |
---|
[652] | 52 | return cumulatedTime; |
---|
[347] | 53 | } |
---|
| 54 | |
---|
[2019] | 55 | CTimer& CTimer::get(const std::string name, bool trace) |
---|
[347] | 56 | { |
---|
[652] | 57 | std::map<std::string,CTimer>::iterator it = allTimer.find(name); |
---|
| 58 | if (it == allTimer.end()) |
---|
[2019] | 59 | it = allTimer.insert(std::make_pair(name, CTimer(name,trace))).first; |
---|
[652] | 60 | return it->second; |
---|
[347] | 61 | } |
---|
[1158] | 62 | |
---|
| 63 | string CTimer::getAllCumulatedTime(void) |
---|
| 64 | { |
---|
| 65 | std::ostringstream strOut ; |
---|
| 66 | for(std::map<std::string,CTimer>::iterator it=allTimer.begin();it!=allTimer.end();++it) |
---|
| 67 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
---|
| 68 | return strOut.str() ; |
---|
| 69 | } |
---|
[347] | 70 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.