Update Profiler to use std::chrono
This commit is contained in:
@@ -50,7 +50,7 @@ Profiler::m_worstCalls;
|
||||
static Mutex profileMutex;
|
||||
|
||||
void
|
||||
Profiler::add(const char *id, float ms)
|
||||
Profiler::add(const char *id, double ms)
|
||||
{
|
||||
profileMutex.lock();
|
||||
|
||||
@@ -95,7 +95,7 @@ Profiler::getReport()
|
||||
#endif
|
||||
report += buffer;
|
||||
|
||||
typedef std::multimap<float, const char *> TimeRMap;
|
||||
typedef std::multimap<double, const char *> TimeRMap;
|
||||
typedef std::multimap<int, const char *> IntRMap;
|
||||
TimeRMap totmap, avgmap, worstmap;
|
||||
IntRMap ncallmap;
|
||||
@@ -186,11 +186,7 @@ Profiler::Profiler(const char* c) :
|
||||
m_c(c),
|
||||
m_ended(false)
|
||||
{
|
||||
#ifdef PROFILE_CLOCKS
|
||||
m_start = clock();
|
||||
#else
|
||||
(void)gettimeofday(&m_start, 0);
|
||||
#endif
|
||||
m_start = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
Profiler::~Profiler()
|
||||
@@ -201,25 +197,9 @@ Profiler::~Profiler()
|
||||
void
|
||||
Profiler::end()
|
||||
{
|
||||
#ifdef PROFILE_CLOCKS
|
||||
clock_t end = clock();
|
||||
clock_t elapsed = end - m_start;
|
||||
float ms = float((double(elapsed) / double(CLOCKS_PER_SEC)) * 1000.0);
|
||||
#else
|
||||
struct timeval tv;
|
||||
(void)gettimeofday(&tv, 0);
|
||||
|
||||
tv.tv_sec -= m_start.tv_sec;
|
||||
if (tv.tv_usec < m_start.tv_usec) {
|
||||
tv.tv_usec += 1000000;
|
||||
tv.tv_sec -= 1;
|
||||
}
|
||||
tv.tv_usec -= m_start.tv_usec;
|
||||
float ms = float((double(tv.tv_sec) + (double(tv.tv_usec) / 1000000.0)) * 1000.0);
|
||||
#endif
|
||||
|
||||
add(m_c, ms);
|
||||
|
||||
auto finish = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double, std::milli> ms = finish - m_start;
|
||||
add(m_c, ms.count());
|
||||
m_ended = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,14 +39,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef NO_TIMING
|
||||
#ifdef PROFILE_CLOCKS
|
||||
#include <time.h>
|
||||
#else
|
||||
#include "sysutils.h"
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
#ifndef NO_TIMING
|
||||
@@ -75,21 +68,17 @@ public:
|
||||
static std::string getReport();
|
||||
|
||||
protected:
|
||||
const char* m_c;
|
||||
#ifdef PROFILE_CLOCKS
|
||||
clock_t m_start;
|
||||
#else
|
||||
struct timeval m_start;
|
||||
#endif
|
||||
const char *const m_c;
|
||||
std::chrono::time_point<std::chrono::steady_clock> m_start;
|
||||
bool m_showOnDestruct;
|
||||
bool m_ended;
|
||||
|
||||
typedef std::pair<int, float> TimePair;
|
||||
typedef std::pair<int, double> TimePair;
|
||||
typedef std::map<const char *, TimePair> ProfileMap;
|
||||
typedef std::map<const char *, float> WorstCallMap;
|
||||
typedef std::map<const char *, double> WorstCallMap;
|
||||
static ProfileMap m_profiles;
|
||||
static WorstCallMap m_worstCalls;
|
||||
static void add(const char *, float);
|
||||
static void add(const char *, double);
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
@@ -150,22 +150,6 @@ system_is_multiprocessor()
|
||||
return mp;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void gettimeofday(struct timeval *tv, void *tz)
|
||||
{
|
||||
union {
|
||||
long long ns100;
|
||||
FILETIME ft;
|
||||
} now;
|
||||
|
||||
::GetSystemTimeAsFileTime(&now.ft);
|
||||
tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL);
|
||||
tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void system_specific_initialise()
|
||||
{
|
||||
#if defined HAVE_IPP
|
||||
|
||||
@@ -99,11 +99,6 @@ extern bool system_is_multiprocessor();
|
||||
extern void system_specific_initialise();
|
||||
extern void system_specific_application_initialise();
|
||||
|
||||
#ifdef _WIN32
|
||||
struct timeval { long tv_sec; long tv_usec; };
|
||||
void gettimeofday(struct timeval *p, void *tz);
|
||||
#endif // _WIN32
|
||||
|
||||
} // end namespace
|
||||
|
||||
// The following should be functions in the RubberBand namespace, really
|
||||
|
||||
Reference in New Issue
Block a user