Last change
on this file since 2424 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
|
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 | #ifdef _usingEP |
---|
9 | using namespace ep_lib; |
---|
10 | #endif |
---|
11 | |
---|
12 | namespace xios |
---|
13 | { |
---|
14 | std::map<std::string,CTimer> *CTimer::allTimer_ptr = 0; |
---|
15 | |
---|
16 | CTimer::CTimer(const std::string& name_) : name(name_) |
---|
17 | { |
---|
18 | reset(); |
---|
19 | } |
---|
20 | |
---|
21 | double CTimer::getTime(void) |
---|
22 | { |
---|
23 | return MPI_Wtime(); |
---|
24 | } |
---|
25 | |
---|
26 | void CTimer::suspend(void) |
---|
27 | { |
---|
28 | if (!suspended) |
---|
29 | { |
---|
30 | traceEnd(name); |
---|
31 | cumulatedTime += getTime() - lastTime; |
---|
32 | } |
---|
33 | suspended = true; |
---|
34 | } |
---|
35 | |
---|
36 | void CTimer::resume(void) |
---|
37 | { |
---|
38 | if (suspended) |
---|
39 | { |
---|
40 | lastTime = getTime(); |
---|
41 | traceBegin(name); |
---|
42 | } |
---|
43 | suspended = false; |
---|
44 | } |
---|
45 | |
---|
46 | void CTimer::reset(void) |
---|
47 | { |
---|
48 | cumulatedTime = 0.; |
---|
49 | suspended = true; |
---|
50 | } |
---|
51 | |
---|
52 | double CTimer::getCumulatedTime(void) |
---|
53 | { |
---|
54 | return cumulatedTime; |
---|
55 | } |
---|
56 | |
---|
57 | CTimer& CTimer::get(const std::string name) |
---|
58 | { |
---|
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 | |
---|
66 | return it->second; |
---|
67 | } |
---|
68 | |
---|
69 | string CTimer::getAllCumulatedTime(void) |
---|
70 | { |
---|
71 | std::ostringstream strOut ; |
---|
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) |
---|
75 | strOut<<"Timer : "<<it->first<<" --> cumulated time : "<<it->second.getCumulatedTime()<<std::endl ; |
---|
76 | return strOut.str() ; |
---|
77 | } |
---|
78 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.