Skip to content
Snippets Groups Projects
Commit 60371c99 authored by Georges Da Costa's avatar Georges Da Costa
Browse files

Cleans the code and go towards g++ support

parent 4be9b828
No related branches found
No related tags found
1 merge request!12Libmoj
Pipeline #11552 passed
......@@ -11,9 +11,9 @@ BIN = mojitos
BINP = mojitos_prometeus
PREFIX = /usr/local
# CC = g++
# CPPFLAGS = -std=c++20 -Wall -Wextra -Wpedantic -Wno-unused-function -I./lib $(NVML_IFLAGS)
CC = clang
CC = g++
CPPFLAGS = -std=c++20 -Wall -Wextra -Wpedantic -Wno-unused-function -I./lib $(NVML_IFLAGS)
CC = gcc
CPPFLAGS = -std=gnu99 -Wall -Wextra -Wpedantic -Wno-unused-function -I./lib $(NVML_IFLAGS)
CFLAGS = $(CPPFLAGS) -O3 -Werror
......
......@@ -57,8 +57,8 @@ void *show_all_counters(void *none1, size_t none2)
void perf_type_key(__u32 **perf_type, __u64 **perf_key, int *indexes, int nb)
{
*perf_type = malloc(nb * sizeof(__u32));
*perf_key = malloc(nb * sizeof(__u64));
*perf_type = (__u32*) malloc(nb * sizeof(__u32));
*perf_key = (__u64*) malloc(nb * sizeof(__u64));
for (int i = 0; i < nb; i++) {
(*perf_key)[i] = perf_static_info[indexes[i]].perf_key;
......@@ -78,7 +78,7 @@ void perf_event_list(char *perf_string, int *nb_perf, int **perf_indexes)
for (i = 0; i < nb_counter_option; i++) {
if (strcmp(perf_static_info[i].name, token) == 0) {
(*nb_perf)++;
(*perf_indexes) = realloc(*perf_indexes, sizeof(int) * (*nb_perf));
(*perf_indexes) = (int*) realloc(*perf_indexes, sizeof(int) * (*nb_perf));
(*perf_indexes)[*nb_perf - 1] = i;
break;
}
......@@ -113,15 +113,15 @@ Counter *_init_counters(const int nb_perf, const __u32 *types, const __u64 *name
pe.size = sizeof(struct perf_event_attr);
pe.disabled = 1;
Counter *counters = malloc(sizeof(struct Counter));
Counter *counters = (Counter*) malloc(sizeof(struct Counter));
counters->nbperf = nb_perf;
counters->nbcores = nbcores;
counters->counters = malloc(nb_perf * sizeof(int *));
counters->counters = (int**) malloc(nb_perf * sizeof(int *));
for (int i = 0; i < nb_perf; i++) {
pe.type = types[i];
pe.config = names[i];
counters->counters[i] = malloc(nbcores * sizeof(int));
counters->counters[i] = (int*) malloc(nbcores * sizeof(int));
for (unsigned int core = 0; core < nbcores; core++) {
counters->counters[i][core] = perf_event_open(&pe, -1, core, -1, PERF_FLAG_FD_CLOEXEC);
......@@ -207,8 +207,8 @@ unsigned int init_counters(char *args, void **state)
free(perf_key);
fd->perf_indexes = perf_indexes;
fd->counters_values = malloc(nb_perf * sizeof(uint64_t));
fd->tmp_counters_values = malloc(nb_perf * sizeof(uint64_t));
fd->counters_values = (uint64_t*) malloc(nb_perf * sizeof(uint64_t));
fd->tmp_counters_values = (uint64_t*) malloc(nb_perf * sizeof(uint64_t));
start_counters(fd);
_get_counters(fd, fd->counters_values);
*state = (void *) fd;
......
......@@ -85,15 +85,15 @@ void *show_all_likwid(void *none1, size_t none2)
unsigned int init_likwid(char *args, void **state)
{
Likwid *likwid = malloc(sizeof(struct Likwid));
Likwid *likwid = (Likwid*) malloc(sizeof(struct Likwid));
likwid->nbperf = 0;
likwid->labels = NULL;
char *events = malloc(sizeof(char)*strlen(args)+1);
char *events = (char*) malloc(sizeof(char)*strlen(args)+1);
strcpy(events, args);
while(events != NULL) {
likwid->nbperf++;
likwid->labels = realloc(likwid->labels, sizeof(char*)*likwid->nbperf);
likwid->labels = (char**) realloc(likwid->labels, sizeof(char*)*likwid->nbperf);
likwid->labels[likwid->nbperf-1] = events;
events = index(events, ',');
if(events != NULL) {
......@@ -125,7 +125,8 @@ unsigned int init_likwid(char *args, void **state)
free(cpus);
// Add eventset string to the perfmon module.
putenv("LIKWID_FORCE=1");
char env[] = "LIKWID_FORCE=1";
putenv(env);
likwid->gid = perfmon_addEventSet(args);
if (likwid->gid < 0) {
printf("perfmon_addEventSet with %s\n", args);
......
......@@ -32,7 +32,7 @@ char buffer[LOAD_BUFFER_SIZE];
static int load_fid = -1;
static uint64_t load_values[LOAD_VALUES_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static uint64_t tmp_load_values[LOAD_VALUES_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static char *stat = "/proc/stat";
static const char *stat = "/proc/stat";
void _get_load(uint64_t *results)
{
......
......@@ -89,8 +89,8 @@ unsigned int get_memory_counters(uint64_t *results, void *ptr)
MemoryCounters *counters = (MemoryCounters *)ptr;
fseek(counters->file, 0, SEEK_SET);
Parser parser = {.storage = (GenericPointer)results,
.capacity = 1,
.nb_stored = 0,
.capacity = 1,
.storage_struct_size = sizeof(uint64_t) * counters->count,
.keys = counters->keys,
.nb_keys = counters->count,
......
......@@ -46,21 +46,25 @@ Optparse opts[NB_OPT + 1] = {
.longname = "freq", .shortname = 'f', .argtype = OPTPARSE_REQUIRED,
.usage_arg = "<freq>",
.usage_msg = "set amount of measurements per second.",
.fn = NULL,
},
{
.longname = "time", .shortname = 't', .argtype = OPTPARSE_REQUIRED,
.usage_arg = "<time>",
.usage_msg = "set duration value (seconds). If 0, then loops infinitely.",
.fn = NULL,
},
{
.longname = "option", .shortname = 'o', .argtype = OPTPARSE_REQUIRED,
.usage_arg = "<output file> or <port number>",
.usage_msg = "specify a log file for MojitO/S or a port number for prometeus_mojitO/S.",
.fn = NULL,
},
{
.longname = "overhead-stats", .shortname = 's', .argtype = OPTPARSE_NONE,
.usage_arg = NULL,
.usage_msg = "enable overhead statistics (nanoseconds).",
.fn = NULL,
},
};
......@@ -150,7 +154,7 @@ int main(int argc, char **argv)
signal(SIGTERM, flush);
signal(SIGINT, flush);
char **save = malloc((argc+1)*sizeof(char*));
char **save = (char**) malloc((argc+1)*sizeof(char*));
memcpy(save, argv, (argc+1)*sizeof(char*));
int opt;
......
......@@ -30,8 +30,8 @@
#define NB_MAX_DEV 8
#define NB_SENSOR 4
static char *route = "/proc/net/route";
char *_labels_network[NB_SENSOR] = {
static const char *route = "/proc/net/route";
const char *_labels_network[NB_SENSOR] = {
"%s:rxp",
"%s:rxb",
"%s:txp",
......@@ -98,14 +98,14 @@ unsigned int init_network(char *dev, void **ptr)
exit(1);
}
char *filenames[] = {
const char *filenames[] = {
"/sys/class/net/%s/statistics/rx_packets",
"/sys/class/net/%s/statistics/rx_bytes",
"/sys/class/net/%s/statistics/tx_packets",
"/sys/class/net/%s/statistics/tx_bytes",
};
struct Network *state = malloc(sizeof(struct Network));
struct Network *state = (struct Network *) malloc(sizeof(struct Network));
memset(state, '\0', sizeof(*state));
if (strcmp(dev, "X") == 0) {
......
......@@ -37,7 +37,7 @@ char *get_rapl_string(const char *filename)
return NULL;
}
char *result = malloc(MAX_HEADER);
char *result = (char*) malloc(MAX_HEADER);
int nb = read(fd, result, MAX_HEADER);
close(fd);
result[nb - 1] = 0;
......@@ -69,11 +69,11 @@ typedef struct IntelRapl IntelRapl;
void add_rapl_source(IntelRapl *rapl, char *name, uint64_t modulo, char *energy_uj)
{
rapl->nb += 1;
rapl->names = realloc(rapl->names, sizeof(char **)*rapl->nb);
rapl->fids = realloc(rapl->fids, sizeof(int *)*rapl->nb);
rapl->modulo = realloc(rapl->modulo, sizeof(uint64_t)*rapl->nb);
rapl->names = (char**) realloc(rapl->names, sizeof(char **)*rapl->nb);
rapl->fids = (int*) realloc(rapl->fids, sizeof(int *)*rapl->nb);
rapl->modulo = (uint64_t*) realloc(rapl->modulo, sizeof(uint64_t)*rapl->nb);
rapl->names[rapl->nb - 1] = malloc(strlen(name) + 1);
rapl->names[rapl->nb - 1] = (char*) malloc(strlen(name) + 1);
strcpy(rapl->names[rapl->nb - 1], name);
//printf("%s\n", energy_uj);
......@@ -132,15 +132,15 @@ int add_rapl_source_from_str(IntelRapl *rapl, const char*name_base, const int i)
unsigned int init_rapl(char *none, void **ptr)
{
UNUSED(none);
IntelRapl *rapl = malloc(sizeof(IntelRapl));
IntelRapl *rapl = (IntelRapl*)malloc(sizeof(IntelRapl));
rapl->nb = 0;
rapl->names = NULL;
rapl->fids = NULL;
rapl->modulo = NULL;
char buffer[BUFFER_SIZE];
char *name_base = "/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/";
char *name_sub = "/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/intel-rapl:%d:%s/";
const char *name_base = "/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/";
const char *name_sub = "/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/intel-rapl:%d:%s/";
for (unsigned int i = 0;; i++) {
......@@ -157,8 +157,8 @@ unsigned int init_rapl(char *none, void **ptr)
}
}
rapl->values = calloc(rapl->nb, sizeof(uint64_t));
rapl->tmp_values = calloc(rapl->nb, sizeof(uint64_t));
rapl->values = (uint64_t*) calloc(rapl->nb, sizeof(uint64_t));
rapl->tmp_values = (uint64_t*) calloc(rapl->nb, sizeof(uint64_t));
_get_rapl(rapl->values, rapl);
......
......@@ -58,8 +58,8 @@ int get_string(char *filename, char *buffer, int max_size)
void add_to_list(char ***list_name, char *source, int nb_elem)
{
//printf("Adds: %s\n", source);
*list_name = realloc(*list_name, (nb_elem + 1) * sizeof(char *));
(*list_name)[nb_elem] = malloc(strlen(source) + 1);
*list_name = (char**) realloc(*list_name, (nb_elem + 1) * sizeof(char *));
(*list_name)[nb_elem] = (char*) malloc(strlen(source) + 1);
strcpy((*list_name)[nb_elem], source);
}
......@@ -92,7 +92,7 @@ void add_temperature_sensor(int id_rep, Temperature *state)
add_to_list(&state->label_list, buffer_label, state->nb_elem);
snprintf(buffer_filename, BUFFER_SIZE, "/sys/class/hwmon/hwmon%d/temp%d_input", id_rep, i);
state->fid_list = realloc(state->fid_list, (state->nb_elem + 1) * sizeof(int));
state->fid_list = (int*) realloc(state->fid_list, (state->nb_elem + 1) * sizeof(int));
int fd = open(buffer_filename, O_RDONLY);
if (fd < 0) {
......@@ -112,7 +112,7 @@ void add_temperature_sensor(int id_rep, Temperature *state)
unsigned int init_temperature(char *args, void **ptr)
{
UNUSED(args);
Temperature *state = malloc(sizeof(Temperature));
Temperature *state = (Temperature *) malloc(sizeof(Temperature));
state->nb_elem = 0;
state->label_list = NULL;
state->fid_list = NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment