Last change
on this file since 2330 was
1646,
checked in by yushan, 6 years ago
|
branch merged with trunk @1645. arch file (ep&mpi) added for ADA
|
-
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
|
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" |
---|
[1646] | 8 | #ifdef _usingEP |
---|
[1601] | 9 | using namespace ep_lib; |
---|
[1646] | 10 | #endif |
---|
[347] | 11 | |
---|
| 12 | namespace xios |
---|
| 13 | { |
---|
[1601] | 14 | std::map<std::string,CTimer> *CTimer::allTimer_ptr = 0; |
---|
[347] | 15 | |
---|
[652] | 16 | CTimer::CTimer(const std::string& name_) : name(name_) |
---|
[347] | 17 | { |
---|
[652] | 18 | reset(); |
---|
[347] | 19 | } |
---|
| 20 | |
---|
| 21 | double CTimer::getTime(void) |
---|
| 22 | { |
---|
| 23 | return MPI_Wtime(); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | void CTimer::suspend(void) |
---|
| 27 | { |
---|
| 28 | if (!suspended) |
---|
| 29 | { |
---|
[652] | 30 | traceEnd(name); |
---|
| 31 | cumulatedTime += getTime() - lastTime; |
---|
[347] | 32 | } |
---|
[652] | 33 | suspended = true; |
---|
[347] | 34 | } |
---|
| 35 | |
---|
| 36 | void CTimer::resume(void) |
---|
| 37 | { |
---|
| 38 | if (suspended) |
---|
| 39 | { |
---|
[652] | 40 | lastTime = getTime(); |
---|
| 41 | traceBegin(name); |
---|
[347] | 42 | } |
---|
[652] | 43 | suspended = false; |
---|
[347] | 44 | } |
---|
| 45 | |
---|
| 46 | void CTimer::reset(void) |
---|
| 47 | { |
---|
[652] | 48 | cumulatedTime = 0.; |
---|
| 49 | suspended = true; |
---|
[347] | 50 | } |
---|
| 51 | |
---|
| 52 | double CTimer::getCumulatedTime(void) |
---|
| 53 | { |
---|
[652] | 54 | return cumulatedTime; |
---|
[347] | 55 | } |
---|
| 56 | |
---|
[652] | 57 | CTimer& CTimer::get(const std::string name) |
---|
[347] | 58 | { |
---|
[1601] | 59 | if(allTimer_ptr == NULL) allTimer_ptr = new std::map<std::string,CTimer>; |
---|
| 60 | |
---|
| 61 | std::map<std::string,CTimer>::iterator it = allTimer_ptr->find(name); |
---|
| 62 | |
---|
| 63 | if (it == allTimer_ptr->end()) |
---|
| 64 | it = allTimer_ptr->insert(std::make_pair(name, CTimer(name))).first; |
---|
| 65 | |
---|
[652] | 66 | return it->second; |
---|
[347] | 67 | } |
---|
[1158] | 68 | |
---|
| 69 | string CTimer::getAllCumulatedTime(void) |
---|
| 70 | { |
---|
| 71 | std::ostringstream strOut ; |
---|
[1601] | 72 | if(allTimer_ptr == 0) allTimer_ptr = new std::map<std::string,CTimer>; |
---|
| 73 | |
---|
| 74 | for(std::map<std::string,CTimer>::iterator it=allTimer_ptr->begin();it!=allTimer_ptr->end();++it) |
---|
[1158] | 75 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
---|
| 76 | return strOut.str() ; |
---|
| 77 | } |
---|
[347] | 78 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.