rack-ebpf 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d2679a34e38a2001f05a21ce0b2c277bf6fc6ead375371f64e877baeb818bd7
4
+ data.tar.gz: 452aa8d5ca8f7057d13dc19734a641c7ca4045f71a49a7e10cc1c6ce42a95d0f
5
+ SHA512:
6
+ metadata.gz: 24f7d42d85aa4f042d3f0626f248b9872f03fa05c135907b99df291e634120811e01ec2f39c865e5f77a13f382cbfabd23ef4c4f2a02e45ad5d52cabeee3946f
7
+ data.tar.gz: 5b274d6e4ffe29a16a6f2afecce675addd251df6d38ad6306841fb490445d6a659d5ead732f9c066d05e1ff326e4893f45cbc6014066493455db139ea677a367
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-ebpf.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-ebpf (0.1.0)
5
+ rbbcc
6
+ usdt_marker
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ minitest (5.14.0)
12
+ rake (12.3.3)
13
+ rbbcc (0.3.1)
14
+ usdt_marker (0.1.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ minitest (~> 5.0)
21
+ rack-ebpf!
22
+ rake (~> 12.0)
23
+
24
+ BUNDLED WITH
25
+ 2.0.2
@@ -0,0 +1,36 @@
1
+ # Rack::Ebpf
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/rack/ebpf`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rack-ebpf'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rack-ebpf
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/udzura/rack-ebpf.
36
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/ebpf"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require "rack/ebpf"
4
+ require "rbbcc"
5
+
6
+ pid = ARGV[0] || raise("arguement required")
7
+
8
+ u = RbBCC::USDT.new(pid: pid.to_i)
9
+ u.enable_probe(probe: "usdt_marker_i2", fn_name: "on_usdt_fired")
10
+
11
+ b = RbBCC::BCC.new(text: <<CLANG, usdt_contexts: [u])
12
+ #include <uapi/linux/ptrace.h>
13
+
14
+ struct countup_t {
15
+ };
16
+
17
+ BPF_HASH(working, u32, u32);
18
+ BPF_HASH(countup, u32, u64);
19
+ BPF_HISTOGRAM(out);
20
+
21
+ int on_usdt_fired(struct pt_regs *ctx) {
22
+ u64 ts, buf, phase, start = 0;
23
+ u32 tid, ok = 1;
24
+ bpf_usdt_readarg(2, ctx, &buf);
25
+ bpf_probe_read(&phase, sizeof(phase), (void *)&buf);
26
+ ts = bpf_ktime_get_ns();
27
+ tid = bpf_get_current_pid_tgid();
28
+
29
+ if(phase == 0) {
30
+ working.insert(&tid, &ok);
31
+ countup.insert(&tid, &start);
32
+ } else {
33
+ working.delete(&tid);
34
+
35
+ u64 *res = countup.lookup(&tid);
36
+ if(res) {
37
+ out.increment(bpf_log2l(*res));
38
+ }
39
+ countup.delete(&tid);
40
+ }
41
+ return 0;
42
+ }
43
+
44
+ /* TRACEPOINT_PROBE(syscalls, sys_enter_openat) {
45
+ u64 ts;
46
+ u32 tid = bpf_get_current_pid_tgid();
47
+
48
+ if (working.lookup(&tid)) {
49
+ ts = bpf_ktime_get_ns();
50
+ countup.increment(&tid);
51
+ }
52
+ return 0;
53
+ } */
54
+
55
+ TRACEPOINT_PROBE(syscalls, sys_enter_read) {
56
+ u64 ts;
57
+ u32 tid = bpf_get_current_pid_tgid();
58
+
59
+ if (working.lookup(&tid)) {
60
+ ts = bpf_ktime_get_ns();
61
+ countup.increment(tid);
62
+ }
63
+ return 0;
64
+ }
65
+
66
+ /* TRACEPOINT_PROBE(syscalls, sys_enter_write) {
67
+ u64 ts;
68
+ u32 tid = bpf_get_current_pid_tgid();
69
+
70
+ if (working.lookup(&tid)) {
71
+ ts = bpf_ktime_get_ns();
72
+ bpf_trace_printk("write fired: [%ld] tid=%d\\n", ts, tid);
73
+ }
74
+ return 0;
75
+ } */
76
+ CLANG
77
+
78
+ # b.trace_fields do |task, pid, cpu, flags, ts, msg|
79
+ # printf("%s", msg)
80
+ # end
81
+
82
+ puts "Tracing... Hit Ctrl-C to end."
83
+
84
+ loop do
85
+ begin
86
+ sleep 0.1
87
+ rescue Interrupt
88
+ puts
89
+ break
90
+ end
91
+ end
92
+ b["out"].print_log2_hist("count of read")
@@ -0,0 +1 @@
1
+ require 'rack/ebpf'
@@ -0,0 +1,21 @@
1
+ require "rack/ebpf/version"
2
+ require "usdt_marker"
3
+
4
+ module Rack
5
+ class EBPF
6
+ REQUEST_START = 0
7
+ REQUEST_FINISH = 1
8
+
9
+ def initialize(app, marker_nr = 1)
10
+ @app = app
11
+ @marker_nr = marker_nr
12
+ end
13
+
14
+ def call(env)
15
+ UsdtMarker.probe_i2(@marker_nr, REQUEST_START)
16
+ ret = @app.call(env)
17
+ UsdtMarker.probe_i2(@marker_nr, REQUEST_FINISH)
18
+ ret
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class EBPF
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/rack/ebpf/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rack-ebpf"
5
+ spec.version = Rack::EBPF::VERSION
6
+ spec.authors = ["Uchio Kondo"]
7
+ spec.email = ["udzura@udzura.jp"]
8
+
9
+ spec.summary = %q{eBPF integration with rack application}
10
+ spec.description = %q{eBPF integration with rack application.}
11
+ spec.homepage = "https://github.com/udzura/rack-ebpf"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'usdt_marker'
24
+ spec.add_dependency 'rbbcc'
25
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ebpf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Uchio Kondo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: usdt_marker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rbbcc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: eBPF integration with rack application.
42
+ email:
43
+ - udzura@udzura.jp
44
+ executables:
45
+ - rack-ebpf-run
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - exe/rack-ebpf-run
58
+ - lib/rack-ebpf.rb
59
+ - lib/rack/ebpf.rb
60
+ - lib/rack/ebpf/version.rb
61
+ - rack-ebpf.gemspec
62
+ homepage: https://github.com/udzura/rack-ebpf
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.3.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.0.6
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: eBPF integration with rack application
84
+ test_files: []