1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
*
* The MIT License
*
* Copyright (c) 1997-2010 Center for the Simulation of Accidental Fires and
* Explosions (CSAFE), and Scientific Computing and Imaging Institute (SCI),
* University of Utah.
*
* License for the specific language governing rights and limitations under
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* */
/* This class was originally written by Justin Luitjens and
subsequently integrated with Cactus/Carpet by Ian Hinder and
heavily modified. */
#ifndef TIMERNODE_HH
#define TIMERNODE_HH
#include <cassert>
#include <iostream>
#include <map>
#include <ostream>
#include <string>
#include <utility>
#include "CactusTimer.hh"
namespace Carpet {
using namespace std;
class TimerNode;
class TimerTree
{
public:
TimerTree()
{
root = 0;
current = 0;
}
TimerNode *root;
TimerNode *current;
};
/**
The TimerNode class implements a tree structure where each node
represents a timer, implemented as a CactusTimer. Each node of the
tree can have zero of more children, where the names of the child
nodes are unique within a single parent, but not necessarily unique
within the entire tree. A tree formed of TimerNode objects represents
the execution profile of the program, inasmuch as it is instrumented
by timers.
Child nodes of a given name are accessed using the getChildTimer
method, where a node is created with the given name if none exists
already. This ensures that the names of the child timers are unique.
*/
class TimerNode
{
public:
TimerNode(TimerTree *root, string name);
~TimerNode();
void instantiate();
void start();
void stop();
string getName() const;
string pathName() const;
// Finds the child timer that matches the name provided. If it is
// not found then that timer is allocated.
TimerNode* getChildTimer(string name);
double getTime();
void getGlobalTime(double& avg, double &max);
vector<pair<string, string> > getAllTimerNames() const;
vector<double> getAllTimerValues();
bool isRunning() const;
void print(ostream& out, double total, int level=0, double threshold=0.0, int precision=1);
void printXML(ostream& out, int level=0);
void outputXML(const string &out_dir, int proc);
private:
string escapeForXML(const string &s) const;
string d_name;
std::map<string,TimerNode*> d_children;
TimerNode *d_parent;
TimerTree *d_tree;
bool d_running;
CactusTimer *timer;
};
}
#endif // TIMERNODE_HH
|