rbbcc 0.0.1.pre → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e221c0642b859704c7ed8d83c5a839eab1f44a82a17523bc59a7cfbc210abb1d
4
- data.tar.gz: 400bd564a7b462eb56489222126ffda7aa0493d91c1fce654c4ce3420a77a5a8
3
+ metadata.gz: 181f92fbe4475f87b329107f70fc1e15ac0cbfa044560e6c030dab5cd2456dab
4
+ data.tar.gz: 8699282acb475db5d641d2aa46234fb341461db78b105bc4520c5dba92226f13
5
5
  SHA512:
6
- metadata.gz: ee72e3ebfc1d6c1ab96a9de7a0a6cef522410f0e9100bdc82d1b516a7f0f7460c874ddd5a9597b5d6e19ed88bd117a97da25ea92fd8586663c1d4de8c493957b
7
- data.tar.gz: 9a85d74d9e8c42bb64e4166f7edeef19bb7449d76229fee81ad67a47df6617f4a5260527d7bc7fc16757134d6fa7a6b3709be1a38a1ab9ee8607682d7cc561bb
6
+ metadata.gz: 93c042656a0023f11759e27fa04bd6d7a8533c0edcf0b2cbf33b99e669792dbec304c6af13f257cee35a35ae80d190d7c42f11e3e99993ec42708747a886f556
7
+ data.tar.gz: 39127d19ed85575e4bc0563802e7523d3bbad4f15541ed6f372d5e29d4036be784c1b881c4a9604b65a631230a5868786116cb7da63ceef73bded49a81703f72
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbbcc (0.1.0)
4
+ rbbcc (0.0.1.pre)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,4 +17,4 @@ DEPENDENCIES
17
17
  rbbcc!
18
18
 
19
19
  BUNDLED WITH
