From cca552c123e6522541b15e7cf4f51f3ec0fcf564 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 31 May 2014 19:49:21 +0300 Subject: Improve profiler speed. --- src/utils/perfomance.cpp | 21 +++++++++++++++++---- src/utils/perfomance.h | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src/utils') diff --git a/src/utils/perfomance.cpp b/src/utils/perfomance.cpp index 93d09cb40..d7ed52d4b 100644 --- a/src/utils/perfomance.cpp +++ b/src/utils/perfomance.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -37,11 +38,12 @@ static const clockid_t clockType = CLOCK_MONOTONIC; #define timeData ((static_cast(time.tv_sec) * 1000000000LL \ - + static_cast(time.tv_nsec)) / 1000) + + static_cast(time.tv_nsec)) / 1) namespace Perfomance { std::ofstream file; + std::string temp; long long unsigned int startTime; void init(const std::string &path) @@ -49,6 +51,7 @@ namespace Perfomance file.open(path.c_str(), std::ios_base::trunc); timespec time; clock_gettime(clockType, &time); + temp.reserve(10000000U); startTime = timeData; } @@ -62,21 +65,31 @@ namespace Perfomance { timespec time; clock_gettime(clockType, &time); - file << (timeData - startTime) << " __init__" << std::endl; + temp.append(toString(timeData - startTime)).append( + " __init__\n"); } void blockStart(const std::string &name) { timespec time; clock_gettime(clockType, &time); - file << (timeData - startTime) << " start: " << name << std::endl; + temp.append(toString(timeData - startTime)).append( + " start: ").append(name).append("\n"); } void blockEnd(const std::string &name) { timespec time; clock_gettime(clockType, &time); - file << (timeData - startTime) << " end: " << name << std::endl; + temp.append(toString(timeData - startTime)).append( + " end: ").append(name).append("\n"); + } + + void flush() + { + file << temp; + temp.clear(); +// file.flush(); } } // namespace Perfomance diff --git a/src/utils/perfomance.h b/src/utils/perfomance.h index c88859730..4a5f4fc17 100644 --- a/src/utils/perfomance.h +++ b/src/utils/perfomance.h @@ -31,6 +31,7 @@ #include "localconsts.h" #define PROFILER_START() Perfomance::start(); +#define PROFILER_END() Perfomance::flush(); #define BLOCK_START(name) Perfomance::blockStart(name); #define BLOCK_END(name) Perfomance::blockEnd(name); #define FUNC_BLOCK(name, id) Perfomance::Func PerfomanceFunc##id(name); @@ -47,6 +48,8 @@ namespace Perfomance void blockEnd(const std::string &name); + void flush(); + class Func final { public: @@ -68,6 +71,7 @@ namespace Perfomance #else // USE_PROFILER #define PROFILER_START() +#define PROFILER_END() #define BLOCK_START(name) #define BLOCK_END(name) #define FUNC_BLOCK(name, id) -- cgit v1.2.3-70-g09d2