63 sample->
stats = calloc(max_stats,
sizeof(*sample->
stats));
64 if (sample->
stats == NULL) {
65 log_error(
"Error allocating sample stats");
73 for (
int i=0; i<n_samples; i++) {
74 free(sample[i].stats);
81 struct stat_sample *sample = calloc(n_samples,
sizeof(*sample));
83 log_error(
"Could not allocate %d stat samples", n_samples);
86 for (
int i=0; i<n_samples; i++) {
88 log_error(
"Error initializing stat sample %d", i);
97 size_t size =
sizeof(sample->
hdr) * n_samples;
98 for (
int i=0; i<n_samples; i++) {
109 log_error(
"Buffer isn't large enough to fit serialized stat sample");
113 char *curr_buff = buffer;
114 memcpy(curr_buff, &sample->
hdr,
sizeof(sample->
hdr));
115 curr_buff +=
sizeof(sample->
hdr);
117 memcpy(curr_buff, sample->
stats, stat_size);
119 return stat_size +
sizeof(sample->
hdr);
123 void *buffer,
size_t buff_len) {
125 log_error(
"Buffer isn't large enough to fit serialized stat samples");
130 memcpy(buffer, &hdr,
sizeof(hdr));
133 char *curr_buff = ((
char*)buffer) +
sizeof(hdr);
134 char *end_buff = curr_buff + buff_len;
139 log_error(
"Erorr serializing stat sample %d", i);
142 curr_buff += new_size;
145 log(LOG_STAT_SERIALIZATION,
"Serialized %d samples into buffer of size %d",
146 n_samples, (
int)(curr_buff - (
char*)buffer));
147 return curr_buff - (
char*)buffer;
154 if (buff_len <
sizeof(sample->
hdr)) {
155 log_error(
"Buffer isn't large enough to fit header");
159 char *curr_buff = buffer;
160 memcpy(&sample->
hdr, buffer,
sizeof(sample->
hdr));
161 curr_buff +=
sizeof(sample->
hdr);
164 if (
sizeof(sample->
hdr) + stat_size > buff_len) {
165 log_error(
"Buffer isn't large enough to fit statistics");
169 log_error(
"Not enough statistics allocated to fit deserialized stats");
172 memcpy(sample->
stats, curr_buff, stat_size);
173 return sizeof(sample->
hdr) + stat_size;
179 if (buff_len <
sizeof(*hdr)) {
180 log_error(
"Buffer not large enough for stat message header");
183 if (n_samples < hdr->n_samples) {
184 log_error(
"Number of allocated samples smaller than in serialized buffer");
188 char *curr_buff = ((
char *)buffer) +
sizeof(*hdr);
189 char *end_buff = curr_buff + buff_len;
193 log_error(
"Error deserializing stat sample %d", i);
196 curr_buff += consumed;
199 log(LOG_STAT_SERIALIZATION,
"Deserialized buffer of size %d into %d samples",
200 ((
int)(curr_buff - (
char*) buffer)), hdr->
n_samples);
202 if (curr_buff - (
char*)buffer < buff_len) {
203 log_warn(
"Entire buffer not used when deserializing stats");
int max_stats
The allocated size of the stat_sample::stats structure.
size_t serialized_stat_sample_size(struct stat_sample *sample, int n_samples)
Determines the size needed to hold the serialized version of sample.
struct timed_stat * stats
The statistics in question.
ssize_t serialize_stat_samples(struct stat_sample *samples, int n_samples, void *buffer, size_t buff_len)
Serializes from the provided samples into the buffer
A single stat sample for a single item.
struct stat_sample * init_stat_samples(int max_stats, int n_samples)
Initilizes n sets of samples of statistics, each of which contains max_stats points.
static struct stat_type_label reported_msu_stat_types[]
int deserialize_stat_samples(void *buffer, size_t buff_len, struct stat_sample *samples, int n_samples)
Deserializes from the provided buffer into the samples structure.
stat_id
The identifiers with which stats can be logged.
static ssize_t serialize_stat_sample(struct stat_sample *sample, void *buffer, size_t buff_len)
Serializes a single stat sample into a buffer of size buff_len.
Logging of status messages to the terminal.
Functions for the sending and receiving of statistics between ctrl and runtime.
int n_stats
The size of the sample (number of stats, not number of items)
static int init_stat_sample(int max_stats, struct stat_sample *sample)
Initializes a single stat sample with room to hold max_stats statistics.
#define N_REPORTED_MSU_STAT_TYPES
#define log_error(fmt,...)
int n_samples
The number of items sampled (not the size of the sample)
static ssize_t deserialize_stat_sample(void *buffer, size_t buff_len, struct stat_sample *sample)
Deserializes a single stat sample from a buffer.
static struct stat_type_label reported_thread_stat_types[]
#define log(level, fmt,...)
Log at a custom level.
int is_msu_stat(enum stat_id id)
#define N_REPORTED_THREAD_STAT_TYPES
Header for a serialized stats message.
struct stat_sample_hdr hdr
#define log_warn(fmt,...)
int is_thread_stat(enum stat_id id)
void free_stat_samples(struct stat_sample *sample, int n_samples)
Frees a set of stat samples.