20
- 2.0.1
20
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2019 Uchio Kondo
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
- # Rbbcc
1
+ # RbBCC
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rbbcc`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/rbbcc.svg)](https://badge.fury.io/rb/rbbcc)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ RbBCC is a port of [BCC](https://github.com/iovisor/bcc) in MRI. See iovisor project page.
6
+
7
+ ![Movie](examples/example.gif)
8
+
9
+ This gem requires `libbcc.so`. Please install it [following BCC's instruction](https://github.com/iovisor/bcc/blob/master/INSTALL.md).
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,7 +26,20 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ```ruby
30
+ require 'rbbcc'
31
+
32
+ code = <<CLANG
33
+ int kprobe__sys_clone(void *ctx)
34
+ {
35
+ bpf_trace_printk("Hello, World!\\n");
36
+ return 0;
37
+ }
38
+ CLANG
39
+ RbBCC::BCC.new(text: code).trace_print
40
+ ```
41
+
42
+ See examples (both in rbbcc and BCC)
26
43
 
27
44
  ## Development
28
45
 
data/bin/console CHANGED
@@ -11,4 +11,6 @@ require "rbbcc"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
+
15
+ include RbBCC
14
16
  IRB.start(__FILE__)
Binary file
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbcc'
4
+ include RbBCC
5
+
6
+ code = <<CLANG
7
+ #include <uapi/linux/ptrace.h>
8
+ int kprobe__sys_execve(struct pt_regs *ctx) {
9
+ if (!PT_REGS_PARM1(ctx))
10
+ return 0;
11
+ char str[80] = {};
12
+ bpf_probe_read(&str, sizeof(str), (void *)PT_REGS_PARM1(ctx));
13
+ bpf_trace_printk("execve detected: %s\\n", &str);
14
+ return 0;
15
+ }
16
+ CLANG
17
+
18
+ BCC.new(text: code).trace_print
@@ -0,0 +1,6 @@
1
+ require 'rbbcc/usdt'
2
+ include RbBCC
3
+ usdt = USDT.new(pid: 13909)
4
+ usdt.enable_probe(probe: 'mruby', fn_name: 'test')
5
+ Clib.bcc_usdt_foreach_uprobe(usdt.context, Clib::UsdtUprobeAttachCallback)
6
+
data/examples/usdt.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'rbbcc'
2
+ include RbBCC
3
+
4
+ pid = ARGV[0]
5
+
6
+ bpf_text = <<CLANG
7
+ #include <uapi/linux/ptrace.h>
8
+ int do_trace(struct pt_regs *ctx) {
9
+ long buf, tgt;
10
+ bpf_usdt_readarg(1, ctx, &buf);
11
+ bpf_probe_read(&tgt, sizeof(tgt), (void *)&buf);
12
+ bpf_trace_printk("%ld\\n", tgt);
13
+ return 0;
14
+ };
15
+ CLANG
16
+
17
+ u = USDT.new(pid: pid.to_i)
18
+ u.enable_probe(probe: "ruby", fn_name: "do_trace")
19
+
20
+ b = BCC.new(text: bpf_text, usdt_contexts: [u])
21
+
22
+ printf("%-18s %-16s %-6s %s\n", "TIME(s)", "COMM", "PID", "value")
23
+
24
+ b.trace_fields do |task, pid, cpu, flags, ts, msg|
25
+ printf("%-18.9f %-16s %-6d %s", ts, task, pid, msg)
26
+ end
data/lib/rbbcc/bcc.rb CHANGED
@@ -11,8 +11,14 @@ module RbBCC
11
11
  TRACEFS = "/sys/kernel/debug/tracing"
12
12
 
13
13
  class BCC
14
- def initialize(text:, debug: 0, cflags: [], sdt_contexts: [], allow_rlimit: 0)
15
- @kprobe_fds = []
14
+ def initialize(text:, debug: 0, cflags: [], usdt_contexts: [], allow_rlimit: 0)
15
+ @kprobe_fds = {}
16
+ @uprobe_fds = {}
17
+ @usdt_contexts = usdt_contexts
18
+ if code = gen_args_from_usdt
19
+ text = code + text
20
+ end
21
+
16
22
  @module = Clib.bpf_module_create_c_from_string(
17
23
  text,
18
24
  debug,
@@ -27,6 +33,29 @@ module RbBCC
27
33
  end
28
34
 
29
35
  trace_autoload!
36
+
37
+ @usdt_contexts.each do |usdt|
38
+ usdt.enumerate_active_probes.each do |probe|
39
+ attach_uprobe(name: probe.binpath, fn_name: probe.fn_name, addr: probe.addr, pid: probe.pid)
40
+ end
41
+ end
42
+
43
+ at_exit { self.cleanup }
44
+ end
45
+
46
+ def gen_args_from_usdt
47
+ ptr = Clib.bcc_usdt_genargs(@usdt_contexts.map(&:context).pack('J*'), @usdt_contexts.size)
48
+ code = ""
49
+ if !ptr || ptr.null?
50
+ return nil
51
+ end
52
+
53
+ idx = 0
54
+ while ptr[idx, 1] != "\x00"
55
+ idx += 1
56
+ end
57
+ ptr.size = idx + 1
58
+ ptr.to_s
30
59
  end
31
60
 
32
61
  def load_func(func_name, prog_type)
@@ -56,8 +85,48 @@ module RbBCC
56
85
  if fd < 0
57
86
  raise SystemCallError.new(Fiddle.last_error)
58
87
  end
59
- puts "Attach: #{event}"
60
- @kprobe_fds << fd
88
+ puts "Attach: #{ev_name}"
89
+ @kprobe_fds[ev_name] = fd
90
+ [ev_name, fd]
91
+ end
92
+
93
+ def attach_uprobe(name: "", sym: "", addr: nil, fn_name: "", pid: -1)
94
+ fn = load_func(fn_name, BPF::KPROBE)
95
+ ev_name = to_uprobe_evname("p", name, addr, pid)
96
+ fd = Clib.bpf_attach_uprobe(fn[:fd], 0, ev_name, name, addr, pid)
97
+ if fd < 0
98
+ raise SystemCallError.new(Fiddle.last_error)
99
+ end
100
+ puts "Attach: #{ev_name}"
101
+
102
+ @uprobe_fds[ev_name] = fd
103
+ [ev_name, fd]
104
+ end
105
+
106
+ def detach_kprobe_event(ev_name)
107
+ unless @kprobe_fds.keys.include?(ev_name)
108
+ raise "Event #{ev_name} not registered"
109
+ end
110
+ if Clib.bpf_close_perf_event_fd(@kprobe_fds[ev_name]) < 0
111
+ raise SystemCallError.new(Fiddle.last_error)
112
+ end
113
+ if Clib.bpf_detach_kprobe(ev_name) < 0
114
+ raise SystemCallError.new(Fiddle.last_error)
115
+ end
116
+ @kprobe_fds.delete(ev_name)
117
+ end
118
+
119
+ def detach_uprobe_event(ev_name)
120
+ unless @uprobe_fds.keys.include?(ev_name)
121
+ raise "Event #{ev_name} not registered"
122
+ end
123
+ if Clib.bpf_close_perf_event_fd(@uprobe_fds[ev_name]) < 0
124
+ raise SystemCallError.new(Fiddle.last_error)
125
+ end
126
+ if Clib.bpf_detach_uprobe(ev_name) < 0
127
+ raise SystemCallError.new(Fiddle.last_error)
128
+ end
129
+ @uprobe_fds.delete(ev_name)
61
130
  end
62
131
 
63
132
  def tracefile
@@ -65,7 +134,7 @@ module RbBCC
65
134
  end
66
135
 
67
136
  def trace_readline
68
- tracefile.readline(1024).rstrip
137
+ tracefile.readline(1024)
69
138
  end
70
139
 
71
140
  def trace_print(fmt: nil)
@@ -80,6 +149,32 @@ module RbBCC
80
149
  end
81
150
  end
82
151
 
152
+ def trace_fields(&do_each_line)
153
+ while buf = trace_readline
154
+ next if buf.start_with? "CPU:"
155
+ task = buf[0..15].lstrip()
156
+ meta, _addr, msg = buf[17..-1].split(": ")
157
+ pid, cpu, flags, ts = meta.split(" ")
158
+ cpu = cpu[1..-2]
159
+
160
+ do_each_line.call(task, pid, cpu, flags, ts, msg)
161
+ end
162
+ end
163
+
164
+ def cleanup
165
+ @kprobe_fds.each do |k, v|
166
+ detach_kprobe_event(k)
167
+ end
168
+
169
+ @uprobe_fds.each do |k, v|
170
+ detach_uprobe_event(k)
171
+ end
172
+
173
+ if @module
174
+ Clib.bpf_module_destroy(@module)
175
+ end
176
+ end
177
+
83
178
  private
84
179
  def trace_autoload!
85
180
  (0..Clib.bpf_num_functions(@module)).each do |i|
@@ -115,5 +210,13 @@ module RbBCC
115
210
  end
116
211
  return name
117
212
  end
213
+
214
+ def to_uprobe_evname(prefix, path, addr, pid)
215
+ if pid == -1
216
+ return "%s_%s_0x%x" % [prefix, path.gsub(/[^_a-zA-Z0-9]/, "_"), addr]
217
+ else
218
+ return "%s_%s_0x%x_%d" % [prefix, path.gsub(/[^_a-zA-Z0-9]/, "_"), addr, pid]
219
+ end
220
+ end
118
221
  end
119
222
  end
data/lib/rbbcc/clib.rb CHANGED
@@ -2,12 +2,23 @@ require 'fiddle/import'
2
2
 
3
3
  module RbBCC
4
4
  module Clib
5
+ def self.__extract_char(ptr)
6
+ return nil if ptr.null?
7
+ idx = 0
8
+ while ptr[idx, 1] != "\x00"
9
+ idx += 1
10
+ end
11
+ ptr.size = idx + 1
12
+ ptr.to_s
13
+ end
14
+
5
15
  extend Fiddle::Importer
6
16
  dlload "libbcc.so.0"
7
17
 
8
18
  extern 'void * bpf_module_create_c_from_string(char *, unsigned int, char **, int, long)'
9
19
  extern 'int bpf_num_functions(void *)'
10
20
  extern 'char * bpf_function_name(void *, int)'
21
+ extern 'void bpf_module_destroy(void *)'
11
22
 
12
23
  extern 'int bcc_func_load(void *, int, char *, void *, int, char *, unsigned int, int, char *, unsigned int)'
13
24
  extern 'void * bpf_function_start(void *, char *)'
@@ -15,6 +26,16 @@ module RbBCC
15
26
  extern 'char * bpf_module_license(void *)'
16
27
  extern 'unsigned int bpf_module_kern_version(void *)'
17
28
 
18
- extern 'int bpf_attach_kprobe(int, int, char *, char *, unsigned int, int)'
29
+ extern 'int bpf_attach_kprobe(int, int, char *, char *, unsigned long, int)'
30
+ extern 'int bpf_detach_kprobe(char *)'
31
+ extern 'int bpf_attach_uprobe(int, int, char *, char *, unsigned long, int)'
32
+ extern 'int bpf_detach_uprobe(char *)'
33
+ extern 'int bpf_open_perf_event(unsigned int, unsigned long, int, int)'
34
+ extern 'int bpf_close_perf_event_fd(int)'
35
+
36
+ extern 'void * bcc_usdt_new_frompid(int, char *)'
37
+ extern 'int bcc_usdt_enable_probe(void *, char *, char *)'
38
+ extern 'char * bcc_usdt_genargs(void **, int)'
39
+ extern 'void bcc_usdt_foreach_uprobe(void *, void *)'
19
40
  end
20
41
  end
data/lib/rbbcc/usdt.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'rbbcc/clib'
2
+
3
+ module RbBCC
4
+ USDTProbe = Struct.new(:binpath, :fn_name, :addr, :pid)
5
+
6
+ class USDT
7
+ # TODO path:
8
+ def initialize(pid:)
9
+ @pid = pid
10
+ @context = Clib.bcc_usdt_new_frompid(pid, nil)
11
+ if !@context || @context.null?
12
+ raise SystemCallError.new(Fiddle.last_error)
13
+ end
14
+ end
15
+ attr_reader :pid, :context
16
+
17
+ def enable_probe(probe:, fn_name:)
18
+ ret = Clib.bcc_usdt_enable_probe(@context, probe, fn_name)
19
+ if(ret < 0)
20
+ raise SystemCallError.new(Fiddle.last_error)
21
+ end
22
+ ret
23
+ end
24
+
25
+ def enumerate_active_probes
26
+ probes = []
27
+ callback = Clib.bind('void _usdt_cb(char *, char *, unsigned long long, int)') do |binpath, fn_name, addr, pid|
28
+ probe = USDTProbe.new(Clib.__extract_char(binpath), Clib.__extract_char(fn_name), addr, pid)
29
+ probes << probe
30
+ end
31
+
32
+ Clib.bcc_usdt_foreach_uprobe(@context, callback)
33
+
34
+ return probes
35
+ end
36
+ end
37
+ end
data/lib/rbbcc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RbBCC
2
- VERSION = "0.0.1.pre"
2
+ VERSION = "0.0.1"
3
3
  end
data/lib/rbbcc.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rbbcc/bcc"
2
2
  require "rbbcc/clib"
3
+ require "rbbcc/usdt"
3
4
  require "rbbcc/version"
4
5
 
5
6
  module RbBCC
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbcc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-28 00:00:00.000000000 Z
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -48,15 +48,21 @@ files:
48
48
  - ".gitignore"
49
49
  - Gemfile
50
50
  - Gemfile.lock
51
+ - LICENSE
51
52
  - README.md
52
53
  - Rakefile
53
54
  - bin/console
54
55
  - bin/setup
56
+ - examples/example.gif
57
+ - examples/extract_arg.rb
55
58
  - examples/hello_world.rb
59
+ - examples/usdt-test.rb
60
+ - examples/usdt.rb
56
61
  - lib/rbbcc.rb
57
62
  - lib/rbbcc/bcc.rb
58
63
  - lib/rbbcc/clib.rb
59
64
  - lib/rbbcc/consts.rb
65
+ - lib/rbbcc/usdt.rb
60
66
  - lib/rbbcc/version.rb
61
67
  - rbbcc.gemspec
62
68
  homepage: https://github.com/udzura/rbbcc
@@ -73,9 +79,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
79
  version: '0'
74
80
  required_rubygems_version: !ruby/object:Gem::Requirement
75
81
  requirements:
76
- - - ">"
82
+ - - ">="
77
83
  - !ruby/object:Gem::Version
78
- version: 1.3.1
84
+ version: '0'
79
85
  requirements: []
80
86
  rubygems_version: 3.0.3
81
87
  signing_key: