| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# Copyright (C) 2014 Red Hat Inc. |
| 4 |
# |
| 5 |
# This file is part of systemtap, and is free software. You can |
| 6 |
# redistribute it and/or modify it under the terms of the GNU General |
| 7 |
# Public License (GPL); either version 2, or (at your option) any |
| 8 |
# later version. |
| 9 |
|
| 10 |
import os |
| 11 |
import sys |
| 12 |
from config_opts import config_opts |
| 13 |
|
| 14 |
def gen_files(dir, subset): |
| 15 |
f = open('%s/probes.stp' % dir, 'w') |
| 16 |
|
| 17 |
# Output the script |
| 18 |
i = 0 |
| 19 |
while i < len(subset): |
| 20 |
print >>f, ("global called%d" % (i)) |
| 21 |
i += 1 |
| 22 |
print >>f, "probe begin(-1)" |
| 23 |
print >>f, "{" |
| 24 |
i = 0 |
| 25 |
while i < len(subset): |
| 26 |
print >>f, ("\tcalled%d <<< 0" % (i)) |
| 27 |
i += 1 |
| 28 |
print >>f, "}" |
| 29 |
i = 0 |
| 30 |
while i < len(subset): |
| 31 |
print >>f, ("probe kernel.function(\"%s\").call { called%d <<< 1 }" % (subset[i], i)) |
| 32 |
i += 1 |
| 33 |
print >>f, "probe end" |
| 34 |
print >>f, "{" |
| 35 |
i = 0 |
| 36 |
while i < len(subset): |
| 37 |
print >>f, ("\tprintf(\"%%d %s\\n\", @sum(called%d))" % (subset[i], i)) |
| 38 |
i += 1 |
| 39 |
print >>f, "\tprintf(\"probe_module unloaded\\n\")" |
| 40 |
print >>f, "}" |
| 41 |
f.close() |
| 42 |
|
| 43 |
def gen_module(): |
| 44 |
f = open(config_opts['probes_current']) |
| 45 |
probes = f.readlines() |
| 46 |
f.close() |
| 47 |
if len(probes) == 0: |
| 48 |
print >>sys.stderr, ("Error: no probe points in %s" |
| 49 |
% config_opts['probes_current']) |
| 50 |
return -1 |
| 51 |
|
| 52 |
# Cleanup each probe by stripping whitespace |
| 53 |
i = 0 |
| 54 |
while i < len(probes): |
| 55 |
probes[i] = probes[i].rstrip() |
| 56 |
i += 1 |
| 57 |
|
| 58 |
# Generate necessary files |
| 59 |
gen_files(os.getcwd(), probes) |
| 60 |
|
| 61 |
# Try to build the module |
| 62 |
os.system('rm -f ./probe_module.ko') |
| 63 |
|
| 64 |
cmd = "stap -g --suppress-handler-errors --suppress-time-limits -vp4 -m probe_module probes.stp >build.log 2>&1" |
| 65 |
print "Running", cmd |
| 66 |
rc = os.system(cmd) |
| 67 |
if os.WEXITSTATUS(rc) != 0: |
| 68 |
print >>sys.stderr, "Error: stap failed, see build.log for details" |
| 69 |
return -1 |
| 70 |
return 0 |
| 71 |
|
| 72 |
def main(): |
| 73 |
rc = gen_module() |
| 74 |
sys.exit(rc) |
| 75 |
|
| 76 |
if __name__ == "__main__": |
| 77 |
main() |