pcptrace 1.0.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 +7 -0
- data/README.md +100 -0
- data/ext/pcptrace/extconf.rb +6 -0
- data/ext/pcptrace/pcptrace.c +64 -0
- data/lib/pcptrace/kernel.rb +54 -0
- data/lib/version.rb +3 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d1409374dfe9cea8944910ccd090d6b9bd43345
|
4
|
+
data.tar.gz: 755c7a8bc579d7d55ce06e44842c585f6819b9cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bd124971686faba63d22d272ee4cee255639421bbe6e87ecbfcfa4442999b42f19fea27ddc26ff0e25ca9ad3fad6e308f324e6a4d6d3f438d8a914d22187dc5
|
7
|
+
data.tar.gz: f99508dde9017c3b83cfc75dc9a61c8ff0dda543cbd3be9eaa318e877a606ea4b6fdad4924d6507dc5f1f4664d15c06f1e1a52e950c1629868c50bb51603fcc4
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
Ruby bindings for PCP trace PMDA & API
|
2
|
+
|
3
|
+
# DESCRIPTION
|
4
|
+
|
5
|
+
Ruby bindings of:
|
6
|
+
|
7
|
+
https://github.com/performancecopilot/pcp/blob/master/src/include/pcp/trace.h
|
8
|
+
|
9
|
+
As easy as that. Visit man page for more info:
|
10
|
+
|
11
|
+
http://pcp.io/man/man3/pmdatrace.3.html
|
12
|
+
|
13
|
+
# USAGE
|
14
|
+
|
15
|
+
require "pcptrace"
|
16
|
+
|
17
|
+
# reached a point in source code
|
18
|
+
PCPTrace::point("a_point"))
|
19
|
+
|
20
|
+
# observation of an arbitrary value
|
21
|
+
PCPTrace::obs("an_observation", 130.513))
|
22
|
+
|
23
|
+
# a counter - increasing or decreasing
|
24
|
+
PCPTrace::counter("a_counter", 1))
|
25
|
+
|
26
|
+
# time spent in a transaction (or block)
|
27
|
+
PCPTrace::begin("a_transaction"))
|
28
|
+
# ...
|
29
|
+
PCPTrace::end("a_transaction"))
|
30
|
+
|
31
|
+
# transactions must be aborted (e.g. exception)
|
32
|
+
#PCPTrace::abort("a_transaction"))
|
33
|
+
|
34
|
+
# all methods return non-zero code
|
35
|
+
result = PCPTrace::counter("a_counter", -5))
|
36
|
+
puts("Error: " + PCPTrace::errstr(result)) if result != 0
|
37
|
+
|
38
|
+
# RUBY-FRIENDLY API
|
39
|
+
|
40
|
+
Little bit more Ruby-friendly wraper:
|
41
|
+
|
42
|
+
require 'pcptrace/kernel'
|
43
|
+
PCPTrace::setup_kernel(true)
|
44
|
+
|
45
|
+
pcp_point("a_point")
|
46
|
+
pcp_observe("an_observation", 99.9)
|
47
|
+
pcp_counter("a_counter", 10)
|
48
|
+
pcp_counter("a_counter") # increment by 1
|
49
|
+
pcp_measure("a_transaction") do
|
50
|
+
# block of code - properly aborted on exception
|
51
|
+
end
|
52
|
+
|
53
|
+
# REQUIREMENTS
|
54
|
+
|
55
|
+
The PCP library and headers.
|
56
|
+
|
57
|
+
## Fedora
|
58
|
+
|
59
|
+
$ dnf install ruby-devel pcp pcp-libs-devel
|
60
|
+
|
61
|
+
## Debian or Ubuntu
|
62
|
+
|
63
|
+
$ sudo apt-get install noidea todo
|
64
|
+
|
65
|
+
# INSTALLATION
|
66
|
+
|
67
|
+
Regular rubygem:
|
68
|
+
|
69
|
+
gem install pcptrace
|
70
|
+
|
71
|
+
When building from source:
|
72
|
+
|
73
|
+
rake compile
|
74
|
+
|
75
|
+
# AUTHORS
|
76
|
+
|
77
|
+
* Lukas Zapletal
|
78
|
+
|
79
|
+
# LICENSE
|
80
|
+
|
81
|
+
(The MIT License)
|
82
|
+
|
83
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
84
|
+
a copy of this software and associated documentation files (the
|
85
|
+
'Software'), to deal in the Software without restriction, including
|
86
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
87
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
88
|
+
permit persons to whom the Software is furnished to do so, subject to
|
89
|
+
the following conditions:
|
90
|
+
|
91
|
+
The above copyright notice and this permission notice shall be
|
92
|
+
included in all copies or substantial portions of the Software.
|
93
|
+
|
94
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
95
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
96
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
97
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
98
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
99
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
100
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <pcp/trace.h>
|
3
|
+
|
4
|
+
VALUE pcp = Qnil;
|
5
|
+
|
6
|
+
static VALUE rb_ext_begin(VALUE self, VALUE str_id)
|
7
|
+
{
|
8
|
+
return INT2NUM(pmtracebegin(StringValueCStr(str_id)));
|
9
|
+
}
|
10
|
+
|
11
|
+
static VALUE rb_ext_end(VALUE self, VALUE str_id)
|
12
|
+
{
|
13
|
+
return INT2NUM(pmtraceend(StringValueCStr(str_id)));
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE rb_ext_abort(VALUE self, VALUE str_id)
|
17
|
+
{
|
18
|
+
return INT2NUM(pmtraceabort(StringValueCStr(str_id)));
|
19
|
+
}
|
20
|
+
|
21
|
+
static VALUE rb_ext_point(VALUE self, VALUE str_id)
|
22
|
+
{
|
23
|
+
return INT2NUM(pmtracepoint(StringValueCStr(str_id)));
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE rb_ext_errstr(VALUE self, VALUE int_code)
|
27
|
+
{
|
28
|
+
return rb_str_new_cstr(pmtraceerrstr(NUM2INT(int_code)));
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rb_ext_counter(VALUE self, VALUE str_id, VALUE double_val)
|
32
|
+
{
|
33
|
+
return INT2NUM(pmtracecounter(StringValueCStr(str_id), NUM2DBL(double_val)));
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE rb_ext_obs(VALUE self, VALUE str_id, VALUE double_val)
|
37
|
+
{
|
38
|
+
return INT2NUM(pmtraceobs(StringValueCStr(str_id), NUM2DBL(double_val)));
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE rb_ext_state(VALUE self, VALUE int_code)
|
42
|
+
{
|
43
|
+
return INT2NUM(pmtracestate(NUM2INT(int_code)));
|
44
|
+
}
|
45
|
+
|
46
|
+
void Init_pcptrace(){
|
47
|
+
pcp = rb_define_module("PCPTrace");
|
48
|
+
rb_define_module_function(pcp, "begin", rb_ext_begin, 1);
|
49
|
+
rb_define_module_function(pcp, "end", rb_ext_end, 1);
|
50
|
+
rb_define_module_function(pcp, "abort", rb_ext_abort, 1);
|
51
|
+
rb_define_module_function(pcp, "point", rb_ext_point, 1);
|
52
|
+
rb_define_module_function(pcp, "counter", rb_ext_counter, 2);
|
53
|
+
rb_define_module_function(pcp, "obs", rb_ext_obs, 2);
|
54
|
+
rb_define_module_function(pcp, "errstr", rb_ext_errstr, 1);
|
55
|
+
rb_define_module_function(pcp, "state", rb_ext_state, 1);
|
56
|
+
|
57
|
+
rb_define_const(pcp, "STATE_NONE", INT2NUM(PMTRACE_STATE_NONE));
|
58
|
+
rb_define_const(pcp, "STATE_API", INT2NUM(PMTRACE_STATE_API));
|
59
|
+
rb_define_const(pcp, "STATE_COMMS", INT2NUM(PMTRACE_STATE_COMMS));
|
60
|
+
rb_define_const(pcp, "STATE_PDU", INT2NUM(PMTRACE_STATE_PDU));
|
61
|
+
rb_define_const(pcp, "STATE_PDUBUF", INT2NUM(PMTRACE_STATE_PDUBUF));
|
62
|
+
rb_define_const(pcp, "STATE_NOAGENT", INT2NUM(PMTRACE_STATE_NOAGENT));
|
63
|
+
rb_define_const(pcp, "STATE_ASYNC", INT2NUM(PMTRACE_STATE_ASYNC));
|
64
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module PCPTrace
|
2
|
+
def self.setup_kernel(enabled, state = PCPTrace::STATE_NONE)
|
3
|
+
Kernel.const_set('PCP_ENABLED', enabled.to_s == "true")
|
4
|
+
Kernel.send(:extend, PCPTrace::KernelMethods)
|
5
|
+
PCPTrace::state(state)
|
6
|
+
end
|
7
|
+
|
8
|
+
module KernelMethods
|
9
|
+
def self.extended(mod)
|
10
|
+
mod.module_eval do
|
11
|
+
def pcp_begin(tag)
|
12
|
+
return 0 unless Kernel::PCP_ENABLED
|
13
|
+
PCPTrace::begin(tag)
|
14
|
+
end
|
15
|
+
|
16
|
+
def pcp_end(tag)
|
17
|
+
return 0 unless Kernel::PCP_ENABLED
|
18
|
+
PCPTrace::end(tag)
|
19
|
+
end
|
20
|
+
|
21
|
+
def pcp_abort(tag)
|
22
|
+
return 0 unless Kernel::PCP_ENABLED
|
23
|
+
PCPTrace::abort(tag)
|
24
|
+
end
|
25
|
+
|
26
|
+
def pcp_measure(tag)
|
27
|
+
return 0 unless Kernel::PCP_ENABLED
|
28
|
+
PCPTrace::begin(tag)
|
29
|
+
result = yield
|
30
|
+
PCPTrace::end(tag)
|
31
|
+
result
|
32
|
+
rescue => e
|
33
|
+
PCPTrace::abort(tag)
|
34
|
+
raise
|
35
|
+
end
|
36
|
+
|
37
|
+
def pcp_point(tag)
|
38
|
+
return 0 unless Kernel::PCP_ENABLED
|
39
|
+
PCPTrace::point(tag)
|
40
|
+
end
|
41
|
+
|
42
|
+
def pcp_counter(tag, value = 1)
|
43
|
+
return 0 unless Kernel::PCP_ENABLED
|
44
|
+
PCPTrace::counter(tag, value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def pcp_observe(tag, value = 1)
|
48
|
+
return 0 unless Kernel::PCP_ENABLED
|
49
|
+
PCPTrace::obs(tag, value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pcptrace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lukas Zapletal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Ruby bindings for PCP tracing library pcp_trace
|
42
|
+
email: lzap+rpm@redhat.com
|
43
|
+
executables: []
|
44
|
+
extensions:
|
45
|
+
- ext/pcptrace/extconf.rb
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- ext/pcptrace/extconf.rb
|
50
|
+
- ext/pcptrace/pcptrace.c
|
51
|
+
- lib/pcptrace/kernel.rb
|
52
|
+
- lib/version.rb
|
53
|
+
homepage: https://github.com/lzap/ruby-pcptrace
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
- ext
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.6.13
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Ruby bindings for pcptrace (pcp_trace library)
|
78
|
+
test_files: []
|