diff --git a/load.c b/load.c new file mode 100644 index 0000000000000000000000000000000000000000..7a90f3ca68fa4017839d0e36a7cf371979b0fdce --- /dev/null +++ b/load.c @@ -0,0 +1,37 @@ +/******************************************************* + Copyright (C) 2019-2020 Georges Da Costa <georges.da-costa@irit.fr> + + This file is part of Mojitos. + + Mojitos is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Mojitos is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. + + *******************************************************/ +#include <stdio.h> +#include <stdlib.h> + +#define LOAD_BUFFER_SIZE 1024 +char buffer[LOAD_BUFFER_SIZE]; + +void get_load(long long* results) { + FILE* f = fopen("/proc/stat", "rb"); + fgets(buffer, LOAD_BUFFER_SIZE, f); + fclose(f); + int pos=0; + while(buffer[pos] > '9' || buffer[pos] < '0') pos++; + for(int i=0; i<10; i++) { + results[i] = atoll(buffer+pos); + while(buffer[pos] <= '9' && buffer[pos] >= '0') pos++; + pos++; + } +} diff --git a/load.h b/load.h new file mode 100644 index 0000000000000000000000000000000000000000..649f47573604cb202b403dd475222021bd90e5f4 --- /dev/null +++ b/load.h @@ -0,0 +1,21 @@ +/******************************************************* + Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr> + + This file is part of Mojitos. + + Mojitos is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Mojitos is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with MojitO/S. If not, see <https://www.gnu.org/licenses/>. + + *******************************************************/ + +void get_load(long long* results); diff --git a/makefile b/makefile index 31d91fbc51d489ff48d85229f67e6a884cbe37b2..059d5f490d45065c8c98ac5f7484c6fa975fd365 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,10 @@ all: mojitos -mojitos_group:mojitos.c counters_group.o counters.h rapl.o rapl.h network.h network.o counters_option.h - gcc $(DEBUG) -O3 -Wall -o mojitos_group mojitos.c counters_group.o rapl.o network.o -lpowercap +mojitos_group:mojitos.c counters_group.o counters.h rapl.o rapl.h network.h network.o counters_option.h load.o + gcc $(DEBUG) -O3 -Wall -o mojitos_group mojitos.c counters_group.o rapl.o network.o load.o -lpowercap -mojitos:mojitos.c counters_individual.o counters.h rapl.o rapl.h network.h network.o counters_option.h - gcc $(DEBUG) -O3 -Wall -o mojitos mojitos.c counters_individual.o rapl.o network.o -lpowercap +mojitos:mojitos.c counters_individual.o counters.h rapl.o rapl.h network.h network.o counters_option.h load.o + gcc $(DEBUG) -O3 -Wall -o mojitos mojitos.c counters_individual.o rapl.o network.o load.o -lpowercap counters_option.h: counters_option.py ./counters_option.py > counters_option.h @@ -13,6 +13,9 @@ debug: DEBUG = -DDEBUG debug: all +load.o: load.c load.h + gcc -O3 -Wall -c load.c + rapl.o: rapl.c rapl.h gcc -O3 -Wall -c rapl.c diff --git a/mojitos.c b/mojitos.c index 2707cd3c5402c31d8eeb13422d8c6199ab3c4627..8936dc3e38da70b1ad6de3533e92084e2f7efde5 100644 --- a/mojitos.c +++ b/mojitos.c @@ -31,6 +31,7 @@ #include "counters.h" #include "rapl.h" #include "network.h" +#include "load.h" int rapl_mode=-1; const int nbzones = 3; @@ -84,8 +85,10 @@ void perf_event_list(char *perf_string, int *nb_perf, int **perf_indexes) { } } +int load_mode = -1; + void usage(char** argv) { - printf("Usage : %s [-t time] [-f freq] [-r] [-p perf_list] [-l] [-d network_device] [-o logfile] [-e command arguments...]\n", argv[0]); + printf("Usage : %s [-t time] [-f freq] [-r] [-p perf_list] [-l] [-u] [-d network_device] [-o logfile] [-e command arguments...]\n", argv[0]); printf("if time==0 then loops infinitively\n"); printf("if -e is present, time and freq are not used\n"); printf("-r activates RAPL\n"); @@ -94,6 +97,7 @@ void usage(char** argv) { printf("-l lists the possible performance counters and quits\n"); printf("-d activates network monitoring\n"); printf("-s activates statistics of overhead in nanoseconds\n"); + printf("-u activates report of system load\n"); exit(EXIT_SUCCESS); } @@ -130,7 +134,7 @@ int main(int argc, char **argv) { signal(15, flush); int c; - while ((c = getopt (argc, argv, "lhftdeoprs")) != -1 && application==NULL) + while ((c = getopt (argc, argv, "lhftdeoprsu")) != -1 && application==NULL) switch (c) { case 'f': frequency=atoi(argv[optind]); @@ -160,6 +164,9 @@ int main(int argc, char **argv) { case 'r': rapl_mode=0; break; + case 'u': + load_mode=0; + break; case 's': stat_mode=0; break; @@ -181,6 +188,12 @@ int main(int argc, char **argv) { long long tmp_network_values[4]={0,0,0,0}; get_network(network_values, network_sources); + // Load initialization + long long load_values[10]={0,0,0,0,0,0,0,0,0,0}; + long long tmp_load_values[10]={0,0,0,0,0,0,0,0,0,0}; + if(load_mode == 0) + get_load(load_values); + // RAPL initialization rapl_t rapl=NULL; size_t rapl_size=0; @@ -221,6 +234,9 @@ int main(int argc, char **argv) { for (int r=0; r<rapl->nbpackages*rapl->nbzones; r++) fprintf(output, "%s%u ", rapl->names[r], (unsigned int)r/rapl->nbzones); + if(load_mode==0) + fprintf(output, "user nice system idle iowait irq softirq steal guest and guest_nice "); + if(stat_mode==0) fprintf(output, "overhead "); fprintf(output, "\n"); @@ -240,7 +256,9 @@ int main(int argc, char **argv) { get_network(tmp_network_values, network_sources); if(rapl_mode==0) get_rapl(tmp_rapl_values, rapl); - + if(load_mode==0) + get_load(tmp_load_values); + if(application != NULL) { if(fork()==0){ @@ -281,6 +299,10 @@ int main(int argc, char **argv) { if(rapl_mode==0) for (int r=0; r<rapl->nbpackages*rapl->nbzones; r++) fprintf(output, "%ld ", tmp_rapl_values[r]-rapl_values[r]); + if(load_mode==0) + for(int i=0; i<10; i++) + fprintf(output, "%lld ", tmp_load_values[i]-load_values[i]); + if(stat_mode==0) fprintf(output, "%ld ", stat_data); @@ -290,6 +312,8 @@ int main(int argc, char **argv) { break; if(rapl_mode==0) memcpy(rapl_values, tmp_rapl_values, rapl_size); + if(load_mode==0) + memcpy(load_values, tmp_load_values, sizeof(load_values)); if(dev !=NULL) memcpy(network_values, tmp_network_values, sizeof(network_values)); clock_gettime(CLOCK_MONOTONIC, &ts);