source:
XIOS/dev/branch_openmp/src/timer.cpp
@
1642
Last change on this file since 1642 was 1642, checked in by yushan, 5 years ago | |
---|---|
|
|
File size: 1.4 KB |
Rev | Line | |
---|---|---|
[347] | 1 | #include "timer.hpp" |
[1642] | 2 | //#include "mpi_std.hpp" |
[382] | 3 | #include "mpi.hpp" |
[347] | 4 | #include <string> |
5 | #include <map> | |
[1157] | 6 | #include <iostream> |
7 | #include <sstream> | |
[1205] | 8 | #include "tracer.hpp" |
[1642] | 9 | //extern ::MPI_Comm MPI_COMM_WORLD; |
[347] | 10 | |
11 | namespace xios | |
12 | { | |
[1642] | 13 | std::map<std::string,CTimer> CTimer::allTimer; |
[347] | 14 | |
[652] | 15 | CTimer::CTimer(const std::string& name_) : name(name_) |
[347] | 16 | { |
[652] | 17 | reset(); |
[347] | 18 | } |
19 | ||
20 | double CTimer::getTime(void) | |
21 | { | |
[1642] | 22 | MPI_COMM_WORLD; |
[347] | 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 | { |
[1642] | 59 | std::map<std::string,CTimer>::iterator it = allTimer.find(name); |
60 | if (it == allTimer.end()) | |
61 | it = allTimer.insert(std::make_pair(name, CTimer(name))).first; | |
[652] | 62 | return it->second; |
[347] | 63 | } |
[1156] | 64 | |
[1205] | 65 | string CTimer::getAllCumulatedTime(void) |
66 | { | |
67 | std::ostringstream strOut ; | |
[1642] | 68 | for(std::map<std::string,CTimer>::iterator it=allTimer.begin();it!=allTimer.end();++it) |
[1205] | 69 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
70 | return strOut.str() ; | |
71 | } | |
[347] | 72 | } |
Note: See TracBrowser
for help on using the repository browser.