statslog: Make this library compatible with the cgroups v2 hierarchy am: 16ba8bc773 am: d3401c8ae9
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1975449 Change-Id: Ic144cf22d834ef77774a2c6f7287d031cf53a993 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
aac55955a2
|
|
@ -55,6 +55,7 @@ cc_library_static {
|
||||||
defaults: ["stats_defaults"],
|
defaults: ["stats_defaults"],
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"liblog",
|
"liblog",
|
||||||
|
"libprocessgroup",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
18
statslog.cpp
18
statslog.cpp
|
|
@ -30,6 +30,10 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <processgroup/processgroup.h>
|
||||||
|
|
||||||
#ifdef LMKD_LOG_STATS
|
#ifdef LMKD_LOG_STATS
|
||||||
|
|
||||||
#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
|
#define STRINGIFY(x) STRINGIFY_INTERNAL(x)
|
||||||
|
|
@ -85,18 +89,20 @@ static void memory_stat_parse_line(char* line, struct memory_stat* mem_st) {
|
||||||
mem_st->swap_in_bytes = value;
|
mem_st->swap_in_bytes = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int memory_stat_from_cgroup(struct memory_stat* mem_st, int pid, uid_t uid) {
|
static int memory_stat_from_cgroup(struct memory_stat* mem_st, int pid, uid_t uid __unused) {
|
||||||
FILE *fp;
|
std::string path;
|
||||||
char buf[PATH_MAX];
|
if (!CgroupGetAttributePathForTask("MemStats", pid, &path)) {
|
||||||
|
ALOGE("Querying MemStats path failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), MEMCG_PROCESS_MEMORY_STAT_PATH, uid, pid);
|
FILE* fp = fopen(path.c_str(), "r");
|
||||||
|
|
||||||
fp = fopen(buf, "r");
|
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char buf[PAGE_SIZE];
|
||||||
while (fgets(buf, PAGE_SIZE, fp) != NULL) {
|
while (fgets(buf, PAGE_SIZE, fp) != NULL) {
|
||||||
memory_stat_parse_line(buf, mem_st);
|
memory_stat_parse_line(buf, mem_st);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,6 @@ enum lmk_state {
|
||||||
|
|
||||||
#ifdef LMKD_LOG_STATS
|
#ifdef LMKD_LOG_STATS
|
||||||
|
|
||||||
#define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%u/pid_%d/memory.stat"
|
|
||||||
#define PROC_STAT_FILE_PATH "/proc/%d/stat"
|
#define PROC_STAT_FILE_PATH "/proc/%d/stat"
|
||||||
#define PROC_STAT_BUFFER_SIZE 1024
|
#define PROC_STAT_BUFFER_SIZE 1024
|
||||||
#define BYTES_IN_KILOBYTE 1024
|
#define BYTES_IN_KILOBYTE 1024
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue