mirror of
https://github.com/troglobit/finit.git
synced 2026-12-05 22:08:20 +00:00
cgutil: new functions to query a cgroup from pid and get memory use
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
728db73b09
commit
3107027132
2 files changed
+33
No files matched your search
@@ -108,6 +108,25 @@ char *pid_comm(int pid, char *buf, size_t len)
|
|||||||
return chomp(buf);
|
return chomp(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *pid_cgroup(int pid, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
fp = fopenf("r", "/proc/%d/cgroup", pid);
|
||||||
|
if (!fp)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
fgets(buf, len, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
ptr = strchr(buf, '/');
|
||||||
|
if (!ptr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return chomp(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
static uint64_t cgroup_uint64(char *path, char *file)
|
static uint64_t cgroup_uint64(char *path, char *file)
|
||||||
{
|
{
|
||||||
uint64_t val = 0;
|
uint64_t val = 0;
|
||||||
@@ -159,6 +178,16 @@ static uint64_t cgroup_memuse(struct cg *cg)
|
|||||||
return cg->cg_vmsize = cgroup_uint64(cg->cg_path, "memory.current");
|
return cg->cg_vmsize = cgroup_uint64(cg->cg_path, "memory.current");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t cgroup_memory(char *group)
|
||||||
|
{
|
||||||
|
char path[256];
|
||||||
|
|
||||||
|
paste(path, sizeof(path), FINIT_CGPATH, group);
|
||||||
|
printf("DBG: %s (%s)\n", path, group);
|
||||||
|
|
||||||
|
return cgroup_uint64(path, "memory.current");
|
||||||
|
}
|
||||||
|
|
||||||
static float cgroup_cpuload(struct cg *cg)
|
static float cgroup_cpuload(struct cg *cg)
|
||||||
{
|
{
|
||||||
char fn[256];
|
char fn[256];
|
||||||
|
|||||||
@@ -24,10 +24,14 @@
|
|||||||
#ifndef FINIT_CGUTIL_H_
|
#ifndef FINIT_CGUTIL_H_
|
||||||
#define FINIT_CGUTIL_H_
|
#define FINIT_CGUTIL_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
char *pid_cmdline (int pid, char *buf, size_t len);
|
char *pid_cmdline (int pid, char *buf, size_t len);
|
||||||
char *pid_comm (int pid, char *buf, size_t len);
|
char *pid_comm (int pid, char *buf, size_t len);
|
||||||
|
char *pid_cgroup (int pid, char *buf, size_t len);
|
||||||
|
|
||||||
|
uint64_t cgroup_memory(char *group);
|
||||||
|
|
||||||
int cgroup_tree (char *path, char *pfx, int top);
|
int cgroup_tree (char *path, char *pfx, int top);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user