Last active
December 24, 2015 01:29
-
-
Save maliubiao/6724128 to your computer and use it in GitHub Desktop.
a sample script to capture stack data of nginx.
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
#! /usr/bin/env python | |
import os | |
import sys | |
import time | |
import signal | |
import subprocess | |
stap_script = """ | |
global s; | |
probe process("/usr/local/nginx/sbin/nginx").function("*") { | |
s[sprint_ubacktrace()] <<< 1; | |
} | |
probe end { | |
foreach ([stack] in s+) { | |
printf("%s\\n\\n", stack); | |
} | |
} | |
""" | |
def handler(signum, frame): | |
exit() | |
def print_usage(): | |
print "nginx-stacks.py" | |
if __name__ == "__main__": | |
tmp = "stap.tmp" | |
with open(tmp, "w+") as f: | |
f.write(stap_script) | |
status3 = 0 | |
try: | |
status3 = os.fork() | |
except OSError as e: | |
print e | |
if status3 == 0: | |
try: | |
os.execvp("stap", ['stap',"-o", "nginx.stacks", | |
"-v", | |
"-d", "/lib64/libc-2.17.so", | |
"-s", "32", | |
"-D", "MAXTRACE=100", | |
"-D", "MAXSTRINGLEN=4096", | |
"-D", "MAXMAPENTRIES=10240", | |
"-D", "MAXACTION=10000", | |
"-D", "STP_OVERLOAD_THRESHOLD=5000000000", | |
"%s" % tmp]) | |
except OSError as e: | |
print e | |
signal.signal(signal.SIGINT, handler) | |
while True: | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment