From c60e25414b43433ea7275829e0df937cfcff3ebb Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 17 Jan 2025 23:42:22 -0500 Subject: Fleshed out program more, added additional import time.h, more argument handling --- main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f921ab8..cf8d1ee 100644 --- a/main.c +++ b/main.c @@ -1,10 +1,12 @@ #include +#include #include #include #include #include #include #include +#include #define CPUINFO "/proc/cpuinfo"; #define CPUFREQ "/sys/devices/system/cpu/cpu0/cpufreq/"; @@ -15,23 +17,65 @@ void move(int row, int col) { printf("\x1b[%d;%df", row, col); } +void die(const char* reason, int ret) { +} + +int printcores() { + return 0; +} + +int printmemory() { + return 0; +} + +int printcpu() { + return 0; +} + int main(int argc, char** argv) { short memory = 0; short cpu = 0; short cores = 0; int samples = 20; long tdelay = 500000; - for (int i = 1; i < argc ; i++) { + + if ((atoi(argv[1]) != 0) || (strlen(argv[1]) == 1)) { + samples = atoi(argv[1]); + } + if ((atoi(argv[2]) != 0) || (strlen(argv[2]) == 1)) { + tdelay = atoi(argv[2]); + } + + for (int i = 1; i < argc ; i++) { if (strstr(*argv, "--memory")) memory = 1; - if (strstr(*argv, "--cpu")) + else if (strstr(*argv, "--cpu")) cpu = 1; - if (strstr(*argv, "--cores")) + else if (strstr(*argv, "--cores")) cores = 1; - if (strstr(argv[i], "--samples=")) - ; - if (strstr(argv[i], "--tdelay=")) - ; + else if (strstr(argv[i], "--samples=")) + samples = atoi(strstr(argv[i], "--samples=")); + else if (strstr(argv[i], "--tdelay=")) + tdelay = atoi(strstr(argv[i], "--tdelay=")); + else { + printf("Invalid argument!"); + die("Invalid argument!", 1); + return 1; + } + } + struct timespec dur; + dur.tv_nsec = tdelay; + for (int i = 0; i < samples; i++) { + CLEAR; + if (memory) { + printmemory(); + } + if (cpu) { + printcpu(); + } + nanosleep(&dur, NULL); } + if (cores) + printcores(); return 0; } -- cgit v1.2.3