Skip to content
Snippets Groups Projects
Commit b6fb43a0 authored by ghuter's avatar ghuter
Browse files

modify memory_option.sh

parent aa98e7f8
No related branches found
No related tags found
2 merge requests!9fix sensor example (doc),!7Add memory counters and fix makefile
......@@ -3,9 +3,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018-2023 Georges Da Costa <georges.da-costa@irit.fr>
MEMINFO_PATH="/proc/meminfo"
meminfo_path=/proc/meminfo
FUNCTION_TEMPLATE="void set_result_offset%s(GenericPointer ptr, GenericPointer data)
function_template="void set_result_offset%s(GenericPointer ptr, GenericPointer data)
{
uint64_t* result = (uint64_t *) ptr;
result[%s] = (uint64_t) data;
......@@ -14,16 +14,15 @@ FUNCTION_TEMPLATE="void set_result_offset%s(GenericPointer ptr, GenericPointer d
nb_counters=0
echo '#include <inttypes.h>'
echo "#include <info_reader.h>"
echo '#include <info_reader.h>'
echo
echo 'static char *memory_counters[] = {'
while read line; do
nb_counters=$(expr $nb_counters + 1)
word=$(echo $line | awk '{print $1}')
echo " \"${word::-1}\","
done <$MEMINFO_PATH
echo "};"
: $((nb_counters += 1))
echo "$line" | awk -F ':' '{printf(" \"%s\",\n", $1)}'
done < "$meminfo_path"
echo '};'
echo
echo "#define NB_COUNTERS $nb_counters"
......@@ -31,16 +30,16 @@ echo
count=0
while [ $count -lt $nb_counters ]; do
printf "$FUNCTION_TEMPLATE" $count $count
count=$(expr $count + 1)
printf "$function_template" $count $count
: $((count += 1))
done
echo "static void (*setter_functions[])(GenericPointer, GenericPointer) = {"
echo 'static void (*setter_functions[])(GenericPointer, GenericPointer) = {'
count=0
while [ $count -lt $nb_counters ]; do
echo " set_result_offset$count,"
count=$(expr $count + 1)
: $((count += 1))
done
echo "};"
echo '};'
echo
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment