Last active
August 7, 2019 15:52
-
-
Save meaksh/0c603a62b7189f051aa31bfba2bb8171 to your computer and use it in GitHub Desktop.
tracemalloc stats dumper for salt-master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tracemalloc | |
import threading | |
from salt.scripts import salt_master | |
import signal | |
import sys | |
stop_flag = False | |
def print_stats(): | |
snapshot = tracemalloc.take_snapshot() | |
top_stats = snapshot.statistics('lineno') | |
print("[ Top 50 ]") | |
for stat in top_stats[:50]: | |
print(stat) | |
def signal_handler(sig, frame): | |
global stop_flag | |
stop_flag = True | |
print_stats() | |
print('You pressed Ctrl+C!') | |
sys.exit(0) | |
def timer_stats(): | |
global stop_flag | |
print_stats() | |
if not stop_flag: | |
t = threading.Timer(5.0, timer_stats) | |
t.daemon = True | |
t.start() | |
signal.signal(signal.SIGINT, signal_handler) | |
tracemalloc.start(25) | |
timer_stats() | |
salt_master() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment