source: src/base/timer.cpp@ 01be70

Last change on this file since 01be70 was 1610dc, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Bugfix. Corrected pugixml api call.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1246 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[dfed1c]1/**
2 * @file timer.cpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Tue Sep 6 16:17:40 2011
5 *
6 * @brief Class to measure timings.
7 *
8 */
9
10#ifdef HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#ifdef HAVE_MPI
15#include <mpi.h>
16#endif
17
18#include <iostream>
19#include <limits>
20#include <sstream>
21
22#include "base/helper.hpp"
23#include "base/timer.hpp"
24#include "comm/comm.hpp"
25#include "thirdparty/pugixml/pugixml.hpp"
26#include "mg.hpp"
27
28using namespace VMG;
29
30std::map<std::string, TimerData> Timer::td;
31
32void Timer::Start(std::string event)
33{
34#ifdef HAVE_MPI
35#ifdef DEBUG_MEASURE_TIME
36 std::map<std::string, TimerData>::iterator iter = td.find(event);
37 if (iter == td.end())
38 iter = td.insert(std::make_pair(event, TimerData())).first;
39
40 iter->second.time_start = MPI_Wtime();
41#endif
42#endif
43}
44
45void Timer::Stop(std::string event)
46{
47#ifdef HAVE_MPI
48#ifdef DEBUG_MEASURE_TIME
49 double time_end = MPI_Wtime();
50
51 std::map<std::string, TimerData>::iterator iter = td.find(event);
52
53 if (time_end - iter->second.time_start < std::numeric_limits<double>::min())
54 ++(iter->second.warning);
55
56 ++(iter->second.total);
57
58 iter->second.duration += time_end - iter->second.time_start;
59#endif
60#endif
61}
62
63void Timer::Clear()
64{
65 td.clear();
66}
67
68pugi::xml_node Timer::ToXMLNode()
69{
70 std::map<std::string, TimerData>::iterator iter;
71
[1610dc]72 pugi::xml_node node_process;
73 node_process.append_attribute("Rank").set_value(MG::GetComm()->GlobalRank());
[dfed1c]74
75 pugi::xml_node node_timings = node_process.append_child("Timings");
76
77 for (iter=Timer::td.begin(); iter!=Timer::td.end(); ++iter) {
78
79 pugi::xml_node node_entry = node_timings.append_child("Sample");
80 node_entry.append_attribute("Name").set_value(Helper::ToString(iter->first).c_str());
81
[1610dc]82 node_entry.append_child("Duration")
83 .append_child(pugi::node_pcdata)
84 .set_value(Helper::ToString(iter->second.duration).c_str());
[dfed1c]85
[1610dc]86 node_entry.append_child("Warnings")
87 .append_child(pugi::node_pcdata)
88 .set_value(Helper::ToString(iter->second.warning).c_str());
[dfed1c]89
[1610dc]90 node_entry.append_child("Total")
91 .append_child(pugi::node_pcdata)
92 .set_value(Helper::ToString(iter->second.total).c_str());
[dfed1c]93
94 }
95
96 return node_process;
97}
98
99std::string Timer::ToString()
100{
101 pugi::xml_node node = Timer::ToXMLNode();
102 std::stringstream str;
103 node.print(str);
104 return str.str();
105}
106
107void Timer::Print()
108{
109#ifdef DEBUG_MEASURE_TIME
110 std::map<std::string, TimerData>::const_iterator iter;
111 Comm& comm = *MG::GetComm();
112
113 if (comm.GlobalRank() == 0) {
114 comm.PrintStringOnce("Running times:");
115 for (iter=Timer::td.begin(); iter!=Timer::td.end(); ++iter)
116 comm.PrintStringOnce(" %s: %es", iter->first.c_str(), iter->second.duration);
117 }
118#endif
119}
120
121std::ostream& VMG::operator<<(std::ostream& out, const Timer&)
122{
123 return out << Timer::ToString();
124}
Note: See TracBrowser for help on using the repository browser.