From 27b4914943dd51aca0600f20b77659bb7532d86e Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Mon, 13 Feb 2023 16:40:07 +0100
Subject: [PATCH 01/16] the README.md file now present all sensors

- add `--all` option to configure.sh
- makefile: readme is no longer a "all" dependency
- plus some minor changes
---
 README.md                    |  9 +++++++++
 configure.sh                 | 14 +++++++++++---
 makefile                     |  6 +++---
 tools/update-readme-usage.sh | 26 +++++++++++++++++++++++---
 4 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 10f5aaf..ac5b2d3 100644
--- a/README.md
+++ b/README.md
@@ -21,13 +21,22 @@ 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>
diff --git a/configure.sh b/configure.sh
index 62f297a..6b48fb5 100755
--- a/configure.sh
+++ b/configure.sh
@@ -23,18 +23,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 <sensor>] [-i <sensor>] [-u <sensor>]\n' "$(basename "$0")" >&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
 }
 
@@ -131,8 +132,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)
diff --git a/makefile b/makefile
index 950028c..07c8061 100644
--- a/makefile
+++ b/makefile
@@ -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,6 +70,6 @@ readme: $(BIN)
 man: $(BIN)
 	awk -v "usage=$$($(BIN_DIR)/$(BIN) -1)" \
 		'/^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
diff --git a/tools/update-readme-usage.sh b/tools/update-readme-usage.sh
index b9f16de..c9e0797 100755
--- a/tools/update-readme-usage.sh
+++ b/tools/update-readme-usage.sh
@@ -5,8 +5,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/ {
@@ -14,7 +30,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
-- 
GitLab


From 9544a1e31849f953c498ebaa861d27a004628c90 Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Mon, 13 Feb 2023 18:02:56 +0100
Subject: [PATCH 02/16] the option to dump all options is now a long option

---
 makefile      | 2 +-
 src/mojitos.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/makefile b/makefile
index 07c8061..cd9be75 100644
--- a/makefile
+++ b/makefile
@@ -68,7 +68,7 @@ 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/$(BIN).pre.1 > doc/$(BIN).1 2>/dev/null
 
diff --git a/src/mojitos.c b/src/mojitos.c
index 3ecf111..343ec21 100644
--- a/src/mojitos.c
+++ b/src/mojitos.c
@@ -24,6 +24,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <unistd.h>
 #include "util.h"
@@ -219,7 +220,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);
     }
-- 
GitLab


From 4691e8d7633fe2a17c7c82e9ec5655e80da58b82 Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Mon, 13 Feb 2023 16:40:07 +0100
Subject: [PATCH 03/16] the README.md file now present all sensors

- add `--all` option to configure.sh
- makefile: readme is no longer a "all" dependency
- plus some minor changes
---
 README.md                    |  9 +++++++++
 configure.sh                 | 14 +++++++++++---
 makefile                     |  6 +++---
 tools/update-readme-usage.sh | 26 +++++++++++++++++++++++---
 4 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 95b6d7e..869c358 100644
--- a/README.md
+++ b/README.md
@@ -21,13 +21,22 @@ 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>
diff --git a/configure.sh b/configure.sh
index 196aaf8..3f82c3b 100755
--- a/configure.sh
+++ b/configure.sh
@@ -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 <sensor>] [-i <sensor>] [-u <sensor>]\n' "$(basename "$0")" >&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
 }
 
@@ -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)
diff --git a/makefile b/makefile
index 646a015..9d24542 100644
--- a/makefile
+++ b/makefile
@@ -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:
@@ -72,6 +72,6 @@ readme: $(BIN)
 man: $(BIN)
 	awk -v "usage=$$($(BIN_DIR)/$(BIN) -1)" \
 		'/^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
diff --git a/tools/update-readme-usage.sh b/tools/update-readme-usage.sh
index ad2f88f..2c1950e 100755
--- a/tools/update-readme-usage.sh
+++ b/tools/update-readme-usage.sh
@@ -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
-- 
GitLab


From 83536ab019b525c21714b1650c5bc255efa454ca Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Mon, 13 Feb 2023 18:02:56 +0100
Subject: [PATCH 04/16] the option to dump all options is now a long option

---
 makefile      | 2 +-
 src/mojitos.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/makefile b/makefile
index 9d24542..a197961 100644
--- a/makefile
+++ b/makefile
@@ -70,7 +70,7 @@ 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/$(BIN).pre.1 > doc/$(BIN).1 2>/dev/null
 
diff --git a/src/mojitos.c b/src/mojitos.c
index 4274b6a..e8cb6fa 100644
--- a/src/mojitos.c
+++ b/src/mojitos.c
@@ -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);
     }
-- 
GitLab


From 5d36e20bd88712be509e2271c842411fc647f251 Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Wed, 15 Feb 2023 19:08:53 +0100
Subject: [PATCH 05/16] remove bc(1) dependency in configure.sh

---
 configure.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.sh b/configure.sh
index 3f82c3b..4f6375b 100755
--- a/configure.sh
+++ b/configure.sh
@@ -63,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
-- 
GitLab


From af9d66eb766053d851018c3cad6e95ea29f680e0 Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Tue, 7 Feb 2023 14:08:42 +0000
Subject: [PATCH 06/16] fix: make tests

---
 tests/info_reader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/info_reader.c b/tests/info_reader.c
index 19d9c0a..5000f48 100644
--- a/tests/info_reader.c
+++ b/tests/info_reader.c
@@ -19,7 +19,7 @@
 *******************************************************/
 
 #include "small_test.h"
-#include "./../src/info_reader.h"
+#include "./../lib/info_reader.h"
 
 TFUNCTION(test_replace_first, {
     // useful variables :
-- 
GitLab


From a985ebc78334dec2a3b32e5882d2effa8353598f Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 13:26:09 +0000
Subject: [PATCH 07/16] update Copyright date

---
 configure.sh                 |  3 +++
 doc/sensor_ex.c              | 20 ++++++++++++++++++++
 doc/sensor_ex.h              | 20 ++++++++++++++++++++
 src/counters.c               |  2 +-
 src/counters.h               |  2 +-
 src/counters_option.sh       |  2 +-
 src/infiniband.c             |  2 +-
 src/infiniband.h             |  2 +-
 src/load.c                   |  2 +-
 src/load.h                   |  2 +-
 src/mojitos.c                |  3 +--
 src/network.c                |  2 +-
 src/network.h                |  2 +-
 src/temperature.c            |  2 +-
 src/temperature.h            |  2 +-
 src/util.h                   |  2 +-
 tools/update-readme-usage.sh |  3 +++
 17 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/configure.sh b/configure.sh
index 6b48fb5..3f82c3b 100755
--- a/configure.sh
+++ b/configure.sh
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Copyright (C) 2023-2023 Georges Da Costa <georges.da-costa@irit.fr>
+
 try() { "$@" || die "cannot $*"; }
 die() { yell "$*"; exit 111; }
 yell() { echo "$0: $*" >&2; }
diff --git a/doc/sensor_ex.c b/doc/sensor_ex.c
index 6b10076..d37cbeb 100644
--- a/doc/sensor_ex.c
+++ b/doc/sensor_ex.c
@@ -1,3 +1,23 @@
+/*******************************************************
+ Copyright (C) 2018-2023 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/>.
+
+ *******************************************************/
+
 /*
  * compilation:
  *
diff --git a/doc/sensor_ex.h b/doc/sensor_ex.h
index a040558..9fd95d3 100644
--- a/doc/sensor_ex.h
+++ b/doc/sensor_ex.h
@@ -1,3 +1,23 @@
+/*******************************************************
+ Copyright (C) 2018-2023 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/>.
+
+ *******************************************************/
+
 /*
  * Example of a basic sensor: an accumulator
 **/
diff --git a/src/counters.c b/src/counters.c
index d42ceae..1a7027e 100644
--- a/src/counters.c
+++ b/src/counters.c
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/counters.h b/src/counters.h
index 0304a07..4374cd1 100644
--- a/src/counters.h
+++ b/src/counters.h
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/counters_option.sh b/src/counters_option.sh
index 7c99eba..38cee08 100644
--- a/src/counters_option.sh
+++ b/src/counters_option.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 # SPDX-License-Identifier: GPL-3.0-or-later
-# Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
+# Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
 linux_include=/usr/include/linux/perf_event.h
 
diff --git a/src/infiniband.c b/src/infiniband.c
index 303795e..2314e1d 100644
--- a/src/infiniband.c
+++ b/src/infiniband.c
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/infiniband.h b/src/infiniband.h
index fac05f8..e30d78b 100644
--- a/src/infiniband.h
+++ b/src/infiniband.h
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/load.c b/src/load.c
index 1c049ce..64502e5 100644
--- a/src/load.c
+++ b/src/load.c
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2019-2021 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2019-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/load.h b/src/load.h
index 038b263..6d8d298 100644
--- a/src/load.h
+++ b/src/load.h
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/mojitos.c b/src/mojitos.c
index 343ec21..e8cb6fa 100644
--- a/src/mojitos.c
+++ b/src/mojitos.c
@@ -1,6 +1,5 @@
 /*******************************************************
-
- Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/network.c b/src/network.c
index 543a053..74d8bb9 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/network.h b/src/network.h
index 994651a..a158dbb 100644
--- a/src/network.h
+++ b/src/network.h
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2019 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/temperature.c b/src/temperature.c
index acc0702..bcddb22 100644
--- a/src/temperature.c
+++ b/src/temperature.c
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/temperature.h b/src/temperature.h
index 8609dba..e70554d 100644
--- a/src/temperature.h
+++ b/src/temperature.h
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2018-2021 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/src/util.h b/src/util.h
index 23978c1..e422d07 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,5 +1,5 @@
 /*******************************************************
- Copyright (C) 2022-2023 Georges Da Costa <georges.da-costa@irit.fr>
+ Copyright (C) 2023-2023 Georges Da Costa <georges.da-costa@irit.fr>
 
     This file is part of Mojitos.
 
diff --git a/tools/update-readme-usage.sh b/tools/update-readme-usage.sh
index c9e0797..2c1950e 100755
--- a/tools/update-readme-usage.sh
+++ b/tools/update-readme-usage.sh
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Copyright (C) 2023-2023 Georges Da Costa <georges.da-costa@irit.fr>
+
 die() { yell "$*"; exit 111; }
 try() { "$@" || die "cannot $*"; }
 yell() { echo "$0: $*" >&2; }
-- 
GitLab


From c24d82e19ac6b9587c00434ebcfffa188d6d61cd Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 13:42:53 +0000
Subject: [PATCH 08/16] update option

---
 README.md      | 2 +-
 src/amd_rapl.h | 2 +-
 src/rapl.h     | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index ac5b2d3..954e7e0 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ SENSORS:
 	system load
 -d|--net-dev <net_dev>
 	network monitoring (if network_device is X, tries to detect it automatically)
--r|--rapl
+-r|--intel-rapl
 	RAPL
 -c|--cpu-temp
 	processor temperature
diff --git a/src/amd_rapl.h b/src/amd_rapl.h
index 1a16db8..e58cc16 100644
--- a/src/amd_rapl.h
+++ b/src/amd_rapl.h
@@ -34,7 +34,7 @@ Sensor amd_rapl = {
 Optparse amd_rapl_opt[1] = {
     {
         .longname = "amd-rapl",
-        .shortname = 'a',
+        .shortname = 'r',
         .argtype = OPTPARSE_NONE,
         .usage_arg = NULL,
         .usage_msg = "AMD RAPL",
diff --git a/src/rapl.h b/src/rapl.h
index a02624d..7720f07 100644
--- a/src/rapl.h
+++ b/src/rapl.h
@@ -33,11 +33,11 @@ Sensor rapl = {
 
 Optparse rapl_opt[1] = {
     {
-        .longname = "rapl",
+        .longname = "intel-rapl",
         .shortname = 'r',
         .argtype = OPTPARSE_NONE,
         .usage_arg = NULL,
-        .usage_msg = "RAPL",
+        .usage_msg = "INTEL RAPL",
     },
 };
 
-- 
GitLab


From e3c98657d45ec85eaa22ba237c17f60410f43542 Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 14:19:14 +0000
Subject: [PATCH 09/16] standardise the names of structures

---
 README.md              |  2 +-
 doc/info_reader_ex.c   |  2 +-
 doc/sensor_ex.c        |  9 ++++----
 src/amd_rapl.c         | 52 +++++++++++++++++++++---------------------
 src/counters.c         | 22 +++++++++---------
 src/counters_option.sh |  6 ++---
 src/infiniband.c       |  6 +++--
 src/network.c          |  9 ++++----
 src/rapl.c             | 16 ++++++-------
 src/temperature.c      | 13 ++++++-----
 tests/amd_rapl.c       | 26 ++++++++++-----------
 11 files changed, 84 insertions(+), 79 deletions(-)

diff --git a/README.md b/README.md
index 954e7e0..869c358 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ SENSORS:
 -d|--net-dev <net_dev>
 	network monitoring (if network_device is X, tries to detect it automatically)
 -r|--intel-rapl
-	RAPL
+	INTEL RAPL
 -c|--cpu-temp
 	processor temperature
 ```
diff --git a/doc/info_reader_ex.c b/doc/info_reader_ex.c
index 2e76251..f1e6d96 100644
--- a/doc/info_reader_ex.c
+++ b/doc/info_reader_ex.c
@@ -20,7 +20,7 @@
 
 
 // ~/mojitos/doc/$ gcc -Wall -Wextra -Wpedantic -O3 -o info_reader_ex info_reader_ex.c ./../src/util.c && ./info_reader_ex
-#include "./../src/info_reader.h"
+#include "./../lib/info_reader.h"
 
 #define MAX_PROCS 64
 
diff --git a/doc/sensor_ex.c b/doc/sensor_ex.c
index d37cbeb..5fc8eeb 100644
--- a/doc/sensor_ex.c
+++ b/doc/sensor_ex.c
@@ -60,9 +60,10 @@ gcc -std=gnu99 -Wall -Wpedantic -I./lib -I./doc -I./src -g -Og obj/util.o obj/mo
 
 #define NB_SENSOR 3
 
-struct accumulator_t {
+struct Accumulator {
     int v[NB_SENSOR];
 };
+typedef struct Accumulator Accumulator;
 
 void _get_acc(int v[NB_SENSOR])
 {
@@ -77,7 +78,7 @@ unsigned int init_acc(char *none, void **ptr)
     /* there is none in this case, so this parameter is not used */
     UNUSED(none);
 
-    struct accumulator_t *state = malloc(sizeof(struct accumulator_t));
+    Accumulator *state = malloc(sizeof(Accumulator));
 
     for (int i = 0; i < NB_SENSOR; i++) {
         state->v[i] = -1;
@@ -91,7 +92,7 @@ unsigned int init_acc(char *none, void **ptr)
 
 unsigned int get_acc(uint64_t *results, void *ptr)
 {
-    struct accumulator_t *state = (struct accumulator_t *)ptr;
+    Accumulator *state = (Accumulator *)ptr;
 
     _get_acc(state->v);
 
@@ -113,7 +114,7 @@ void label_acc(char **labels, void *none)
 
 void clean_acc(void *ptr)
 {
-    struct accumulator_t *state = (struct accumulator_t *)ptr;
+    Accumulator *state = (Accumulator *)ptr;
 
     if (state == NULL) {
         return;
diff --git a/src/amd_rapl.c b/src/amd_rapl.c
index 805e698..34ccb47 100644
--- a/src/amd_rapl.c
+++ b/src/amd_rapl.c
@@ -41,7 +41,7 @@ static const uint64_t energy_core_msr = 0xC001029A;
 // ------------------------------FILE_PATHS
 static const char *base_str = "/dev/cpu/%d/msr";
 
-struct cpu_sensor_t {
+struct CpuSensor {
     unsigned int cpu_id;
     unsigned int package_id;
     unsigned int core_id;
@@ -52,13 +52,13 @@ struct cpu_sensor_t {
     unsigned int energy_units;
     uint64_t core_energy;
 };
-typedef struct cpu_sensor_t cpu_sensor_t;
+typedef struct CpuSensor CpuSensor;
 
-struct _amd_rapl_t {
-    cpu_sensor_t *sensors;
+struct AmdRapl {
+    CpuSensor *sensors;
     unsigned int sensor_count;
 };
-typedef struct _amd_rapl_t _amd_rapl_t;
+typedef struct AmdRapl AmdRapl;
 
 // -----------------------------INFO_READER
 
@@ -75,19 +75,19 @@ static GenericPointer uint_allocator(char *s)
 
 static void _set_cpu_id(GenericPointer storage, GenericPointer data)
 {
-    cpu_sensor_t *cpu = (cpu_sensor_t *) storage;
+    CpuSensor *cpu = (CpuSensor *) storage;
     cpu->cpu_id = (unsigned int) data;
 }
 
 static void _set_package_id(GenericPointer storage, GenericPointer data)
 {
-    cpu_sensor_t *cpu = (cpu_sensor_t *) storage;
+    CpuSensor *cpu = (CpuSensor *) storage;
     cpu->package_id = (unsigned int) data;
 }
 
 static void _set_core_id(GenericPointer storage, GenericPointer data)
 {
-    cpu_sensor_t *cpu = (cpu_sensor_t *) storage;
+    CpuSensor *cpu = (CpuSensor *) storage;
     cpu->core_id = (unsigned int) data;
 }
 
@@ -98,13 +98,13 @@ static KeyFinder keys[NB_KEYS] = {
 };
 
 
-static unsigned int parse_cpuinfo(cpu_sensor_t *storage, unsigned int capacity)
+static unsigned int parse_cpuinfo(CpuSensor *storage, unsigned int capacity)
 {
     Parser parser = {
         .storage = (GenericPointer) storage,
         .nb_stored = 0,
         .capacity = capacity,
-        .storage_struct_size = sizeof(cpu_sensor_t),
+        .storage_struct_size = sizeof(CpuSensor),
         .keys = keys,
         .nb_keys = NB_KEYS,
         .file = fopen(cpuinfo, "r")
@@ -171,9 +171,9 @@ uint64_t raw_to_joule(uint64_t raw, uint64_t unit)
 // -----------------------------------DEBUG
 
 #ifdef DEBUG
-void debug_print_sensor(cpu_sensor_t *sensor)
+void debug_print_sensor(CpuSensor *sensor)
 {
-    //CASSERT(sizeof(cpu_sensor_t) == 56, amd_rapl_c);
+    //CASSERT(sizeof(CpuSensor) == 56, amd_rapl_c);
     printf("cpu_id : %d, package_id : %d, core_id : %d, name : %s, fd: %d,  energy_units : %d, core_energy: %ld\n",
            sensor->cpu_id,
            sensor->package_id,
@@ -185,7 +185,7 @@ void debug_print_sensor(cpu_sensor_t *sensor)
           );
 }
 
-void debug_print_amd_rapl(_amd_rapl_t *rapl)
+void debug_print_amd_rapl(AmdRapl *rapl)
 {
     for (unsigned int i = 0; i < rapl->sensor_count; i++) {
         debug_print_sensor(&rapl->sensors[i]);
@@ -213,7 +213,7 @@ unsigned int get_nb_cpu()
     return n_cpu;
 }
 
-void get_arch(unsigned int *ret_nb_package, unsigned int *ret_nb_core, cpu_sensor_t *sensors, unsigned int nb_sensor)
+void get_arch(unsigned int *ret_nb_package, unsigned int *ret_nb_core, CpuSensor *sensors, unsigned int nb_sensor)
 {
     unsigned int nb_package = 0;
     unsigned int nb_core = 0;
@@ -238,7 +238,7 @@ char *get_name(unsigned int cpu_id)
     return name;
 }
 
-void update_cpu_sensor(cpu_sensor_t *sensor, uint64_t *energy_consumed)
+void update_cpu_sensor(CpuSensor *sensor, uint64_t *energy_consumed)
 {
     sensor->energy_units = read_unit(sensor->fd);
     uint64_t raw_core_energy = read_raw_core_energy(sensor->fd);
@@ -248,7 +248,7 @@ void update_cpu_sensor(cpu_sensor_t *sensor, uint64_t *energy_consumed)
     sensor->core_energy = core_energy;
 }
 
-unsigned int is_duplicate(cpu_sensor_t *sensor,unsigned int nb_core, unsigned int nb_package, unsigned char map[nb_core][nb_package])
+unsigned int is_duplicate(CpuSensor *sensor,unsigned int nb_core, unsigned int nb_package, unsigned char map[nb_core][nb_package])
 {
     if (map[sensor->core_id][sensor->package_id] == 1) {
         return 0;
@@ -257,7 +257,7 @@ unsigned int is_duplicate(cpu_sensor_t *sensor,unsigned int nb_core, unsigned in
     return 1;
 }
 
-void init_cpu_sensor(cpu_sensor_t *sensor, cpu_sensor_t *cpu_info)
+void init_cpu_sensor(CpuSensor *sensor, CpuSensor *cpu_info)
 {
     static char filename[BUFFER_SIZE];
     snprintf(filename,BUFFER_SIZE, base_str, cpu_info->cpu_id);
@@ -269,18 +269,18 @@ void init_cpu_sensor(cpu_sensor_t *sensor, cpu_sensor_t *cpu_info)
         exit(127);
     }
 
-    memcpy(sensor, cpu_info, sizeof(cpu_sensor_t));
+    memcpy(sensor, cpu_info, sizeof(CpuSensor));
     sensor->name = get_name(sensor->cpu_id);
     sensor->fd = fd;
 }
 
-void clean_cpu_sensor(cpu_sensor_t *sensor)
+void clean_cpu_sensor(CpuSensor *sensor)
 {
     close(sensor->fd);
     free(sensor->name);
 }
 
-void free_amd_rapl(_amd_rapl_t *rapl)
+void free_amd_rapl(AmdRapl *rapl)
 {
     free(rapl->sensors);
     free(rapl);
@@ -299,7 +299,7 @@ unsigned int init_amd_rapl(char *none, void **ptr)
         exit(127);
     }
 
-    cpu_sensor_t *cpu_information = (cpu_sensor_t *) calloc(max_cpus, sizeof(cpu_sensor_t));
+    CpuSensor *cpu_information = (CpuSensor *) calloc(max_cpus, sizeof(CpuSensor));
     if (parse_cpuinfo(cpu_information, max_cpus)) {
         free(cpu_information);
         PANIC(1, "cpuinfo");
@@ -311,7 +311,7 @@ unsigned int init_amd_rapl(char *none, void **ptr)
 
     unsigned char cpu_map[nb_core][nb_package];
     memset(cpu_map, 0, sizeof(cpu_map));
-    cpu_sensor_t *sensors = (cpu_sensor_t *) calloc(max_cpus, sizeof(cpu_sensor_t));
+    CpuSensor *sensors = (CpuSensor *) calloc(max_cpus, sizeof(CpuSensor));
 
     unsigned int sensor_count = 0;
     for (unsigned int i = 0; i < max_cpus; i++) {
@@ -322,7 +322,7 @@ unsigned int init_amd_rapl(char *none, void **ptr)
     }
     free(cpu_information);
 
-    _amd_rapl_t *rapl = (_amd_rapl_t *) calloc(1, sizeof(_amd_rapl_t));
+    AmdRapl *rapl = (AmdRapl *) calloc(1, sizeof(AmdRapl));
     rapl->sensors = sensors;
     rapl->sensor_count = sensor_count;
     *ptr = (void *) rapl;
@@ -332,7 +332,7 @@ unsigned int init_amd_rapl(char *none, void **ptr)
 
 unsigned int get_amd_rapl(uint64_t *results, void *ptr)
 {
-    _amd_rapl_t *rapl = (_amd_rapl_t *) ptr;
+    AmdRapl *rapl = (AmdRapl *) ptr;
     for (unsigned int i = 0; i < rapl->sensor_count; i++) {
         update_cpu_sensor(&rapl->sensors[i], &results[i]);
     }
@@ -341,7 +341,7 @@ unsigned int get_amd_rapl(uint64_t *results, void *ptr)
 
 void label_amd_rapl(char **labels, void *ptr)
 {
-    _amd_rapl_t *rapl = (_amd_rapl_t *) ptr;
+    AmdRapl *rapl = (AmdRapl *) ptr;
     for (unsigned int i = 0; i < rapl->sensor_count; i++) {
         labels[i] = rapl->sensors[i].name;
     }
@@ -349,7 +349,7 @@ void label_amd_rapl(char **labels, void *ptr)
 
 void clean_amd_rapl(void *ptr)
 {
-    _amd_rapl_t *rapl = (_amd_rapl_t *) ptr;
+    AmdRapl *rapl = (AmdRapl *) ptr;
 
     for (unsigned int i = 0; i < rapl->sensor_count; ++i) {
         clean_cpu_sensor(&rapl->sensors[i]);
diff --git a/src/counters.c b/src/counters.c
index 1a7027e..e809f88 100644
--- a/src/counters.c
+++ b/src/counters.c
@@ -30,7 +30,7 @@
 #include "util.h"
 
 
-struct _counter_t {
+struct Counter {
     int nbcores;
     int nbperf;
     int **counters;
@@ -40,7 +40,7 @@ struct _counter_t {
     int *perf_indexes;
 
 };
-typedef struct _counter_t *counter_t;
+typedef struct Counter Counter;
 
 #include "counters_option.h"
 
@@ -105,7 +105,7 @@ static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
     return res;
 }
 
-counter_t _init_counters(const int nb_perf, const __u32 *types, const __u64 *names)
+Counter *_init_counters(const int nb_perf, const __u32 *types, const __u64 *names)
 {
     struct perf_event_attr pe;
     unsigned int nbcores = sysconf(_SC_NPROCESSORS_ONLN);
@@ -113,7 +113,7 @@ counter_t _init_counters(const int nb_perf, const __u32 *types, const __u64 *nam
     pe.size = sizeof(struct perf_event_attr);
     pe.disabled = 1;
 
-    counter_t counters = malloc(sizeof(struct _counter_t));
+    Counter *counters = malloc(sizeof(struct Counter));
     counters->nbperf = nb_perf;
     counters->nbcores = nbcores;
     counters->counters = malloc(nb_perf * sizeof(int *));
@@ -133,7 +133,7 @@ counter_t _init_counters(const int nb_perf, const __u32 *types, const __u64 *nam
 
 void clean_counters(void *ptr)
 {
-    counter_t counters = (counter_t) ptr;
+    Counter *counters = (Counter *) ptr;
 
     for (int counter = 0; counter < counters->nbperf; counter++) {
         for (int core = 0; core < counters->nbcores; core++) {
@@ -151,7 +151,7 @@ void clean_counters(void *ptr)
     free(counters);
 }
 
-void start_counters(counter_t counters)
+void start_counters(Counter *counters)
 {
     for (int counter = 0; counter < counters->nbperf; counter++) {
         for (int core = 0; core < counters->nbcores; core++) {
@@ -160,7 +160,7 @@ void start_counters(counter_t counters)
     }
 }
 
-void reset_counters(counter_t counters)
+void reset_counters(Counter *counters)
 {
     for (int counter = 0; counter < counters->nbperf; counter++) {
         for (int core = 0; core < counters->nbcores; core++) {
@@ -169,7 +169,7 @@ void reset_counters(counter_t counters)
     }
 }
 
-void _get_counters(counter_t counters, uint64_t *values)
+void _get_counters(Counter *counters, uint64_t *values)
 {
     for (int i = 0; i < counters->nbperf; i++) {
         uint64_t accu = 0;
@@ -202,7 +202,7 @@ unsigned int init_counters(char *args, void **state)
     __u32 *perf_type;
     __u64 *perf_key;
     perf_type_key(&perf_type, &perf_key, perf_indexes, nb_perf);
-    counter_t fd = _init_counters(nb_perf, perf_type, perf_key);
+    Counter *fd = _init_counters(nb_perf, perf_type, perf_key);
     free(perf_type);
     free(perf_key);
 
@@ -218,7 +218,7 @@ unsigned int init_counters(char *args, void **state)
 
 unsigned int get_counters(uint64_t *results, void *ptr)
 {
-    counter_t state = (counter_t) ptr;
+    Counter *state = (Counter *) ptr;
 
     _get_counters(state, state->tmp_counters_values);
 
@@ -232,7 +232,7 @@ unsigned int get_counters(uint64_t *results, void *ptr)
 
 void label_counters(char **labels, void *ptr)
 {
-    counter_t state = (counter_t) ptr;
+    Counter *state = (Counter *) ptr;
 
     for (int i = 0; i < state->nbperf; i++) {
         labels[i] = perf_static_info[state->perf_indexes[i]].name;
diff --git a/src/counters_option.sh b/src/counters_option.sh
index 38cee08..76f9275 100644
--- a/src/counters_option.sh
+++ b/src/counters_option.sh
@@ -6,13 +6,13 @@
 linux_include=/usr/include/linux/perf_event.h
 
 echo '
-typedef struct counter_option {
+typedef struct CounterOption{
     char *name;
     __u32 perf_type;
     __u64 perf_key;
-} counter_option;
+} CounterOption;
 
-static counter_option perf_static_info[] = {'
+static CounterOption perf_static_info[] = {'
 
 nb=0
 
diff --git a/src/infiniband.c b/src/infiniband.c
index 2314e1d..bbc0fee 100644
--- a/src/infiniband.c
+++ b/src/infiniband.c
@@ -27,11 +27,13 @@
 
 #define NB_SENSOR 4
 
-struct network_t {
+struct Network {
     uint64_t values[NB_SENSOR];
     uint64_t tmp_values[NB_SENSOR];
     int sources[NB_SENSOR];
 };
+typedef struct Network Network;
+
 unsigned int _get_network(uint64_t *results, int *sources);
 
 
@@ -60,7 +62,7 @@ unsigned int init_infiniband(char *infi_path, void **ptr)
                          "%s/port_xmit_data"
                         };
 
-    struct network_t *state = malloc(sizeof(struct network_t));
+    Network *state = malloc(sizeof(Network));
 
     char buffer[1024];
     for (int i = 0; i < NB_SENSOR; i++) {
diff --git a/src/network.c b/src/network.c
index 74d8bb9..d361d47 100644
--- a/src/network.c
+++ b/src/network.c
@@ -28,11 +28,12 @@
 #define NB_SENSOR 4
 
 static char *route = "/proc/net/route";
-struct network_t {
+struct Network {
     uint64_t values[NB_SENSOR];
     uint64_t tmp_values[NB_SENSOR];
     int sources[NB_SENSOR];
 };
+typedef struct Network Network;
 
 unsigned int _get_network(uint64_t *results, int *sources)
 {
@@ -92,7 +93,7 @@ unsigned int init_network(char *dev, void **ptr)
                          "/sys/class/net/%s/statistics/tx_bytes"
                         };
 
-    struct network_t *state = malloc(sizeof(struct network_t));
+    Network *state = malloc(sizeof(Network));
 
     char buffer2[256];
     for (int i = 0; i < NB_SENSOR; i++) {
@@ -108,7 +109,7 @@ unsigned int init_network(char *dev, void **ptr)
 
 unsigned int get_network(uint64_t *results, void *ptr)
 {
-    struct network_t *state = (struct network_t *) ptr;
+    Network *state = (Network *) ptr;
     _get_network(state->tmp_values, state->sources);
 
     for (int i = 0; i < NB_SENSOR; i++) {
@@ -121,7 +122,7 @@ unsigned int get_network(uint64_t *results, void *ptr)
 
 void clean_network(void *ptr)
 {
-    struct network_t *state = (struct network_t *) ptr;
+    Network *state = (Network *) ptr;
 
     if (state == NULL) {
         return;
diff --git a/src/rapl.c b/src/rapl.c
index 8a04d31..5d7eca7 100644
--- a/src/rapl.c
+++ b/src/rapl.c
@@ -52,7 +52,7 @@ void test_append(char *name, int i)
 }
 
 
-struct _rapl_t {
+struct IntelRapl {
     unsigned int nb;
     char **names;
     int *fids;
@@ -60,10 +60,10 @@ struct _rapl_t {
     uint64_t *tmp_values;
 
 };
-typedef struct _rapl_t _rapl_t;
+typedef struct IntelRapl IntelRapl;
 
 
-void add_rapl_source(_rapl_t *rapl, char *name, char *energy_uj)
+void add_rapl_source(IntelRapl *rapl, char *name, char *energy_uj)
 {
     rapl->nb += 1;
     rapl->names = realloc(rapl->names, sizeof(char **)*rapl->nb);
@@ -85,7 +85,7 @@ void add_rapl_source(_rapl_t *rapl, char *name, char *energy_uj)
 }
 
 
-void _get_rapl(uint64_t *values, _rapl_t *rapl)
+void _get_rapl(uint64_t *values, IntelRapl *rapl)
 {
     static char buffer[512];
 
@@ -104,7 +104,7 @@ void _get_rapl(uint64_t *values, _rapl_t *rapl)
 unsigned int init_rapl(char *none, void **ptr)
 {
     UNUSED(none);
-    _rapl_t *rapl = malloc(sizeof(_rapl_t));
+    IntelRapl *rapl = malloc(sizeof(IntelRapl));
     rapl->nb = 0;
     rapl->names = NULL;
     rapl->fids = NULL;
@@ -161,7 +161,7 @@ unsigned int init_rapl(char *none, void **ptr)
 
 unsigned int get_rapl(uint64_t *results, void *ptr)
 {
-    _rapl_t *state = (_rapl_t *) ptr;
+    IntelRapl *state = (IntelRapl *) ptr;
     _get_rapl(state->tmp_values, state);
 
     for (unsigned int i = 0; i < state->nb; i++) {
@@ -174,7 +174,7 @@ unsigned int get_rapl(uint64_t *results, void *ptr)
 
 void clean_rapl(void *ptr)
 {
-    _rapl_t *rapl = (_rapl_t *) ptr;
+    IntelRapl *rapl = (IntelRapl *) ptr;
 
     for (unsigned int i = 0; i < rapl->nb; i++) {
         free(rapl->names[i]);
@@ -191,7 +191,7 @@ void clean_rapl(void *ptr)
 
 void label_rapl(char **labels, void *ptr)
 {
-    _rapl_t *rapl = (_rapl_t *) ptr;
+    IntelRapl *rapl = (IntelRapl *) ptr;
 
     for (unsigned int i = 0; i < rapl->nb; i++) {
         labels[i] = rapl->names[i];
diff --git a/src/temperature.c b/src/temperature.c
index bcddb22..a9cf74b 100644
--- a/src/temperature.c
+++ b/src/temperature.c
@@ -26,11 +26,12 @@
 #include <stdint.h>
 #include "util.h"
 
-struct temperature_t {
+struct Temperature {
     char **label_list;
     int *fid_list;
     int nb_elem;
 };
+typedef struct Temperature Temperature;
 
 int get_string(char *filename, char *buffer, int max_size)
 {
@@ -61,7 +62,7 @@ void add_to_list(char ***list_name, char *source, int nb_elem)
 
 }
 
-void add_temperature_sensor(int id_rep, struct temperature_t *state)
+void add_temperature_sensor(int id_rep, Temperature *state)
 {
     static int key = 0;
     static char buffer_filename[512];
@@ -109,7 +110,7 @@ void add_temperature_sensor(int id_rep, struct temperature_t *state)
 unsigned int init_temperature(char *args, void **ptr)
 {
     UNUSED(args);
-    struct temperature_t *state = malloc(sizeof(struct temperature_t));
+    Temperature *state = malloc(sizeof(Temperature));
     state->nb_elem = 0;
     state->label_list = NULL;
     state->fid_list = NULL;
@@ -136,7 +137,7 @@ unsigned int init_temperature(char *args, void **ptr)
 
 unsigned int get_temperature(uint64_t *results, void *ptr)
 {
-    struct temperature_t *state = (struct temperature_t *)ptr;
+    Temperature *state = (Temperature *)ptr;
     static char buffer[512];
 
     for (int i = 0; i < state->nb_elem; i++) {
@@ -152,7 +153,7 @@ unsigned int get_temperature(uint64_t *results, void *ptr)
 
 void clean_temperature(void *ptr)
 {
-    struct temperature_t *state = (struct temperature_t *)ptr;
+    Temperature *state = (Temperature *)ptr;
 
     for (int i = 0; i < state->nb_elem; i++) {
         free(state->label_list[i]);
@@ -166,7 +167,7 @@ void clean_temperature(void *ptr)
 
 void label_temperature(char **labels, void *ptr)
 {
-    struct temperature_t *state = (struct temperature_t *)ptr;
+    Temperature *state = (Temperature *)ptr;
 
     for (int i = 0; i < state->nb_elem; i++) {
         labels[i] = state->label_list[i];
diff --git a/tests/amd_rapl.c b/tests/amd_rapl.c
index 0485099..7c05ab5 100644
--- a/tests/amd_rapl.c
+++ b/tests/amd_rapl.c
@@ -107,7 +107,7 @@ TFUNCTION(test_get_name, {
 #define NONE 0
 #define DUMMY_SENSOR(__sensor, __cpu_id, __name) \
 do {                                             \
-  __sensor = (cpu_sensor_t) {                    \
+  __sensor = (CpuSensor) {                    \
     .cpu_id = __cpu_id,                          \
     .package_id = NONE,                          \
     .core_id = NONE,                             \
@@ -120,15 +120,15 @@ do {                                             \
 
 #define DUMMY_RAPL(__rapl, __sensors, __sensors_count) \
 do {                                                   \
-    __rapl = (_amd_rapl_t) {                           \
+    __rapl = (AmdRapl) {                           \
         .sensors = __sensors,                          \
         .sensor_count = __sensors_count                \
     };                                                 \
 } while(0);
 
 TFUNCTION(test_label_amd_rapl, {
-    cpu_sensor_t sensors[100];
-    _amd_rapl_t rapl;
+    CpuSensor sensors[100];
+    AmdRapl rapl;
     char *results[100];
     char expecteds[10][100];
     uint64_t nb = 0;
@@ -190,7 +190,7 @@ TFUNCTION(test_label_amd_rapl, {
 
 #define DUMMY_CPUINFO(__sensor, __cpu_id, __package_id, __core_id) \
 do {                                                               \
-    __sensor = (cpu_sensor_t) {                                    \
+    __sensor = (CpuSensor) {                                    \
         .cpu_id = __cpu_id,                                        \
         .package_id = __package_id,                                \
         .core_id = __core_id,                                      \
@@ -207,13 +207,13 @@ TFUNCTION(test_is_duplicate, {
     static const unsigned int max_cpu = 10;
 
     unsigned char map[nb_core][nb_package];
-    cpu_sensor_t cpu_information[max_cpu];
+    CpuSensor cpu_information[max_cpu];
     unsigned int results[max_cpu];
     unsigned int expecteds[max_cpu];
 
     // -- Setup
     memset(map, NONE, sizeof(map));
-    memset(cpu_information,NONE, sizeof(cpu_sensor_t) * max_cpu);
+    memset(cpu_information,NONE, sizeof(CpuSensor) * max_cpu);
     DUMMY_CPUINFO(cpu_information[0], 0, 1, 1);
     expecteds[0] = 1;
     expecteds[1] = 0;
@@ -226,7 +226,7 @@ TFUNCTION(test_is_duplicate, {
 
     // -- Setup
     memset(map, NONE, sizeof(map));
-    memset(cpu_information,NONE, sizeof(cpu_sensor_t) * max_cpu);
+    memset(cpu_information,NONE, sizeof(CpuSensor) * max_cpu);
     DUMMY_CPUINFO(cpu_information[0], 0, 1, 1);
     DUMMY_CPUINFO(cpu_information[1], 0, 1, 1);
     expecteds[0] = 1;
@@ -240,7 +240,7 @@ TFUNCTION(test_is_duplicate, {
 
     // -- Setup
     memset(map, NONE, sizeof(map));
-    memset(cpu_information,NONE, sizeof(cpu_sensor_t) * max_cpu);
+    memset(cpu_information,NONE, sizeof(CpuSensor) * max_cpu);
     DUMMY_CPUINFO(cpu_information[0], 0, 1, 1);
     DUMMY_CPUINFO(cpu_information[1], 0, 0, 0);
     expecteds[0] = 1;
@@ -254,7 +254,7 @@ TFUNCTION(test_is_duplicate, {
 
     // -- Setup
     memset(map, NONE, sizeof(map));
-    memset(cpu_information,NONE, sizeof(cpu_sensor_t) * max_cpu);
+    memset(cpu_information,NONE, sizeof(CpuSensor) * max_cpu);
     DUMMY_CPUINFO(cpu_information[0], 0, 1, 1);
     DUMMY_CPUINFO(cpu_information[1], 0, 1, 0);
     expecteds[0] = 1;
@@ -268,7 +268,7 @@ TFUNCTION(test_is_duplicate, {
 
     // -- Setup
     memset(map, NONE, sizeof(map));
-    memset(cpu_information,NONE, sizeof(cpu_sensor_t) * max_cpu);
+    memset(cpu_information,NONE, sizeof(CpuSensor) * max_cpu);
     DUMMY_CPUINFO(cpu_information[0], 0, 1, 1);
     DUMMY_CPUINFO(cpu_information[1], 0, 0, 1);
     expecteds[0] = 1;
@@ -282,7 +282,7 @@ TFUNCTION(test_is_duplicate, {
 
     // -- Setup
     memset(map, NONE, sizeof(map));
-    memset(cpu_information,NONE, sizeof(cpu_sensor_t) * max_cpu);
+    memset(cpu_information,NONE, sizeof(CpuSensor) * max_cpu);
     DUMMY_CPUINFO(cpu_information[0], 0, 0, 0);
     DUMMY_CPUINFO(cpu_information[1], 0, 0, 1);
     DUMMY_CPUINFO(cpu_information[2], 0, 1, 0);
@@ -317,7 +317,7 @@ TFILE_ENTRY_POINT(test_amd_rapl, {
 int main()
 {
     static const unsigned int time = 10;
-    _amd_rapl_t *rapl = NULL;
+    AmdRapl *rapl = NULL;
     unsigned int count_cpu = init_amd_rapl(NULL, (void **) &rapl);
     uint64_t results[count_cpu];
     char *labels[count_cpu];
-- 
GitLab


From d5978ba397b79ecc3442e96e10bdb62177b7f868 Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 14:46:28 +0000
Subject: [PATCH 10/16] sprintf -> snprintf

---
 src/amd_rapl.c    |  3 ++-
 src/counters.c    |  2 +-
 src/infiniband.c  |  2 +-
 src/network.c     |  2 +-
 src/rapl.c        | 35 +++++++++++++++--------------------
 src/temperature.c | 22 ++++++++++++----------
 6 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/src/amd_rapl.c b/src/amd_rapl.c
index 34ccb47..1e08517 100644
--- a/src/amd_rapl.c
+++ b/src/amd_rapl.c
@@ -161,6 +161,7 @@ uint64_t raw_to_microjoule(uint64_t raw, unsigned int unit)
     // Joule * 1000000 -> uJoule
     return (uint64_t) (((double) raw * to_microjoule) / (double)(1U << unit));
 }
+
 uint64_t raw_to_joule(uint64_t raw, uint64_t unit)
 {
     // raw * (1 / (unit^2)) -> Joule
@@ -202,7 +203,7 @@ unsigned int get_nb_cpu()
 
     unsigned int n_cpu = 0;
     for (;; n_cpu++) {
-        sprintf(filename, base_str, n_cpu);
+        snprintf(filename, BUFFER_SIZE, base_str, n_cpu);
 
         int fd = open(filename, O_RDONLY);
         if (fd < 0) {
diff --git a/src/counters.c b/src/counters.c
index e809f88..8013ff8 100644
--- a/src/counters.c
+++ b/src/counters.c
@@ -52,7 +52,7 @@ void *show_all_counters(void *none1, size_t none2)
     UNUSED(none1);
     UNUSED(none2);
     exit(EXIT_SUCCESS);
-    return NULL;	/* not reached */
+    return NULL; /* not reached */
 }
 
 void perf_type_key(__u32 **perf_type, __u64 **perf_key, int *indexes, int nb)
diff --git a/src/infiniband.c b/src/infiniband.c
index bbc0fee..aa4a8de 100644
--- a/src/infiniband.c
+++ b/src/infiniband.c
@@ -66,7 +66,7 @@ unsigned int init_infiniband(char *infi_path, void **ptr)
 
     char buffer[1024];
     for (int i = 0; i < NB_SENSOR; i++) {
-        sprintf(buffer, filenames[i], infi_path);
+        snprintf(buffer, 1024, filenames[i], infi_path);
         state->sources[i] = open(buffer, O_RDONLY);
     }
 
diff --git a/src/network.c b/src/network.c
index d361d47..977b92e 100644
--- a/src/network.c
+++ b/src/network.c
@@ -97,7 +97,7 @@ unsigned int init_network(char *dev, void **ptr)
 
     char buffer2[256];
     for (int i = 0; i < NB_SENSOR; i++) {
-        sprintf(buffer2, filenames[i], dev);
+        sprintf(buffer2, 256, filenames[i], dev);
         state->sources[i] = open(buffer2, O_RDONLY);
     }
 
diff --git a/src/rapl.c b/src/rapl.c
index 5d7eca7..eb88553 100644
--- a/src/rapl.c
+++ b/src/rapl.c
@@ -28,6 +28,7 @@
 #include "util.h"
 
 #define MAX_HEADER 128
+#define BUFFER_SIZE 1024
 
 char *get_rapl_string(const char *filename)
 {
@@ -40,15 +41,16 @@ char *get_rapl_string(const char *filename)
     int nb = read(fd, result, MAX_HEADER);
     close(fd);
     result[nb - 1] = 0;
-    return (result);
+    return result;
 }
 
-void test_append(char *name, int i)
+void append(char *name, int i, size_t buffer_size)
 {
-    //char last = name[strlen(name)-1];
-    //if (last>='0' && last <= '9')
-    //  return;
-    sprintf(name + strlen(name), "%d", i);
+    size_t name_len = strlen(name);
+    char* ptr = name + name_len;
+
+    size_t remaining_space = buffer_size - name_len;
+    snprintf(ptr, remaining_space, "%d", i);
 }
 
 
@@ -109,40 +111,33 @@ unsigned int init_rapl(char *none, void **ptr)
     rapl->names = NULL;
     rapl->fids = NULL;
 
-    char buffer[1024];
+    char buffer[BUFFER_SIZE];
     char *name_base = "/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/%s";
     char *name_sub = "/sys/devices/virtual/powercap/intel-rapl/intel-rapl:%d/intel-rapl:%d:%d/%s";
 
     for (unsigned int i = 0;; i++) {
-        sprintf(buffer, name_base, i, "name");
+        snprintf(buffer, BUFFER_SIZE, name_base, i, "name");
         char *tmp = get_rapl_string(buffer);
 
         if (tmp == NULL) {
             break;
         }
 
-        //printf("%s\n", tmp);
-        test_append(tmp, i);
-        //printf("%s -> %s\n", buffer, tmp);
-
-        sprintf(buffer, name_base, i, "energy_uj");
+        append(tmp, i, MAX_HEADER);
+        snprintf(buffer, BUFFER_SIZE, name_base, i, "energy_uj");
         add_rapl_source(rapl, tmp, buffer);
         free(tmp);
 
         for (unsigned int j = 0;; j++) {
-            sprintf(buffer, name_sub, i, i, j, "name");
+            snprintf(buffer, BUFFER_SIZE, name_sub, i, i, j, "name");
             char *tmp_sub = get_rapl_string(buffer);
 
             if (tmp_sub == NULL) {
                 break;
             }
 
-            //printf("%s\n", tmp_sub);
-            test_append(tmp_sub, i);
-            //printf("%s -> %s\n", buffer, tmp_sub);
-
-
-            sprintf(buffer, name_sub, i, i, j, "energy_uj");
+            append(tmp_sub, i, MAX_HEADER);
+            snprintf(buffer, BUFFER_SIZE, name_sub, i, i, j, "energy_uj");
             add_rapl_source(rapl, tmp_sub, buffer);
 
             free(tmp_sub);
diff --git a/src/temperature.c b/src/temperature.c
index a9cf74b..1dc1099 100644
--- a/src/temperature.c
+++ b/src/temperature.c
@@ -26,6 +26,8 @@
 #include <stdint.h>
 #include "util.h"
 
+#define BUFFER_SIZE 512
+
 struct Temperature {
     char **label_list;
     int *fid_list;
@@ -65,13 +67,13 @@ void add_to_list(char ***list_name, char *source, int nb_elem)
 void add_temperature_sensor(int id_rep, Temperature *state)
 {
     static int key = 0;
-    static char buffer_filename[512];
-    static char buffer_label[512];
+    static char buffer_filename[BUFFER_SIZE];
+    static char buffer_label[BUFFER_SIZE];
 
-    int delta = sprintf(buffer_label, "Temp_%d_", key);
+    int delta = snprintf(buffer_label, BUFFER_SIZE, "Temp_%d_", key);
 
     for (int i = 1;; i++) {
-        sprintf(buffer_filename, "/sys/class/hwmon/hwmon%d/temp%d_label", id_rep, i);
+        snprintf(buffer_filename, BUFFER_SIZE, "/sys/class/hwmon/hwmon%d/temp%d_label", id_rep, i);
 
         if (get_string(buffer_filename, buffer_label + delta, 100) == -1) {
             break;
@@ -89,7 +91,7 @@ void add_temperature_sensor(int id_rep, Temperature *state)
 
         add_to_list(&state->label_list, buffer_label, state->nb_elem);
 
-        sprintf(buffer_filename, "/sys/class/hwmon/hwmon%d/temp%d_input", id_rep, i);
+        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));
         int fd = open(buffer_filename, O_RDONLY);
 
@@ -116,11 +118,11 @@ unsigned int init_temperature(char *args, void **ptr)
     state->fid_list = NULL;
 
     char base_name[] = "/sys/class/hwmon/hwmon%d/name";
-    static char name[512];
-    static char buffer[512];
+    static char name[BUFFER_SIZE];
+    static char buffer[BUFFER_SIZE];
 
     int i = 0;
-    sprintf(name, base_name, i);
+    snprintf(name, BUFFER_SIZE, base_name, i);
 
     while (get_string(name, buffer, 8) != -1) {
         if (strcmp(buffer, "coretemp") == 0) {
@@ -128,7 +130,7 @@ unsigned int init_temperature(char *args, void **ptr)
         }
 
         i++;
-        sprintf(name, base_name, i);
+        snprintf(name, BUFFER_SIZE, base_name, i);
     }
 
     *ptr = (void *) state;
@@ -138,7 +140,7 @@ unsigned int init_temperature(char *args, void **ptr)
 unsigned int get_temperature(uint64_t *results, void *ptr)
 {
     Temperature *state = (Temperature *)ptr;
-    static char buffer[512];
+    static char buffer[BUFFER_SIZE];
 
     for (int i = 0; i < state->nb_elem; i++) {
         if (pread(state->fid_list[i], buffer, 100, 0) < 0) {
-- 
GitLab


From 8546c84fb3145e6dbbe80b035aa6afc5ac602b9d Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 15:05:13 +0000
Subject: [PATCH 11/16] format

---
 src/network.c | 2 +-
 src/rapl.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/network.c b/src/network.c
index 977b92e..37d2373 100644
--- a/src/network.c
+++ b/src/network.c
@@ -97,7 +97,7 @@ unsigned int init_network(char *dev, void **ptr)
 
     char buffer2[256];
     for (int i = 0; i < NB_SENSOR; i++) {
-        sprintf(buffer2, 256, filenames[i], dev);
+        snprintf(buffer2, 256, filenames[i], dev);
         state->sources[i] = open(buffer2, O_RDONLY);
     }
 
diff --git a/src/rapl.c b/src/rapl.c
index eb88553..3d13367 100644
--- a/src/rapl.c
+++ b/src/rapl.c
@@ -47,7 +47,7 @@ char *get_rapl_string(const char *filename)
 void append(char *name, int i, size_t buffer_size)
 {
     size_t name_len = strlen(name);
-    char* ptr = name + name_len;
+    char *ptr = name + name_len;
 
     size_t remaining_space = buffer_size - name_len;
     snprintf(ptr, remaining_space, "%d", i);
-- 
GitLab


From 8e57326b26cd88dd37b615c1d19275bb4b1bf3f4 Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 15:06:47 +0000
Subject: [PATCH 12/16] add authors

---
 AUTHORS | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/AUTHORS b/AUTHORS
index 0bfc663..13ddd11 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1 +1,4 @@
-Georges Da Costa georges.da-costa@irit.fr
\ No newline at end of file
+Georges Da Costa georges.da-costa@irit.fr
+Floréal Risso floreal.risso@univ-tlse3.fr
+Alexis Paronnaud alexis.paronnaud@univ-tlse3.fr
+Téo Tinarrage teo.tinarrage@univ-tlse3.fr
-- 
GitLab


From c27d5e1f5677eba93117e50ec76d31bc0d8b7c13 Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ3-tlse.fr>
Date: Mon, 13 Feb 2023 15:11:11 +0000
Subject: [PATCH 13/16] clear doc

---
 makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/makefile b/makefile
index cd9be75..a197961 100644
--- a/makefile
+++ b/makefile
@@ -62,7 +62,9 @@ format:
 clean:
 	\rm -f $(OBJ_DIR)/* $(BIN_DIR)/* \
 		$(SRC_DIR)/counters_option.h \
-		$(TESTS_DIR)/run
+		$(TESTS_DIR)/run \
+		$(DOC_DIR)/test_main_ex \
+		$(DOC_DIR)/info_reader_ex
 
 readme: $(BIN)
 	sh ./tools/update-readme-usage.sh
-- 
GitLab


From 9edca7def641888d20204f5afb390434a5f33a5d Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Wed, 15 Feb 2023 19:08:53 +0100
Subject: [PATCH 14/16] remove bc(1) dependency in configure.sh

---
 configure.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.sh b/configure.sh
index 3f82c3b..4f6375b 100755
--- a/configure.sh
+++ b/configure.sh
@@ -63,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
-- 
GitLab


From de5e735b03a1b8820dd3d2df9bd62438bb1b8463 Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Thu, 16 Feb 2023 18:24:28 +0100
Subject: [PATCH 15/16] add quotation marks

---
 configure.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.sh b/configure.sh
index 4f6375b..21c94ef 100755
--- a/configure.sh
+++ b/configure.sh
@@ -107,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
-- 
GitLab


From a0c1db322c0c5e6525724a56998c6af634ef322e Mon Sep 17 00:00:00 2001
From: ghuter <ghuter@disroot.org>
Date: Tue, 21 Feb 2023 11:26:50 +0100
Subject: [PATCH 16/16] fix infiniband

---
 src/infiniband.c | 64 ++++++++++++++++++++++++++++++++++++++++++------
 src/infiniband.h |  6 +++--
 2 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/src/infiniband.c b/src/infiniband.c
index aa4a8de..6a5a6b4 100644
--- a/src/infiniband.c
+++ b/src/infiniband.c
@@ -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)
 {
diff --git a/src/infiniband.h b/src/infiniband.h
index e30d78b..8098cf5 100644
--- a/src/infiniband.h
+++ b/src/infiniband.h
@@ -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,
 };
-- 
GitLab