summaryrefslogtreecommitdiff
path: root/main.c
blob: cf8d1eeec0b58be4a7062fd0c52098e72c2a26a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#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/";
#define CLEAR "\033[2J";
#define REPOS "\033[H"; // Re-positions the cursor to top left of screen

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;

    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;
	else if (strstr(*argv, "--cpu"))
	    cpu = 1;
	else if (strstr(*argv, "--cores"))
	    cores = 1;
	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;
}