2 #include <unordered_map>
32 const std::string sectionName,
33 const std::string filePath,
34 const size_t lineNumber)
35 : m_sectionName(sectionName), m_filePath(filePath), m_lineNumber(lineNumber),
36 m_hash(((std::
hash<std::string>()(filePath) << 1) ^ (std::
hash<size_t>()(lineNumber) << 1)) ^ std::
hash<std::string>()(sectionName))
44 return m_hash == rhs.m_hash &&
45 m_sectionName == rhs.m_sectionName &&
46 m_filePath == rhs.m_filePath &&
47 m_lineNumber == rhs.m_lineNumber;
56 const std::string m_sectionName;
57 const std::string m_filePath;
58 const size_t m_lineNumber;
93 : m_top(top), m_parent(parent), m_hash(m_top->
hash() ^ (m_parent ? m_parent->
hash() : 0))
100 {
return (m_hash == rhs.m_hash && m_top == rhs.m_top && m_parent == rhs.m_parent); }
116 #ifndef AL_GENERATING_DOCS
118 template<>
struct hash<AL::maya::ProfilerSectionTag> {
123 template<>
struct hash<AL::maya::ProfilerSectionPath> {
179 assert(m_stackPos == 0);
192 typedef std::unordered_map<ProfilerSectionPath, timespec> ProfilerSectionPathLUT;
193 typedef ProfilerSectionPathLUT::const_iterator iter_t;
194 static inline bool compareTimeStamps(
const iter_t,
const iter_t);
195 static void print(std::ostream& os, iter_t,
const ProfilerSectionPathLUT&, uint32_t,
double);
197 struct ProfilerSectionStackNode
201 ProfilerSectionPathLUT::iterator m_path;
204 static inline timespec timeDiff(
const timespec startTime,
const timespec endTime)
206 if (endTime.tv_nsec < startTime.tv_nsec)
209 tv_sec: endTime.tv_sec - 1 - startTime.tv_sec,
210 tv_nsec: 1000000000 + endTime.tv_nsec - startTime.tv_nsec
214 tv_sec: endTime.tv_sec - startTime.tv_sec,
215 tv_nsec: endTime.tv_nsec - startTime.tv_nsec
218 static inline timespec timeAdd(timespec t1, timespec t2)
220 int32_t sec = t2.tv_sec + t1.tv_sec;
221 int32_t nsec = t2.tv_nsec + t1.tv_nsec;
222 if (nsec >= 1000000000)
227 return (timespec){ tv_sec: sec, tv_nsec: nsec };
231 static int32_t m_stackPos;
232 static ProfilerSectionPathLUT m_map;
242 #define AL_BEGIN_PROFILE_SECTION(TimedSection) \
244 static const AL::maya::ProfilerSectionTag __entry(#TimedSection, __FILE__, __LINE__); \
245 AL::maya::Profiler::pushTime(&__entry); \
250 #define AL_END_PROFILE_SECTION() \
251 { AL::maya::Profiler::popTime(); }
static void printReport(std::ostream &os)
call to output the report
This class implements a very simple incode profiler. This profiler is NOT thread safe. It is mainly used to get some basic stats on the where the bottlenecks are during a file import/export operation. A simple example of usage:
Definition: CodeTimings.h:168
const uint32_t MAX_TIMESTAMP_STACK_SIZE
Definition: CodeTimings.h:16
size_t hash() const
return the hash of this class
Definition: CodeTimings.h:104
bool operator==(const ProfilerSectionPath &rhs) const
equality operator
Definition: CodeTimings.h:99
This class provides a static hash that should be unique for a line within a specific function...
Definition: CodeTimings.h:22
ProfilerSectionPath(const ProfilerSectionTag *const top, const ProfilerSectionPath *const parent=0)
ctor
Definition: CodeTimings.h:92
ProfilerSectionTag(const std::string sectionName, const std::string filePath, const size_t lineNumber)
ctor
Definition: CodeTimings.h:31
static void pushTime(const ProfilerSectionTag *entry)
do not call directly. Use the AL_BEGIN_PROFILE_SECTION macro
static void clearAll()
call to clear internal timers
Definition: CodeTimings.h:177
This class represents a path made up of ProfilerSectionTag's. It is used so that we can distinguish b...
Definition: CodeTimings.h:84
static void popTime()
do not call directly. Use the AL_END_PROFILE_SECTION macro
size_t hash() const
return the hash of this class
Definition: CodeTimings.h:52
bool operator==(const ProfilerSectionTag &rhs) const
equality operator
Definition: CodeTimings.h:42