stapsdt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd54b0665a386aa7d0edb3fdb1faf98efe8ff64a3fe60bbe386836a549248db4
4
+ data.tar.gz: 86b1d0c8a8a0d3e335312032821696338699fcaba43e30d036a06fa7b2cffb07
5
+ SHA512:
6
+ metadata.gz: 2d21b28243a2814a90b2d55ddd39479ee03f45cdf2a90bd92f8bbdbd66723cb01bee87dbeb025f4755047543c161ca9d636c08fd22754b4de3d16e13145e07ff
7
+ data.tar.gz: dae381c9a71a7ed3a529409c1554ba73daa8ab75c6c484f1eda4bde9899087ee7f61453ee776a57148a093969956352ad85068ce299d6fb0835ecad9d7261bd5
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+ vendor/
@@ -0,0 +1,3 @@
1
+ [submodule "ext/libstapsdt"]
2
+ path = ext/libstapsdt
3
+ url = https://github.com/sthima/libstapsdt
@@ -0,0 +1,8 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+
4
+ Layout/IndentationWidth:
5
+ Width: 4
6
+
7
+ Metrics/BlockLength:
8
+ Exclude: test/**/*_test.rb
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sylvain.joyeux@13robotics.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'rubocop', group: :development
6
+ gem 'solargraph', group: :development
7
+ gem 'debase', group: :development
8
+ gem 'ruby-debug-ide', group: :development
9
+
10
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sylvain Joyeux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,114 @@
1
+ # StapSDT
2
+
3
+ Runtime definition of StapSDT (Dtrace) probes within Ruby programs
4
+
5
+ This gem allows one to define StapSDT probes on Linux, and then use the StapSDT tooling
6
+ to list and inspect them (mainly the bcc suite of tools)
7
+
8
+ ## Installation
9
+
10
+ This gem requires that libelf is installed on the system. On Ubuntu systems, do
11
+
12
+ ~~~
13
+ sudo apt-get install libelf-dev
14
+ ~~~
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'stapsdt'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install stapsdt
29
+
30
+ ## Usage
31
+
32
+ An example should be worth a 1000 words. Let's create `example.rb` with:
33
+
34
+ ```ruby
35
+ require 'stapsdt'
36
+
37
+ puts "PID: #{Process.pid}"
38
+
39
+ provider = StapSDT::Provider.new('example')
40
+
41
+ probe = provider.add_probe("test", String, Integer)
42
+ provider.load
43
+
44
+ i = 0
45
+ loop do
46
+ probe.fire("some string", i += 1)
47
+ end
48
+ ```
49
+
50
+ and run it with `bundle exec example.rb`
51
+
52
+ Then, `/usr/share/bcc/tools/tplist -p 25175 example:test` (replace 25175 with
53
+ the PID shown by the script) will display:
54
+
55
+ ~~~
56
+ example:test [sema 0x0]
57
+ 1 location(s)
58
+ 2 argument(s)
59
+ ~~~
60
+
61
+ Finally, `sudo /usr/share/bcc/tools/trace -p 25175 -M 10 'u::test "%s - %llu" arg1, arg2'`
62
+
63
+ ~~~
64
+ PID TID COMM FUNC -
65
+ 25175 25175 ruby test some string - -1241438585
66
+ 25175 25175 ruby test some string - -1241438584
67
+ 25175 25175 ruby test some string - -1241438583
68
+ 25175 25175 ruby test some string - -1241438582
69
+ 25175 25175 ruby test some string - -1241438581
70
+ 25175 25175 ruby test some string - -1241438580
71
+ 25175 25175 ruby test some string - -1241438579
72
+ 25175 25175 ruby test some string - -1241438578
73
+ 25175 25175 ruby test some string - -1241438577
74
+ 25175 25175 ruby test some string - -1241438576
75
+ ~~~
76
+
77
+ Note that the probes can be inspected and traced only after the provider has
78
+ been loaded. They won't appear until then.
79
+
80
+ ## Thanks
81
+
82
+ Thanks to Matheus Marchini who wrote [this medium article](https://medium.com/sthima-insights/we-just-got-a-new-super-power-runtime-usdt-comes-to-linux-814dc47e909f)
83
+ showing the same capability on Node.js and Python. I would not even have
84
+ realized it was possible before that.
85
+
86
+ ## Development
87
+
88
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
89
+ run `rake test` to run the tests. You can also run `bin/console` for an
90
+ interactive prompt that will allow you to experiment.
91
+
92
+ To install this gem onto your local machine, run `bundle exec rake install`.
93
+ To release a new version, update the version number in `version.rb`, and then
94
+ run `bundle exec rake release`, which will create a git tag for the version,
95
+ push git commits and tags, and push the `.gem` file to
96
+ [rubygems.org](https://rubygems.org).
97
+
98
+ ## Contributing
99
+
100
+ Bug reports and pull requests are welcome on GitHub at
101
+ https://github.com/rock-core/ruby-stapsdt. This project is intended to be a safe,
102
+ welcoming space for collaboration, and contributors are expected to adhere to
103
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT
108
+ License](https://opensource.org/licenses/MIT).
109
+
110
+ ## Code of Conduct
111
+
112
+ Everyone interacting in the Usdt project’s codebases, issue trackers, chat
113
+ rooms and mailing lists is expected to follow the [code of
114
+ conduct](https://github.com/[USERNAME]/usdt/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,18 @@
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
+ require "rake/extensiontask"
11
+
12
+ task :build => :compile
13
+
14
+ Rake::ExtensionTask.new("stapsdt") do |ext|
15
+ ext.lib_dir = "lib/stapsdt"
16
+ end
17
+
18
+ task :default => [:clobber, :compile, :test]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "usdt"
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,13 @@
1
+ require 'stapsdt'
2
+
3
+ puts "PID: #{Process.pid}"
4
+
5
+ provider = StapSDT::Provider.new('example')
6
+
7
+ probe = provider.add_probe("test", String, Integer)
8
+ provider.load
9
+
10
+ i = 0
11
+ loop do
12
+ probe.fire("some string", i += 1)
13
+ end
@@ -0,0 +1,19 @@
1
+ require "mkmf"
2
+
3
+ unless system("make", "-C", File.join(__dir__, "..", "libstapsdt"))
4
+ raise "Failed to compile libstapstd"
5
+ end
6
+
7
+ dir_config('libstapsdt',
8
+ [File.join(__dir__, '..', 'libstapsdt', 'src')],
9
+ [File.join(__dir__, '..', 'libstapsdt', 'out')])
10
+
11
+ unless find_library('elf', 'elf_begin')
12
+ abort "cannot link to libelf"
13
+ end
14
+
15
+ unless find_library('stapsdt', 'probeIsEnabled')
16
+ abort "cannot link to libstapsdt.a"
17
+ end
18
+
19
+ create_makefile("stapsdt/stapsdt")
@@ -0,0 +1,232 @@
1
+ #include "stapsdt.h"
2
+
3
+ VALUE rb_mProvider;
4
+ VALUE rb_mProbe;
5
+ VALUE rb_mStapSDT;
6
+
7
+ typedef struct Provider
8
+ {
9
+ SDTProvider_t* provider;
10
+ } Provider_t;
11
+
12
+ typedef struct Probe
13
+ {
14
+ VALUE input_args[MAX_ARGUMENTS];
15
+ SDTProbe_t* probe;
16
+ } Probe_t;
17
+
18
+ void provider_free(Provider_t* wrap)
19
+ {
20
+ providerDestroy(wrap->provider);
21
+ xfree(wrap);
22
+ }
23
+
24
+ VALUE provider_new(VALUE self, VALUE _name)
25
+ {
26
+ char const* name = StringValueCStr(_name);
27
+ SDTProvider_t* provider = providerInit(name);
28
+ if (!provider)
29
+ rb_raise(rb_eRuntimeError, "could not create provider with name %s", name);
30
+
31
+ Provider_t* wrap = ALLOC(Provider_t);
32
+ wrap->provider = provider;
33
+ return rb_data_object_wrap(rb_mProvider, wrap, NULL, (RUBY_DATA_FUNC)provider_free);
34
+ }
35
+
36
+ void interpretError(int result, Provider_t* wrap)
37
+ {
38
+ if (result != -1)
39
+ return;
40
+
41
+ if (wrap->provider->errno == noError)
42
+ return;
43
+
44
+ rb_raise(rb_eRuntimeError, "%s", wrap->provider->error);
45
+ }
46
+
47
+ VALUE provider_load(VALUE self)
48
+ {
49
+ Provider_t* wrap;
50
+ Data_Get_Struct(self, Provider_t, wrap);
51
+ int result = providerLoad(wrap->provider);
52
+ interpretError(result, wrap);
53
+ return Qnil;
54
+ }
55
+
56
+ VALUE provider_unload(VALUE self)
57
+ {
58
+ Provider_t* wrap;
59
+ Data_Get_Struct(self, Provider_t, wrap);
60
+ int result = providerUnload(wrap->provider);
61
+ interpretError(result, wrap);
62
+ return Qnil;
63
+ }
64
+
65
+ VALUE provider_add_probe(int argc, VALUE* argv, VALUE self)
66
+ {
67
+ VALUE input_args[MAX_ARGUMENTS];
68
+ int args[MAX_ARGUMENTS];
69
+ if (argc < 1)
70
+ rb_raise(rb_eArgError, "expected at least 1 argument, got 0");
71
+ if (argc > MAX_ARGUMENTS + 1)
72
+ rb_raise(rb_eArgError,
73
+ "libstapstd only supports up to %i arguments, got %i",
74
+ MAX_ARGUMENTS, argc - 1);
75
+
76
+ for (int i = 0; i < argc - 1; ++i)
77
+ {
78
+ VALUE arg_type = argv[i + 1];
79
+ input_args[i] = arg_type;
80
+ if (arg_type == rb_cString || arg_type == rb_cFloat || arg_type == rb_cInteger)
81
+ args[i] = uint64;
82
+ else
83
+ args[i] = NUM2INT(arg_type);
84
+ }
85
+
86
+ char const* probe_name = StringValueCStr(argv[0]);
87
+
88
+ Provider_t* wrap;
89
+ Data_Get_Struct(self, Provider_t, wrap);
90
+
91
+ SDTProbe_t* probe = NULL;
92
+ if (argc == 1)
93
+ probe = providerAddProbe(wrap->provider, probe_name, 0);
94
+ else if (argc == 2)
95
+ probe = providerAddProbe(wrap->provider, probe_name, 1,
96
+ (ArgType_t)args[0]);
97
+ else if (argc == 3)
98
+ probe = providerAddProbe(wrap->provider, probe_name, 2,
99
+ (ArgType_t)args[0], (ArgType_t)args[1]);
100
+ else if (argc == 4)
101
+ probe = providerAddProbe(wrap->provider, probe_name, 3,
102
+ (ArgType_t)args[0], (ArgType_t)args[1], (ArgType_t)args[2]);
103
+ else if (argc == 5)
104
+ probe = providerAddProbe(wrap->provider, probe_name, 4,
105
+ (ArgType_t)args[0], (ArgType_t)args[1], (ArgType_t)args[2],
106
+ (ArgType_t)args[3]);
107
+ else if (argc == 6)
108
+ probe = providerAddProbe(wrap->provider, probe_name, 5,
109
+ (ArgType_t)args[0], (ArgType_t)args[1], (ArgType_t)args[2],
110
+ (ArgType_t)args[3], (ArgType_t)args[4]);
111
+ else if (argc == 7)
112
+ probe = providerAddProbe(wrap->provider, probe_name, 6,
113
+ (ArgType_t)args[0], (ArgType_t)args[1], (ArgType_t)args[2],
114
+ (ArgType_t)args[3], (ArgType_t)args[4], (ArgType_t)args[5]);
115
+
116
+ if (!probe)
117
+ rb_raise(rb_eArgError, "failed to create probe");
118
+
119
+ Probe_t* probe_wrap = ALLOC(Probe_t);
120
+ memcpy(probe_wrap->input_args, input_args, sizeof(VALUE)*(argc - 1));
121
+ probe_wrap->probe = probe;
122
+ /* NOTE: probes cannot be deallocated. They're freed when the provider is */
123
+ return rb_data_object_wrap(rb_mProbe, probe_wrap, NULL, NULL);
124
+ }
125
+
126
+ VALUE probe_fire(int argc, VALUE* argv, VALUE self)
127
+ {
128
+
129
+ uint64_t args[MAX_ARGUMENTS];
130
+ VALUE block_args[MAX_ARGUMENTS];
131
+ VALUE* in_args;
132
+
133
+ Probe_t* wrap;
134
+ Data_Get_Struct(self, Probe_t, wrap);
135
+ int expected_argc = wrap->probe->argCount;
136
+
137
+ if (rb_block_given_p()) {
138
+ if (argc != 0)
139
+ {
140
+ rb_raise(rb_eArgError, "cannot provide arguments "\
141
+ "and block at the same time");
142
+ }
143
+
144
+ if (!probeIsEnabled(wrap->probe)) {
145
+ return Qfalse;
146
+ }
147
+
148
+ VALUE block_ret = rb_yield_values(0);
149
+ if (!NIL_P(block_ret)) {
150
+ argc = RARRAY_LEN(block_ret);
151
+ if (argc != expected_argc)
152
+ rb_raise(rb_eArgError, "expected %i argument(s), got %i",
153
+ expected_argc, argc);
154
+
155
+ for (int i = 0; i < argc; ++i)
156
+ block_args[i] = rb_ary_entry(block_ret, i);
157
+
158
+ in_args = block_args;
159
+ }
160
+ }
161
+ else {
162
+ if (argc != expected_argc)
163
+ rb_raise(rb_eArgError, "expected %i argument(s), got %i",
164
+ expected_argc, argc);
165
+
166
+ in_args = argv;
167
+ }
168
+
169
+ for (int i = 0; i < argc; ++i)
170
+ {
171
+ if (wrap->input_args[i] == rb_cString)
172
+ {
173
+ char const* s = StringValueCStr(in_args[i]);
174
+ args[i] = *(uint64_t*)&s;
175
+ }
176
+ else if (wrap->input_args[i] == rb_cFloat)
177
+ {
178
+ double d = NUM2DBL(in_args[i]);
179
+ args[i] = *(uint64_t*)&d;
180
+ }
181
+ else
182
+ args[i] = NUM2ULL(in_args[i]);
183
+ }
184
+
185
+ if (argc == 0)
186
+ probeFire(wrap->probe);
187
+ if (argc == 1)
188
+ probeFire(wrap->probe, args[0]);
189
+ if (argc == 2)
190
+ probeFire(wrap->probe, args[0], args[1]);
191
+ if (argc == 3)
192
+ probeFire(wrap->probe, args[0], args[1], args[2]);
193
+ if (argc == 4)
194
+ probeFire(wrap->probe, args[0], args[1], args[2], args[3]);
195
+ if (argc == 5)
196
+ probeFire(wrap->probe, args[0], args[1], args[2], args[3], args[4]);
197
+ if (argc == 6)
198
+ probeFire(wrap->probe, args[0], args[1], args[2], args[3], args[4], args[5]);
199
+
200
+ return probeIsEnabled(wrap->probe) ? Qtrue : Qfalse;
201
+ }
202
+
203
+ VALUE probe_enabled_p(VALUE self)
204
+ {
205
+ Probe_t* wrap;
206
+ Data_Get_Struct(self, Probe_t, wrap);
207
+ return probeIsEnabled(wrap->probe) ? Qtrue : Qfalse;
208
+ }
209
+
210
+ VALUE probe_name(VALUE self)
211
+ {
212
+ Probe_t* wrap;
213
+ Data_Get_Struct(self, Probe_t, wrap);
214
+ return rb_str_new_cstr(wrap->probe->name);
215
+ }
216
+
217
+ void
218
+ Init_stapsdt(void)
219
+ {
220
+ rb_mStapSDT = rb_define_module("StapSDT");
221
+ rb_mProvider = rb_define_class_under(rb_mStapSDT, "Provider", rb_cObject);
222
+ rb_define_singleton_method(rb_mProvider, "new", provider_new, 1);
223
+ rb_define_method(rb_mProvider, "add_probe_c", provider_add_probe, -1);
224
+ rb_define_method(rb_mProvider, "load_c", provider_load, 0);
225
+ rb_define_method(rb_mProvider, "unload_c", provider_unload, 0);
226
+
227
+ rb_mProbe = rb_define_class_under(rb_mStapSDT, "Probe", rb_cObject);
228
+ rb_define_method(rb_mProbe, "fire", probe_fire, -1);
229
+ rb_define_method(rb_mProbe, "enabled?", probe_enabled_p, 0);
230
+ rb_define_method(rb_mProbe, "name", probe_name, 0);
231
+ }
232
+
@@ -0,0 +1,7 @@
1
+ #ifndef STAPSDT_H
2
+ #define STAPSDT_H 1
3
+
4
+ #include "ruby.h"
5
+ #include <libstapsdt.h>
6
+
7
+ #endif /* USDT_H */
@@ -0,0 +1,23 @@
1
+ require "stapsdt/version"
2
+ require "stapsdt/stapsdt"
3
+ require "stapsdt/provider"
4
+ require "stapsdt/probe"
5
+
6
+ # Runtime definition of StapSDT (Dtrace) probes on Linux
7
+ #
8
+ # To use, create a {StapSDT::Provider} instance, define probes with
9
+ # {StapSDT::Provider#add_probe}. Once the provider is loaded with {Provider#load},
10
+ # the StapSDT probes are available to tracing tools such as bcc's tplist and
11
+ # trace. Within the program, the {Probe} objects returned by add_probe can be
12
+ # fired with {Probe#fire}.
13
+ module StapSDT
14
+ ARG_UINT8 = 1
15
+ ARG_INT8 = -1
16
+ ARG_UINT16 = 2
17
+ ARG_INT16 = -2
18
+ ARG_UINT32 = 4
19
+ ARG_INT32 = -4
20
+ ARG_UINT64 = 8
21
+ ARG_INT64 = -8
22
+ end
23
+
@@ -0,0 +1,17 @@
1
+ module StapSDT
2
+ # A single USDT probe
3
+ #
4
+ # Probe objects are exclusively created with {Provider#add_probe}
5
+ class Probe
6
+ private_class_method :new
7
+
8
+ # @!method fire(*args)
9
+ #
10
+ # @param [Array] args arguments matching the types defined when
11
+ # the probe was created
12
+
13
+ # @!method enabled?
14
+ #
15
+ # Whether the probe is being traced
16
+ end
17
+ end
@@ -0,0 +1,62 @@
1
+ module StapSDT
2
+ # Collection of probes that can be activated and deactivated
3
+ #
4
+ # Providers are the entry point for probe definition
5
+ #
6
+ # After creation, probes are added with {#add_probe} and then
7
+ # activated with {#load}. Probes can only be defined before the
8
+ # provider gets loaded.
9
+ class Provider
10
+ class StateError < RuntimeError; end
11
+
12
+ def initialize
13
+ @loaded = false
14
+ end
15
+
16
+ # Whether this provider has been loaded
17
+ def loaded?
18
+ @loaded
19
+ end
20
+
21
+ private :load_c, :unload_c, :add_probe_c
22
+
23
+ # Load the provider
24
+ #
25
+ # @raise [StateError] if the provider was already loaded. Call
26
+ # {#unload} first in this case
27
+ def load
28
+ raise StateError, "already loaded, call #unload first" if loaded?
29
+
30
+ load_c
31
+ @loaded = true
32
+ end
33
+
34
+ # Unloads the provider
35
+ #
36
+ # Does nothing if the provider was not yet loaded
37
+ def unload
38
+ return unless loaded?
39
+
40
+ unload_c
41
+ @loaded = false
42
+ end
43
+
44
+ # Add a new probe to this provider
45
+ #
46
+ # Probes must be added before the provider is loaded. Call {#unload} to
47
+ # add new probes to an already-loaded provider
48
+ #
49
+ # @param [String] probe_name the name of the probe
50
+ # @param [Array] arg_types the type of probe arguments.
51
+ # It is either one of the ARG_ constants defined within {StapSDT},
52
+ # or one of the Integer, Float and String classes.
53
+ # @return [Probe]
54
+ # @raise [StateError] if the provider was already loaded
55
+ def add_probe(probe_name, *arg_types)
56
+ if loaded?
57
+ raise StateError, "already loaded, call #unload before adding new probes"
58
+ end
59
+ add_probe_c(probe_name, *arg_types)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module StapSDT
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "stapsdt/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stapsdt"
8
+ spec.version = StapSDT::VERSION
9
+ spec.authors = ["Sylvain Joyeux"]
10
+ spec.email = ["sylvain.joyeux@13robotics.com"]
11
+
12
+ spec.summary = %q{Define SDT (DTrace) probes at runtime in a Ruby program}
13
+ spec.homepage = "https://github.com/rock-core/ruby-stapsdt"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.extensions = ["ext/stapsdt/extconf.rb"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rake-compiler"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stapsdt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sylvain Joyeux
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - sylvain.joyeux@13robotics.com
72
+ executables: []
73
+ extensions:
74
+ - ext/stapsdt/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".gitmodules"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - example.rb
89
+ - ext/stapsdt/extconf.rb
90
+ - ext/stapsdt/stapsdt.c
91
+ - ext/stapsdt/stapsdt.h
92
+ - lib/stapsdt.rb
93
+ - lib/stapsdt/probe.rb
94
+ - lib/stapsdt/provider.rb
95
+ - lib/stapsdt/version.rb
96
+ - stapsdt.gemspec
97
+ homepage: https://github.com/rock-core/ruby-stapsdt
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.7.6
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Define SDT (DTrace) probes at runtime in a Ruby program
121
+ test_files: []