29 auto startPoint = std::chrono::high_resolution_clock::now();
30 _sessionStart = std::chrono::time_point_cast<std::chrono::microseconds>(startPoint).time_since_epoch().count();
59 std::ofstream fileStream(
_filePath, std::ios::binary);
65 std::vector<const char*> scopeNames;
66 std::vector<uint32_t> threadIds;
70 if (std::find(scopeNames.begin(), scopeNames.end(), result.name) == scopeNames.end())
71 scopeNames.push_back(result.name);
73 if (std::find(threadIds.begin(), threadIds.end(), result.threadId) == threadIds.end())
74 threadIds.push_back(result.threadId);
82 auto numScopeNames = (uint32_t)scopeNames.size();
86 for (
const char* scopeName : scopeNames)
96 auto numThreads = (uint32_t)threadIds.size();
99 for (uint32_t threadId : threadIds)
105 uint32_t numScopes = 0;
108 if (result.threadId == threadId) numScopes++;
115 if (result.threadId != threadId)
continue;
117 auto nameIndex = (uint32_t)(std::find(scopeNames.begin(), scopeNames.end(), result.name) - scopeNames.begin());
118 auto depth = result.depth;
194 std::cout << (
"Warning: Attempted to profile scope in non-profiled thread\nScope name: " + std::string(name) +
"\n").c_str();
199 _startPoint = std::chrono::high_resolution_clock::now();
218 auto endTimePoint = std::chrono::high_resolution_clock::now();
219 uint64_t start = std::chrono::time_point_cast<std::chrono::microseconds>(
_startPoint).time_since_epoch().count();
220 uint64_t end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimePoint).time_since_epoch().count();
static Profiler & instance()
std::string _filePath
Future path of the trace file.
std::vector< std::string > _threadNames
List of thread names (the thread ID is the index)
std::vector< ProfilingResult > _results
List of profiling results (of all threads)
void profileThread(const std::string &name)
uint64_t _sessionStart
Start timestamp of the session in microseconds.
static void writeString(const char *s, std::ofstream &stream)
Writes the length (32-bit) and the string (non-null-terminated) itself to the file stream.
void recordResult(ProfilingResult result)
std::mutex _mutex
Mutex for accessing profiling results and thread names.
void beginSession(std::string filePath)
std::chrono::time_point< std::chrono::high_resolution_clock > _startPoint
ProfilerTimer(const char *name)
static thread_local uint32_t threadId
static thread_local uint32_t threadDepth
static constexpr uint32_t INVALID_THREAD_ID
The SLScene class represents the top level instance holding the scene structure.
void writeBigEndian32(uint32_t number, std::ostream &stream)
void writeBigEndian64(uint64_t number, std::ostream &stream)