source:
XIOS/dev/branch_openmp/src/timer.cpp
@
1552
Last change on this file since 1552 was 1545, checked in by yushan, 6 years ago | |
---|---|
|
|
File size: 1.6 KB |
Rev | Line | |
---|---|---|
[347] | 1 | #include "timer.hpp" |
[382] | 2 | #include "mpi.hpp" |
[347] | 3 | #include <string> |
4 | #include <map> | |
[1157] | 5 | #include <iostream> |
6 | #include <sstream> | |
[1205] | 7 | #include "tracer.hpp" |
[1328] | 8 | using namespace ep_lib; |
[347] | 9 | |
10 | namespace xios | |
11 | { | |
[1134] | 12 | std::map<std::string,CTimer> *CTimer::allTimer_ptr = 0; |
[347] | 13 | |
[652] | 14 | CTimer::CTimer(const std::string& name_) : name(name_) |
[347] | 15 | { |
[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 | { | |
[652] | 28 | traceEnd(name); |
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(); |
39 | 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 | ||
[652] | 55 | CTimer& CTimer::get(const std::string name) |
[347] | 56 | { |
[1328] | 57 | if(allTimer_ptr == NULL) allTimer_ptr = new std::map<std::string,CTimer>; |
[1134] | 58 | |
[1328] | 59 | std::map<std::string,CTimer>::iterator it = allTimer_ptr->find(name); |
[1545] | 60 | |
[1328] | 61 | if (it == allTimer_ptr->end()) |
62 | it = allTimer_ptr->insert(std::make_pair(name, CTimer(name))).first; | |
[1134] | 63 | |
[652] | 64 | return it->second; |
[347] | 65 | } |
[1156] | 66 | |
[1205] | 67 | string CTimer::getAllCumulatedTime(void) |
68 | { | |
69 | std::ostringstream strOut ; | |
[1328] | 70 | if(allTimer_ptr == 0) allTimer_ptr = new std::map<std::string,CTimer>; |
[1545] | 71 | |
[1328] | 72 | for(std::map<std::string,CTimer>::iterator it=allTimer_ptr->begin();it!=allTimer_ptr->end();++it) |
[1205] | 73 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
74 | return strOut.str() ; | |
75 | } | |
[347] | 76 | } |
Note: See TracBrowser
for help on using the repository browser.