fix thanatolog

This commit is contained in:
Alexey Avramov 2019-06-30 02:28:24 +09:00
parent 1a7a84ce1f
commit a6d77470d1

View File

@ -3,7 +3,8 @@
import os import os
from time import sleep, time from time import sleep, time
from signal import (signal, from signal import (signal,
SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGCONT, SIGUSR1, SIGUSR2, SIGKILL, SIGTERM, SIGINT, SIGQUIT,
SIGCONT, SIGUSR1, SIGUSR2,
SIGHUP, SIGABRT, SIGSEGV, SIGBUS) SIGHUP, SIGABRT, SIGSEGV, SIGBUS)
from sys import argv, exit from sys import argv, exit
@ -34,7 +35,6 @@ def mlockall():
print('All memory locked with MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT') print('All memory locked with MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT')
def check_mem(): def check_mem():
"""find mem_available""" """find mem_available"""
with open('/proc/meminfo') as f: with open('/proc/meminfo') as f:
@ -44,8 +44,6 @@ def check_mem():
return mem_available return mem_available
def pid_to_name(pid): def pid_to_name(pid):
""" """
""" """
@ -102,6 +100,12 @@ def rline1(path):
############################################################################### ###############################################################################
if len(argv) != 2:
print("""Usage:
thanatolog PID""")
exit()
mlockall() mlockall()
@ -116,16 +120,14 @@ print('Name:', name)
print('RSS at startup: {} (100.0 %)'.format(int(rss0))) print('RSS at startup: {} (100.0 %)'.format(int(rss0)))
print('MemAvail:', ma) print('MemAvail:', ma)
send_signal = SIGTERM send_signal = SIGKILL
# os.kill(int(pid), SIGCONT) # os.kill(int(pid), SIGCONT)
os.kill(int(pid), send_signal)
# os.kill(int(pid), send_signal)
t0 = time() t0 = time()
while True: while True:
rpe = os.path.exists('/proc/{}/exe'.format(pid)) rpe = os.path.exists('/proc/{}/exe'.format(pid))
rss = pid_to_rss(pid) rss = pid_to_rss(pid)
@ -135,12 +137,10 @@ while True:
state = pid_to_state(pid) state = pid_to_state(pid)
ma = check_mem() ma = check_mem()
print('RP: {} | RSS: {} ({} %) | State: {} | time: {} | MemAv'
'ail: {}'.format(rpe, rss, round(float(rss) / (
rss0 + 0.0001) * 100, 1), state, round(d, 3), ma))
if pe is False: if pe is False:
print('Process {} ({}) died in {} sec'.format(pid, name, round(d, 3)))
exit() exit()
print('RP: {} | RSS: {} ({} %) | State: {} | time: {} | MemAvail: {}'.format(
rpe, rss, round(float(rss) / (rss0 + 0.0001) * 100, 1), state, round(d, 4), ma
)
)
# sleep(0.0001)