[debug] timers with ns resolution

This commit is contained in:
Matthias Koefferlein 2024-09-14 10:45:28 +02:00
parent fc729584e1
commit 9e55a664fb
3 changed files with 40 additions and 30 deletions

View File

@ -23,6 +23,7 @@
#include "dbPolygonGenerators.h"
#include "tlTimer.h"
#include <vector>
#include <deque>
@ -175,11 +176,14 @@ public:
iterator insert (iterator at, I from, I to)
{
m_size += std::distance (from, to);
#if 0
// NOTE: in some STL m_contour.insert already returns the new iterator
size_t index_at = at - m_contour.begin ();
m_contour.insert (at, from, to);
return m_contour.begin () + index_at;
#else
return m_contour.insert (at, from, to);
#endif
}
private:
@ -701,14 +705,20 @@ PolygonGenerator::join_contours (db::Coord x)
} else if (! m_open_pos->first && ! n->first) {
{
tl::SelfTimer timer ("PGContour::insert");
// remove c1 from list of contours, join with c2
if (c2.is_hole ()) {
c2.insert (c2.end (), c1.begin () + 1, c1.end ());
} else {
c2.insert (c2.begin (), c1.begin (), c1.end () - 1);
}
}
{
tl::SelfTimer timer ("join_contours");
mp_contours->join (i2, i1);
}
open_map_iterator_type o = m_open_pos;
do {

View File

@ -82,9 +82,9 @@ void current_utc_time (struct timespec *ts)
}
// -------------------------------------------------------------
// Gets the current time in ms from epoch
// Gets the current time in ns from epoch
static int64_t ms_time ()
static int64_t ns_time ()
{
#if defined(__MACH__) && defined(__APPLE__)
@ -94,7 +94,7 @@ static int64_t ms_time ()
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
return int64_t (mts.tv_sec) * 1000 + int64_t (0.5 + mts.tv_nsec / 1.0e6);
return int64_t (mts.tv_sec) * 1000000000 + int64_t (mts.tv_nsec);
#elif defined(_MSC_VER)
@ -104,14 +104,14 @@ static int64_t ms_time ()
uint64_t t = (uint64_t (ft.dwHighDateTime) << (sizeof (ft.dwHighDateTime) * 8)) | uint64_t (ft.dwLowDateTime);
t -= ft_to_epoch_offset;
// FILETIME uses 100ns resolution, hence divide by 10000 to get ms:
return int64_t (t / 10000);
// FILETIME uses 100ns resolution, hence multiply with 100 to get ns:
return int64_t (t) * 100;
#else
timespec ts;
clock_gettime (CLOCK_REALTIME, &ts);
return int64_t (ts.tv_sec) * 1000 + int64_t (0.5 + ts.tv_nsec / 1.0e6);
return int64_t (ts.tv_sec) * 1000000000 + int64_t (ts.tv_nsec);
#endif
}
@ -120,8 +120,8 @@ static int64_t ms_time ()
// Implementation of Timer
Timer::Timer ()
: m_user_ms (0), m_sys_ms (0), m_wall_ms (0),
m_user_ms_res (0), m_sys_ms_res (0), m_wall_ms_res (0)
: m_user_ms (0), m_sys_ms (0), m_wall_ns (0),
m_user_ms_res (0), m_sys_ms_res (0), m_wall_ns_res (0)
{
// ..
}
@ -142,7 +142,7 @@ Timer::start ()
m_sys_ms += (timer_t) ((clks.tms_stime + clks.tms_cstime) * clk2msec + 0.5);
#endif
m_wall_ms += ms_time ();
m_wall_ns += ns_time ();
}
void
@ -150,15 +150,15 @@ Timer::stop ()
{
m_user_ms = -m_user_ms;
m_sys_ms = -m_sys_ms;
m_wall_ms = -m_wall_ms;
m_wall_ns = -m_wall_ns;
start ();
m_user_ms_res = m_user_ms;
m_sys_ms_res = m_sys_ms;
m_wall_ms_res = m_wall_ms;
m_wall_ns_res = m_wall_ns;
m_user_ms = 0;
m_sys_ms = 0;
m_wall_ms = 0;
m_wall_ns = 0;
}
void
@ -166,20 +166,20 @@ Timer::take ()
{
timer_t user_ms = m_user_ms;
timer_t sys_ms = m_sys_ms;
timer_t wall_ms = m_wall_ms;
timer_t wall_ns = m_wall_ns;
m_user_ms = -m_user_ms;
m_sys_ms = -m_sys_ms;
m_wall_ms = -m_wall_ms;
m_wall_ns = -m_wall_ns;
start ();
m_user_ms_res = m_user_ms;
m_sys_ms_res = m_sys_ms;
m_wall_ms_res = m_wall_ms;
m_wall_ns_res = m_wall_ns;
m_user_ms = user_ms;
m_sys_ms = sys_ms;
m_wall_ms = wall_ms;
m_wall_ns = wall_ns;
}
size_t
@ -288,20 +288,20 @@ SelfTimer::report () const
Clock::Clock (double s)
{
m_clock_ms = s * 1000.0;
m_clock_ns = s * 1e9;
}
double
Clock::seconds () const
{
return double (m_clock_ms) * 0.001;
return double (m_clock_ns) * 1e-9;
}
Clock
Clock::current ()
{
Clock c;
c.m_clock_ms += ms_time ();
c.m_clock_ns += ns_time ();
return c;
}

View File

@ -92,7 +92,7 @@ public:
*/
double sec_wall () const
{
return (double (m_wall_ms_res) * 0.001);
return (double (m_wall_ns_res) * 1e-9);
}
/**
@ -101,8 +101,8 @@ public:
static size_t memory_size ();
private:
timer_t m_user_ms, m_sys_ms, m_wall_ms;
timer_t m_user_ms_res, m_sys_ms_res, m_wall_ms_res;
timer_t m_user_ms, m_sys_ms, m_wall_ns;
timer_t m_user_ms_res, m_sys_ms_res, m_wall_ns_res;
};
/**
@ -182,7 +182,7 @@ public:
/**
* @brief Default constructor: construct a clock object pointing to an arbitrary value
*/
Clock () : m_clock_ms (0)
Clock () : m_clock_ns (0)
{
// .. nothing yet ..
}
@ -196,7 +196,7 @@ public:
* @brief Copy constructor
*/
Clock (const Clock &d)
: m_clock_ms (d.m_clock_ms)
: m_clock_ns (d.m_clock_ns)
{
// .. nothing yet ..
}
@ -206,7 +206,7 @@ public:
*/
Clock &operator= (Clock d)
{
m_clock_ms = d.m_clock_ms;
m_clock_ns = d.m_clock_ns;
return *this;
}
@ -215,7 +215,7 @@ public:
*/
bool operator== (Clock d) const
{
return m_clock_ms == d.m_clock_ms;
return m_clock_ns == d.m_clock_ns;
}
/**
@ -231,7 +231,7 @@ public:
*/
bool operator< (Clock d) const
{
return m_clock_ms < d.m_clock_ms;
return m_clock_ns < d.m_clock_ns;
}
/**
@ -239,7 +239,7 @@ public:
*/
Clock &operator-= (Clock d)
{
m_clock_ms -= d.m_clock_ms;
m_clock_ns -= d.m_clock_ns;
return *this;
}
@ -264,7 +264,7 @@ public:
static Clock current ();
private:
timer_t m_clock_ms;
timer_t m_clock_ns;
};
} // namespace tl