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