From b847e69abbbe16b7dc8f75e19925dc27f0a3d0bf Mon Sep 17 00:00:00 2001 From: Tahsincan Köse Date: Tue, 30 Nov 2021 20:28:41 +0300 Subject: Provide stimuli output capability. --- src/zenmonitor-cli.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/zenmonitor-cli.c b/src/zenmonitor-cli.c index 7cf79f1..6792d02 100644 --- a/src/zenmonitor-cli.c +++ b/src/zenmonitor-cli.c @@ -14,6 +14,7 @@ gdouble delay = 0.5; gchar *file = ""; SensorDataStore *store; int quit = 0; +int output_once = 0; static GOptionEntry options[] = { {"file", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &file, @@ -22,6 +23,8 @@ static GOptionEntry options[] = { "Interval of refreshing informations", "SECONDS"}, {"coreid", 'c', 0, G_OPTION_ARG_NONE, &display_coreid, "Display core_id instead of core index", NULL}, + {"output-once", 'o', 0, G_OPTION_ARG_NONE, &output_once, + "Output CPU information once and quit", NULL}, {NULL}}; static SensorSource sensor_sources[] = { @@ -164,8 +167,12 @@ void update_data() void start_watching() { while(!quit) - { + { update_data(); + if (output_once) + { + break; + } usleep(delay * 1000 * 1000); } } @@ -190,7 +197,6 @@ int main(int argc, char *argv[]) init_sensors(); start_watching(); - sensor_data_store_free(store); return EXIT_SUCCESS; -- cgit v1.2.3-70-g09d2 From 48bf54c46c3061d9344f89d2dab3bd4613ec3a17 Mon Sep 17 00:00:00 2001 From: Tahsincan Köse Date: Tue, 30 Nov 2021 20:42:41 +0300 Subject: Separate CLI uninstall rule. --- makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/makefile b/makefile index 93b7bf5..21cc9e4 100755 --- a/makefile +++ b/makefile @@ -52,6 +52,9 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/share/applications/zenmonitor-root.desktop rm -f $(DESTDIR)/usr/share/polkit-1/actions/org.pkexec.zenmonitor.policy +uninstall-cli: + rm -f $(DESTDIR)$(PREFIX)/bin/zenmonitor-cli + all: build build-cli clean: -- cgit v1.2.3-70-g09d2 From ef2c1793d943c43fa1ebe2aa632270aa308012a2 Mon Sep 17 00:00:00 2001 From: Tahsincan Köse Date: Tue, 30 Nov 2021 20:46:24 +0300 Subject: Refresh in place capability. --- README.md | 2 +- makefile | 2 +- src/zenmonitor-cli.c | 29 +++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7e7d82a..9c33365 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Then: ```sh sudo modprobe msr sudo bash -c 'echo "msr" > /etc/modules-load.d/msr.conf' -sudo apt install build-essential libgtk-3-dev git +sudo apt install build-essential libgtk-3-dev libncurses5-dev git cd ~ git clone https://github.com/Ta180m/zenmonitor3 cd zenmonitor3 diff --git a/makefile b/makefile index 21cc9e4..282d7ef 100755 --- a/makefile +++ b/makefile @@ -22,7 +22,7 @@ build: $(CC) -Isrc/include `pkg-config --cflags gtk+-3.0` $(BUILD_FILES_GUI) -o zenmonitor `pkg-config --libs gtk+-3.0` -lm -no-pie -Wall $(CFLAGS) build-cli: - $(CC) -Isrc/include `pkg-config --cflags glib-2.0` $(BUILD_FILES_CLI) -o zenmonitor-cli `pkg-config --libs glib-2.0` -lm -no-pie -Wall $(CFLAGS) + $(CC) -Isrc/include `pkg-config --cflags glib-2.0` $(BUILD_FILES_CLI) -o zenmonitor-cli `pkg-config --libs glib-2.0` -lm -lncurses -no-pie -Wall $(CFLAGS) install: mkdir -p $(DESTDIR)$(PREFIX)/bin diff --git a/src/zenmonitor-cli.c b/src/zenmonitor-cli.c index 6792d02..a89c14b 100644 --- a/src/zenmonitor-cli.c +++ b/src/zenmonitor-cli.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "msr.h" #include "os.h" #include "zenpower.h" @@ -14,6 +15,7 @@ gdouble delay = 0.5; gchar *file = ""; SensorDataStore *store; int quit = 0; +int refresh_in_place = 0; int output_once = 0; static GOptionEntry options[] = { @@ -23,6 +25,8 @@ static GOptionEntry options[] = { "Interval of refreshing informations", "SECONDS"}, {"coreid", 'c', 0, G_OPTION_ARG_NONE, &display_coreid, "Display core_id instead of core index", NULL}, + {"refresh-in-place", 'r', 0, G_OPTION_ARG_NONE, &refresh_in_place, + "Whether to flush stdout block in-place.", NULL}, {"output-once", 'o', 0, G_OPTION_ARG_NONE, &output_once, "Output CPU information once and quit", NULL}, {NULL}}; @@ -141,7 +145,7 @@ void update_data() const SensorInit *sensorData; sensor_data_store_keep_time(store); - + int i = 1; //ncurses uses 1-based indexing. for(source = sensor_sources; source->drv; source++) { if(source->enabled) @@ -151,11 +155,19 @@ void update_data() { node = source->sensors; - while(node) + while (node) { - sensorData = (SensorInit*)node->data; + sensorData = (SensorInit *)node->data; sensor_data_store_add_data(store, sensorData->label, *sensorData->value); - printf("%s\t%f\n", sensorData->label, *sensorData->value); + if (refresh_in_place) + { + mvprintw(i++, 0, "%s\t%f", sensorData->label, *sensorData->value); + refresh(); + } + else + { + printf("%s\t%f\n", sensorData->label, *sensorData->value); + } node = node->next; } } @@ -196,7 +208,16 @@ int main(int argc, char *argv[]) store = sensor_data_store_new(); init_sensors(); + if (refresh_in_place) + { + initscr(); + curs_set(0); + } start_watching(); + if (refresh_in_place) + { + endwin(); + } sensor_data_store_free(store); return EXIT_SUCCESS; -- cgit v1.2.3-70-g09d2