15#ifndef ML_CALL_GRAPH_H
16#define ML_CALL_GRAPH_H
22#include <unordered_map>
25#include <boost/unordered_map.hpp>
62 size_t hash = boost::hash_value(key.
function);
63 boost::hash_combine(hash, key.
file);
64 boost::hash_combine(hash, key.
line);
103 void* userData =
nullptr,
105 const std::string& nodeInfo =
"");
115 const std::vector<MLCallGraphNode*>&
children()
const {
return _children; }
120 inline bool isRecursive(
const MLTimeProfile* timeProfile)
const;
123 inline bool isRecursive()
const;
125 void print(std::ostream& out,
const std::string& indent =
"")
const;
145 const std::string&
nodeInfo()
const {
return _nodeInfo; }
157 std::vector<MLCallGraphNode*> _children;
161 std::string _nodeInfo;
175 int linenumber,
int type);
180 int type()
const {
return _type; }
182 const std::string&
name()
const {
return _name; }
184 const std::string&
filename()
const {
return _filename; }
204 const std::vector<MLCallGraphNode*>&
callGraphNodes()
const {
return _callGraphNodes; }
244 std::vector<MLCallGraphNode*> _callGraphNodes;
246 std::string _filename;
251 TimeStatisticsMap _statisticsByTimeProfile;
253 CallGraphFunctionMap _callers;
254 CallGraphFunctionMap _callees;
267 if (_function == next->_function) {
270 next = next->_parent;
281 if ( (_function == next->_function) && (timeProfile_ == next->_timeProfile) ) {
284 next = next->_parent;
void addCallGraphNode(MLCallGraphNode *node)
Returns the line number of the function.
const std::string & name() const
Returns the name of the function.
int type() const
Returns the user ID.
const TimeStatisticsMap & statisticsByTimeProfile() const
MLCallGraphFunction * copiedFrom() const
const MLTimeStatistics * statisticsByCallee(MLCallGraphFunction *callee)
Returns the statistics of the given callee.
const MLTimeStatistics & statistics() const
const MLTimeStatistics * statisticsByCaller(MLCallGraphFunction *caller)
Returns the statistics of the given caller.
void addCaller(MLCallGraphFunction *function, MLProfilingTimeType elapsed, MLProfilingTimeType consumed)
Adds a caller function. If it is already added, then only the statistics are updated.
void removeCallGraphNode(MLCallGraphNode *node)
Removes a call graph node that represents a function call to this function.
MLCallGraphFunction * copiedTo() const
MLTimeStatistics & statistics(const MLTimeProfile *timeProfile)
@
const std::string & filename() const
Returns the filename of the function.
std::vector< MLCallGraphNode * > & callGraphNodes()
Returns all call graph nodes.
int linenumber() const
Returns the line number of the function.
MLTimeStatistics & statistics()
Returns the time statistics.
const CallGraphFunctionMap & callees() const
Returns the IDs of the functions that are called by this function.
MLCallGraphFunction(const std::string &name, const std::string &filename, int linenumber, int type)
const std::vector< MLCallGraphNode * > & callGraphNodes() const
Returns all call graph nodes.
const CallGraphFunctionMap & callers() const
Returns the IDs of the functions that called this function.
boost::unordered_map< const MLTimeProfile *, MLTimeStatistics > TimeStatisticsMap
bool hasStatisticsForTimeProfile(const MLTimeProfile *timeProfile) const
@
MLCallGraphFunction * copyWithStatistics() const
MLCallGraphFunction * cachedCopy(MLCallGraphNode::CallGraphCopyFunctionMap *copyFunctionMap)
boost::unordered_map< MLCallGraphFunction *, MLTimeStatistics > CallGraphFunctionMap
const MLTimeStatistics & statistics(const MLTimeProfile *timeProfile) const
MLCallGraphNode * createChild(MLTimeProfile *timeProfile, const MLCallGraphFunctionPtr &function, void *userData, const std::string &nodeInfo)
void printTrace(std::ostream &out) const
Prints the current call graph node for tracing.
const std::vector< MLCallGraphNode * > & children() const
const MLTimeStatistics & statistics() const
Returns the time statistics of the call graph node.
const MLTimer & timer() const
bool isRecursive() const
Returns true if the node is a recursive call of its function.
MLCallGraphNode(MLTimeProfile *timeProfile=nullptr, MLCallGraphNode *parent=nullptr, void *userData=nullptr, const MLCallGraphFunctionPtr &callGraphFunction=MLCallGraphFunctionPtr(), const std::string &nodeInfo="")
void removeFromParent()
Removes the node from its parent.
const std::string & nodeInfo() const
Returns the node information.
void print(std::ostream &out, const std::string &indent="") const
MLCallGraphNode * parent() const
void clearFunctionRecursive()
const MLCallGraphFunctionPtr & function() const
MLCallGraphNode * deepCopy(CallGraphCopyFunctionMap *copyFunctionMap) const
const MLTimeProfile * timeProfile() const
void clearUserData()
Clears the user data.
std::unordered_map< MLCallGraphFunction *, MLCallGraphFunction * > CallGraphCopyFunctionMap
void * userData() const
Returns the user data.
MLGlobalFunctionKey()
Initializes line to 0.
MLGlobalFunctionKey(const std::string &function_, const std::string &file_, int line_)
Initializes internal variables with the given ones.
bool operator==(const MLGlobalFunctionKey &other) const
double MLProfilingTimeType
size_t hash_value(MLGlobalFunctionKey const &key)
Calculates the hash key from last string segment.
std::shared_ptr< MLCallGraphFunction > MLCallGraphFunctionPtr
#define MLPROFILINGMANAGER_EXPORT
MLProfilingTimeType minimum
MLProfilingTimeType maximum
MLProfilingTimeType total
void add(MLProfilingTimeType time)
Values & operator+=(const Values &other)
Time is stored in seconds.
MLTimeStatistics & operator+=(const MLTimeStatistics &other)
MLTimeStatistics copy() const