rbbcc 0.6.2 → 0.7.0

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: fb13ef05006088db3a3d16fdf3b5f444cd36a51c1d88278d5ddcb3ccb9e69663
4
- data.tar.gz: 9cded3bc218135ef79af4376a8973dedad2e3614ab5c93f49850799842c0e5c2
3
+ metadata.gz: 69a172609924d64c58b36abca26df8fc707505724961ac16d18355441e1d56ff
4
+ data.tar.gz: e567230d248ba2c79739efdaa3dab96ce302ace021df1639707ee0c7c11aeaa3
5
5
  SHA512:
6
- metadata.gz: a05af6a130f05942ce7f9901afc8d65434b7b5851483522f875ef3a9d75d1bcb30cafb1b8ce972feea2b273329e736182740d1cc99e561139d82fd1cccd297c4
7
- data.tar.gz: '0938ed389aa2b4159618c2c79ebd841e9c74160a8b40877b54075dff9590713f6ccc1d67c27593c13bd0e1bf9fe57d4296eb1a7d58e7f357526de7144e0b8ba4'
6
+ metadata.gz: 10a1ab7568b5c3798ab9e1e35c083bdcef1acabd08d730033283fbf971f9853154a6bff99c15b58b450a891b7bff450285d29c7e08067a2d63d523294f2a2dcd
7
+ data.tar.gz: fd5ea7879da82d203f22c6351d45b2811a3d5101d0b7996ad205406131c546a5b86fc85d2644066223e79746bd6ccd34106a791b9e239b013ff2a3787840cc27
data/.dockerignore ADDED
@@ -0,0 +1,4 @@
1
+ vendor/*
2
+ pkg/*
3
+ examples/*.gif
4
+ .git/*
@@ -0,0 +1,38 @@
1
+ name: Tests
2
+ on:
3
+ push:
4
+ branches: [ default ]
5
+ pull_request:
6
+ branches: [ default ]
7
+
8
+ jobs:
9
+ test:
10
+ strategy:
11
+ matrix:
12
+ libbcc_version: [0.17.0, 0.16.0, 0.12.0]
13
+ ruby_version: [2.7.2, 3.0.0]
14
+
15
+ runs-on: ubuntu-18.04
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Login to ghcr.io
19
+ run: |
20
+ echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u udzura --password-stdin
21
+ - name: Build docker container with all deps
22
+ run: |
23
+ docker build -t rbbcc-ci-${{ matrix.libbcc_version }}-${{ matrix.ruby_version }} \
24
+ -f ci/Dockerfile.${{ matrix.libbcc_version }}-${{ matrix.ruby_version }} ci/
25
+ - name: Run test
26
+ run: |
27
+ /bin/bash -c \
28
+ "docker run --privileged \
29
+ --pid=host \
30
+ -v $(pwd):/rbbcc \
31
+ -v /sys/kernel/debug:/sys/kernel/debug:rw \
32
+ -v /lib/modules:/lib/modules:ro \
33
+ -v /usr/src:/usr/src:ro \
34
+ -v /usr/include/linux:/usr/include/linux:ro \
35
+ rbbcc-ci-${{ matrix.libbcc_version }}-${{ matrix.ruby_version }} \
36
+ /bin/bash -c \
37
+ 'cd /rbbcc && bundle install && bundle exec rake test'"
38
+
data/Dockerfile.ci ADDED
@@ -0,0 +1,98 @@
1
+ # ref: https://github.com/iovisor/bcc/blob/master/Dockerfile.tests
2
+ FROM ubuntu:18.04
3
+
4
+ ENV LLVM_VERSION="9"
5
+
6
+ ARG BCC_VERSION="0.16.0"
7
+ ENV BCC_VERSION=$BCC_VERSION
8
+
9
+ ARG RUBY_VERSION="2.7.2"
10
+ ENV RUBY_VERSION=$RUBY_VERSION
11
+
12
+ ARG RUBY_VERSION_ARCHIVE="ruby-${RUBY_VERSION}.tar.bz2"
13
+ ENV RUBY_VERSION_ARCHIVE=$RUBY_VERSION_ARCHIVE
14
+
15
+ ARG RUBY_EXTRA_OPTS=""
16
+ ENV RUBY_EXTRA_OPTS=$RUBY_EXTRA_OPTS
17
+
18
+ ARG BCC_EXTRA_OPTS=""
19
+ ENV BCC_EXTRA_OPTS=$BCC_EXTRA_OPTS
20
+
21
+ RUN apt-get update && apt-get install -y curl gnupg && \
22
+ llvmRepository="\n\
23
+ deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main\n\
24
+ deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main\n\
25
+ deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${LLVM_VERSION} main\n\
26
+ deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${LLVM_VERSION} main\n" && \
27
+ echo $llvmRepository >> /etc/apt/sources.list && \
28
+ curl -L https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
29
+ apt-get update && apt-get install -y \
30
+ util-linux \
31
+ bison \
32
+ binutils-dev \
33
+ cmake \
34
+ flex \
35
+ g++ \
36
+ git \
37
+ kmod \
38
+ wget \
39
+ libelf-dev \
40
+ zlib1g-dev \
41
+ libiberty-dev \
42
+ libbfd-dev \
43
+ libedit-dev \
44
+ clang-${LLVM_VERSION} \
45
+ libclang-${LLVM_VERSION}-dev \
46
+ libclang-common-${LLVM_VERSION}-dev \
47
+ libclang1-${LLVM_VERSION} \
48
+ llvm-${LLVM_VERSION} \
49
+ llvm-${LLVM_VERSION}-dev \
50
+ llvm-${LLVM_VERSION}-runtime \
51
+ libllvm${LLVM_VERSION} \
52
+ systemtap-sdt-dev \
53
+ sudo \
54
+ iproute2 \
55
+ iputils-ping \
56
+ bridge-utils \
57
+ libtinfo5 \
58
+ libtinfo-dev && \
59
+ wget -O ruby-install-0.7.1.tar.gz \
60
+ https://github.com/postmodern/ruby-install/archive/v0.7.1.tar.gz && \
61
+ tar -xzvf ruby-install-0.7.1.tar.gz && \
62
+ cd ruby-install-0.7.1/ && \
63
+ make install && \
64
+ sed -i 's/^ruby_archive=.*/ruby_archive="${ruby_archive:-ruby-$ruby_version.tar.bz2}"/' /usr/local/share/ruby-install/ruby/functions.sh && \
65
+ env ruby_archive=$RUBY_VERSION_ARCHIVE ruby-install --system $RUBY_EXTRA_OPTS ruby $RUBY_VERSION && \
66
+ git config --global user.name 'udzura' && \
67
+ git config --global user.email 'udzura@udzura.jp' && \
68
+ wget -O bcc-$BCC_VERSION.tar.gz \
69
+ https://github.com/iovisor/bcc/releases/download/v$BCC_VERSION/bcc-src-with-submodule.tar.gz && \
70
+ tar -xzvf bcc-$BCC_VERSION.tar.gz && \
71
+ cd bcc/ && \
72
+ ( test "$BCC_VERSION" = "0.12.0" && curl https://github.com/iovisor/bcc/commit/977a7e3a568c4c929fabeb4a025528d9b6f1e84c.patch | patch -p1 || true ) && \
73
+ git init . && git add . && git commit -m 'Dummy' && git tag v$BCC_VERSION && \
74
+ mkdir build && cd build/ && \
75
+ cmake $BCC_EXTRA_OPTS -DCMAKE_BUILD_TYPE=Release .. && \
76
+ cd src/cc && \
77
+ make -j8 && make install && \
78
+ cd ../.. && \
79
+ apt-get remove --purge -y \
80
+ binutils-dev \
81
+ libelf-dev \
82
+ zlib1g-dev \
83
+ libiberty-dev \
84
+ libbfd-dev \
85
+ libedit-dev \
86
+ clang-${LLVM_VERSION} \
87
+ libclang-${LLVM_VERSION}-dev \
88
+ libclang-common-${LLVM_VERSION}-dev \
89
+ libclang1-${LLVM_VERSION} \
90
+ llvm-${LLVM_VERSION} \
91
+ llvm-${LLVM_VERSION}-dev \
92
+ llvm-${LLVM_VERSION}-runtime \
93
+ libllvm${LLVM_VERSION} \
94
+ systemtap-sdt-dev \
95
+ libtinfo-dev && \
96
+ apt autoremove -y && \
97
+ apt-get clean -y && \
98
+ rm -rf *.tar.gz bcc/
data/Gemfile CHANGED
@@ -7,3 +7,12 @@ gem "bundler", "~> 2.0"
7
7
  gem "rake", "~> 13.0"
8
8
  gem "pry", "~> 0.12"
9
9
  gem "minitest", ">= 5"
10
+
11
+ group :omnibus_package do
12
+ gem "appbundler"
13
+ gem "specific_install"
14
+ end
15
+
16
+ group :plugin_dev do
17
+ gem "rbbcc-hello", git: "https://github.com/udzura/rbbcc-hello.git"
18
+ end
data/Gemfile.lock CHANGED
@@ -1,28 +1,49 @@
1
+ GIT
2
+ remote: https://github.com/udzura/rbbcc-hello.git
3
+ revision: 2e1af47d22e7cc92e970dc6c058e113cf00821db
4
+ specs:
5
+ rbbcc-hello (0.1.0)
6
+ rbbcc
7
+
1
8
  PATH
2
9
  remote: .
3
10
  specs:
4
- rbbcc (0.6.2)
11
+ rbbcc (0.7.0)
5
12
 
6
13
  GEM
7
14
  remote: https://rubygems.org/
8
15
  specs:
16
+ appbundler (0.13.4)
17
+ mixlib-cli (>= 1.4, < 3.0)
18
+ mixlib-shellout (>= 2.0, < 4.0)
19
+ chef-utils (17.10.0)
20
+ concurrent-ruby
9
21
  coderay (1.1.3)
22
+ concurrent-ruby (1.1.10)
10
23
  method_source (1.0.0)
11
- minitest (5.14.2)
12
- pry (0.13.1)
24
+ minitest (5.16.1)
25
+ mixlib-cli (2.1.8)
26
+ mixlib-shellout (3.2.7)
27
+ chef-utils
28
+ pry (0.14.1)
13
29
  coderay (~> 1.1)
14
30
  method_source (~> 1.0)
15
- rake (13.0.1)
31
+ rake (13.0.6)
32
+ specific_install (0.3.7)
16
33
 
17
34
  PLATFORMS
18
- ruby
35
+ aarch64-linux
36
+ arm64-darwin-21
19
37
 
20
38
  DEPENDENCIES
39
+ appbundler
21
40
  bundler (~> 2.0)
22
41
  minitest (>= 5)
23
42
  pry (~> 0.12)
24
43
  rake (~> 13.0)
25
44
  rbbcc!
45
+ rbbcc-hello!
46
+ specific_install
26
47
 
27
48
  BUNDLED WITH
28
- 2.1.4
49
+ 2.3.16
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RbBCC
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/rbbcc.svg)](https://badge.fury.io/rb/rbbcc) [![CI status](https://udzura.semaphoreci.com/badges/rbbcc.svg)](https://udzura.semaphoreci.com/projects/rbbcc)
3
+ [![Gem Version](https://badge.fury.io/rb/rbbcc.svg)](https://badge.fury.io/rb/rbbcc) [![CI Status](https://github.com/udzura/rbbcc/workflows/Tests/badge.svg)](https://github.com/udzura/rbbcc/actions?query=workflow%3ATests)
4
4
 
5
5
  RbBCC is a port of [BCC](https://github.com/iovisor/bcc) in MRI. See iovisor project page.
6
6
 
@@ -0,0 +1 @@
1
+ FROM ghcr.io/udzura/rbbcc-ci-images:libbcc-0.12.0
@@ -0,0 +1 @@
1
+ FROM ghcr.io/udzura/rbbcc-ci-images:libbcc-0.12.0-ruby-3.0.0
@@ -0,0 +1 @@
1
+ FROM ghcr.io/udzura/rbbcc-ci-images:libbcc-0.16.0
@@ -0,0 +1 @@
1
+ FROM ghcr.io/udzura/rbbcc-ci-images:libbcc-0.16.0-ruby-3.0.0
@@ -0,0 +1 @@
1
+ FROM ghcr.io/udzura/rbbcc-ci-images:libbcc-0.17.0
@@ -0,0 +1 @@
1
+ FROM ghcr.io/udzura/rbbcc-ci-images:libbcc-0.17.0-ruby-3.0.0
data/examples/bitehist.rb CHANGED
@@ -17,7 +17,7 @@ b = BCC.new(text: <<CLANG)
17
17
  BPF_HISTOGRAM(dist);
18
18
  BPF_HISTOGRAM(dist_linear);
19
19
 
20
- int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req)
20
+ int kprobe__blk_account_io_done(struct pt_regs *ctx, struct request *req)
21
21
  {
22
22
  dist.increment(bpf_log2l(req->__data_len / 1024));
23
23
  dist_linear.increment(req->__data_len / 1024);
@@ -38,10 +38,14 @@ require 'rbbcc'
38
38
  include RbBCC
39
39
 
40
40
  $pid = nil
41
+ $comm = nil
41
42
 
42
43
  if ARGV.size == 2 &&
43
44
  ARGV[0] == '-p'
44
45
  $pid = ARGV[1].to_i
46
+ elsif ARGV.size == 2 &&
47
+ ARGV[0] == '-c'
48
+ $comm = ARGV[1]
45
49
  elsif ARGV[0] == '-h' ||
46
50
  ARGV[0] == '--help'
47
51
  $stderr.puts "Usage: #{$0} [-p PID]"
@@ -77,11 +81,15 @@ BPF_HASH(store, struct key_t, struct leaf_t);
77
81
  TRACEPOINT_PROBE(raw_syscalls, sys_enter) {
78
82
  struct key_t key = {0};
79
83
  struct leaf_t initial = {0}, *val_;
84
+ char comm[16];
80
85
 
81
- key.pid = bpf_get_current_pid_tgid();
86
+ // key.pid = bpf_get_current_pid_tgid();
87
+ key.pid = (bpf_get_current_pid_tgid() >> 32);
82
88
  key.syscall_nr = args->id;
83
89
 
84
90
  DO_FILTER_BY_PID
91
+ bpf_get_current_comm(&comm, sizeof(comm));
92
+ DO_FILTER_BY_COMM
85
93
 
86
94
  val_ = store.lookup_or_try_init(&key, &initial);
87
95
  if (val_) {
@@ -98,15 +106,17 @@ TRACEPOINT_PROBE(raw_syscalls, sys_exit) {
98
106
  struct key_t key = {0};
99
107
  struct leaf_t *val_;
100
108
 
101
- key.pid = bpf_get_current_pid_tgid();
109
+ key.pid = (bpf_get_current_pid_tgid() >> 32);
102
110
  key.syscall_nr = args->id;
103
111
 
104
112
  val_ = store.lookup(&key);
105
113
  if (val_) {
106
114
  struct leaf_t val = *val_;
107
- u64 delta = bpf_ktime_get_ns() - val.enter_ns;
108
- val.enter_ns = 0;
109
- val.elapsed_ns += delta;
115
+ if(val.enter_ns) {
116
+ u64 delta = bpf_ktime_get_ns() - val.enter_ns;
117
+ val.enter_ns = 0;
118
+ val.elapsed_ns += delta;
119
+ }
110
120
  store.update(&key, &val);
111
121
  }
112
122
  return 0;
@@ -121,6 +131,22 @@ else
121
131
  prog.sub!('DO_FILTER_BY_PID', '')
122
132
  end
123
133
 
134
+ if $comm
135
+ prog.sub!('DO_FILTER_BY_COMM', <<~FILTER)
136
+ int idx;
137
+ int matched = 1;
138
+ char *needle = "#{$comm}";
139
+ for(idx=0;idx<sizeof(comm);++idx) {
140
+ if (comm[idx] != needle[idx]) matched = 0;
141
+ if (!needle[idx]) break;
142
+ if (!comm[idx]) break;
143
+ }
144
+ if(!matched) return 0;
145
+ FILTER
146
+ else
147
+ prog.sub!('DO_FILTER_BY_COMM', '')
148
+ end
149
+
124
150
  b = BCC.new(text: prog)
125
151
 
126
152
  puts "Collecting syscalls..."
@@ -134,14 +160,15 @@ info_by_pids = {}
134
160
  comms = {}
135
161
  store = b.get_table("store")
136
162
  store.items.each do |k, v|
137
- # require 'pry'; binding.pry
163
+ #require 'pry'; binding.pry
164
+ count, elapsed_ns, _dummy, comm = v[0, 40].unpack("Q Q Q Z16")
138
165
  info_by_pids[k.pid] ||= {}
139
166
  info_by_pids[k.pid][k.syscall_nr] = {
140
167
  name: to_name(k.syscall_nr),
141
- count: v.count,
142
- elapsed_ms: v.elapsed_ns / 1000000.0
168
+ count: count,
169
+ elapsed_ms: elapsed_ns / 1000000.0
143
170
  }
144
- comms[k.pid] ||= v.comm
171
+ comms[k.pid] ||= comm
145
172
  end
146
173
 
147
174
  pids = info_by_pids.keys.sort
@@ -149,7 +176,7 @@ pids.each do |pid|
149
176
  puts "PID=#{pid}(maybe: #{comms[pid]}) --->"
150
177
  i = info_by_pids[pid]
151
178
  i.to_a.sort_by {|k, v| [-v[:count], -v[:elapsed_ms]] }.each do |nr, record|
152
- puts "\t%<name>-20s %<count>3d %<elapsed_ms>8.3f ms" % record
179
+ puts "\t%<name>-22s %<count>7d %<elapsed_ms>10.3f ms" % record
153
180
  end
154
181
  puts
155
182
  end
@@ -33,7 +33,7 @@ def find_libc_location
33
33
  if File.exist?('/lib/x86_64-linux-gnu/libc.so.6')
34
34
  '/lib/x86_64-linux-gnu/libc.so.6'
35
35
  else
36
- `find /lib -name 'libc.so*' | grep -v musl | head -1`.chomp
36
+ `find /lib/ -name 'libc.so*' | tail -1`.chomp
37
37
  end
38
38
  end
39
39
 
data/exe/rbbcc CHANGED
@@ -1,4 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- binpath = File.readlink "/proc/self/exe"
4
- exec binpath, *ARGV
3
+ if ARGV[0] == '-v' || ARGV[0] == '--version'
4
+ require 'rbbcc/version'
5
+ print "RbBCC: version "
6
+ puts RbBCC::VERSION
7
+ print "Using "
8
+ puts RUBY_DESCRIPTION
9
+ elsif ARGV[0] == '--invoke'
10
+ require 'rbbcc/invoker'
11
+ ARGV.shift
12
+ RbBCC::Invoker.new(ARGV).run
13
+ else
14
+ binpath = File.readlink "/proc/self/exe"
15
+ exec binpath, *ARGV
16
+ end
data/lib/rbbcc/bcc.rb CHANGED
@@ -220,7 +220,7 @@ module RbBCC
220
220
  end
221
221
  end
222
222
 
223
- def initialize(text: "", src_file: nil, hdr_file: nil, debug: 0, cflags: [], usdt_contexts: [], allow_rlimit: 0)
223
+ def initialize(text: "", src_file: nil, hdr_file: nil, debug: 0, cflags: [], usdt_contexts: [], allow_rlimit: 0, dev_name: nil)
224
224
  @kprobe_fds = {}
225
225
  @uprobe_fds = {}
226
226
  @tracepoint_fds = {}
@@ -232,7 +232,7 @@ module RbBCC
232
232
  end
233
233
 
234
234
  if src_file && src_file.end_with?(".b")
235
- @module = Clib.bpf_module_create_b(src_file, hdr_file, debug, device)
235
+ @module = Clib.bpf_module_create_b(src_file, hdr_file, debug, dev_name)
236
236
  else
237
237
  if src_file
238
238
  text = File.read(src_file)
@@ -250,12 +250,13 @@ module RbBCC
250
250
  cflags
251
251
  end
252
252
 
253
- @module = Clib.bpf_module_create_c_from_string(
253
+ @module = Clib.do_bpf_module_create_c_from_string(
254
254
  text,
255
255
  debug,
256
256
  cflags_safe.pack("p*"),
257
257
  cflags_safe.size,
258
- allow_rlimit
258
+ allow_rlimit,
259
+ dev_name
259
260
  )
260
261
  end
261
262
  @funcs = {}
@@ -479,6 +480,7 @@ module RbBCC
479
480
  def trace_fields(&do_each_line)
480
481
  ret = []
481
482
  while buf = trace_readline
483
+ next if buf.chomp.empty?
482
484
  next if buf.start_with? "CPU:"
483
485
  task = buf[0..15].lstrip()
484
486
  meta, _addr, msg = buf[17..-1].split(": ", 3)
data/lib/rbbcc/clib.rb CHANGED
@@ -25,7 +25,7 @@ module RbBCC
25
25
  end
26
26
 
27
27
  extend Fiddle::Importer
28
- targets = %w(0.17.0 0.16.0 0.15.0 0.14.0 0.13.0 0.12.0 0.11.0 0.10.0)
28
+ targets = %w(0.18.0 0.17.0 0.16.0 0.15.0 0.14.0 0.13.0 0.12.0 0.11.0 0.10.0)
29
29
  if default_load = ENV['LIBBCC_VERSION']
30
30
  targets.unshift(default_load)
31
31
  targets.uniq!
@@ -44,24 +44,38 @@ module RbBCC
44
44
  end
45
45
  typealias "size_t", "int"
46
46
 
47
- extern 'void * bpf_module_create_c_from_string(char *, unsigned int, char **, int, long)'
48
47
  extern 'void * bpf_module_create_b(char *filename, char *proto_filename, unsigned int flags, char *dev_name)'
49
48
  extern 'int bpf_num_functions(void *)'
50
49
  extern 'char * bpf_function_name(void *, int)'
51
50
  extern 'void bpf_module_destroy(void *)'
52
51
 
53
52
  if libbcc_version_gteq?("0.11.0")
53
+ extern 'void * bpf_module_create_c_from_string(
54
+ const char *text, unsigned int flags, const char *cflags[],
55
+ int ncflags, int allow_rlimit,
56
+ const char *dev_name)'
54
57
  extern 'int bcc_func_load(
55
58
  void *program, int prog_type, const char *name,
56
59
  const struct bpf_insn *insns, int prog_len,
57
60
  const char *license, unsigned int kern_version,
58
61
  int log_level, char *log_buf, unsigned int log_buf_size,
59
62
  const char *dev_name)'
63
+ def self.do_bpf_module_create_c_from_string(text, flags, cflags, ncflags, allow_limit, dev_name)
64
+ bpf_module_create_c_from_string(text, flags, cflags, ncflags, allow_limit, dev_name)
65
+ end
66
+
60
67
  def self.do_bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size, device)
61
68
  bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size, device)
62
69
  end
63
70
  else
71
+ extern 'void * bpf_module_create_c_from_string(
72
+ const char *text, unsigned int flags, const char *cflags[],
73
+ int ncflags, int allow_rlimit)'
64
74
  extern 'int bcc_func_load(void *, int, char *, void *, int, char *, unsigned int, int, char *, unsigned int)'
75
+ def self.do_bpf_module_create_c_from_string(text, flags, cflags, ncflags, allow_limit, dev_name=nil)
76
+ bpf_module_create_c_from_string(text, flags, cflags, ncflags, allow_limit)
77
+ end
78
+
65
79
  def self.do_bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size, device)
66
80
  bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size)
67
81
  end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'rbbcc/plugin'
3
+
4
+ module RbBCC
5
+ class Invoker
6
+ def initialize(args)
7
+ @command = args.shift
8
+ raise "Invalid option. Please specify script name" unless @command
9
+
10
+ args.shift if args[0] == '--'
11
+ @args = args
12
+ end
13
+
14
+ def run
15
+ plugins = Gem::Specification
16
+ .find_all
17
+ .select{|s| s.name =~ /^rbbcc-/ }
18
+ .map(&:name)
19
+ plugins.each {|n| require n }
20
+
21
+ script = RbBCC::Plugin.find_script_name(@command)
22
+ raise Errno::ENOENT, "Script not found: #{@command}" unless script
23
+
24
+ binpath = File.readlink "/proc/self/exe"
25
+ Process.exec binpath, script, *@args
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module RbBCC
2
+ module Plugin
3
+ ScriptLocation = Struct.new(:name, :location)
4
+
5
+ def self.scripts
6
+ @scripts ||= []
7
+ end
8
+
9
+ def self.find_script_name(name)
10
+ scripts.find{|s|
11
+ s.name == name || "#{s.name}.rb" == name
12
+ }&.location
13
+ end
14
+
15
+ def self.register!
16
+ caller_loc = caller[0].split(':')[0]
17
+ plugin_loc = File.expand_path("../../script", caller_loc)
18
+ unless File.directory?(plugin_loc)
19
+ raise "Cannot find a script directory #{plugin_loc}. Maybe an invalid project"
20
+ end
21
+
22
+ found = Dir.glob("#{plugin_loc}/*.rb")
23
+ .map{|path| ScriptLocation.new File.basename(path, '.rb'), path }
24
+ self.scripts.concat found
25
+ self.scripts
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module RbBCC
2
+ class Pointer
3
+ def initialize(p, value_type: nil, size: nil)
4
+ @raw_pointer = p
5
+ @size = size || p.size
6
+ @value_type = value_type
7
+ end
8
+
9
+ attr_reader :raw_pointer
10
+
11
+ def value
12
+
13
+ end
14
+ end
15
+ end
data/lib/rbbcc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RbBCC
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/rbbcc.rb CHANGED
@@ -1,9 +1,10 @@
1
+ module RbBCC
2
+ autoload :Plugin, 'rbbcc/plugin'
3
+ end
4
+
1
5
  require "rbbcc/fiddle_ext"
2
6
  require "rbbcc/bcc"
3
7
  require "rbbcc/clib"
4
8
  require "rbbcc/usdt"
5
9
  require "rbbcc/symbol_cache"
6
10
  require "rbbcc/version"
7
-
8
- module RbBCC
9
- end
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.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: BCC port for MRI. See https://github.com/iovisor/bcc
14
14
  email:
@@ -18,9 +18,11 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".dockerignore"
22
+ - ".github/workflows/ci.yml"
21
23
  - ".gitignore"
22
- - ".semaphore/semaphore.yml"
23
24
  - Dockerfile
25
+ - Dockerfile.ci
24
26
  - Dockerfile.dfm-example
25
27
  - Gemfile
26
28
  - Gemfile.lock
@@ -29,6 +31,12 @@ files:
29
31
  - Rakefile
30
32
  - bin/console
31
33
  - bin/setup
34
+ - ci/Dockerfile.0.12.0-2.7.2
35
+ - ci/Dockerfile.0.12.0-3.0.0
36
+ - ci/Dockerfile.0.16.0-2.7.2
37
+ - ci/Dockerfile.0.16.0-3.0.0
38
+ - ci/Dockerfile.0.17.0-2.7.2
39
+ - ci/Dockerfile.0.17.0-3.0.0
32
40
  - docs/README.md
33
41
  - docs/answers/01-hello-world.rb
34
42
  - docs/answers/02-sys_sync.rb
@@ -87,6 +95,9 @@ files:
87
95
  - lib/rbbcc/debug.rb
88
96
  - lib/rbbcc/disp_helper.rb
89
97
  - lib/rbbcc/fiddle_ext.rb
98
+ - lib/rbbcc/invoker.rb
99
+ - lib/rbbcc/plugin.rb
100
+ - lib/rbbcc/pointer.rb
90
101
  - lib/rbbcc/symbol_cache.rb
91
102
  - lib/rbbcc/table.rb
92
103
  - lib/rbbcc/usdt.rb
@@ -98,7 +109,7 @@ homepage: https://github.com/udzura/rbbcc
98
109
  licenses:
99
110
  - Apache-2.0
100
111
  metadata: {}
101
- post_install_message:
112
+ post_install_message:
102
113
  rdoc_options: []
103
114
  require_paths:
104
115
  - lib
@@ -113,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
124
  - !ruby/object:Gem::Version
114
125
  version: '0'
115
126
  requirements: []
116
- rubygems_version: 3.1.2
117
- signing_key:
127
+ rubygems_version: 3.4.0.dev
128
+ signing_key:
118
129
  specification_version: 4
119
130
  summary: BCC port for MRI
120
131
  test_files: []
@@ -1,21 +0,0 @@
1
- version: v1.0
2
- name: Ruby Test
3
- agent:
4
- machine:
5
- type: e1-standard-2
6
- os_image: ubuntu1804
7
- blocks:
8
- - name: Basic Test
9
- task:
10
- jobs:
11
- - name: ruby test
12
- matrix:
13
- - env_var: RUBY_VERSION
14
- values: [ "2.6.5", "2.6.6", "2.7.1" ]
15
- - env_var: LIBBCC_VERSION
16
- values: [ "0.12.0", "0.11.0", "0.10.0" ]
17
- commands:
18
- - sem-version c 7
19
- - sem-version ruby $RUBY_VERSION
20
- - checkout
21
- - ./semaphore.sh