2 # -*- coding: us-ascii -*-
3 # Create a tapset for systemtap and DTrace
4 # usage: ./ruby gen_ruby_tapset.rb --ruby-path=/path/to/ruby probes.d > output
8 def set_argument(argname, nth)
9 # remove C style type info
10 argname.gsub!(/.+ (.+)/, '\1') # e.g. char *hoge -> *hoge
11 argname.gsub!(/^\*/, '') # e.g. *filename -> filename
13 "#{argname} = $arg#{nth}"
16 ruby_path = "/usr/local/ruby"
18 opts = OptionParser.new
19 opts.on("--ruby-path=PATH"){|v| ruby_path = v}
24 # remove preprocessor directives
25 text.gsub!(/^#.*$/, '')
27 # remove provider name
28 text.gsub!(/^provider ruby \{/, "")
29 text.gsub!(/^\};/, "")
32 text.gsub!(/probe (.+)\( *\);/) {
35 probe #{probe_name} = process("ruby").provider("ruby").mark("#{probe_name}")
42 text.gsub!(/ *probe (.+)\(([^,)]+)\);/) {
47 probe #{probe_name} = process("ruby").provider("ruby").mark("#{probe_name}")
49 #{set_argument(arg1, 1)}
54 # probename(arg1, arg2)
55 text.gsub!(/ *probe (.+)\(([^,)]+),([^,)]+)\);/) {
61 probe #{probe_name} = process("#{ruby_path}").provider("ruby").mark("#{probe_name}")
63 #{set_argument(arg1, 1)}
64 #{set_argument(arg2, 2)}
69 # probename(arg1, arg2, arg3)
70 text.gsub!(/ *probe (.+)\(([^,)]+),([^,)]+),([^,)]+)\);/) {
77 probe #{probe_name} = process("#{ruby_path}").provider("ruby").mark("#{probe_name}")
79 #{set_argument(arg1, 1)}
80 #{set_argument(arg2, 2)}
81 #{set_argument(arg3, 3)}
86 # probename(arg1, arg2, arg3, arg4)
87 text.gsub!(/ *probe (.+)\(([^,)]+),([^,)]+),([^,)]+),([^,)]+)\);/) {
95 probe #{probe_name} = process("#{ruby_path}").provider("ruby").mark("#{probe_name}")
97 #{set_argument(arg1, 1)}
98 #{set_argument(arg2, 2)}
99 #{set_argument(arg3, 3)}
100 #{set_argument(arg4, 4)}