2022-07-15 13:53:01 +00:00
|
|
|
#if 0
|
|
|
|
/*─────────────────────────────────────────────────────────────────╗
|
|
|
|
│ To the extent possible under law, Justine Tunney has waived │
|
|
|
|
│ all copyright and related or neighboring rights to this file, │
|
|
|
|
│ as it is written in the following disclaimers: │
|
|
|
|
│ • http://unlicense.org/ │
|
|
|
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
|
|
|
╚─────────────────────────────────────────────────────────────────*/
|
|
|
|
#endif
|
|
|
|
#include "libc/calls/struct/sysinfo.h"
|
2023-10-11 18:45:31 +00:00
|
|
|
#include "libc/calls/struct/timespec.h"
|
2022-08-17 20:41:21 +00:00
|
|
|
#include "libc/fmt/conv.h"
|
2022-07-15 13:53:01 +00:00
|
|
|
#include "libc/fmt/itoa.h"
|
|
|
|
#include "libc/log/check.h"
|
|
|
|
#include "libc/stdio/stdio.h"
|
2023-10-11 18:45:31 +00:00
|
|
|
#include "libc/sysv/consts/clock.h"
|
2022-07-15 13:53:01 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
int64_t x;
|
|
|
|
char ibuf[21];
|
|
|
|
struct sysinfo si;
|
|
|
|
CHECK_NE(-1, sysinfo(&si));
|
|
|
|
|
|
|
|
printf("%-16s", "uptime");
|
|
|
|
x = si.uptime / (24 * 60 * 60);
|
|
|
|
si.uptime %= 24 * 60 * 60;
|
|
|
|
if (x) {
|
|
|
|
printf(" %ld day%s", x, x == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
x = si.uptime / (60 * 60);
|
|
|
|
si.uptime %= 60 * 60;
|
|
|
|
if (x) {
|
|
|
|
printf(" %ld hour%s", x, x == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
x = si.uptime / (60);
|
|
|
|
si.uptime %= 60;
|
|
|
|
if (x) {
|
|
|
|
printf(" %ld minute%s", x, x == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
x = si.uptime;
|
|
|
|
if (x) {
|
|
|
|
printf(" %ld second%s", x, x == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("%-16s %g %g %g\n", "load", //
|
|
|
|
1. / 65536 * si.loads[0], //
|
|
|
|
1. / 65536 * si.loads[1], //
|
|
|
|
1. / 65536 * si.loads[2]); //
|
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.totalram * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "totalram", si.totalram, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.freeram * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "freeram", si.freeram, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.sharedram * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "sharedram", si.sharedram, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.bufferram * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "bufferram", si.bufferram, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.totalswap * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "totalswap", si.totalswap, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.freeswap * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "freeswap", si.freeswap, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
|
|
|
printf("%-16s %lu\n", "processes", si.procs);
|
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.totalhigh * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "totalhigh", si.totalhigh, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2023-02-23 14:00:18 +00:00
|
|
|
sizefmt(ibuf, si.freehigh * si.mem_unit, 1024);
|
|
|
|
printf("%-16s %ld (%s)\n", "freehigh", si.freehigh, ibuf);
|
2022-07-15 13:53:01 +00:00
|
|
|
|
2022-08-17 20:41:21 +00:00
|
|
|
sizefmt(ibuf, si.mem_unit, 1024);
|
2022-07-15 13:53:01 +00:00
|
|
|
printf("%-16s %s\n", "mem_unit", ibuf);
|
|
|
|
|
|
|
|
//
|
|
|
|
}
|