diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2013-06-04 13:35:53 -0400 |
---|---|---|
committer | Tim O'Shea <tim.oshea753@gmail.com> | 2013-06-05 14:20:05 -0400 |
commit | 8c5d3f8b4d2b84bb214e7f7bd6b3c0d3c60df1db (patch) | |
tree | 7468b7ab1a7a0a538dcdcd466038c681cf9cd817 | |
parent | 5e3fd0144cd3dde787985601416f798a37ebae86 (diff) |
runtime: adding config file + ctrlport selectable gr::high_res_timer to select clock type for performance counters
-rw-r--r-- | gnuradio-runtime/gnuradio-runtime.conf.in | 3 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/high_res_timer.h | 43 | ||||
-rw-r--r-- | gnuradio-runtime/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-runtime/lib/high_res_timer.cc | 8 | ||||
-rw-r--r-- | gnuradio-runtime/lib/top_block.cc | 19 |
5 files changed, 56 insertions, 18 deletions
diff --git a/gnuradio-runtime/gnuradio-runtime.conf.in b/gnuradio-runtime/gnuradio-runtime.conf.in index d41801aa23..37d9be6f9d 100644 --- a/gnuradio-runtime/gnuradio-runtime.conf.in +++ b/gnuradio-runtime/gnuradio-runtime.conf.in @@ -31,7 +31,8 @@ debug_file = stderr [PerfCounters] on = False export = True - +clock = thread +#clock = monotonic [ControlPort] on = False diff --git a/gnuradio-runtime/include/gnuradio/high_res_timer.h b/gnuradio-runtime/include/gnuradio/high_res_timer.h index fc7b007c61..7ec51602b0 100644 --- a/gnuradio-runtime/include/gnuradio/high_res_timer.h +++ b/gnuradio-runtime/include/gnuradio/high_res_timer.h @@ -22,44 +22,53 @@ #ifndef INCLUDED_GNURADIO_HIGH_RES_TIMER_H #define INCLUDED_GNURADIO_HIGH_RES_TIMER_H -namespace gr { - - //! Typedef for the timer tick count - typedef signed long long high_res_timer_type; - - //! Get the current time in ticks - high_res_timer_type high_res_timer_now(void); - - //! Get the number of ticks per second - high_res_timer_type high_res_timer_tps(void); - - //! Get the tick count at the epoch - high_res_timer_type high_res_timer_epoch(void); - -} /* namespace gr */ +#include <gnuradio/api.h> //////////////////////////////////////////////////////////////////////// // Use architecture defines to determine the implementation //////////////////////////////////////////////////////////////////////// #if defined(linux) || defined(__linux) || defined(__linux__) #define GNURADIO_HRT_USE_CLOCK_GETTIME + #include <ctime> #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) #define GNURADIO_HRT_USE_QUERY_PERFORMANCE_COUNTER #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) #define GNURADIO_HRT_USE_MACH_ABSOLUTE_TIME #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #define GNURADIO_HRT_USE_CLOCK_GETTIME + #include <ctime> #else #define GNURADIO_HRT_USE_MICROSEC_CLOCK #endif + //////////////////////////////////////////////////////////////////////// +namespace gr { + + //! Typedef for the timer tick count + typedef signed long long high_res_timer_type; + + //! Get the current time in ticks + high_res_timer_type high_res_timer_now(void); + + //! Get the number of ticks per second + high_res_timer_type high_res_timer_tps(void); + + //! Get the tick count at the epoch + high_res_timer_type high_res_timer_epoch(void); + #ifdef GNURADIO_HRT_USE_CLOCK_GETTIME - #include <ctime> + //! storage for high res timer type + GR_RUNTIME_API extern clockid_t high_res_timer_source; +#endif +} /* namespace gr */ + +//////////////////////////////////////////////////////////////////////// +#ifdef GNURADIO_HRT_USE_CLOCK_GETTIME inline gr::high_res_timer_type gr::high_res_timer_now(void){ timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(high_res_timer_source, &ts); return ts.tv_sec*high_res_timer_tps() + ts.tv_nsec; } diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt index 29222ae91f..a7b2638c21 100644 --- a/gnuradio-runtime/lib/CMakeLists.txt +++ b/gnuradio-runtime/lib/CMakeLists.txt @@ -83,6 +83,7 @@ list(APPEND gnuradio_runtime_sources flowgraph.cc hier_block2.cc hier_block2_detail.cc + high_res_timer.cc io_signature.cc local_sighandler.cc logger.cc diff --git a/gnuradio-runtime/lib/high_res_timer.cc b/gnuradio-runtime/lib/high_res_timer.cc new file mode 100644 index 0000000000..37e7e322a8 --- /dev/null +++ b/gnuradio-runtime/lib/high_res_timer.cc @@ -0,0 +1,8 @@ +#include <gnuradio/high_res_timer.h> + +#ifdef GNURADIO_HRT_USE_CLOCK_GETTIME +clockid_t gr::high_res_timer_source = CLOCK_THREAD_CPUTIME_ID; +#endif + + + diff --git a/gnuradio-runtime/lib/top_block.cc b/gnuradio-runtime/lib/top_block.cc index 8d2e42bb12..0cffbcadee 100644 --- a/gnuradio-runtime/lib/top_block.cc +++ b/gnuradio-runtime/lib/top_block.cc @@ -28,6 +28,7 @@ #include <gnuradio/top_block.h> #include <gnuradio/io_signature.h> #include <gnuradio/prefs.h> +#include <gnuradio/high_res_timer.h> #include <unistd.h> #include <iostream> @@ -152,6 +153,24 @@ namespace gr { RPC_PRIVLVL_MIN, DISPNULL))); } +#ifdef GNURADIO_HRT_USE_CLOCK_GETTIME + std::string initial_clock = prefs::singleton()->get_string("PerfCounters", "clock", "thread"); + if(initial_clock.compare("thread") == 0){ + gr::high_res_timer_source = CLOCK_THREAD_CPUTIME_ID; + } else if(initial_clock.compare("monotonic") == 0){ + gr::high_res_timer_source = CLOCK_MONOTONIC; + } else { + throw std::runtime_error("bad argument for PerfCounters.clock!"); + } + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_variable_rw<int>( + alias(), "perfcounter_clock", + (int*)&gr::high_res_timer_source, + pmt::mp(0), pmt::mp(2), pmt::mp(2), + "clock", "Performance Counters Realtime Clock Type", + RPC_PRIVLVL_MIN, DISPNULL))); +#endif + // Setters add_rpc_variable( rpcbasic_sptr(new rpcbasic_register_set<top_block, int>( |