Last change
on this file since 1599 was
1545,
checked in by yushan, 6 years ago
|
branch_openmp merged with trunk r1544
|
-
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 | using namespace ep_lib; |
---|
9 | |
---|
10 | namespace xios |
---|
11 | { |
---|
12 | std::map<std::string,CTimer> *CTimer::allTimer_ptr = 0; |
---|
13 | |
---|
14 | CTimer::CTimer(const std::string& name_) : name(name_) |
---|
15 | { |
---|
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 | traceEnd(name); |
---|
29 | cumulatedTime += getTime() - lastTime; |
---|
30 | } |
---|
31 | suspended = true; |
---|
32 | } |
---|
33 | |
---|
34 | void CTimer::resume(void) |
---|
35 | { |
---|
36 | if (suspended) |
---|
37 | { |
---|
38 | lastTime = getTime(); |
---|
39 | traceBegin(name); |
---|
40 | } |
---|
41 | suspended = false; |
---|
42 | } |
---|
43 | |
---|
44 | void CTimer::reset(void) |
---|
45 | { |
---|
46 | cumulatedTime = 0.; |
---|
47 | suspended = true; |
---|
48 | } |
---|
49 | |
---|
50 | double CTimer::getCumulatedTime(void) |
---|
51 | { |
---|
52 | return cumulatedTime; |
---|
53 | } |
---|
54 | |
---|
55 | CTimer& CTimer::get(const std::string name) |
---|
56 | { |
---|
57 | if(allTimer_ptr == NULL) allTimer_ptr = new std::map<std::string,CTimer>; |
---|
58 | |
---|
59 | std::map<std::string,CTimer>::iterator it = allTimer_ptr->find(name); |
---|
60 | |
---|
61 | if (it == allTimer_ptr->end()) |
---|
62 | it = allTimer_ptr->insert(std::make_pair(name, CTimer(name))).first; |
---|
63 | |
---|
64 | return it->second; |
---|
65 | } |
---|
66 | |
---|
67 | string CTimer::getAllCumulatedTime(void) |
---|
68 | { |
---|
69 | std::ostringstream strOut ; |
---|
70 | if(allTimer_ptr == 0) allTimer_ptr = new std::map<std::string,CTimer>; |
---|
71 | |
---|
72 | for(std::map<std::string,CTimer>::iterator it=allTimer_ptr->begin();it!=allTimer_ptr->end();++it) |
---|
73 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
---|
74 | return strOut.str() ; |
---|
75 | } |
---|
76 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.