#include <vpr/Perf/ProfileNode.h>
Collaboration diagram for vpr::ProfileNode:

Metric getters | |
| typedef std::pair< std::deque< vpr::Interval >::const_iterator, std::deque< vpr::Interval >::const_iterator > | NodeHistoryRange |
| vpr::Interval | getLastSample () |
| Returns the last sample taken. | |
| unsigned int | getTotalCalls () |
| Returns the total number of samples made on this node. | |
| vpr::Interval | getTotalTime () |
| Returns the total sampled time for this node. | |
| const NodeHistoryRange | getNodeHistoryRange () |
| vpr::Interval | getAverage () |
| Gets the average time sample. | |
| vpr::Interval | getSTA () |
| Gets the short term average. | |
Public Member Functions | |
| ProfileNode (const char *name, const unsigned int queueSize=0) | |
| Constructor for a profile node. | |
| ~ProfileNode () | |
| Destructor. | |
| void | addChild (ProfileNode *newChild) |
| Adds a new node as a child. | |
| ProfileNode * | getChild (const char *nodeName) |
| Returns pointer to sub-node (child) with the given name. | |
| ProfileNode * | getNamedChild (const char *nodeName) |
| Finds a child using string name instead of pointer comparison. | |
| ProfileNode * | getSubNode (const char *name, const unsigned int queueSize=0) |
| Returns named node or creates new child. | |
| const char * | getName () |
| Gets the static string name associated with this node. | |
| ProfileNode * | getParent () |
| Returns this node's parent. | |
| ProfileNode * | getSibling () |
| Returns a pointer to next sibling node in line. | |
| ProfileNode * | getChild () |
| Returns a pointer to its child. | |
| void | printTree (const unsigned int depth=0) |
| Prints tree rooted at this node. | |
| std::string | getXMLRep () |
| Gets an XML representation of the profile hierarchy. | |
| void | reset () |
| Recursively resets the metric values for all nodes rooted here. | |
| void | startSample () |
| Starts a sampling period for this profile node. | |
| bool | stopSample () |
| Stops the sampling period for this profile node. | |
Protected Member Functions | |
| void | getXMLRep (std::stringstream &s, unsigned int depth=0) |
| Helper for building up XML representation recursively. | |
Protected Attributes | |
| const char * | mName |
| Pointer to the name for this node. | |
| unsigned int | mTotalCalls |
| Total number of times called since last reset. | |
| vpr::Interval | mTotalTime |
| Total summed time over mTotalCalls. | |
| vpr::Interval | mLastSample |
| The last sample taken. | |
| std::deque< vpr::Interval > | mHistory |
| History of samples. | |
| unsigned int | mMaxHistorySize |
| Max size allowed for history. | |
| vpr::Interval | mStartTime |
| The time that this sample started. | |
| int | mRecursionCounter |
| The number of calls without a return. | |
| ProfileNode * | mParent |
| Parent of this node. | |
| ProfileNode * | mChild |
| Direct child of this node. | |
| ProfileNode * | mSibling |
| Next node in linked list of children. | |
This is the main class for performance profiling. The performance profile is built out of a tree of these nodes. They are connected in a standard parent child relationship. Each node can have one parent and 0 or more children.
Definition at line 76 of file ProfileNode.h.
| typedef std::pair<std::deque<vpr::Interval>::const_iterator, std::deque<vpr::Interval>::const_iterator> vpr::ProfileNode::NodeHistoryRange |
Definition at line 199 of file ProfileNode.h.
| vpr::ProfileNode::ProfileNode | ( | const char * | name, | |
| const unsigned int | queueSize = 0 | |||
| ) |
Constructor for a profile node.
Takes a static string pointer for the name and a reference to a parent. Parent and children default to NULL.
| name | Static string pointer and name for this node. | |
| queueSize | Queue size. |
Definition at line 52 of file ProfileNode.cpp.
References mMaxHistorySize, mStartTime, mTotalTime, reset(), and vpr::Interval::secf().
Referenced by getSubNode().
00053 : mName(name) 00054 , mTotalCalls(0) 00055 , mRecursionCounter(0) 00056 , mParent(NULL) 00057 , mChild(NULL) 00058 , mSibling(NULL) 00059 { 00060 mTotalTime.secf(0.0f); 00061 mMaxHistorySize = queue_size; 00062 mStartTime.secf(0); 00063 reset(); 00064 }
| vpr::ProfileNode::~ProfileNode | ( | ) |
| void vpr::ProfileNode::addChild | ( | ProfileNode * | newChild | ) |
Adds a new node as a child.
| newChild | New child to add. It will have its parent set to us. |
Definition at line 75 of file ProfileNode.cpp.
References mChild, mParent, mSibling, and vprASSERT.
Referenced by getSubNode().
00076 { 00077 vprASSERT(NULL != newNode); 00078 newNode->mParent = this; 00079 00080 if(NULL == mChild) 00081 { 00082 mChild = newNode; 00083 newNode->mSibling = NULL; 00084 } 00085 else 00086 { 00087 ProfileNode* last_child = mChild; 00088 while ( last_child->mSibling ) // Iterate down the list 00089 { 00090 last_child = last_child->mSibling; 00091 } 00092 last_child->mSibling = newNode; 00093 newNode->mSibling = NULL; 00094 } 00095 }
| ProfileNode * vpr::ProfileNode::getChild | ( | const char * | nodeName | ) |
Returns pointer to sub-node (child) with the given name.
Definition at line 97 of file ProfileNode.cpp.
References mChild, mName, and mSibling.
Referenced by vpr::ProfileIterator::operator++().
00098 { 00099 // Try to find this sub node by iterating through children 00100 ProfileNode* child = mChild; 00101 while ( child ) 00102 { 00103 if ( child->mName == nodeName ) 00104 { 00105 return child; 00106 } 00107 child = child->mSibling; 00108 } 00109 00110 return NULL; 00111 }
| ProfileNode * vpr::ProfileNode::getNamedChild | ( | const char * | nodeName | ) |
Finds a child using string name instead of pointer comparison.
Definition at line 113 of file ProfileNode.cpp.
References mChild, mName, and mSibling.
00114 { 00115 std::string needed_name(nodeName); 00116 00117 // Try to find this sub node by iterating through children 00118 ProfileNode* child = mChild; 00119 while ( child ) 00120 { 00121 std::string cur_name(child->mName); 00122 if(needed_name == cur_name) 00123 { 00124 return child; 00125 } 00126 child = child->mSibling; 00127 } 00128 00129 return NULL; 00130 }
| ProfileNode * vpr::ProfileNode::getSubNode | ( | const char * | name, | |
| const unsigned int | queueSize = 0 | |||
| ) |
Returns named node or creates new child.
Returns a pointer to a subnode of this node given the name of the subnode. If the name doesn't exist it creates the new node and adds it as a child to this node and returns this new node.
Definition at line 132 of file ProfileNode.cpp.
References addChild(), mChild, mName, mSibling, and ProfileNode().
00134 { 00135 // Try to find this sub node 00136 ProfileNode* child = mChild; 00137 while ( child ) 00138 { 00139 if ( child->mName == profileName ) 00140 { 00141 return child; 00142 } 00143 child = child->mSibling; 00144 } 00145 00146 // We didn't find it, so add it at end 00147 ProfileNode* node = new ProfileNode( profileName, queueSize); 00148 addChild(node); 00149 return node; 00150 }
| const char* vpr::ProfileNode::getName | ( | ) | [inline] |
Gets the static string name associated with this node.
Definition at line 123 of file ProfileNode.h.
Referenced by getXMLRep(), and printTree().
00124 { 00125 return mName; 00126 }
| ProfileNode* vpr::ProfileNode::getParent | ( | ) | [inline] |
Returns this node's parent.
Definition at line 131 of file ProfileNode.h.
Referenced by vpr::ProfileIterator::operator++(), vpr::ProfileIterator::ProfileIterator(), and vpr::ProfileManager::stopProfile().
00132 { 00133 return mParent; 00134 }
| ProfileNode* vpr::ProfileNode::getSibling | ( | ) | [inline] |
Returns a pointer to next sibling node in line.
Definition at line 139 of file ProfileNode.h.
Referenced by getXMLRep(), vpr::ProfileIterator::operator++(), and printTree().
00140 { 00141 return mSibling; 00142 }
| ProfileNode* vpr::ProfileNode::getChild | ( | ) | [inline] |
Returns a pointer to its child.
Definition at line 147 of file ProfileNode.h.
Referenced by getXMLRep(), and printTree().
00148 { 00149 return mChild; 00150 }
| void vpr::ProfileNode::printTree | ( | const unsigned int | depth = 0 |
) |
Prints tree rooted at this node.
| depth | Depth in the traversal. Used for indentation and the like. |
Definition at line 153 of file ProfileNode.cpp.
References clrGREEN, clrOutBOLD, clrRED, clrRESET, clrSetBOLD, clrYELLOW, getAverage(), getChild(), getName(), getNodeHistoryRange(), getSibling(), getTotalCalls(), getTotalTime(), vpr::Interval::msecf(), printTree(), vprDBG_ALL(), vprDEBUG, and vprDEBUG_FLUSH.
Referenced by printTree(), and vpr::ProfileManager::printTree().
00154 { 00155 std::string indent_str(depth * 3, ' '); 00156 if ( 0 == depth ) 00157 { 00158 vprDEBUG(vprDBG_ALL, 0) << clrSetBOLD(clrGREEN) 00159 << "--- [PROFILE STATS] ---" << clrRESET << std::endl 00160 << vprDEBUG_FLUSH; 00161 } 00162 00163 vprDEBUG(vprDBG_ALL, 0) << indent_str 00164 << clrSetBOLD(clrRED) << getName() << clrRESET 00165 << clrSetBOLD(clrYELLOW) << " total calls: " << clrRESET << getTotalCalls() 00166 << clrSetBOLD(clrYELLOW) << " total time: " << clrRESET << getTotalTime().msecf() 00167 << clrSetBOLD(clrYELLOW) << " avg: " << clrRESET 00168 << getAverage().msecf() << std::endl << vprDEBUG_FLUSH; 00169 00170 std::stringstream s; 00171 NodeHistoryRange p = getNodeHistoryRange(); 00172 for ( ; p.first != p.second; p.first++ ) 00173 { 00174 s << p.first->msecf() << " "; 00175 } 00176 00177 vprDEBUG(vprDBG_ALL, 0) << indent_str << " " 00178 << clrOutBOLD(clrYELLOW, " history: ") 00179 << s.str() << std::endl << vprDEBUG_FLUSH; 00180 00181 if ( getChild() != NULL ) 00182 { 00183 getChild()->printTree(depth+1); 00184 } 00185 00186 if ( getSibling() != NULL ) 00187 { 00188 getSibling()->printTree(depth); 00189 } 00190 }
| std::string vpr::ProfileNode::getXMLRep | ( | ) |
Gets an XML representation of the profile hierarchy.
Definition at line 193 of file ProfileNode.cpp.
Referenced by getXMLRep().
00194 { 00195 std::stringstream s; 00196 getXMLRep(s,0); 00197 return s.str(); 00198 }
| void vpr::ProfileNode::reset | ( | ) |
Recursively resets the metric values for all nodes rooted here.
Resets total calls and total times. Also resets the history.
Definition at line 238 of file ProfileNode.cpp.
References vpr::Interval::Base, mChild, mHistory, mLastSample, mSibling, mTotalCalls, mTotalTime, reset(), and vpr::Interval::set().
Referenced by ProfileNode(), reset(), and vpr::ProfileManager::reset().
00239 { 00240 mTotalCalls = 0; 00241 mTotalTime.set(0, vpr::Interval::Base); 00242 mLastSample.set(0, vpr::Interval::Base); 00243 mHistory.clear(); 00244 00245 if ( mChild ) 00246 { 00247 mChild->reset(); 00248 } 00249 00250 if ( mSibling ) 00251 { 00252 mSibling->reset(); 00253 } 00254 }
| void vpr::ProfileNode::startSample | ( | ) |
Starts a sampling period for this profile node.
Starts the time running for us.
Definition at line 256 of file ProfileNode.cpp.
References mRecursionCounter, mStartTime, mTotalCalls, and vpr::Interval::setNow().
00257 { 00258 mTotalCalls++; 00259 if ( mRecursionCounter++ == 0 ) 00260 { 00261 mStartTime.setNow(); 00262 } 00263 }
| bool vpr::ProfileNode::stopSample | ( | ) |
Stops the sampling period for this profile node.
Definition at line 265 of file ProfileNode.cpp.
References mHistory, mLastSample, mMaxHistorySize, mRecursionCounter, mStartTime, mTotalCalls, mTotalTime, and vpr::Interval::setNow().
Referenced by vpr::ProfileManager::stopProfile().
00266 { 00267 if ( --mRecursionCounter == 0 && mTotalCalls != 0 ) 00268 { 00269 mLastSample.setNow(); 00270 mLastSample -= mStartTime; 00271 if ( 0 != mMaxHistorySize ) 00272 { 00273 mHistory.push_front(mLastSample); 00274 if ( mHistory.size() > mMaxHistorySize ) 00275 { 00276 mHistory.resize(mMaxHistorySize); 00277 } 00278 } 00279 mTotalTime += mLastSample; 00280 } 00281 00282 return( mRecursionCounter == 0 ); 00283 }
| vpr::Interval vpr::ProfileNode::getLastSample | ( | ) | [inline] |
Returns the last sample taken.
Definition at line 181 of file ProfileNode.h.
Referenced by vpr::ProfileManager::getNamedNodeSample().
00182 { 00183 return mLastSample; 00184 }
| unsigned int vpr::ProfileNode::getTotalCalls | ( | ) | [inline] |
Returns the total number of samples made on this node.
Definition at line 187 of file ProfileNode.h.
Referenced by getAverage(), getXMLRep(), and printTree().
00188 { 00189 return mTotalCalls; 00190 }
| vpr::Interval vpr::ProfileNode::getTotalTime | ( | ) | [inline] |
Returns the total sampled time for this node.
Definition at line 193 of file ProfileNode.h.
Referenced by getAverage(), getXMLRep(), and printTree().
00194 { 00195 return mTotalTime; 00196 }
| const NodeHistoryRange vpr::ProfileNode::getNodeHistoryRange | ( | ) | [inline] |
| vpr::Interval vpr::ProfileNode::getAverage | ( | ) |
Gets the average time sample.
Returns total time sampled/total calls.
Definition at line 285 of file ProfileNode.cpp.
References vpr::Interval::Base, getTotalCalls(), getTotalTime(), and mTotalCalls.
Referenced by getXMLRep(), and printTree().
00286 { 00287 if ( getTotalCalls() == 0 ) 00288 { 00289 return vpr::Interval(); 00290 } 00291 else 00292 { 00293 return vpr::Interval(getTotalTime().getBaseVal() / mTotalCalls, 00294 vpr::Interval::Base); 00295 } 00296 }
| vpr::Interval vpr::ProfileNode::getSTA | ( | ) |
Gets the short term average.
Computed as the average of the history.
Definition at line 298 of file ProfileNode.cpp.
References vpr::Interval::Base, vpr::Interval::getBaseVal(), mHistory, mLastSample, mMaxHistorySize, and vpr::Interval::set().
Referenced by getXMLRep().
00299 { 00300 // If we are making no history or have no history yet 00301 if ( 0 == mMaxHistorySize || mHistory.empty() ) 00302 { 00303 return mLastSample; 00304 } 00305 else 00306 { 00307 vpr::Interval sta_interval; 00308 std::deque<vpr::Interval>::iterator i; 00309 for ( i = mHistory.begin(); i != mHistory.end(); ++i ) 00310 { 00311 sta_interval += *i; 00312 } 00313 sta_interval.set(sta_interval.getBaseVal() / mHistory.size(), 00314 vpr::Interval::Base); 00315 return sta_interval; 00316 } 00317 }
| void vpr::ProfileNode::getXMLRep | ( | std::stringstream & | s, | |
| unsigned int | depth = 0 | |||
| ) | [protected] |
Helper for building up XML representation recursively.
Definition at line 201 of file ProfileNode.cpp.
References getAverage(), getChild(), getName(), getNodeHistoryRange(), getSibling(), getSTA(), getTotalCalls(), getTotalTime(), getXMLRep(), and vpr::Interval::msecf().
00202 { 00203 std::string indent_str(depth*3,' '); 00204 00205 s << indent_str 00206 << "<profile_node name=\"" << getName() 00207 << "\" total_calls=\"" << getTotalCalls() 00208 << "\" total_time=\"" << getTotalTime().msecf() 00209 << "\" average=\"" << getAverage().msecf() 00210 << "\" sta=\"" << getSTA().msecf() 00211 << "\">\n"; 00212 00213 NodeHistoryRange p = getNodeHistoryRange(); 00214 if ( p.first != p.second ) 00215 { 00216 s << indent_str << " "; 00217 for ( ; p.first != p.second; p.first++ ) 00218 { 00219 s << p.first->msecf() << " "; 00220 } 00221 s << std::endl; 00222 } 00223 00224 std::string child_xml_rep, sibling_xml_rep; 00225 00226 if ( getChild() != NULL ) 00227 { 00228 getChild()->getXMLRep(s, depth + 1); 00229 } 00230 s << indent_str << "</profile_node>\n"; 00231 00232 if ( getSibling() != NULL ) 00233 { 00234 getSibling()->getXMLRep(s, depth); 00235 } 00236 }
const char* vpr::ProfileNode::mName [protected] |
Pointer to the name for this node.
Must be a static string.
Definition at line 224 of file ProfileNode.h.
Referenced by getChild(), getNamedChild(), and getSubNode().
unsigned int vpr::ProfileNode::mTotalCalls [protected] |
Total number of times called since last reset.
Definition at line 225 of file ProfileNode.h.
Referenced by getAverage(), reset(), startSample(), and stopSample().
vpr::Interval vpr::ProfileNode::mTotalTime [protected] |
Total summed time over mTotalCalls.
Definition at line 226 of file ProfileNode.h.
Referenced by ProfileNode(), reset(), and stopSample().
vpr::Interval vpr::ProfileNode::mLastSample [protected] |
The last sample taken.
Definition at line 227 of file ProfileNode.h.
Referenced by getSTA(), reset(), and stopSample().
std::deque<vpr::Interval> vpr::ProfileNode::mHistory [protected] |
History of samples.
Definition at line 229 of file ProfileNode.h.
Referenced by getSTA(), reset(), and stopSample().
unsigned int vpr::ProfileNode::mMaxHistorySize [protected] |
Max size allowed for history.
If 0, then ignore history.
Definition at line 230 of file ProfileNode.h.
Referenced by getSTA(), ProfileNode(), and stopSample().
vpr::Interval vpr::ProfileNode::mStartTime [protected] |
The time that this sample started.
Definition at line 232 of file ProfileNode.h.
Referenced by ProfileNode(), startSample(), and stopSample().
int vpr::ProfileNode::mRecursionCounter [protected] |
The number of calls without a return.
tracks recursion.
Definition at line 233 of file ProfileNode.h.
Referenced by startSample(), and stopSample().
ProfileNode* vpr::ProfileNode::mParent [protected] |
ProfileNode* vpr::ProfileNode::mChild [protected] |
Direct child of this node.
(first node in child list)
Definition at line 236 of file ProfileNode.h.
Referenced by addChild(), getChild(), getNamedChild(), getSubNode(), reset(), and ~ProfileNode().
ProfileNode* vpr::ProfileNode::mSibling [protected] |
Next node in linked list of children.
Definition at line 237 of file ProfileNode.h.
Referenced by addChild(), getChild(), getNamedChild(), getSubNode(), reset(), and ~ProfileNode().
1.5.1