My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
stats.h
Go to the documentation of this file.
1 /*
2 START OF LICENSE STUB
3  DeDOS: Declarative Dispersion-Oriented Software
4  Copyright (C) 2017 University of Pennsylvania, Georgetown University
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 END OF LICENSE STUB
19 */
26 #ifndef STATS_H_
27 #define STATS_H_
28 #include "unused_def.h"
29 #include "stat_ids.h"
30 
31 #include <time.h>
32 #include <stdlib.h>
33 
37 struct timed_stat {
38  struct timespec time;
39  long double value;
40 };
41 
47  unsigned int item_id;
49  int n_stats;
50 };
51 
53 struct stat_sample {
56  int max_stats;
58  struct timed_stat *stats;
59 };
60 
63  enum stat_id id;
64  char *name;
65 };
66 
67 #ifndef REPORTED_MSU_STAT_TYPES
68 #define REPORTED_MSU_STAT_TYPES \
69  {MSU_QUEUE_LEN, "QUEUE_LEN"}, \
70  {MSU_ITEMS_PROCESSED, "ITEMS_PROCESSED"}, \
71  {MSU_MEM_ALLOC, "MEMORY_ALLOCATED"}, \
72  {MSU_NUM_STATES, "NUM_STATES"}, \
73  {MSU_EXEC_TIME, "EXEC_TIME"}, \
74  {MSU_IDLE_TIME, "IDLE_TIME"}, \
75  {MSU_ERROR_CNT, "ERROR_COUNT"}, \
76  {MSU_UCPUTIME, "MSU_USER_TIME"}, \
77  {MSU_SCPUTIME, "MSU_KERNEL_TIME"}, \
78  {MSU_MINFLT, "MSU_MINOR_FAULTS"}, \
79  {MSU_MAJFLT, "MSU_MAJOR_FAULTS"}, \
80  {MSU_VCSW, "MSU_VOL_CTX_SW"}, \
81  {MSU_IVCSW, "MSU_INVOL_CTX_SW"}
82 #endif
83 
84 #ifndef REPORTED_THREAD_STAT_TYPES
85 #define REPORTED_THREAD_STAT_TYPES \
86  {THREAD_UCPUTIME, "USER_TIME"}, \
87  {THREAD_SCPUTIME, "KERNAL_TIME"}, \
88  {THREAD_MAXRSS, "MAX_RSS"}, \
89  {THREAD_MINFLT, "MINOR_FAULTS"}, \
90  {THREAD_MAJFLT, "MAJOR_FAULTS"}, \
91  {THREAD_VCSW, "VOL_CTX_SW"}, \
92  {THREAD_IVCSW, "INVOL_CTX_SW"}
93 #endif
94 
95 #ifndef REPORTED_STAT_TYPES
96 #define REPORTED_STAT_TYPES \
97  REPORTED_MSU_STAT_TYPES, \
98  REPORTED_THREAD_STAT_TYPES
99 #endif
100 
101 int is_thread_stat(enum stat_id id);
102 int is_msu_stat(enum stat_id id);
103 
107 };
109 #define N_REPORTED_STAT_TYPES sizeof(reported_stat_types) / sizeof(*reported_stat_types)
110 
113 };
114 #define N_REPORTED_MSU_STAT_TYPES \
115  sizeof(reported_msu_stat_types) / sizeof(*reported_msu_stat_types)
116 
119 };
120 #define N_REPORTED_THREAD_STAT_TYPES \
121  sizeof(reported_thread_stat_types) / sizeof(*reported_thread_stat_types)
122 
123 
124 
126 #define MAX_STAT_ITEM_ID 4192
127 
129 #define STAT_SAMPLE_SIZE 5
130 
132 #define STAT_SAMPLE_PERIOD_MS 500
133 
135 void free_stat_samples(struct stat_sample *samples, int n_samples);
136 
141 struct stat_sample *init_stat_samples(int max_stats, int n_samples);
142 
151 int deserialize_stat_samples(void *buffer, size_t buff_len, struct stat_sample *samples,
152  int n_samples);
153 
162 ssize_t serialize_stat_samples(struct stat_sample *samples, int n_samples,
163  void *buffer, size_t buff_len);
164 
172 size_t serialized_stat_sample_size(struct stat_sample *sample, int n_samples);
173 #endif
int max_stats
The allocated size of the stat_sample::stats structure.
Definition: stats.h:56
enum stat_id id
Definition: stats.h:63
Macro for declaring functions or variables as unused to avoid compiler warnings.
struct timed_stat * stats
The statistics in question.
Definition: stats.h:58
A single stat sample for a single item.
Definition: stats.h:53
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.
Definition: stats.c:176
static struct stat_type_label reported_msu_stat_types[]
Definition: stats.h:111
stat_id
The identifiers with which stats can be logged.
Definition: stat_ids.h:32
int is_thread_stat(enum stat_id id)
Definition: stats.c:40
static struct stat_type_label reported_stat_types[]
Static structure so the reported stat types can be referenced as an array.
Definition: stats.h:105
int is_msu_stat(enum stat_id id)
Definition: stats.c:49
#define REPORTED_STAT_TYPES
Definition: stats.h:96
int n_stats
The size of the sample (number of stats, not number of items)
Definition: stats.h:49
enum stat_id stat_id
The ID of the statistic being sampled.
Definition: stats.h:45
struct timespec time
Definition: stats.h:38
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
Definition: stats.c:122
size_t serialized_stat_sample_size(struct stat_sample *sample, int n_samples)
Determines the size needed to hold the serialized version of sample.
Definition: stats.c:96
unsigned int item_id
The ID for the item being sampled.
Definition: stats.h:47
Header for a single stat sample for a single item.
Definition: stats.h:43
#define REPORTED_THREAD_STAT_TYPES
Definition: stats.h:85
Declares the identifiers with which stats can be logged.
static struct stat_type_label reported_thread_stat_types[]
Definition: stats.h:117
#define UNUSED
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.
Definition: stats.c:80
void free_stat_samples(struct stat_sample *samples, int n_samples)
Frees a set of stat samples.
Definition: stats.c:71
char * name
Definition: stats.h:64
Holds a single timestamped value.
Definition: stats.h:37
Structure to hold both the stat ID and the string describing it.
Definition: stats.h:62
struct stat_sample_hdr hdr
Definition: stats.h:54
#define REPORTED_MSU_STAT_TYPES
Definition: stats.h:68
long double value
Definition: stats.h:39