-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
122 lines (95 loc) · 2.32 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <unistd.h>
#include "debug.h"
#include "loop.h"
#include "input.h"
#include "opts.h"
#include "plot.h"
#include "psi.h"
#include "alloc.h"
#include "opts_psi.h"
#define Y_LABEL_REQUESTED 2048
#define Y_LABEL (MAX_HEIGHT-1) > Y_LABEL_REQUESTED ? Y_LABEL_REQUESTED : (MAX_HEIGHT-1)
/* TODO: plumb some options:
* - select between memory/io/cpu
* - different cgroups
* - define colors
* - configure speed/timestep?
* - configure y axis?
*/
int
main(int argc, char **argv)
{
int i;
struct opts o = {0};
struct psi ** metrics;
struct plot pl = { 0 };
FILE ** temp_files;
// TODO randomize this
char *tmp_filenames[] = {
"/tmp/DEADBEAF.file0",
"/tmp/DEADBEAF.file1",
"/tmp/DEADBEAF.file2",
"/tmp/DEADBEAF.file3",
"/tmp/DEADBEAF.file4",
};
char *psi_filenames[] = {
/* some */
"/proc/pressure/cpu",
"/proc/pressure/io",
"/proc/pressure/memory",
/* full */
"/proc/pressure/io",
"/proc/pressure/memory",
};
// ALLOC
temp_files = ccalloc(16, sizeof(FILE *));
metrics = ccalloc(5, sizeof(struct psi *));
for(i=0; i<NUM_METRICS; i++){
metrics[i] = ccalloc(1, sizeof(struct psi));
}
// initialize to zero
for(i=0; i< NUM_METRICS; i++){
metrics[i]->is_active = 0;
}
parse_opts_psi(&o, argc, argv);
// fopen files
for(i=0; i<NUM_METRICS; i++){
temp_files[i] = fopen(tmp_filenames[i], "w");
}
// init psi
for(i=0; i<NUM_METRICS; i++){
psi_init(metrics[i], psi_filenames[i], temp_files[i]);
}
// TEMPORARY FOR TESTING
for(i=2; i<NUM_METRICS; i++){
metrics[i]->is_active = 0;
}
// hardcoded array needs to be dynamically constructed based on filenames available
char* argv_fake[] = {
"plot", \
"-m", \
"-f", \
"-c", "r", "-i",tmp_filenames[0], \
"-c", "b", "-i",tmp_filenames[1], \
"-c", "y", "-i",tmp_filenames[2], \
"-c", "R", "-i",tmp_filenames[3], \
"-c", "B", "-i",tmp_filenames[4]};
// plot initialization
plot_init(&pl);
//parse_opts(&pl, 23, argv_fake);
parse_opts(&pl, 11, argv_fake);
set_input_buffer_size(8);
// should probably construct a legend based on params passed
printf("\n psimon cpu=red io=blue mem=yell \n\n");
// DO THINGS
loop(&pl, metrics, pl.follow_rate);
// FREE
free(temp_files);
for(i=0; i<NUM_METRICS; i++){
psi_destroy(metrics[i]);
}
free(metrics);
plot_destroy(&pl);
fflush(stdout);
return 0;
}