PerformanceCounters
Performance Counters
Performance Counters can be used to capture/monitor information about a block inside a running flowgraph. The performance counters are calculated for each block after work has been called. Because these calculations are done inline with the GNU Radio scheduler, it will affect performance, though it should be minor.
Types of Counters
Currently, there are five performance counters. For each counter, the block keeps track of both its average and variance. These counters are:
- noutput_items: the number of noutput_items the block is called with.
- nproduced: the number of items the block produces.
- input_buffers_full: the percentage of how full each input buffer is.
- ouptut_buffers_full: the percentage of how full each output buffer is.
- work_time: the number of CPU clock ticks during the call to general_work().
- work_time_total: cumulative sum of all time spent in work.
Turn on/off counters
Counters can be turned on and off at compile time and via the standard GNU Radio config files. By default, GNU Radio is built with the performance counters turned off so they add no extra computational overhead to GNU Radio. To compile with the performance counters on, add the following option to the cmake commandline:
-DENABLE_PERFORMANCE_COUNTERS=On
The use of performance counters can also be toggled on/off through the GNU Radio configuration file. This is not exactly the same as turning them off when compiling. Using the configuration files, a bool is created to test if the performance counters are configured on or off, so a test is done before calling the performance counter calculator functions. On machines with good branch prediction, this should add almost no extra overhead to the system.
The configuration file is located at ${prefix}/etc/gnuradio/conf.d/gnuradio-core.conf (for GR 3.7 ${prefix}/etc/gnuradio/conf.d/gnuradio-runtime.conf). Inside this, there is a section for with the option on. Using False/Off/0 and True/On/1 (not case sensitive), the performance counters can be toggled off/on. Also remember you can set GR_CONF_PERFCOUNTERS_ON=True|False to override this parameter.
Queries
Can query state of input/output buffers (mean/standard deviation)
Queries to the performance counters can be made directly to a particular block. The getter functions for all performance counters are part of the gr_block class and exported to Python through SWIG. For each performance counter, there is a getter function for both the average and the variance.
- float pc_noutput_items();
- float pc_noutput_items_var();
- float pc_nproduced();
- float pc_nproduced_var();
- float pc_input_buffers_full(int which);
- float pc_input_buffers_full_var(int which);
- std::vector<float> pc_input_buffers_full();
- std::vector<float> pc_input_buffers_full_var();
- float pc_output_buffers_full(int which);
- float pc_output_buffers_full_var(int which);
- std::vector<float> pc_output_buffers_full();
- std::vector<float> pc_output_buffers_full_var();
- float pc_work_time();
- float pc_work_time_var();
Note here that the API allows for getting access to the in/out buffers fullness either as a vector for all of the buffers or by specifying a particular buffer of interest
There is another function called reset_perf_counters() that can be called at any time on any block to reset the performance counters back to 0.
Export via ControlPort
If the performance counters are turned on and ControlPort is used, then by default all of the performance counters are made available over ControlPort. This can also be toggled using the config file by changing the value for the option export in the section .
The interfaces to the performance counters will have the name of the performance counter and either 'avg' or 'var' to specify if this is the average or variance counter for that counter.