Skip to content
Snippets Groups Projects
Commit d22c9bda authored by TwilCynder's avatar TwilCynder
Browse files

Merge branch 'dev' into teo_CICD

parents b6bd0080 a0c1db32
2 merge requests!9fix sensor example (doc),!4Amd, Tests, Doc, CI/CD
Checking pipeline status
......@@ -21,7 +21,26 @@ OPTIONS:
-s|--overhead-stats
enable overhead statistics (nanoseconds).
```
The following is an exhaustive list of all the sensors (it is very likely
that one will not have all the sensors activated in his build):
```bash
SENSORS:
-a|--amd-rapl
AMD RAPL
-p|--perf-list <perf_list>
performance counters
perf_list is a coma separated list of performance counters.
Ex: instructions,cache_misses
-l|--list
list the available performance counters and quit
-i|--monitor-infiniband <infiniband_path>
infiniband monitoring (if infiniband_path is X, tries to detect it automatically)
-u|--sysload
system load
-d|--net-dev <net_dev>
network monitoring (if network_device is X, tries to detect it automatically)
-r|--intel-rapl
INTEL RAPL
```
......
......@@ -26,18 +26,19 @@ debug=0
target_hdr=src/sensors.h
target_mk=sensors.mk
nonsensor='counters_option|optparse|sensors|util|info_reader'
nonsensor='counters_option|sensors|util'
hdr_blacklist=$nonsensor
hdr_whitelist=''
usage() {
printf -- 'Usage: %s [-l] [-e <captor>] [-i <captor>] [-u <captor>]\n' "$(basename "$0")" >&2
printf -- '-e | --exclude : exclude captor, can be called multiple times\n' >&2
printf -- '-i | --include : include captor, can be called multiple times\n' >&2
printf -- '-l | --list-captors : list all captors and exit\n' >&2
printf -- '-u | --unique : only include the specified captor\n' >&2
printf -- ' if this option is used, any use of `-e` or `-i` will be ignored\n' >&2
printf -- 'Usage: %s [-la] [-e <sensor>] [-i <sensor>] [-u <sensor>]\n' "$(basename "$0")" >&2
printf -- '-e | --exclude : exclude sensor, can be called multiple times\n' >&2
printf -- '-i | --include : include sensor, can be called multiple times\n' >&2
printf -- '-l | --list-sensors : list all sensors and exit\n' >&2
printf -- '-u | --unique : only include the specified sensor\n' >&2
printf -- ' if this option is used, any usage of `-e` or `-i` will be ignored\n' >&2
printf -- '-a | --all : include all sensors, meant to be used only by the makefile\n' >&2
exit 1
}
......@@ -62,9 +63,9 @@ gen_sensors_h() {
for sensor in $sensors; do
sed -n 's/.*'"${sensor}"'_opt\[\([0-9]\+\)\].*/\1/p' "src/${sensor}.h"
done |
paste -s -d '+' |
bc
paste -s -d '+'
)
nb_sensor_opts=$(eval "echo \$(($nb_sensor_opts))")
dprint sensors >&2
dprint nb_sensor_opts >&2
......@@ -106,7 +107,7 @@ gen_sensors_mk() {
detect_caps() {
[ -r /usr/include/linux/perf_event.h ] && hdr_whitelist=counters
[ -d /sys/class/infiniband ] && hdr_whitelist=${hdr_whitelist}|infiniband
[ -d /sys/class/infiniband ] && hdr_whitelist="${hdr_whitelist}|infiniband"
[ -r /proc/stat ] && hdr_whitelist="${hdr_whitelist}|load"
if [ -r /proc/net/route ]; then
......@@ -134,8 +135,15 @@ detect_caps() {
[ $(ls -1 /sys/class/hwmon | wc -l) -gt 0 ] && hdr_whitelist="${hdr_whitelist}|temperature"
}
detect_caps
case $1 in
--all|-a)
all=1
;;
esac
[ "$all" ] || detect_caps
[ "$all" ] ||
while [ "$1" ]; do
case $1 in
--include|-i)
......
......@@ -24,7 +24,7 @@ LDFLAGS =
ASTYLE = astyle --style=kr -xf -s4 -k3 -n -Z -Q
all: $(BIN) readme man
all: $(BIN) man
$(BIN): $(BIN_DIR) $(OBJ) $(OBJ_DIR)/$(BIN).o
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$(BIN) $(OBJ) $(OBJ_DIR)/$(BIN).o
......@@ -51,7 +51,7 @@ debug: CFLAGS = $(CPPFLAGS) -DDEBUG -g -Og
debug: $(BIN)
tests:
gcc $(CPPFLAGS) $(TESTS_DIR)/main.c $(SRC_DIR)/util.c -o $(TESTS_DIR)/run
$(CC) $(CPPFLAGS) $(TESTS_DIR)/main.c $(SRC_DIR)/util.c -o $(TESTS_DIR)/run
$(TESTS_DIR)/run
format:
......@@ -70,8 +70,8 @@ readme: $(BIN)
sh ./tools/update-readme-usage.sh
man: $(BIN)
awk -v "usage=$$($(BIN_DIR)/$(BIN) -1)" \
awk -v "usage=$$($(BIN_DIR)/$(BIN) --dump-opts)" \
'/^USAGE/ { $$0=usage } 1' \
doc/mojitos.pre.1 > doc/mojitos.1 2>/dev/null
doc/$(BIN).pre.1 > doc/$(BIN).1 2>/dev/null
.PHONY: all clean mojitos debug format tests readme man
......@@ -17,25 +17,44 @@
along with MojitO/S. If not, see <https://www.gnu.org/licenses/>.
*******************************************************/
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <glob.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "util.h"
#define NB_SENSOR 4
struct Network {
struct Infiniband {
uint64_t values[NB_SENSOR];
uint64_t tmp_values[NB_SENSOR];
int sources[NB_SENSOR];
};
typedef struct Network Network;
typedef struct Infiniband Infiniband;
unsigned int _get_infiniband(uint64_t *results, int *sources)
{
if (sources == NULL) {
return 0;
}
char buffer[128];
unsigned int _get_network(uint64_t *results, int *sources);
for (int i = 0; i < NB_SENSOR; i++) {
if (pread(sources[i], buffer, 127, 0) < 0) {
perror("pread");
exit(1);
}
results[i] = strtoull(buffer, NULL, 10);
}
return NB_SENSOR;
}
unsigned int init_infiniband(char *infi_path, void **ptr)
{
......@@ -50,6 +69,7 @@ unsigned int init_infiniband(char *infi_path, void **ptr)
glob("/sys/class/infiniband/*/ports/*/counters/", 0, NULL, &res);
if (res.gl_pathc == 0) {
fprintf(stderr, "No infiniband found.\n");
return 0;
}
......@@ -62,7 +82,7 @@ unsigned int init_infiniband(char *infi_path, void **ptr)
"%s/port_xmit_data"
};
Network *state = malloc(sizeof(Network));
Infiniband *state = malloc(sizeof(Infiniband));
char buffer[1024];
for (int i = 0; i < NB_SENSOR; i++) {
......@@ -71,11 +91,39 @@ unsigned int init_infiniband(char *infi_path, void **ptr)
}
*ptr = (void *) state;
_get_network(state->values, state->sources);
_get_infiniband(state->values, state->sources);
return NB_SENSOR;
}
unsigned int get_infiniband(uint64_t *results, void *ptr)
{
Infiniband *state = (Infiniband *) ptr;
_get_infiniband(state->tmp_values, state->sources);
for (int i = 0; i < NB_SENSOR; i++) {
results[i] = modulo_substraction(state->tmp_values[i], state->values[i]);
}
memcpy(state->values, state->tmp_values, NB_SENSOR * sizeof(uint64_t));
return NB_SENSOR;
}
void clean_infiniband(void *ptr)
{
Infiniband *state = (Infiniband *) ptr;
if (state == NULL) {
return;
}
for (int i = 0; i < NB_SENSOR; i++) {
close(state->sources[i]);
}
free(state);
}
char *_labels_infiniband[NB_SENSOR] = {"irxp", "irxb", "itxp", "itxb"};
void label_infiniband(char **labels, void *none)
{
......
......@@ -19,12 +19,14 @@
*******************************************************/
unsigned int init_infiniband(char *infi_path, void **ptr);
unsigned int get_infiniband(uint64_t *results, void *ptr);
void clean_infiniband(void *ptr);
void label_infiniband(char **labels, void *);
Sensor infiniband = {
.init = init_infiniband,
.get = NULL,
.clean = NULL,
.get = get_infiniband,
.clean = clean_infiniband,
.label = label_infiniband,
.nb_opt = 1,
};
......
......@@ -23,6 +23,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "util.h"
......@@ -218,7 +219,7 @@ int main(int argc, char **argv)
usage(argv);
}
if (argc == 2 && argv[1][0] == '-' && argv[1][1] == '1' && argv[1][2] == '\0') {
if (argc == 2 && strcmp(argv[1], "--dump-opts") == 0) {
dumpopts(opts, NB_OPT, NB_SENSOR_OPT);
exit(EXIT_SUCCESS);
}
......
......@@ -8,8 +8,24 @@ try() { "$@" || die "cannot $*"; }
yell() { echo "$0: $*" >&2; }
echo() { printf '%s\n' "$*"; }
usage=$(./bin/mojitos)
[ -n "$usage" ] || die 'empty usage. try to recompile mojitos.'
try ./configure.sh --all
try make mojitos
usage=$(
./bin/mojitos |
awk '
/^SENSORS/ {
$0 = ""
printf "```\n"
printf "\n"
printf "The following is an exhaustive list of all the sensors (it is very likely\n"
printf "that one will not have all the sensors activated in his build):\n"
printf "```bash\n"
printf "SENSORS:"
}
{ print }
'
)
[ -n "$usage" ] || die 'empty usage. cannot continue.'
try awk -v "usage=$usage" '
/^Usage/ {
......@@ -17,7 +33,11 @@ try awk -v "usage=$usage" '
del = 1
}
{
if (del == 1) {
if (del == 1 || del == 2) {
if (match($0, "^```")) {
del++
}
} else if (del == 3) {
if (match($0, "^```")) {
del = 0
print $0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment