This repository has been archived on 2024-06-01. You can view files and clone it, but cannot push or open issues or pull requests.
cathook/include/profiler.hpp
2017-11-13 09:41:53 +03:00

53 lines
1.1 KiB
C++

/*
* profiler.h
*
* Created on: Nov 26, 2016
* Author: nullifiedcat
*/
#ifndef PROFILER_H_
#define PROFILER_H_
#include <aftercheaders.hpp>
#include <beforecheaders.hpp>
#include <chrono>
#include <string>
class ProfilerNode;
class ProfilerSection {
public:
ProfilerSection(std::string name, ProfilerSection* parent = nullptr);
void OnNodeDeath(ProfilerNode& node);
std::chrono::nanoseconds m_min;
std::chrono::nanoseconds m_max;
std::chrono::nanoseconds m_sum;
unsigned m_spewcount;
unsigned m_calls;
std::chrono::time_point<std::chrono::high_resolution_clock> m_log;
std::string m_name;
ProfilerSection* m_parent;
};
class ProfilerNode {
public:
ProfilerNode(ProfilerSection& section);
~ProfilerNode();
std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
ProfilerSection& m_section;
};
#define ENABLE_PROFILER true
#if ENABLE_PROFILER
#define PROF_SECTION(id) \
static ProfilerSection __PROFILER__##id(#id); \
ProfilerNode __PROFILER_NODE__##id(__PROFILER__##id);
#else
#define PROF_SECTION(id)
#endif
#endif /* PROFILER_H_ */