diff options
Diffstat (limited to 'stp')
-rwxr-xr-x | stp/spice_generic.py | 41 | ||||
-rw-r--r-- | stp/spice_generic.stp.template | 9 |
2 files changed, 50 insertions, 0 deletions
diff --git a/stp/spice_generic.py b/stp/spice_generic.py new file mode 100755 index 0000000..d42015e --- /dev/null +++ b/stp/spice_generic.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +import sys +from argparse import ArgumentParser +from glob import glob +import os + +def get_library_path(): + # TODO: /etc/ld.so.conf + return os.environ['LD_LIBRARY_PATH'].split(':') + ["/usr/lib64"] + +def find_spice_library(args): + paths = get_library_path() + candidates = sum([glob(os.path.join(p, 'libspice-server.so*')) + for p in paths], []) + if len(candidates) == 0: + print "no libspice-server.so* in %s" % repr(paths) + raise SystemExit + library = candidates[args.lib_num or 0] + if len(candidates) > 1 and not args.lib_num: + print "warning: guessing library as %s\noptions: %s" % ( + library, repr(candidates)) + return library + +def main(): + parser = ArgumentParser() + parser.add_argument('--lib-num', help='index of library in candidates') + parser.add_argument('--template', default='spice_generic.stp.template') + parser.add_argument('--target', default='spice_generic.stp') + args = parser.parse_args(sys.argv[1:]) + library = find_spice_library(args) + with open(args.template, 'r') as fd: + base_template = fd.read() + with open(args.target, 'w+') as fd: + fd.write("//Automatically Generated File, do not edit\n") + fd.write("//=========================================\n\n") + template = base_template.replace('%', '%%').replace('<>', '%') + fd.write(template % dict(library=library)) + os.system('sudo stap -v %s' % args.target) + +if __name__ == '__main__': + main() diff --git a/stp/spice_generic.stp.template b/stp/spice_generic.stp.template new file mode 100644 index 0000000..859e42b --- /dev/null +++ b/stp/spice_generic.stp.template @@ -0,0 +1,9 @@ +// Template is filled with the correct spice server library by searching +// LD_LIBRARY_PATH, /usr/lib64, /lib64 +probe process("<>(library)s").function("red_channel_client_create") +{ + printf("[%d] new channel %d:%d; caps %d; common %d\n", + pid(), @cast($channel, "RedChannel")->type, + @cast($channel, "RedChannel")->id, + user_long($caps), user_long($common_caps)); +} |