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

Adds system load with -u

parent 854b0ce1
Branches
No related tags found
No related merge requests found
load.c 0 → 100644
/*******************************************************
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++;
}
}
load.h 0 → 100644
/*******************************************************
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);
all: mojitos all: mojitos
mojitos_group:mojitos.c counters_group.o counters.h rapl.o rapl.h network.h network.o counters_option.h 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 -lpowercap 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 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 -lpowercap 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.h: counters_option.py
./counters_option.py > counters_option.h ./counters_option.py > counters_option.h
...@@ -13,6 +13,9 @@ debug: DEBUG = -DDEBUG ...@@ -13,6 +13,9 @@ debug: DEBUG = -DDEBUG
debug: all debug: all
load.o: load.c load.h
gcc -O3 -Wall -c load.c
rapl.o: rapl.c rapl.h rapl.o: rapl.c rapl.h
gcc -O3 -Wall -c rapl.c gcc -O3 -Wall -c rapl.c
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "counters.h" #include "counters.h"
#include "rapl.h" #include "rapl.h"
#include "network.h" #include "network.h"
#include "load.h"
int rapl_mode=-1; int rapl_mode=-1;
const int nbzones = 3; const int nbzones = 3;
...@@ -84,8 +85,10 @@ void perf_event_list(char *perf_string, int *nb_perf, int **perf_indexes) { ...@@ -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) { 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 time==0 then loops infinitively\n");
printf("if -e is present, time and freq are not used\n"); printf("if -e is present, time and freq are not used\n");
printf("-r activates RAPL\n"); printf("-r activates RAPL\n");
...@@ -94,6 +97,7 @@ void usage(char** argv) { ...@@ -94,6 +97,7 @@ void usage(char** argv) {
printf("-l lists the possible performance counters and quits\n"); printf("-l lists the possible performance counters and quits\n");
printf("-d activates network monitoring\n"); printf("-d activates network monitoring\n");
printf("-s activates statistics of overhead in nanoseconds\n"); printf("-s activates statistics of overhead in nanoseconds\n");
printf("-u activates report of system load\n");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -130,7 +134,7 @@ int main(int argc, char **argv) { ...@@ -130,7 +134,7 @@ int main(int argc, char **argv) {
signal(15, flush); signal(15, flush);
int c; int c;
while ((c = getopt (argc, argv, "lhftdeoprs")) != -1 && application==NULL) while ((c = getopt (argc, argv, "lhftdeoprsu")) != -1 && application==NULL)
switch (c) { switch (c) {
case 'f': case 'f':
frequency=atoi(argv[optind]); frequency=atoi(argv[optind]);
...@@ -160,6 +164,9 @@ int main(int argc, char **argv) { ...@@ -160,6 +164,9 @@ int main(int argc, char **argv) {
case 'r': case 'r':
rapl_mode=0; rapl_mode=0;
break; break;
case 'u':
load_mode=0;
break;
case 's': case 's':
stat_mode=0; stat_mode=0;
break; break;
...@@ -181,6 +188,12 @@ int main(int argc, char **argv) { ...@@ -181,6 +188,12 @@ int main(int argc, char **argv) {
long long tmp_network_values[4]={0,0,0,0}; long long tmp_network_values[4]={0,0,0,0};
get_network(network_values, network_sources); 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 initialization
rapl_t rapl=NULL; rapl_t rapl=NULL;
size_t rapl_size=0; size_t rapl_size=0;
...@@ -221,6 +234,9 @@ int main(int argc, char **argv) { ...@@ -221,6 +234,9 @@ int main(int argc, char **argv) {
for (int r=0; r<rapl->nbpackages*rapl->nbzones; r++) for (int r=0; r<rapl->nbpackages*rapl->nbzones; r++)
fprintf(output, "%s%u ", rapl->names[r], (unsigned int)r/rapl->nbzones); 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) if(stat_mode==0)
fprintf(output, "overhead "); fprintf(output, "overhead ");
fprintf(output, "\n"); fprintf(output, "\n");
...@@ -240,7 +256,9 @@ int main(int argc, char **argv) { ...@@ -240,7 +256,9 @@ int main(int argc, char **argv) {
get_network(tmp_network_values, network_sources); get_network(tmp_network_values, network_sources);
if(rapl_mode==0) if(rapl_mode==0)
get_rapl(tmp_rapl_values, rapl); get_rapl(tmp_rapl_values, rapl);
if(load_mode==0)
get_load(tmp_load_values);
if(application != NULL) { if(application != NULL) {
if(fork()==0){ if(fork()==0){
...@@ -281,6 +299,10 @@ int main(int argc, char **argv) { ...@@ -281,6 +299,10 @@ int main(int argc, char **argv) {
if(rapl_mode==0) if(rapl_mode==0)
for (int r=0; r<rapl->nbpackages*rapl->nbzones; r++) for (int r=0; r<rapl->nbpackages*rapl->nbzones; r++)
fprintf(output, "%ld ", tmp_rapl_values[r]-rapl_values[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) if(stat_mode==0)
fprintf(output, "%ld ", stat_data); fprintf(output, "%ld ", stat_data);
...@@ -290,6 +312,8 @@ int main(int argc, char **argv) { ...@@ -290,6 +312,8 @@ int main(int argc, char **argv) {
break; break;
if(rapl_mode==0) if(rapl_mode==0)
memcpy(rapl_values, tmp_rapl_values, rapl_size); memcpy(rapl_values, tmp_rapl_values, rapl_size);
if(load_mode==0)
memcpy(load_values, tmp_load_values, sizeof(load_values));
if(dev !=NULL) if(dev !=NULL)
memcpy(network_values, tmp_network_values, sizeof(network_values)); memcpy(network_values, tmp_network_values, sizeof(network_values));
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment