change profiler a bit

This commit is contained in:
nullifiedcat 2017-05-13 13:05:15 +03:00
parent 196c920ef9
commit 7869cb5e68
3 changed files with 17 additions and 12 deletions

View File

@ -1,5 +1,5 @@
CXX=$(shell sh -c "which g++-6 || which g++")
CXXFLAGS=-std=gnu++14 -D_GLIBCXX_USE_CXX11_ABI=0 -D_POSIX=1 -DRAD_TELEMETRY_DISABLED -DLINUX=1 -DUSE_SDL -D_LINUX=1 -DPOSIX=1 -DGNUC=1 -D_DEVELOPER=1 -DNO_MALLOC_OVERRIDE -O3 -g3 -ggdb -w -shared -Wall -Wno-unknown-pragmas -fmessage-length=0 -m32 -fvisibility=hidden -fPIC
CXXFLAGS=-std=gnu++17 -D_GLIBCXX_USE_CXX11_ABI=0 -D_POSIX=1 -DRAD_TELEMETRY_DISABLED -DLINUX=1 -DUSE_SDL -D_LINUX=1 -DPOSIX=1 -DGNUC=1 -D_DEVELOPER=1 -DNO_MALLOC_OVERRIDE -O3 -g3 -ggdb -w -shared -Wall -Wno-unknown-pragmas -fmessage-length=0 -m32 -fvisibility=hidden -fPIC
SDKFOLDER=$(realpath source-sdk-2013/mp/src)
SIMPLE_IPC_DIR = $(realpath simple-ipc/src/include)
INCLUDES=-I$(SIMPLE_IPC_DIR) -I$(SDKFOLDER)/public -I$(SDKFOLDER)/mathlib -I$(SDKFOLDER)/common -I$(SDKFOLDER)/public/tier1 -I$(SDKFOLDER)/public/tier0 -I$(SDKFOLDER)

View File

@ -9,6 +9,12 @@
#include "cvwrapper.h"
#include "logging.h"
unsigned g_spewcount { 0 };
static CatCommand profiler_begin("profiler_spew", "Spew and reset", []() {
g_spewcount++;
});
ProfilerSection::ProfilerSection(std::string name, ProfilerSection* parent) {
m_name = name;
m_calls = 0;
@ -19,8 +25,6 @@ ProfilerSection::ProfilerSection(std::string name, ProfilerSection* parent) {
m_parent = parent;
}
static CatVar do_profiler_logging(CV_SWITCH, "profiler_log", "0", "Profiler Log");
void ProfilerSection::OnNodeDeath(ProfilerNode& node) {
auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - node.m_start);
if (m_min == std::chrono::nanoseconds::zero()) m_min = dur;
@ -31,19 +35,19 @@ void ProfilerSection::OnNodeDeath(ProfilerNode& node) {
m_sum += dur;
m_calls++;
if (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now() - m_log).count() > 3) {
if (do_profiler_logging)
logging::Info("[P],'%-32s',%12llu,%12llu,%12llu,%12llu,%u", m_name.c_str(),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_sum).count(),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_sum).count() / (m_calls ? m_calls : 1),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_min).count(),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_max).count(),
m_calls);
if (g_spewcount > m_spewcount) {
logging::Info("[P],'%-32s',%12llu,%12llu,%12llu,%12llu,%u", m_name.c_str(),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_sum).count(),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_sum).count() / (m_calls ? m_calls : 1),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_min).count(),
std::chrono::duration_cast<std::chrono::nanoseconds>(m_max).count(),
m_calls);
m_log = std::chrono::high_resolution_clock::now();
m_min = std::chrono::nanoseconds::zero();
m_max = std::chrono::nanoseconds::zero();
m_sum = std::chrono::nanoseconds::zero();
m_calls = 0;
m_spewcount = g_spewcount;
}
}

View File

@ -24,6 +24,7 @@ public:
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;
@ -39,7 +40,7 @@ public:
ProfilerSection& m_section;
};
#define ENABLE_PROFILER true
#define ENABLE_PROFILER false
#if ENABLE_PROFILER
#define PROF_SECTION(id) \
static ProfilerSection __PROFILER__##id(#id); \