summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh <eeei3.joshua0307lol@gmail.com>2025-01-17 23:42:22 -0500
committerJosh <eeei3.joshua0307lol@gmail.com>2025-01-17 23:42:22 -0500
commitc60e25414b43433ea7275829e0df937cfcff3ebb (patch)
treea173e142f771568f0e0e1bdb2bc762cfbb1b3200
parenta0c0359009fbdf64925666299000e6dc0b3a1282 (diff)
Fleshed out program more, added additional import time.h, more argument handling
-rw-r--r--.gitignore1
-rw-r--r--main.c58
2 files changed, 52 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..cba7efc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+a.out
diff --git a/main.c b/main.c
index f921ab8..cf8d1ee 100644
--- a/main.c
+++ b/main.c
@@ -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;
}