Collecting statistics within the runtime. More...
#include "rt_stats.h"
#include "stats.h"
#include "logging.h"
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdbool.h>
Go to the source code of this file.
Classes | |
struct | stat_item |
The internal statistics structure where stats are aggregated One per statistic-item. More... | |
struct | stat_type |
The structure holding all items of a type of stats. More... | |
Macros | |
#define | CLOCK_ID CLOCK_REALTIME_COARSE |
The clock used to mark the time at which events take place. More... | |
#define | DURATION_CLOCK_ID CLOCK_MONOTONIC |
#define | MAX_STATS 8192 |
The maximum number of statistics that can be held in the rrdb. More... | |
#define | GATHER_STATS 1 |
If set to 0, will disable all gathering of statistics. More... | |
#define | GATHER_MSU_STATS 1 & GATHER_STATS |
#define | GATHER_CUSTOM_STATS 1 & GATHER_STATS |
#define | GATHER_THREAD_STATS 1 & GATHER_STATS |
#define | GATHER_PROFILING 0 |
#define | N_STAT_TYPES (sizeof(stat_types) / sizeof(*stat_types)) |
The number of types of statistics. More... | |
#define | CHECK_INITIALIZATION |
#define | WARN_ROLLOVER(label, item_id) |
Functions | |
static int | write_item_to_log (FILE *out_file, struct stat_type *type, struct stat_item *item) |
Writes a single stat item to the log file. More... | |
static void | get_elapsed_time (struct timespec *t) |
Gets the amount of time that has elapsed since logging started. More... | |
static int | wrlock_type (struct stat_type *type) |
Locks a stat type for writing. More... | |
static int | unlock_type (struct stat_type *type) |
Unlocks a stat type. More... | |
static int | rlock_type (struct stat_type *type) |
Locks a stat type for reading. More... | |
static int | lock_item (struct stat_item *item) |
Locks an item_stats structure, printing an error message on failure. More... | |
static int | unlock_item (struct stat_item *item) |
Unlocks an item_stats structure, printing an error message on failure. More... | |
static void UNUSED | flush_all_stats_to_log (FILE *file) |
Writes all statistics to the provided log file. More... | |
static void | destroy_stat_item (struct stat_item *item) |
Frees the memory associated with an individual stat item. More... | |
static struct stat_item * | get_item_stat (struct stat_type *type, unsigned int item_id) |
Gets the stat item associated with the given item_id in the given type. More... | |
static long double | current_double_time () |
int | record_start_time (enum stat_id stat_id, unsigned int item_id) |
Starts a measurement of elapsed time. More... | |
int | record_end_time (enum stat_id stat_id, unsigned int item_id) |
Records the elapsed time since the previous call to record_start_time. More... | |
int | increment_stat (enum stat_id stat_id, unsigned int item_id, double value) |
Increments the given statistic by the provided value. More... | |
int | record_stat (enum stat_id stat_id, unsigned int item_id, double stat, bool relog) |
Records a statistic in the statlog. More... | |
double | get_last_stat (enum stat_id stat_id, unsigned int item_id) |
Returns the last statistic recorded. More... | |
static int | time_cmp (struct timespec *t1, struct timespec *t2) |
Returns 1 if t1 > t2, -1 if t2 > t1, 0 otherwise. More... | |
static int | find_time_index (struct timed_stat *stats, struct timespec *time, int start_index, int stat_size) |
Finds the index at which the given time occurred in the stats. More... | |
static int | sample_stat_item (struct stat_item *item, int stat_size, struct timespec *sample_end, struct timespec *interval, int sample_size, struct timed_stat *sample) |
Takes a sample of the provided stat item and stores it in sample More... | |
static int | sample_stat (enum stat_id stat_id, struct timespec *end, struct timespec *interval, int sample_size, struct stat_sample *sample, int n_samples) |
Takes a sample of the provided stat type (stat_id) and places it in sample More... | |
static int UNUSED | sample_recent_stats (enum stat_id stat_id, struct timespec *interval, int sample_size, struct stat_sample *sample, int n_samples) |
Samples sample_size most recent stats in interval intervals. More... | |
struct stat_sample * | get_stat_samples (enum stat_id stat_id, struct timespec *sample_time, int *n_samples_out) |
Samples the statistic with the provided stat_id. More... | |
static void | realloc_stat_samples (enum stat_id stat_id, int n_samples) |
Reallocates the existing stats structure to store the provided number of samples. More... | |
int | remove_stat_item (enum stat_id stat_id, unsigned int item_id) |
Un-registers an item so it can no longer have statistics registered, and will not be reported to the global controller. More... | |
int | init_stat_item (enum stat_id stat_id, unsigned int item_id) |
Initializes a stat item so that statistics can be logged to it. More... | |
int | init_statistics () |
Initializes the entire stats module. More... | |
void | finalize_statistics (char *statlog) |
Writes the statistics to statlog if provided, and frees assocated structure. More... | |
Variables | |
static struct timespec | stats_start_time |
The time at which the runtime started. More... | |
static bool | stats_initialized = false |
Whether init_statistics has been called. More... | |
struct stat_type | stat_types [] |
The list of all statistics that can be gathered in the system. More... | |
static struct stat_sample * | stat_samples [N_REPORTED_STAT_TYPES] |
A statically allocated stat_sample structure which is pre-allocated to store samples from each stat type. More... | |
static struct timespec | stat_sample_interval |
The interval at which stats should be sampled. More... | |
Collecting statistics within the runtime.
Definition in file rt_stats.c.
#define CHECK_INITIALIZATION |
Definition at line 131 of file rt_stats.c.
#define CLOCK_ID CLOCK_REALTIME_COARSE |
The clock used to mark the time at which events take place.
Definition at line 37 of file rt_stats.c.
#define DURATION_CLOCK_ID CLOCK_MONOTONIC |
Definition at line 38 of file rt_stats.c.
#define GATHER_CUSTOM_STATS 1 & GATHER_STATS |
Definition at line 86 of file rt_stats.c.
#define GATHER_MSU_STATS 1 & GATHER_STATS |
Definition at line 85 of file rt_stats.c.
#define GATHER_PROFILING 0 |
Definition at line 92 of file rt_stats.c.
#define GATHER_STATS 1 |
If set to 0, will disable all gathering of statistics.
Definition at line 83 of file rt_stats.c.
#define GATHER_THREAD_STATS 1 & GATHER_STATS |
Definition at line 87 of file rt_stats.c.
#define MAX_STATS 8192 |
The maximum number of statistics that can be held in the rrdb.
Definition at line 79 of file rt_stats.c.
#define N_STAT_TYPES (sizeof(stat_types) / sizeof(*stat_types)) |
The number of types of statistics.
Definition at line 129 of file rt_stats.c.
#define WARN_ROLLOVER | ( | label, | |
item_id | |||
) |
Definition at line 351 of file rt_stats.c.
|
inlinestatic |
Definition at line 314 of file rt_stats.c.
|
static |
Frees the memory associated with an individual stat item.
Definition at line 294 of file rt_stats.c.
void finalize_statistics | ( | char * | statlog | ) |
Writes the statistics to statlog if provided, and frees assocated structure.
statlog | Log file to dump statistics to or NULL if N/A |
Definition at line 822 of file rt_stats.c.
|
static |
Finds the index at which the given time occurred in the stats.
Definition at line 505 of file rt_stats.c.
|
static |
Writes all statistics to the provided log file.
Definition at line 278 of file rt_stats.c.
|
static |
Gets the amount of time that has elapsed since logging started.
*t | the elapsed time is output into this variable |
Definition at line 221 of file rt_stats.c.
Gets the stat item associated with the given item_id in the given type.
Definition at line 300 of file rt_stats.c.
Returns the last statistic recorded.
Definition at line 466 of file rt_stats.c.
struct stat_sample* get_stat_samples | ( | enum stat_id | stat_id, |
struct timespec * | time, | ||
int * | n_sample_out | ||
) |
Samples the statistic with the provided stat_id.
stat_id | the ID of the stat_type to sample |
time | The time at which the samples should be taken |
n_samples_out | Output argument, stores the number of samples acquired |
Definition at line 634 of file rt_stats.c.
int increment_stat | ( | enum stat_id | stat_id, |
unsigned int | item_id, | ||
double | value | ||
) |
Increments the given statistic by the provided value.
stat_id | ID for the stat being logged |
item_id | ID for the item to which the stat refers (must be registered!) |
value | The amount to add to the given stat |
Definition at line 389 of file rt_stats.c.
Initializes a stat item so that statistics can be logged to it.
Initializes a new stat item so it can have stats registered and can be reported to the global controller.
(e.g. initializing MSU_QUEUE_LEN for item N, corresponding to msu # N)
stat_id | ID of the statistic type to be logged |
item_id | ID of the item to be logged |
Definition at line 719 of file rt_stats.c.
int init_statistics | ( | ) |
Initializes the entire stats module.
MUST BE CALLED before runtime starts
Definition at line 783 of file rt_stats.c.
|
inlinestatic |
Locks an item_stats structure, printing an error message on failure.
*item | the item_stats structure to lock |
Definition at line 257 of file rt_stats.c.
|
static |
Reallocates the existing stats structure to store the provided number of samples.
Definition at line 672 of file rt_stats.c.
int record_end_time | ( | enum stat_id | stat_id, |
unsigned int | item_id | ||
) |
Records the elapsed time since the previous call to record_start_time.
stat_id | ID for stat being logged |
item_id | ID for item within the statistic |
Definition at line 355 of file rt_stats.c.
int record_start_time | ( | enum stat_id | stat_id, |
unsigned int | item_id | ||
) |
Starts a measurement of elapsed time.
Not added to the log until a call to record_end_time
stat_id | ID for stat type being logged |
item_id | ID for the item to which the stat refers |
Definition at line 320 of file rt_stats.c.
int record_stat | ( | enum stat_id | stat_id, |
unsigned int | item_id, | ||
double | stat, | ||
bool | relog | ||
) |
Records a statistic in the statlog.
stat_id | ID for stat being logged |
item_id | ID for item to which stat refers (must be registered!) |
stat | Statistic to record |
relog | Whether to log statistic if it matches the previously logged stat |
Definition at line 426 of file rt_stats.c.
Un-registers an item so it can no longer have statistics registered, and will not be reported to the global controller.
Definition at line 683 of file rt_stats.c.
|
inlinestatic |
Locks a stat type for reading.
Definition at line 245 of file rt_stats.c.
|
static |
Samples sample_size
most recent stats in interval
intervals.
Note: Not used at the moment, deferring to sample_stat instead
Definition at line 612 of file rt_stats.c.
|
static |
Takes a sample of the provided stat type (stat_id) and places it in sample
Definition at line 565 of file rt_stats.c.
|
static |
Takes a sample of the provided stat item and stores it in sample
Definition at line 527 of file rt_stats.c.
|
inlinestatic |
Returns 1 if t1 > t2, -1 if t2 > t1, 0 otherwise.
Definition at line 497 of file rt_stats.c.
|
inlinestatic |
Unlocks an item_stats structure, printing an error message on failure.
*item | the item_stats structure to unlock |
Definition at line 269 of file rt_stats.c.
|
inlinestatic |
Unlocks a stat type.
Definition at line 236 of file rt_stats.c.
|
static |
Writes a single stat item to the log file.
Definition at line 187 of file rt_stats.c.
|
inlinestatic |
Locks a stat type for writing.
Definition at line 227 of file rt_stats.c.
|
static |
The interval at which stats should be sampled.
Definition at line 629 of file rt_stats.c.
|
static |
A statically allocated stat_sample structure which is pre-allocated to store samples from each stat type.
Definition at line 626 of file rt_stats.c.
struct stat_type stat_types[] |
The list of all statistics that can be gathered in the system.
Definition at line 96 of file rt_stats.c.
|
static |
Whether init_statistics has been called.
Definition at line 43 of file rt_stats.c.
|
static |
The time at which the runtime started.
Definition at line 41 of file rt_stats.c.