Skip to content

Instantly share code, notes, and snippets.

@maliubiao
Last active January 1, 2016 14:39
Show Gist options
  • Select an option

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

Select an option

Save maliubiao/8159510 to your computer and use it in GitHub Desktop.
ngx_modules
#! /usr/bin/env python
import os
import sys
import signal
stap_script = """
global i = 0;
global j = 0;
global k = 0;
probe process("/data/project/c/nginx-build/sbin/nginx").function("ngx_worker_process_cycle") {
if (i < 1) {
printf("%s\\n", user_string($cycle->hostname->data))
i += 1
}
}
probe process("/data/project/c/nginx-build/sbin/nginx").function("ngx_epoll_process_events*") {
if (k < 1) {
while (j < 512) {
ngx_modules = @var("ngx_modules@ngx_modules.c")[j]
try {
index = @cast(ngx_modules, "ngx_module_s")->index
} catch(msg) {
j+=1
break
}
if (index != j) {
break
}
ngx_modules = @var("ngx_modules@ngx_modules.c")[j]
ctx = @cast(ngx_modules, "ngx_module_s")->ctx
try {
len = @cast(ctx, "ngx_core_module_t")->name->len
name = @cast(ctx, "ngx_core_module_t")->name->data
if (len) {
printf("index: %d %s\\n", j, user_string(name));
}
} catch(msg) { }
j += 1
}
k += 1
}
}
"""
def sigint_handler(signum, frame):
exit(0)
def print_usage():
print "nginx-var.py"
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", "gcc.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=500000000",
"%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