kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #27059
[PATCH 2/4] Use std::chrono and std::cerr in PROF_COUNTER
---
include/profile.h | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/include/profile.h b/include/profile.h
index fdfeea1ca..ae2840e53 100644
--- a/include/profile.h
+++ b/include/profile.h
@@ -34,7 +34,10 @@
#include <stdint.h>
#include <cstdio>
+#include <chrono>
#include <string>
+#include <iostream>
+#include <iomanip>
/**
* Function get_tics
@@ -104,7 +107,7 @@ public:
void start()
{
m_running = true;
- prof_start( &m_cnt );
+ starttime = std::chrono::system_clock::now();
}
void stop()
@@ -112,26 +115,34 @@ public:
if( !m_running )
return;
- m_running = false;
- prof_end( &m_cnt );
+ stoptime = std::chrono::system_clock::now();
}
void show()
{
- stop();
- fprintf( stderr, "%s took %.1f milliseconds.\n", m_name.c_str(), (double)m_cnt.msecs() );
- start();
+ time_point display_stoptime;
+ if( m_running )
+ display_stoptime = std::chrono::system_clock::now();
+ else
+ display_stoptime = stoptime;
+
+ std::chrono::duration<double, std::milli> d = display_stoptime - starttime;
+ std::cerr << m_name << " took " << std::setprecision(1) << d.count() << "milliseconds." << std::endl;
}
double msecs() const
{
- return m_cnt.msecs();
+ std::chrono::duration<double, std::milli> d = stoptime - starttime;
+ return d.count();
}
private:
std::string m_name;
- prof_counter m_cnt;
bool m_running;
+
+ typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point;
+
+ time_point starttime, stoptime;
};
Follow ups
References