rbbcc 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d467cf3f971af1d5a6cc25342768dc87c50edd97cc236fa2610e4de5a49fe45
4
- data.tar.gz: 83495ff5a1dc88c671db426690e1075641cb50dd6734f078a8e082f32a148e4e
3
+ metadata.gz: a1911b0a6e9450e76b3fda2c56c45bfc17846638e1ca99e64e983d99f99dff64
4
+ data.tar.gz: e4841d103a87ee45ced700ea7dff562a305e1cbf1172ef35da40be063d4ee698
5
5
  SHA512:
6
- metadata.gz: 35f38c830eb046b72da90dddff2e9f6e050a34b0c0bb82c372bdcc144ab82bab3ba3e8ec6450879f3d086f7d4437f99fdb55b54f4b204974c9fa0fb2940892bc
7
- data.tar.gz: 9f14a1979cf8892920b443915f5773e743562ae5f391ed0e9bdbaa97d0524932f0c4fa1a5397f4987a0e5c4bf2d404755c6eb55bd0cd6a687279fcce4bc66e63
6
+ metadata.gz: fd3aba48720c19d46efa02eac50fd758e883306616bb14068e13c4062f8d8efd4f9852b2b5d7f8eded678a9954e36070cb13f2be99c271b6983ab8ec75e53807
7
+ data.tar.gz: 63170a77e06d0c15d5dac6eed68112232b475259fcce7a07f4c99ba21baf9df0e85faa307fa2c868afc4aea9888ac7b4779188f03e0cd40d0cbedfab28c41873
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbbcc (0.1.1)
4
+ rbbcc (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,7 +4,7 @@ RbBCC is a project to utilize the power of eBPF/BCC from Ruby.
4
4
 
5
5
  ## Setup
6
6
 
7
- RbBCC requires `libbcc.so` version **0.10.0**(we plan to support newer version of libbcc, but it may be done after rbbcc 1.0...).
7
+ RbBCC requires `libbcc.so` version **0.11.0 or 0.10.0**(we plan to support newer version of libbcc, such as 0.12.0; but it may be done after rbbcc 1.0...).
8
8
 
9
9
  BTW we do not need to install header files, becuase current version of RbBCC uses the functionality of libbcc via ffi(We use MRI's standard library **fiddle**, not external gems).
10
10
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gem "rbbcc", path: '../../'
8
+ gem "charty", path: '/usr/local/ghq/github.com/udzura/charty'
9
+ gem "unicode_plot"
10
+ gem "numo"
11
+ gem "matplotlib"
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ rbbcc (0.2.0)
5
+
6
+ PATH
7
+ remote: /usr/local/ghq/github.com/udzura/charty
8
+ specs:
9
+ charty (0.2.2)
10
+ red-colors
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ enumerable-statistics (2.0.1)
16
+ matplotlib (1.1.0)
17
+ pycall (>= 1.0.0)
18
+ numo (0.1.1)
19
+ numo-fftw (~> 0.1.1)
20
+ numo-gnuplot (~> 0.2.4)
21
+ numo-gsl (~> 0.1.1)
22
+ numo-linalg (~> 0.1.0)
23
+ numo-narray (~> 0.9.1)
24
+ numo-fftw (0.1.1)
25
+ numo-narray (~> 0.9.0)
26
+ numo-gnuplot (0.2.4)
27
+ numo-gsl (0.1.2)
28
+ numo-narray (>= 0.9.0.8)
29
+ numo-linalg (0.1.5)
30
+ numo-narray (>= 0.9.1.4)
31
+ numo-narray (0.9.1.6)
32
+ pycall (1.3.0)
33
+ red-colors (0.1.1)
34
+ unicode_plot (0.0.4)
35
+ enumerable-statistics (>= 2.0.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ charty!
42
+ matplotlib
43
+ numo
44
+ rbbcc!
45
+ unicode_plot
46
+
47
+ BUNDLED WITH
48
+ 2.0.2
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # bitehist.rb, ported from bitehist.py. See license on that file
4
+ #
5
+ # Written as a basic example of using histograms to show a distribution.
6
+ #
7
+ # A Ctrl-C will print the gathered histogram then exit.
8
+ #
9
+
10
+ require 'rbbcc'
11
+ include RbBCC
12
+
13
+ b = BCC.new(text: <<CLANG)
14
+ #include <uapi/linux/ptrace.h>
15
+ #include <linux/blkdev.h>
16
+
17
+ BPF_HISTOGRAM(dist);
18
+ BPF_HISTOGRAM(dist_linear);
19
+
20
+ int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req)
21
+ {
22
+ dist.increment(bpf_log2l(req->__data_len / 1024));
23
+ dist_linear.increment(req->__data_len / 1024);
24
+ return 0;
25
+ }
26
+ CLANG
27
+
28
+ puts "Tracing... Hit Ctrl-C to end."
29
+
30
+ loop do
31
+ begin
32
+ sleep 0.1
33
+ rescue Interrupt
34
+ puts
35
+ break
36
+ end
37
+ end
38
+
39
+ require 'unicode_plot'
40
+ def log2hist_unicode(table)
41
+ strip_leading_zero = true
42
+ vals = Array.new($log2_index_max) { 0 }
43
+ data = {}
44
+ table.each_pair do |k, v|
45
+ vals[k.to_bcc_value] = v.to_bcc_value
46
+ end
47
+
48
+ log2_dist_max = 64
49
+ idx_max = -1
50
+ val_max = 0
51
+
52
+ vals.each_with_index do |v, i|
53
+ idx_max = i if v > 0
54
+ val_max = v if v > val_max
55
+ end
56
+
57
+ (1...(idx_max + 1)).each do |i|
58
+ low = (1 << i) >> 1
59
+ high = (1 << i)
60
+ if (low == high)
61
+ low -= 1
62
+ end
63
+ val = vals[i]
64
+
65
+ if strip_leading_zero
66
+ if val
67
+ data["[#{low}, #{high})"] = val
68
+ strip_leading_zero = false
69
+ end
70
+ else
71
+ data["[#{low}, #{high})"] = val
72
+ end
73
+ end
74
+
75
+ unless data.empty?
76
+ puts UnicodePlot.barplot(ylabel: "kbytes", data: data, title: "log2 histogram", color: :magenta).render
77
+ else
78
+ puts "No sample found."
79
+ end
80
+ end
81
+
82
+ log2hist_unicode b["dist"]
83
+
84
+ # puts
85
+ # puts "linear histogram"
86
+ # puts "~~~~~~~~~~~~~~~~"
87
+ # b["dist_linear"].print_linear_hist("kbytes")
@@ -57,7 +57,7 @@ parser.on_tail("-h", "--help", "show this help message and exit") do
57
57
  end
58
58
 
59
59
  parser.parse!
60
- args.max_arges ||= "20"
60
+ args.max_args ||= "20"
61
61
 
62
62
  bpf_text = <<CLANG
63
63
  #include <uapi/linux/ptrace.h>
data/lib/rbbcc/bcc.rb CHANGED
@@ -210,18 +210,18 @@ module RbBCC
210
210
  Clib.__extract_char ptr
211
211
  end
212
212
 
213
- def load_func(func_name, prog_type)
213
+ def load_func(func_name, prog_type, device: nil)
214
214
  if @funcs.keys.include?(func_name)
215
215
  return @funcs[func_name]
216
216
  end
217
217
 
218
218
  log_level = 0
219
- fd = Clib.bcc_func_load(@module, prog_type, func_name,
219
+ fd = Clib.do_bcc_func_load(@module, prog_type, func_name,
220
220
  Clib.bpf_function_start(@module, func_name),
221
221
  Clib.bpf_function_size(@module, func_name),
222
222
  Clib.bpf_module_license(@module),
223
223
  Clib.bpf_module_kern_version(@module),
224
- log_level, nil, 0);
224
+ log_level, nil, 0, device);
225
225
  if fd < 0
226
226
  raise SystemCallError.new(Fiddle.last_error)
227
227
  end
data/lib/rbbcc/clib.rb CHANGED
@@ -12,8 +12,29 @@ module RbBCC
12
12
  ptr.to_s
13
13
  end
14
14
 
15
+ def self.libbcc_version=(ver)
16
+ @@libbcc_version ||= Gem::Version.new(ver)
17
+ end
18
+
19
+ def self.libbcc_version
20
+ @@libbcc_version
21
+ end
22
+
23
+ def self.libbcc_version_gteq?(ver)
24
+ @@libbcc_version >= Gem::Version.new(ver)
25
+ end
26
+
15
27
  extend Fiddle::Importer
16
- dlload "libbcc.so.0.10.0"
28
+ begin
29
+ default_load = ENV['LIBBCC_VERSION'] || "0.11.0"
30
+
31
+ dlload "libbcc.so.#{default_load}"
32
+ self.libbcc_version = default_load
33
+ rescue Fiddle::DLError => e
34
+ warn "Fall back to libbcc 0.10.0: #{e.inspect}"
35
+ dlload "libbcc.so.0.10.0"
36
+ self.libbcc_version = "0.10.0"
37
+ end
17
38
  typealias "size_t", "int"
18
39
 
19
40
  extern 'void * bpf_module_create_c_from_string(char *, unsigned int, char **, int, long)'
@@ -21,7 +42,23 @@ module RbBCC
21
42
  extern 'char * bpf_function_name(void *, int)'
22
43
  extern 'void bpf_module_destroy(void *)'
23
44
 
24
- extern 'int bcc_func_load(void *, int, char *, void *, int, char *, unsigned int, int, char *, unsigned int)'
45
+ if libbcc_version_gteq?("0.11.0")
46
+ extern 'int bcc_func_load(
47
+ void *program, int prog_type, const char *name,
48
+ const struct bpf_insn *insns, int prog_len,
49
+ const char *license, unsigned int kern_version,
50
+ int log_level, char *log_buf, unsigned int log_buf_size,
51
+ const char *dev_name)'
52
+ def self.do_bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size, device)
53
+ bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size, device)
54
+ end
55
+ else
56
+ extern 'int bcc_func_load(void *, int, char *, void *, int, char *, unsigned int, int, char *, unsigned int)'
57
+ def self.do_bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size, device)
58
+ bcc_func_load(mod, prog_type, name, insns, len, license, kver, loglv, buf, buf_size)
59
+ end
60
+ end
61
+
25
62
  extern 'void * bpf_function_start(void *, char *)'
26
63
  extern 'int bpf_function_size(void *, char *)'
27
64
  extern 'char * bpf_module_license(void *)'
data/lib/rbbcc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RbBCC
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,9 @@ files:
72
72
  - docs/README.md
73
73
  - docs/getting_started.md
74
74
  - examples/bitehist.rb
75
+ - examples/charty/Gemfile
76
+ - examples/charty/Gemfile.lock
77
+ - examples/charty/bitehist-unicode.rb
75
78
  - examples/dddos.rb
76
79
  - examples/disksnoop.rb
77
80
  - examples/example.gif
@@ -118,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
121
  - !ruby/object:Gem::Version
119
122
  version: '0'
120
123
  requirements: []
121
- rubygems_version: 3.0.6
124
+ rubygems_version: 3.0.3
122
125
  signing_key:
123
126
  specification_version: 4
124
127
  summary: BCC port for MRI