From 93afc6bff6ce58c08d8ae4b1509f682a05a9c59d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 11 Feb 2013 23:57:01 -0800 Subject: gras: ifdef'd chrono for timing purposes --- include/gras/CMakeLists.txt | 1 + include/gras/chrono.hpp | 77 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 include/gras/chrono.hpp (limited to 'include') diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index f0b0d3a..0ec3c98 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -3,6 +3,7 @@ ######################################################################## install(FILES + chrono.hpp block.hpp block.i element.hpp diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp new file mode 100644 index 0000000..dc013cc --- /dev/null +++ b/include/gras/chrono.hpp @@ -0,0 +1,77 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +//Boost chrono has awesome high res timer! +//But its only in very recent boosts, +//so we have this little wrapper... + +#ifndef INCLUDED_GRAS_CHRONO_HPP +#define INCLUDED_GRAS_CHRONO_HPP + +#include +#include + +#if BOOST_VERSION >= 104700 +#include + +namespace gras +{ + +namespace chrono +{ + +typedef boost::chrono::time_point TimePoint; +typedef boost::chrono::nanoseconds Duration; + +GRAS_FORCE_INLINE TimePoint high_res_now(void) +{ + return boost::posix_time::microsec_clock::universal_time(); +} + +GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) +{ + return d.count(); +} + +GRAS_FORCE_INLINE unsigned long long tps(void) +{ + return (unsigned long long)(1e9); +} + +} //namespace chrono + +} //namespace gras + +#else +#include + +namespace gras +{ + +namespace chrono +{ + +typedef boost::posix_time::ptime TimePoint; +typedef boost::posix_time::time_duration Duration; + +GRAS_FORCE_INLINE TimePoint high_res_now(void) +{ + return boost::posix_time::microsec_clock::universal_time(); +} + +GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) +{ + return d.ticks(); +} + +GRAS_FORCE_INLINE unsigned long long tps(void) +{ + return boost::posix_time::time_duration::ticks_per_second(); +} + +} //namespace chrono + +} //namespace gras + +#endif + +#endif /*INCLUDED_GRAS_CHRONO_HPP*/ -- cgit From 9191fbce9f4d161e4f871231469ef009c86f177f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 12 Feb 2013 21:43:27 -0800 Subject: gras: working on block stats --- include/gras/chrono.hpp | 81 ++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp index dc013cc..c976675 100644 --- a/include/gras/chrono.hpp +++ b/include/gras/chrono.hpp @@ -3,72 +3,69 @@ //Boost chrono has awesome high res timer! //But its only in very recent boosts, //so we have this little wrapper... +//now/tps inspired by libnumanuma. #ifndef INCLUDED_GRAS_CHRONO_HPP #define INCLUDED_GRAS_CHRONO_HPP #include -#include - -#if BOOST_VERSION >= 104700 -#include namespace gras { + typedef long long time_ticks_t; -namespace chrono -{ - -typedef boost::chrono::time_point TimePoint; -typedef boost::chrono::nanoseconds Duration; + //! Get the time now in tick counts + time_ticks_t time_now(void); -GRAS_FORCE_INLINE TimePoint high_res_now(void) -{ - return boost::posix_time::microsec_clock::universal_time(); + //! Get the number of ticks per second + time_ticks_t time_tps(void); } -GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) -{ - return d.count(); -} +//--------------------------------------------------------------------// +//------------------ implementation details below --------------------// +//--------------------------------------------------------------------// -GRAS_FORCE_INLINE unsigned long long tps(void) -{ - return (unsigned long long)(1e9); -} - -} //namespace chrono - -} //namespace gras +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -#else -#include +#include namespace gras { -namespace chrono -{ + GRAS_FORCE_INLINE time_ticks_t time_now(void) + { + LARGE_INTEGER counts; + QueryPerformanceCounter(&counts); + return counts.QuadPart; + } -typedef boost::posix_time::ptime TimePoint; -typedef boost::posix_time::time_duration Duration; + GRAS_FORCE_INLINE time_ticks_t time_tps(void) + { + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + return freq.QuadPart; + } -GRAS_FORCE_INLINE TimePoint high_res_now(void) -{ - return boost::posix_time::microsec_clock::universal_time(); -} +} //namespace gras -GRAS_FORCE_INLINE long long duration_to_ticks(const Duration &d) -{ - return d.ticks(); -} +#else + +#include -GRAS_FORCE_INLINE unsigned long long tps(void) +namespace gras { - return boost::posix_time::time_duration::ticks_per_second(); -} -} //namespace chrono + GRAS_FORCE_INLINE time_ticks_t time_now(void) + { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec*1000000000UL + ts.tv_nsec; + } + + GRAS_FORCE_INLINE time_ticks_t time_tps(void) + { + return 1000000000UL; + } } //namespace gras -- cgit From 67e0e06f155f4a2eeecafabd4c63b840b41b0709 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 13 Feb 2013 01:18:31 -0800 Subject: gras: work on stats messages and xml formatting --- include/gras/top_block.hpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/gras/top_block.hpp b/include/gras/top_block.hpp index 2f0dc87..a96cfe8 100644 --- a/include/gras/top_block.hpp +++ b/include/gras/top_block.hpp @@ -77,6 +77,12 @@ struct GRAS_API TopBlock : HierBlock */ virtual bool wait(const double timeout); + /*! + * Get block usage statistics in XML format. + * An external app will visualize the data. + */ + std::string get_stats_xml(void); + //! Deprecated void start(const size_t max_items); -- cgit