Report up-to-date RSS in LMK_PROCKILL cmd
Add RSS field, in LMK_PROCKILL cmd, to report the latest memory usage of the killed process. Test: Verified RSS field is captured in ApplicationExitInfo Bug: 322549716 Change-Id: Ic1788e8121da97cd879bd7e9d685c7b879ea5475 Signed-off-by: Carlos Galo <carlosgalo@google.com>
This commit is contained in:
parent
0aeff477af
commit
1e50c6ecc4
|
|
@ -245,11 +245,14 @@ static inline size_t lmkd_pack_set_subscribe(LMKD_CTRL_PACKET packet, enum async
|
||||||
* Prepare LMK_PROCKILL unsolicited packet and return packet size in bytes.
|
* Prepare LMK_PROCKILL unsolicited packet and return packet size in bytes.
|
||||||
* Warning: no checks performed, caller should ensure valid parameters.
|
* Warning: no checks performed, caller should ensure valid parameters.
|
||||||
*/
|
*/
|
||||||
static inline size_t lmkd_pack_set_prockills(LMKD_CTRL_PACKET packet, pid_t pid, uid_t uid) {
|
static inline size_t lmkd_pack_set_prockills(LMKD_CTRL_PACKET packet, pid_t pid, uid_t uid,
|
||||||
|
int rss_kb) {
|
||||||
packet[0] = htonl(LMK_PROCKILL);
|
packet[0] = htonl(LMK_PROCKILL);
|
||||||
packet[1] = htonl(pid);
|
packet[1] = htonl(pid);
|
||||||
packet[2] = htonl(uid);
|
packet[2] = htonl(uid);
|
||||||
return 3 * sizeof(int);
|
packet[3] = htonl(rss_kb);
|
||||||
|
|
||||||
|
return 4 * sizeof(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
12
lmkd.cpp
12
lmkd.cpp
|
|
@ -807,9 +807,9 @@ static int ctrl_data_write(int dsock_idx, char* buf, size_t bufsz) {
|
||||||
* Write the pid/uid pair over the data socket, note: all active clients
|
* Write the pid/uid pair over the data socket, note: all active clients
|
||||||
* will receive this unsolicited notification.
|
* will receive this unsolicited notification.
|
||||||
*/
|
*/
|
||||||
static void ctrl_data_write_lmk_kill_occurred(pid_t pid, uid_t uid) {
|
static void ctrl_data_write_lmk_kill_occurred(pid_t pid, uid_t uid, int64_t rss_kb) {
|
||||||
LMKD_CTRL_PACKET packet;
|
LMKD_CTRL_PACKET packet;
|
||||||
size_t len = lmkd_pack_set_prockills(packet, pid, uid);
|
size_t len = lmkd_pack_set_prockills(packet, pid, uid, static_cast<int>(rss_kb));
|
||||||
|
|
||||||
for (int i = 0; i < MAX_DATA_CONN; i++) {
|
for (int i = 0; i < MAX_DATA_CONN; i++) {
|
||||||
if (data_sock[i].sock >= 0 && data_sock[i].async_event_mask & 1 << LMK_ASYNC_EVENT_KILL) {
|
if (data_sock[i].sock >= 0 && data_sock[i].async_event_mask & 1 << LMK_ASYNC_EVENT_KILL) {
|
||||||
|
|
@ -866,6 +866,7 @@ static void poll_kernel(int poll_fd) {
|
||||||
int16_t min_score_adj;
|
int16_t min_score_adj;
|
||||||
int64_t starttime;
|
int64_t starttime;
|
||||||
char* taskname = 0;
|
char* taskname = 0;
|
||||||
|
int64_t rss_kb;
|
||||||
|
|
||||||
int fields_read =
|
int fields_read =
|
||||||
sscanf(rd_buf,
|
sscanf(rd_buf,
|
||||||
|
|
@ -876,9 +877,10 @@ static void poll_kernel(int poll_fd) {
|
||||||
|
|
||||||
/* only the death of the group leader process is logged */
|
/* only the death of the group leader process is logged */
|
||||||
if (fields_read == 10 && group_leader_pid == pid) {
|
if (fields_read == 10 && group_leader_pid == pid) {
|
||||||
ctrl_data_write_lmk_kill_occurred((pid_t)pid, (uid_t)uid);
|
|
||||||
mem_st.process_start_time_ns = starttime * (NS_PER_SEC / sysconf(_SC_CLK_TCK));
|
|
||||||
mem_st.rss_in_bytes = rss_in_pages * pagesize;
|
mem_st.rss_in_bytes = rss_in_pages * pagesize;
|
||||||
|
rss_kb = mem_st.rss_in_bytes >> 10;
|
||||||
|
ctrl_data_write_lmk_kill_occurred((pid_t)pid, (uid_t)uid, rss_kb);
|
||||||
|
mem_st.process_start_time_ns = starttime * (NS_PER_SEC / sysconf(_SC_CLK_TCK));
|
||||||
|
|
||||||
struct kill_stat kill_st = {
|
struct kill_stat kill_st = {
|
||||||
.uid = static_cast<int32_t>(uid),
|
.uid = static_cast<int32_t>(uid),
|
||||||
|
|
@ -2682,7 +2684,7 @@ static int kill_one_process(struct proc* procp, int min_oom_score, struct kill_i
|
||||||
kill_st.free_swap_kb = get_free_swap(mi) * page_k;
|
kill_st.free_swap_kb = get_free_swap(mi) * page_k;
|
||||||
stats_write_lmk_kill_occurred(&kill_st, mem_st);
|
stats_write_lmk_kill_occurred(&kill_st, mem_st);
|
||||||
|
|
||||||
ctrl_data_write_lmk_kill_occurred((pid_t)pid, uid);
|
ctrl_data_write_lmk_kill_occurred((pid_t)pid, uid, rss_kb);
|
||||||
|
|
||||||
result = rss_kb / page_k;
|
result = rss_kb / page_k;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue