| 10 | |
| 11 | |
| 12 | SimpleProfiler::SimpleProfiler(char* fileName, int lineNumber) |
| 13 | : |
| 14 | m_frame(nullptr), m_time(0) { |
| 15 | for (auto& f : s_frames) { |
| 16 | if ((f.fileName == fileName) && (f.lineNumber == lineNumber)) { |
| 17 | m_frame = &f; |
| 18 | break; |
| 19 | } |
| 20 | } |
| 21 | if (m_frame == nullptr) { |
| 22 | FrameEntry entry(fileName, lineNumber); |
| 23 | s_frames.push_back(entry); |
| 24 | m_frame = &s_frames.back(); |
| 25 | } |
| 26 | ++m_frame->stackCount; |
| 27 | if (m_frame->stackCount == 1) { |
| 28 | struct timespec nowt; |
| 29 | clock_gettime(CLOCK_MONOTONIC, &nowt); |
| 30 | m_time = (int64_t) nowt.tv_sec * 1000000000LL + nowt.tv_nsec; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | SimpleProfiler::~SimpleProfiler() { |
| 35 | --m_frame->stackCount; |