JayBeams
0.1
Another project to have fun coding.
|
Keep statistics about a feed and its offline processor. More...
#include <offline_feed_statistics.hpp>
Classes | |
class | config |
Configure an offline_feed_statistics object. More... | |
Public Member Functions | |
offline_feed_statistics (config const &cfg) | |
Constructor. More... | |
template<typename event_timestamp_t , typename duration_t > | |
void | sample (event_timestamp_t ts, duration_t processing_latency) |
Record a sample, that is process a message received at the given timestamp. More... | |
void | print_csv (std::string const &name, std::ostream &os) const |
Print all the measurements in CSV format. More... | |
void | log_final_progress () const |
Final progress report at the end of the input. More... | |
Static Public Member Functions | |
static void | print_csv_header (std::ostream &os) |
Print a CSV header. More... | |
Private Types | |
typedef event_rate_histogram< std::chrono::nanoseconds, std::int64_t > | rate_histogram |
typedef histogram< integer_range_binning< std::int64_t > > | interarrival_histogram_t |
typedef histogram< integer_range_binning< std::uint64_t > > | processing_latency_histogram_t |
Private Member Functions | |
void | log_progress (std::chrono::nanoseconds ts) const |
Report progress up to a certain point in the input. More... | |
void | record_sample (std::chrono::nanoseconds ts, std::chrono::nanoseconds processing_latency) |
Refactor non-template portions of sample() More... | |
Private Attributes | |
rate_histogram | per_sec_rate_ |
rate_histogram | per_msec_rate_ |
rate_histogram | per_usec_rate_ |
interarrival_histogram_t | interarrival_ |
processing_latency_histogram_t | processing_latency_ |
std::chrono::seconds | reporting_interval_ |
std::chrono::nanoseconds | last_ts_ |
std::chrono::nanoseconds | last_report_ts_ |
Keep statistics about a feed and its offline processor.
In JayBeams we will find ourselves processing all kinds of offline feeds, that is, files with the contents of a real-time feed. We want to measure things like the processing time for the data, what is the distribution of message rates like, what is the distribution of mesage inter-arrival times like.
This class encapsulates a lot of the logic for those computations. The class can be thoroughly configured at run-time, for ease of experimentation, but the default values should be reasonable.
The source of timestamps can be an actual clock, the recorded timestamps is a feed file, or some virtual clock used in simulations. The only requirement is for the timestamps to be compatible with std::chrono::duration<>. It might seem odd to use std::chrono::duration<> instead of std::chrono::time_point<>, this is because most feeds are timestamps to a well known time point: midnight at the beginning of the day, or 00:00:00am.
Likewise, the processing latency measurements can be generated from an actual clock or some virtual measurement (say counting interrupts, or CPU cycles vs. elapsed time). The only requirement is for the measurements to be compatible with std::chono::duration<>.
Definition at line 40 of file offline_feed_statistics.hpp.
|
private |
Definition at line 145 of file offline_feed_statistics.hpp.
|
private |
Definition at line 149 of file offline_feed_statistics.hpp.
|
private |
Definition at line 140 of file offline_feed_statistics.hpp.
|
explicit |
Constructor.
Definition at line 166 of file offline_feed_statistics.cpp.
void jb::offline_feed_statistics::log_final_progress | ( | ) | const |
Final progress report at the end of the input.
Definition at line 205 of file offline_feed_statistics.cpp.
References log_progress().
Referenced by BOOST_AUTO_TEST_CASE(), and sample().
|
private |
Report progress up to a certain point in the input.
ts | the (logical) timestamp of the current event in the input |
Definition at line 210 of file offline_feed_statistics.cpp.
References interarrival_, jb::histogram< binning_strategy_t, counter_type_t >::nsamples(), per_msec_rate_, per_sec_rate_, per_usec_rate_, and processing_latency_.
Referenced by log_final_progress(), record_sample(), and sample().
void jb::offline_feed_statistics::print_csv | ( | std::string const & | name, |
std::ostream & | os | ||
) | const |
Print all the measurements in CSV format.
Definition at line 254 of file offline_feed_statistics.cpp.
References interarrival_, jb::histogram< binning_strategy_t, counter_type_t >::nsamples(), per_msec_rate_, per_sec_rate_, per_usec_rate_, and processing_latency_.
Referenced by BOOST_AUTO_TEST_CASE(), and sample().
|
static |
Print a CSV header.
Assuming there are many offline_feed_statistics<> objects (say one for each symbol, or one for each minute interval) this function can be used to print the CSV header for all of them.
The fields include:
os | the output stream |
Definition at line 186 of file offline_feed_statistics.cpp.
Referenced by BOOST_AUTO_TEST_CASE(), main(), run_inside(), and sample().
|
private |
Refactor non-template portions of sample()
ts | the logical timestamp of the event in the input stream |
processing_latency | the processing latency for the event |
Definition at line 224 of file offline_feed_statistics.cpp.
References interarrival_, last_report_ts_, last_ts_, log_progress(), jb::histogram< binning_strategy_t, counter_type_t >::nsamples(), per_msec_rate_, per_sec_rate_, per_usec_rate_, processing_latency_, reporting_interval_, jb::event_rate_histogram< duration_type, counter_type, rate_counter_type >::sample(), and jb::histogram< binning_strategy_t, counter_type_t >::sample().
Referenced by sample().
|
inline |
Record a sample, that is process a message received at the given timestamp.
event_timestamp_t | the type used to record the event timestamps. |
duration_t | the type used to record the processing latency for the event. |
ts | the event timestamp, please see the class documentation for timestamps vs. time points. |
processing_latency | the time it took to process the event. |
Definition at line 61 of file offline_feed_statistics.hpp.
References log_final_progress(), log_progress(), print_csv(), print_csv_header(), and record_sample().
Referenced by BOOST_AUTO_TEST_CASE(), and jb::itch5::record_latency_stats().
|
private |
Definition at line 146 of file offline_feed_statistics.hpp.
Referenced by log_progress(), print_csv(), and record_sample().
|
private |
Definition at line 154 of file offline_feed_statistics.hpp.
Referenced by record_sample().
|
private |
Definition at line 153 of file offline_feed_statistics.hpp.
Referenced by record_sample().
|
private |
Definition at line 142 of file offline_feed_statistics.hpp.
Referenced by log_progress(), print_csv(), and record_sample().
|
private |
Definition at line 141 of file offline_feed_statistics.hpp.
Referenced by log_progress(), print_csv(), and record_sample().
|
private |
Definition at line 143 of file offline_feed_statistics.hpp.
Referenced by log_progress(), print_csv(), and record_sample().
|
private |
Definition at line 150 of file offline_feed_statistics.hpp.
Referenced by log_progress(), print_csv(), and record_sample().
|
private |
Definition at line 152 of file offline_feed_statistics.hpp.
Referenced by record_sample().