diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 58 |
1 files changed, 51 insertions, 7 deletions
@@ -1,10 +1,12 @@ #include<stdio.h> +#include<stdlib.h> #include<string.h> #include<sys/resource.h> #include<sys/utsname.h> #include<sys/sysinfo.h> #include<sys/types.h> #include<unistd.h> +#include<time.h> #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; } |