initctl: add CPU throttled information alongside memory usage

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2025-12-15 22:04:33 +01:00
1 parent 2681444b07
commit fb0ad18d3a
3 files changed
+65 -1

No files matched your search

+35
View File
@@ -252,6 +252,41 @@ uint64_t cgroup_memory(char *group)
return cgroup_uint64(path, "memory.current");
}
int cgroup_throttle(char *group, uint64_t *throttled_usec, uint64_t *nr_throttled)
{
char path[256];
char buf[256];
FILE *fp;
int found = 0;
paste(path, sizeof(path), FINIT_CGPATH, group);
fp = fopenf("r", "%s/cpu.stat", path);
if (!fp)
return -1;
*throttled_usec = 0;
*nr_throttled = 0;
while (fgets(buf, sizeof(buf), fp)) {
chomp(buf);
if (!strncmp(buf, "throttled_usec", 14)) {
*throttled_usec = strtoull(&buf[15], NULL, 10);
found++;
} else if (!strncmp(buf, "nr_throttled", 12)) {
*nr_throttled = strtoull(&buf[13], NULL, 10);
found++;
}
if (found == 2)
break;
}
fclose(fp);
return 0;
}
static float cgroup_cpuload(struct cg *cg)
{
char fn[256];