-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAVPApp.cpp
149 lines (122 loc) · 5.34 KB
/
AVPApp.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// ---------------------------------------------------------------
// AVPApp.cpp
// ---------------------------------------------------------------
#include <algorithm>
#include <AVPApp.H>
#include <GlobalUtilities.H>
using namespace amrex;
// -------------------------------------------------------------------
void AVPApp::DrawTimeRange(Widget wCF, int sdLineXL, int sdLineXH,
int axisLengthX, int axisLengthY,
Real subTimeRangeStart, Real subTimeRangeStop,
const std::string &yAxisLabel)
{
const std::string timeLabel(" time");
const int xpos(10), ypos(15), positionPad(5);
std::ostringstream timeRangeS;
timeRangeS << '[' << subTimeRangeStart << ", " << subTimeRangeStop << ']';
XDrawLine(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad, ypos + positionPad,
xpos + positionPad, ypos + axisLengthY);
XDrawLine(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad, ypos + axisLengthY,
xpos + positionPad + axisLengthX, ypos + axisLengthY);
XDrawString(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad + axisLengthX, ypos+positionPad + axisLengthY,
timeLabel.c_str(), timeLabel.length());
XDrawString(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad, ypos,
yAxisLabel.c_str(), yAxisLabel.length());
// ---- lines indicating subregion
XDrawLine(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad + sdLineXL, ypos + axisLengthY,
xpos + positionPad + sdLineXL, ypos + axisLengthY + 8);
XDrawLine(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad + sdLineXH, ypos + axisLengthY,
xpos + positionPad + sdLineXH, ypos + axisLengthY + 8);
XDrawString(XtDisplay(wCF), XtWindow(wCF), xgc,
xpos + positionPad, ypos + axisLengthY + 24,
timeRangeS.str().c_str(), timeRangeS.str().length());
}
// -------------------------------------------------------------------
void AVPApp::ParseCallTraceFile(std::ifstream &ctFile)
{
amrex::Vector<CallTraceLine> &cTLines = callTraceData.callTraceLines;
std::map<int, std::string> &fNNames = callTraceData.funcNumberNames;
std::string line;
cTLines.clear();
fNNames.clear();
do {
std::getline(ctFile, line);
const std::vector<std::string>& tokens = amrex::Tokenize(line, "\t");
int offset;
if(tokens.size() == 7) {
offset = 0;
} else if(tokens.size() == 8) {
offset = 1; // ---- skip the ---|---|---| entries
} else {
continue;
}
CallTraceLine ctl;
ctl.funcNumber = atoi(tokens[offset + 0].c_str());
fNNames[ctl.funcNumber] = tokens[offset + 1].c_str();
ctl.inclTime = atof(tokens[offset + 2].c_str());
ctl.exclTime = atof(tokens[offset + 3].c_str());
ctl.nCalls = atol(tokens[offset + 4].c_str());
ctl.callStackDepth = atoi(tokens[offset + 5].c_str());
ctl.callTime = atof(tokens[offset + 6].c_str());
cTLines.push_back(ctl);
} while( ! ctFile.eof());
amrex::Print() << "_in ParseCallTraceFile: fNNames.size() = " << fNNames.size() << std::endl;
amrex::Print() << "_in ParseCallTraceFile: cTLines.size() = " << cTLines.size() << std::endl;
}
// -------------------------------------------------------------------
void AVPApp::DeriveCallStack(std::ostream &os, Real startTime, Real endTime)
{
amrex::Vector<CallTraceLine> &cTLines = callTraceData.callTraceLines;
std::map<int, std::string> &fNNames = callTraceData.funcNumberNames;
std::vector<CallTraceLine>::iterator lowB, highB;
lowB = std::lower_bound(cTLines.begin(), cTLines.end(), startTime,
[] (const CallTraceLine &a, const Real &b)
{ return a.callTime < b; });
highB = std::upper_bound(cTLines.begin(), cTLines.end(), endTime,
[] (const Real &a, const CallTraceLine &b)
{ return a < b.callTime; });
long lowIndex(lowB - cTLines.begin());
long highIndex(highB - cTLines.begin());
lowIndex = std::min(lowIndex, cTLines.size() - 1);
highIndex = std::min(highIndex, cTLines.size() - 1);
amrex::Print() << "_in DeriveCallStack: startTime lowIndex highIndex = "
<< startTime << " " << lowIndex << " " << highIndex << std::endl;
amrex::Print() << "_in DeriveCallStack: lowLine = "
<< fNNames[cTLines[lowIndex].funcNumber] << std::endl;
amrex::Vector<int> callStack;
for(int ci(highIndex); ci > lowIndex; --ci) { // ---- push the range [high ,low)
callStack.push_back(ci);
}
int currentCallDepth(cTLines[lowIndex].callStackDepth);
for(int ci(lowIndex); ci >= 0; --ci) {
CallTraceLine &ctl = cTLines[ci];
if(ctl.callStackDepth == currentCallDepth) {
callStack.push_back(ci);
--currentCallDepth;
}
}
for(int i(callStack.size() - 1); i >= 0; --i) {
int index(callStack[i]);
CallTraceLine &ctl = cTLines[index];
if(index == lowIndex) {
for(int d(0); d < ctl.callStackDepth; ++d) {
os << "->->";
}
} else {
for(int d(0); d < ctl.callStackDepth; ++d) {
os << "---|";
}
}
os << " " << fNNames[ctl.funcNumber] << " " << ctl.callTime << '\n';
}
os << std::endl;
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------