![]() |
Somtimes, the simple way of exposing a single value as a Performance Counter is not sufficient. For that reason, HPX provides a means of implementing full Performance Counters which support:
Every full Performance Counter will implement a predefined interface:
// Abstract base interface for all Performance Counters. struct performance_counter { // Retrieve the descriptive information about the Performance Counter. virtual counter_info get_counter_info() const = 0; // Retrieve the current Performance Counter value. virtual counter_value get_counter_value(bool reset = false) = 0; // Reset the Performance Counter (value). virtual void reset_counter_value() = 0; // Set the (initial) value of the Performance Counter. virtual void set_counter_value(counter_value const& /*value*/) = 0; // Start the Performance Counter. virtual bool start() = 0; // Stop the Performance Counter. virtual bool stop() = 0; };
In order to implement a full Performance Counter you have to create an
HPX component exposing this interface. To simplify
this task, HPX provides a ready made base class
which handles all the boiler plate of creating a component for you. The
remainder of this section will explain the process of creating a full
Performance Counter based on the Sine example which you can find in the
directory examples/performance_counters/sine/
.
The base class is defined in the header file hpx/performance_counters/base_performance_counter.hpp as:
[base_performance_counter_class]
The single template parameter is expected to receive the type of the derived class implementing the Performance Counter. In the Sine example this looks like:
class sine_counter : public hpx::performance_counters::base_performance_counter<sine_counter>
i.e. the type sine_counter
is derived from the base class passing the type as a template argument
(please see sine.hpp
for
the full source code of the counter definition). For more information
about this technique (called Curiously Recurring Template Pattern - CRTP),
please see for instance the corresponding Wikipedia
article. This base class itself is derived from the performance_counter
interface described
above.
Additionally, full Performance Counter implementation not only exposes the actual value but also provides information about