Skip to content

Instantly share code, notes, and snippets.

@maliubiao
Last active December 29, 2015 09:49
Show Gist options
  • Select an option

  • Save maliubiao/7653178 to your computer and use it in GitHub Desktop.

Select an option

Save maliubiao/7653178 to your computer and use it in GitHub Desktop.
uwsgi-request-time
#! /usr/bin/env python
import os
import sys
import signal
stap_script = """
global counter
global start = 0
global end = 0
probe process("/usr/bin/uwsgi").function("uwsgi_request_wsgi")
{
if (end == 0) {
start = gettimeofday_ns()
end = 1
} else {
counter <<< (gettimeofday_ns() - start)
end = 0
}
}
probe end {
printf("\\naverage: %ldns\\n", @avg(counter))
printf("max: %ldns\\n", @max(counter))
printf("min: %ldns\\n", @min(counter))
printf("sum: %ldns\\n", @sum(counter))
printf("count: %ld\\n", @count(counter))
}
"""
def sigint_handler(signum, frame):
exit(0)
def print_usage():
print "uwsgi-stacks.py pid"
def main():
tmp = "stap.tmp"
signal.signal(signal.SIGINT, sigint_handler)
with open(tmp, "w+") as f:
f.write(stap_script)
if os.fork() == 0:
os.execvp("stap", ['stap', "-v", "-o", "uwsgi.stacks", "-d", "/lib64/libc.so.6", "-D", "MAXERRORS=10", "-s", "32", "-D", "MAXTRACE=100", "-D", "MAXSTRINGLEN=4096", "-D", "MAXMAPENTRIES=10240", "-D", "MAXACTION=10000", "-D", "STP_OVERLOAD_THRESHOLD=50000000", "%s" % tmp ])
os.wait()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment