From f1348876b0dd2f8872f0ebf0bab6b9f80ca63f79 Mon Sep 17 00:00:00 2001
From: FlorealRISSO <floreal.risso@univ-tlse3.fr>
Date: Tue, 28 Mar 2023 10:11:08 +0200
Subject: [PATCH] update header

---
 src/memory_counters.c | 13 ++++++++++-
 src/memory_counters.h | 54 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 src/memory_counters.h

diff --git a/src/memory_counters.c b/src/memory_counters.c
index 7225352..23e3f96 100644
--- a/src/memory_counters.c
+++ b/src/memory_counters.c
@@ -1,5 +1,5 @@
 #include "meminfo_option.h"
-#include <bits/stdint-uintn.h>
+#include "util.h"
 #include <fcntl.h>
 #include <info_reader.h>
 #include <inttypes.h>
@@ -107,3 +107,14 @@ void clean_memory_counters(void *ptr) {
   free(counters->keys);
   free(ptr);
 }
+
+void *show_all_memory_counters(void *none1, size_t none2) {
+  for (unsigned int i = 0; i < NB_COUNTERS; i++) {
+    printf("%s\n", memory_counters[i]);
+  }
+
+  UNUSED(none1);
+  UNUSED(none2);
+  exit(EXIT_SUCCESS);
+  return NULL; /* not reached */
+}
diff --git a/src/memory_counters.h b/src/memory_counters.h
new file mode 100644
index 0000000..a066c42
--- /dev/null
+++ b/src/memory_counters.h
@@ -0,0 +1,54 @@
+/*******************************************************
+ Copyright (C) 2023-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/>.
+
+ *******************************************************/
+
+unsigned int init_memory_counters(char *args, void **ptr);
+unsigned int get_memory_counters(uint64_t *results, void *ptr);
+void label_memory_counters(char **labels, void *ptr);
+void clean_memory_counters(void *ptr);
+void *show_all_memory_counters(void *, size_t);
+
+sensor memory_counters = {
+    .init = init_memory_counters,
+    .get = get_memory_counters,
+    .clean = clean_memory_counters,
+    .label = label_memory_counters,
+    .nb_opt = 2,
+};
+
+Optparse memory_counters_opt[2] = {
+    {
+        .longname = "memory-counters",
+        .shortname = 'M',
+        .argtype = OPTPARSE_REQUIRED,
+        .usage_arg = "<memory_list>",
+        .usage_msg =
+            "memory counters\n"
+            "\tmemory_list is a coma separated list of memory counters.\n"
+            "\tEx: Zswap,Zswapped",
+    },
+    {
+        .longname = "memory-list",
+        .shortname = 'L',
+        .argtype = OPTPARSE_NONE,
+        .usage_arg = NULL,
+        .usage_msg = "list the available performance counters and quit",
+        .fn = show_all_memory_counters,
+    },
+};
-- 
GitLab