diff options
author | Aaron Ball <nullspoon@oper.io> | 2020-11-12 09:34:34 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2020-11-12 09:38:20 -0700 |
commit | e5d0257f562ae4ad0a29e4cd8160d655a6be4955 (patch) | |
tree | c2462aa35f17c690d6b3c225e8999bf4f049cae8 /src | |
parent | b6dffdf3fa31028bb7f4097e62411ba679a7545a (diff) | |
download | i3cstat-e5d0257f562ae4ad0a29e4cd8160d655a6be4955.tar.gz i3cstat-e5d0257f562ae4ad0a29e4cd8160d655a6be4955.tar.xz |
Implement support for new interval configuration
This allows the user to specify run intervals for each configured module
in seconds. The purpose of this is for the modules that the user may not
want running on every load cycle, so they can specify to run less
frequently (minimum resolution is 1 second). Running less frequently on
more cpu intensive operations can save power and reduce unecessary
processing (such as checking free space on storage, which doesn't update
often).
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 3 | ||||
-rw-r--r-- | src/config_node.c | 4 | ||||
-rw-r--r-- | src/config_node.h | 3 | ||||
-rw-r--r-- | src/main.c | 8 |
4 files changed, 15 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c index 51503c3..eeaa5fe 100644 --- a/src/config.c +++ b/src/config.c @@ -111,7 +111,8 @@ struct node* config_load(char* path) { || strcmp(key, "text") == 0 || strcmp(key, "color") == 0 || strcmp(key, "label_color") == 0 - || strcmp(key, "display") == 0) { + || strcmp(key, "display") == 0 + || strcmp(key, "interval") == 0) { _load_node_key(cur, key, val); continue; } diff --git a/src/config_node.c b/src/config_node.c index 16aa0ed..159ceed 100644 --- a/src/config_node.c +++ b/src/config_node.c @@ -25,6 +25,8 @@ struct node* node_new(void (*init_callback)(struct node*)) { out->display[0] = '\0'; out->text[0] = '\0'; out->label[0] = '\0'; + out->interval = 0; + out->lastrun = 0; strcpy(out->color, "#eeeeee"); strcpy(out->label_color, "#eeeeee"); init_callback(out); @@ -58,6 +60,8 @@ void _load_node_key(struct node* n, char* key, char* val) { strcpy(n->text, val); else if(strcmp(key, "display") == 0) strcpy(n->display, val); + else if(strcmp(key, "interval") == 0) + n->interval = strtol(val, NULL, 10); else printf("ERROR: Unknown node key %s\n", key); } diff --git a/src/config_node.h b/src/config_node.h index 520c533..0f73b10 100644 --- a/src/config_node.h +++ b/src/config_node.h @@ -21,6 +21,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> struct node { struct node* next; @@ -33,6 +34,8 @@ struct node { char label[256]; // Label for the node char text[256]; // Value for full_text char display[64]; // How to display the data (eg: bar, percent, etc) + size_t interval; // How frequently the load function should be called + time_t lastrun; // Last time the node's load function was called }; //struct node* config_node_new(void* data, void(*init_callback)(struct node*)) { @@ -19,6 +19,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <time.h> #include <locale.h> @@ -31,7 +32,7 @@ int main(int argc, char* argv[]) { char confpath[256]; - int sleeptime = 500 * 1000; // 200 ms * 1000 + int sleeptime = 500 * 1000; // 500 ms struct node* list = NULL; struct node* cur = NULL; @@ -54,7 +55,10 @@ int main(int argc, char* argv[]) { while(1) { printf("[\n"); while(cur) { - cur->loadfunc(cur); + if(time(NULL) - cur->lastrun > cur->interval) { + cur->loadfunc(cur); + cur->lastrun = time(NULL); + } node_print(cur); cur = cur->next; } |