babeltrace2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/babeltrace2.gemspec +13 -0
- data/lib/babeltrace2.rb +49 -0
- data/lib/babeltrace2/error-reporting.rb +432 -0
- data/lib/babeltrace2/func-status.rb +26 -0
- data/lib/babeltrace2/graph/component-class-dev.rb +801 -0
- data/lib/babeltrace2/graph/component-class.rb +134 -0
- data/lib/babeltrace2/graph/component-descriptor-set.rb +78 -0
- data/lib/babeltrace2/graph/component.rb +362 -0
- data/lib/babeltrace2/graph/connection.rb +35 -0
- data/lib/babeltrace2/graph/graph.rb +523 -0
- data/lib/babeltrace2/graph/interrupter.rb +57 -0
- data/lib/babeltrace2/graph/message-iterator-class.rb +374 -0
- data/lib/babeltrace2/graph/message-iterator.rb +253 -0
- data/lib/babeltrace2/graph/message.rb +721 -0
- data/lib/babeltrace2/graph/port.rb +124 -0
- data/lib/babeltrace2/graph/private-query-executor.rb +4 -0
- data/lib/babeltrace2/graph/query-executor.rb +142 -0
- data/lib/babeltrace2/graph/self-component-class.rb +37 -0
- data/lib/babeltrace2/graph/self-component-port.rb +35 -0
- data/lib/babeltrace2/graph/self-component.rb +264 -0
- data/lib/babeltrace2/graph/self-message-iterator.rb +147 -0
- data/lib/babeltrace2/integer-range-set.rb +275 -0
- data/lib/babeltrace2/logging-defs.rb +19 -0
- data/lib/babeltrace2/logging.rb +77 -0
- data/lib/babeltrace2/plugin/plugin-dev.rb +335 -0
- data/lib/babeltrace2/plugin/plugin-loading.rb +459 -0
- data/lib/babeltrace2/trace-ir/clock-class.rb +258 -0
- data/lib/babeltrace2/trace-ir/clock-snapshot.rb +45 -0
- data/lib/babeltrace2/trace-ir/event-class.rb +292 -0
- data/lib/babeltrace2/trace-ir/event.rb +91 -0
- data/lib/babeltrace2/trace-ir/field-class.rb +1416 -0
- data/lib/babeltrace2/trace-ir/field-path.rb +123 -0
- data/lib/babeltrace2/trace-ir/field.rb +871 -0
- data/lib/babeltrace2/trace-ir/packet.rb +57 -0
- data/lib/babeltrace2/trace-ir/stream-class.rb +425 -0
- data/lib/babeltrace2/trace-ir/stream.rb +137 -0
- data/lib/babeltrace2/trace-ir/trace-class.rb +343 -0
- data/lib/babeltrace2/trace-ir/trace.rb +321 -0
- data/lib/babeltrace2/types.rb +667 -0
- data/lib/babeltrace2/util.rb +23 -0
- data/lib/babeltrace2/value.rb +869 -0
- data/lib/babeltrace2/version.rb +126 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b661027d46180b1a162ce91aad9ad783e5700abc1182199408d19c61410f2df6
|
4
|
+
data.tar.gz: 9f207749e36ecf12c8e0aae0b54749f967e1aa9830b4bf38b72eac47d1443017
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5b73639f60a15169307c2c52708478211e445298a294d98bc745ee364c2a009e4a320008c58fac46b3408483ef487869b8a77d88f45e91f8d77d3cd140c960e
|
7
|
+
data.tar.gz: feb554583fb6ad8e3ac8c80f148a44fe497295167891f0bac620933848b4f8b36c5d57d5751dca613fcabc427c012913c7699f856d3f46c0467a9eaac2ad4bde
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 alcf-perfengr
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/babeltrace2.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'babeltrace2'
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.author = "Brice Videau"
|
5
|
+
s.email = "bvideau@anl.gov"
|
6
|
+
s.homepage = "https://github.com/alcf-perfengr/babeltrace2-ruby"
|
7
|
+
s.summary = "Ruby Babeltrace 2 bindings"
|
8
|
+
s.description = "Ruby Babeltrace 2 ffi bindings"
|
9
|
+
s.files = Dir[ 'babeltrace2.gemspec', 'LICENSE', 'lib/**/**/*.rb', 'ext/**/*.rb' ]
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.required_ruby_version = '>= 2.3.0'
|
12
|
+
s.add_dependency 'ffi', '~> 1.9', '>=1.9.3'
|
13
|
+
end
|
data/lib/babeltrace2.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Babeltrace2
|
4
|
+
extend FFI::Library
|
5
|
+
ffi_lib "babeltrace2"
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative 'babeltrace2/func-status'
|
9
|
+
require_relative 'babeltrace2/logging-defs'
|
10
|
+
require_relative 'babeltrace2/logging'
|
11
|
+
require_relative 'babeltrace2/types'
|
12
|
+
require_relative 'babeltrace2/integer-range-set'
|
13
|
+
require_relative 'babeltrace2/value'
|
14
|
+
require_relative 'babeltrace2/version'
|
15
|
+
require_relative 'babeltrace2/util'
|
16
|
+
require_relative 'babeltrace2/graph/port'
|
17
|
+
require_relative 'babeltrace2/graph/connection'
|
18
|
+
require_relative 'babeltrace2/graph/component-class'
|
19
|
+
require_relative 'babeltrace2/graph/component-class-dev'
|
20
|
+
require_relative 'babeltrace2/graph/component'
|
21
|
+
require_relative 'babeltrace2/graph/self-component-class'
|
22
|
+
require_relative 'babeltrace2/graph/self-component'
|
23
|
+
require_relative 'babeltrace2/graph/self-component-port'
|
24
|
+
require_relative 'babeltrace2/graph/graph'
|
25
|
+
require_relative 'babeltrace2/graph/message-iterator-class'
|
26
|
+
require_relative 'babeltrace2/graph/message-iterator'
|
27
|
+
require_relative 'babeltrace2/graph/self-message-iterator'
|
28
|
+
require_relative 'babeltrace2/graph/message'
|
29
|
+
require_relative 'babeltrace2/graph/component-descriptor-set'
|
30
|
+
require_relative 'babeltrace2/graph/interrupter'
|
31
|
+
require_relative 'babeltrace2/graph/query-executor'
|
32
|
+
require_relative 'babeltrace2/graph/private-query-executor'
|
33
|
+
require_relative 'babeltrace2/error-reporting'
|
34
|
+
require_relative 'babeltrace2/plugin/plugin-loading'
|
35
|
+
require_relative 'babeltrace2/plugin/plugin-dev'
|
36
|
+
require_relative 'babeltrace2/trace-ir/clock-class'
|
37
|
+
require_relative 'babeltrace2/trace-ir/clock-snapshot'
|
38
|
+
require_relative 'babeltrace2/trace-ir/event'
|
39
|
+
require_relative 'babeltrace2/trace-ir/event-class'
|
40
|
+
require_relative 'babeltrace2/trace-ir/field-class'
|
41
|
+
require_relative 'babeltrace2/trace-ir/field'
|
42
|
+
require_relative 'babeltrace2/trace-ir/field-path'
|
43
|
+
require_relative 'babeltrace2/trace-ir/packet'
|
44
|
+
require_relative 'babeltrace2/trace-ir/stream-class'
|
45
|
+
require_relative 'babeltrace2/trace-ir/stream'
|
46
|
+
require_relative 'babeltrace2/trace-ir/trace-class'
|
47
|
+
require_relative 'babeltrace2/trace-ir/trace'
|
48
|
+
|
49
|
+
BT2 = Babeltrace2
|
@@ -0,0 +1,432 @@
|
|
1
|
+
module Babeltrace2
|
2
|
+
|
3
|
+
BTErrorCauseActorType = enum :bt_error_cause_actor_type,
|
4
|
+
[ :BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN, 1 << 0,
|
5
|
+
:BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT, 1 << 1,
|
6
|
+
:BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS, 1 << 2,
|
7
|
+
:BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR, 1 << 3]
|
8
|
+
|
9
|
+
class BTError < BTObject
|
10
|
+
end
|
11
|
+
|
12
|
+
attach_function :bt_error_cause_get_actor_type,
|
13
|
+
[:bt_error_cause_handle],
|
14
|
+
:bt_error_cause_actor_type
|
15
|
+
attach_function :bt_error_cause_get_message,
|
16
|
+
[:bt_error_cause_handle],
|
17
|
+
:string
|
18
|
+
attach_function :bt_error_cause_get_module_name,
|
19
|
+
[:bt_error_cause_handle],
|
20
|
+
:string
|
21
|
+
attach_function :bt_error_cause_get_file_name,
|
22
|
+
[:bt_error_cause_handle],
|
23
|
+
:string
|
24
|
+
attach_function :bt_error_cause_get_line_number,
|
25
|
+
[:bt_error_cause_handle],
|
26
|
+
:uint64_t
|
27
|
+
|
28
|
+
class BTError
|
29
|
+
class Cause < BTObject
|
30
|
+
ActorType = BTErrorCauseActorType
|
31
|
+
|
32
|
+
def self.from_handle(handle)
|
33
|
+
case Babeltrace2.bt_error_cause_get_actor_type(handle)
|
34
|
+
when :BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN
|
35
|
+
Cause
|
36
|
+
when :BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT
|
37
|
+
ComponentActor
|
38
|
+
when :BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS
|
39
|
+
ComponentClassActor
|
40
|
+
when :BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR
|
41
|
+
MessageIteratorActor
|
42
|
+
else
|
43
|
+
raise Error.new("Unknown error cause actor type")
|
44
|
+
end.new(handle)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_actor_type
|
48
|
+
Babeltrace2.bt_error_cause_get_actor_type(@handle)
|
49
|
+
end
|
50
|
+
alias actor_type get_actor_type
|
51
|
+
|
52
|
+
def get_message
|
53
|
+
Babeltrace2.bt_error_cause_get_message(@handle)
|
54
|
+
end
|
55
|
+
alias message get_message
|
56
|
+
|
57
|
+
def get_module_name
|
58
|
+
Babeltrace2.bt_error_cause_get_module_name(@handle)
|
59
|
+
end
|
60
|
+
alias module_name get_module_name
|
61
|
+
|
62
|
+
def get_file_name
|
63
|
+
Babeltrace2.bt_error_cause_get_file_name(@handle)
|
64
|
+
end
|
65
|
+
alias file_name get_file_name
|
66
|
+
|
67
|
+
def get_line_number
|
68
|
+
Babeltrace2.bt_error_cause_get_line_number(@handle)
|
69
|
+
end
|
70
|
+
alias line_number get_line_number
|
71
|
+
end
|
72
|
+
end
|
73
|
+
BTErrorCause = BTError::Cause
|
74
|
+
|
75
|
+
attach_function :bt_error_cause_component_actor_get_component_name,
|
76
|
+
[:bt_error_cause_handle],
|
77
|
+
:string
|
78
|
+
attach_function :bt_error_cause_component_actor_get_component_class_type,
|
79
|
+
[:bt_error_cause_handle],
|
80
|
+
:bt_component_class_type
|
81
|
+
attach_function :bt_error_cause_component_actor_get_component_class_name,
|
82
|
+
[:bt_error_cause_handle],
|
83
|
+
:string
|
84
|
+
attach_function :bt_error_cause_component_actor_get_plugin_name,
|
85
|
+
[:bt_error_cause_handle],
|
86
|
+
:string
|
87
|
+
|
88
|
+
class BTError::Cause
|
89
|
+
class ComponentActor < BTError::Cause
|
90
|
+
def get_component_name
|
91
|
+
Babeltrace2.bt_error_cause_component_actor_get_component_name(@handle)
|
92
|
+
end
|
93
|
+
alias component_name get_component_name
|
94
|
+
|
95
|
+
def get_component_class_type
|
96
|
+
Babeltrace2.bt_error_cause_component_actor_get_component_class_type(@handle)
|
97
|
+
end
|
98
|
+
alias component_class_type get_component_class_type
|
99
|
+
|
100
|
+
def get_component_class_name
|
101
|
+
Babeltrace2.bt_error_cause_component_actor_get_component_class_name(@handle)
|
102
|
+
end
|
103
|
+
alias component_class_name get_component_class_name
|
104
|
+
|
105
|
+
def get_component_plugin_name
|
106
|
+
Babeltrace2.bt_error_cause_component_actor_get_component_plugin_name(@handle)
|
107
|
+
end
|
108
|
+
alias component_plugin_name get_component_plugin_name
|
109
|
+
end
|
110
|
+
end
|
111
|
+
BTErrorCauseComponentActor = BTError::Cause::ComponentActor
|
112
|
+
|
113
|
+
attach_function :bt_error_cause_message_iterator_actor_get_component_output_port_name,
|
114
|
+
[:bt_error_cause_handle],
|
115
|
+
:string
|
116
|
+
attach_function :bt_error_cause_message_iterator_actor_get_component_name,
|
117
|
+
[:bt_error_cause_handle],
|
118
|
+
:string
|
119
|
+
attach_function :bt_error_cause_message_iterator_actor_get_component_class_type,
|
120
|
+
[:bt_error_cause_handle],
|
121
|
+
:bt_component_class_type
|
122
|
+
attach_function :bt_error_cause_message_iterator_actor_get_component_class_name,
|
123
|
+
[:bt_error_cause_handle],
|
124
|
+
:string
|
125
|
+
attach_function :bt_error_cause_message_iterator_actor_get_plugin_name,
|
126
|
+
[:bt_error_cause_handle],
|
127
|
+
:string
|
128
|
+
|
129
|
+
class BTError::Cause
|
130
|
+
class MessageIteratorActor < BTError::Cause
|
131
|
+
def get_component_output_port_name
|
132
|
+
Babeltrace2.bt_error_cause_message_iterator_actor_get_component_output_port_name(@handle)
|
133
|
+
end
|
134
|
+
alias component_output_port_name get_component_output_port_name
|
135
|
+
|
136
|
+
def get_component_name
|
137
|
+
Babeltrace2.bt_error_cause_message_iterator_actor_get_component_name(@handle)
|
138
|
+
end
|
139
|
+
alias component_name get_component_name
|
140
|
+
|
141
|
+
def get_component_class_type
|
142
|
+
Babeltrace2.bt_error_cause_message_iterator_actor_get_component_class_type(@handle)
|
143
|
+
end
|
144
|
+
alias component_class_type get_component_class_type
|
145
|
+
|
146
|
+
def get_component_class_name
|
147
|
+
Babeltrace2.bt_error_cause_message_iterator_actor_get_component_class_name(@handle)
|
148
|
+
end
|
149
|
+
alias component_class_name get_component_class_name
|
150
|
+
|
151
|
+
def get_plugin_name
|
152
|
+
Babeltrace2.bt_error_cause_message_iterator_actor_get_plugin_name(@handle)
|
153
|
+
end
|
154
|
+
alias plugin_name get_plugin_name
|
155
|
+
end
|
156
|
+
end
|
157
|
+
BTErrorCauseMessageIteratorActor = BTError::Cause::MessageIteratorActor
|
158
|
+
|
159
|
+
attach_function :bt_error_cause_component_class_actor_get_component_class_type,
|
160
|
+
[:bt_error_cause_handle],
|
161
|
+
:bt_component_class_type
|
162
|
+
attach_function :bt_error_cause_component_class_actor_get_component_class_name,
|
163
|
+
[:bt_error_cause_handle],
|
164
|
+
:string
|
165
|
+
attach_function :bt_error_cause_component_class_actor_get_plugin_name,
|
166
|
+
[:bt_error_cause_handle],
|
167
|
+
:string
|
168
|
+
|
169
|
+
class BTError::Cause
|
170
|
+
class ComponentClassActor < BTError::Cause
|
171
|
+
def get_component_class_type
|
172
|
+
Babeltrace2.bt_error_cause_component_class_actor_get_component_class_type(@hanlde)
|
173
|
+
end
|
174
|
+
alias component_class_type get_component_class_type
|
175
|
+
|
176
|
+
def get_component_class_name
|
177
|
+
Babeltrace2.bt_error_cause_component_class_actor_get_component_class_name(@handle)
|
178
|
+
end
|
179
|
+
alias get_component_class_name get_component_class_name
|
180
|
+
|
181
|
+
def get_plugin_name
|
182
|
+
Babeltrace2.bt_error_cause_component_class_actor_get_plugin_name(@handle)
|
183
|
+
end
|
184
|
+
alias plugin_name get_plugin_name
|
185
|
+
end
|
186
|
+
end
|
187
|
+
BTErrorCauseComponentClassActor = BTError::Cause::ComponentClassActor
|
188
|
+
|
189
|
+
BTCurrentThreadErrorAppendCauseStatus = enum :bt_current_thread_error_append_cause_status,
|
190
|
+
[ :BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK, BT_FUNC_STATUS_OK,
|
191
|
+
:BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_MEMORY_ERROR, BT_FUNC_STATUS_MEMORY_ERROR ]
|
192
|
+
|
193
|
+
attach_function :bt_current_thread_take_error,
|
194
|
+
[],
|
195
|
+
:bt_error_handle
|
196
|
+
attach_function :bt_current_thread_move_error,
|
197
|
+
[:bt_error_handle],
|
198
|
+
:void
|
199
|
+
attach_function :bt_current_thread_clear_error,
|
200
|
+
[],
|
201
|
+
:void
|
202
|
+
attach_function :bt_current_thread_error_append_cause_from_component,
|
203
|
+
[:bt_self_component_handle, :string, :uint64, :string, :varargs],
|
204
|
+
:bt_current_thread_error_append_cause_status
|
205
|
+
attach_function :bt_current_thread_error_append_cause_from_message_iterator,
|
206
|
+
[:bt_self_message_iterator_handle, :string, :uint64, :string, :varargs],
|
207
|
+
:bt_current_thread_error_append_cause_status
|
208
|
+
attach_function :bt_current_thread_error_append_cause_from_component_class,
|
209
|
+
[:bt_self_component_class_handle, :string, :uint64, :string, :varargs],
|
210
|
+
:bt_current_thread_error_append_cause_status
|
211
|
+
attach_function :bt_current_thread_error_append_cause_from_unknown,
|
212
|
+
[:string, :string, :uint64, :string, :varargs],
|
213
|
+
:bt_current_thread_error_append_cause_status
|
214
|
+
|
215
|
+
module BTCurrentThread
|
216
|
+
ErrorAppendCauseStatus = BTCurrentThreadErrorAppendCauseStatus
|
217
|
+
def self.take_error
|
218
|
+
handle = Babeltrace2.bt_current_thread_take_error
|
219
|
+
return nil if handle.null?
|
220
|
+
BTError.new(handle)
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.clear_error
|
224
|
+
Babeltrace2.bt_current_thread_clear_error
|
225
|
+
self
|
226
|
+
end
|
227
|
+
|
228
|
+
def self.move_error(error)
|
229
|
+
raise Error.new("Error already released") unless error.handle
|
230
|
+
Babeltrace2.bt_current_thread_move_error(error.handle)
|
231
|
+
error.instance_variable_set(:@handle, nil)
|
232
|
+
self
|
233
|
+
end
|
234
|
+
|
235
|
+
module Error
|
236
|
+
AppendCauseStatus = BTCurrentThreadErrorAppendCauseStatus
|
237
|
+
def self.append_cause_from_component(self_component, message_format, *args,
|
238
|
+
file_name: nil, line_number: nil)
|
239
|
+
loc = caller_locations.first
|
240
|
+
file_name = loc.path unless file_name
|
241
|
+
line_number = loc.lineno unless line_number
|
242
|
+
res = Babeltrace2.bt_current_thread_error_append_cause_from_component(
|
243
|
+
self_component, file_name, line_number, message_format, *args)
|
244
|
+
raise res.to_s if res != :BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
|
245
|
+
self
|
246
|
+
end
|
247
|
+
|
248
|
+
def self.append_cause_from_message_iterator(self_message_iterator, message_format,
|
249
|
+
*args, file_name: nil, line_number: nil)
|
250
|
+
loc = caller_locations.first
|
251
|
+
file_name = loc.path unless file_name
|
252
|
+
line_number = loc.lineno unless line_number
|
253
|
+
res = Babeltrace2.bt_current_thread_error_append_cause_from_message_iterator(
|
254
|
+
self_message_iterator, file_name, line_number, message_format, *args)
|
255
|
+
raise res.to_s if res != :BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
|
256
|
+
self
|
257
|
+
end
|
258
|
+
|
259
|
+
def self.append_cause_from_component_class(self_component_class, message_format,
|
260
|
+
*args, file_name: nil, line_number: nil)
|
261
|
+
loc = caller_locations.first
|
262
|
+
file_name = loc.path unless file_name
|
263
|
+
line_number = loc.lineno unless line_number
|
264
|
+
res = Babeltrace2.bt_current_thread_error_append_cause_from_component_class(
|
265
|
+
self_component_class, file_name, line_number, message_format, *args)
|
266
|
+
raise res.to_s if res != :BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
|
267
|
+
self
|
268
|
+
end
|
269
|
+
|
270
|
+
def self.append_cause_from_unknown(module_name, message_format, *args,
|
271
|
+
file_name: nil, line_number: nil)
|
272
|
+
loc = caller_locations.first
|
273
|
+
file_name = loc.path unless file_name
|
274
|
+
line_number = loc.lineno unless line_number
|
275
|
+
res = Babeltrace2.bt_current_thread_error_append_cause_from_unknown(
|
276
|
+
module_name, file_name, line_number, message_format, *args)
|
277
|
+
raise res.to_s if res != :BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_STATUS_OK
|
278
|
+
self
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
attach_function :bt_error_get_cause_count,
|
284
|
+
[:bt_error_handle],
|
285
|
+
:uint64
|
286
|
+
attach_function :bt_error_borrow_cause_by_index,
|
287
|
+
[:bt_error_handle, :uint64],
|
288
|
+
:bt_error_cause_handle
|
289
|
+
attach_function :bt_error_release,
|
290
|
+
[:bt_error_handle],
|
291
|
+
:void
|
292
|
+
|
293
|
+
class BTError
|
294
|
+
def get_cause_count
|
295
|
+
raise Error.new("Error already released") unless @handle
|
296
|
+
Babeltrace2.bt_error_get_cause_count(@handle)
|
297
|
+
end
|
298
|
+
alias cause_count get_cause_count
|
299
|
+
|
300
|
+
def get_cause_by_index(indx)
|
301
|
+
return nil unless indx < get_cause_count
|
302
|
+
ref = Babeltrace2.bt_error_borrow_cause_by_index(@handle, indx)
|
303
|
+
Cause.new(ref)
|
304
|
+
end
|
305
|
+
|
306
|
+
def causes
|
307
|
+
get_cause_count.times.collect { |i|
|
308
|
+
ref = Babeltrace2.bt_error_borrow_cause_by_index(@handle, i)
|
309
|
+
Cause.new(ref)
|
310
|
+
}
|
311
|
+
end
|
312
|
+
|
313
|
+
def release
|
314
|
+
raise Error.new("Error already released") unless @handle
|
315
|
+
Babeltrace2.bt_error_release(@handle)
|
316
|
+
@handle = nil
|
317
|
+
end
|
318
|
+
|
319
|
+
def to_s
|
320
|
+
str = ""
|
321
|
+
causes.each { |c|
|
322
|
+
file_name = c.file_name
|
323
|
+
line_number = c.line_number
|
324
|
+
str << file_name << ":" if file_name
|
325
|
+
str << line_number.to_s << ":" if line_number
|
326
|
+
str << " "
|
327
|
+
str << c.message
|
328
|
+
str << "\n"
|
329
|
+
}
|
330
|
+
str
|
331
|
+
end
|
332
|
+
|
333
|
+
def exception_params()
|
334
|
+
klass = nil
|
335
|
+
message = nil
|
336
|
+
backtrace = []
|
337
|
+
cs = causes
|
338
|
+
return [klass, message, backtrace] if cs.empty?
|
339
|
+
c = cs.first
|
340
|
+
mess = c.message
|
341
|
+
m = mess.match(/ ::(.*?): (.*)/m)
|
342
|
+
if m
|
343
|
+
klass = m[1]
|
344
|
+
message = m[2]
|
345
|
+
mess.sub!( m[0], "" )
|
346
|
+
end
|
347
|
+
item = ""
|
348
|
+
item << c.file_name << ":"
|
349
|
+
item << c.line_number.to_s
|
350
|
+
item << (mess.match(/:in /) ? mess : ".")
|
351
|
+
backtrace.push(item)
|
352
|
+
cs[1..-1].each { |c|
|
353
|
+
item = ""
|
354
|
+
item << c.file_name << ":"
|
355
|
+
item << c.line_number.to_s
|
356
|
+
mess = c.message
|
357
|
+
item << (mess.match(/:in /) ? mess : ".")
|
358
|
+
backtrace.push(item)
|
359
|
+
}
|
360
|
+
[klass, message, backtrace]
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
def self.stack_error(source, message, absolute_path, lineno)
|
365
|
+
case source
|
366
|
+
when BTSelfComponent, BTSelfComponentHandle
|
367
|
+
BTCurrentThread::Error.append_cause_from_component(
|
368
|
+
source, message, file_name: absolute_path, line_number: lineno)
|
369
|
+
when BTSelfComponentClass, BTSelfComponentClassHandle
|
370
|
+
BTCurrentThread::Error.append_cause_from_component_class(
|
371
|
+
source, message, file_name: absolute_path, line_number: lineno)
|
372
|
+
when BTSelfMessageIterator, BTSelfMessageIteratorHandle
|
373
|
+
BTCurrentThread::Error.append_cause_from_message_iterator(
|
374
|
+
source, message, file_name: absolute_path, line_number: lineno)
|
375
|
+
else
|
376
|
+
BTCurrentThread::Error.append_cause_from_unknown(
|
377
|
+
"babeltrace2-ruby", message, file_name: absolute_path, line_number: lineno)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
def self.stack_ruby_error(err, source: nil)
|
382
|
+
mess = "#{err.class}: #{err.message}"
|
383
|
+
backtrace_locations = err.backtrace_locations
|
384
|
+
if backtrace_locations
|
385
|
+
err.backtrace_locations.each { |loc|
|
386
|
+
lineno = loc.lineno
|
387
|
+
absolute_path = loc.absolute_path
|
388
|
+
label = loc.label
|
389
|
+
message = ""
|
390
|
+
if label
|
391
|
+
message << ":in `" << label << "'"
|
392
|
+
else
|
393
|
+
message << "."
|
394
|
+
end
|
395
|
+
message << " :: " << mess if mess
|
396
|
+
stack_error(source, message, absolute_path, lineno)
|
397
|
+
mess = nil
|
398
|
+
}
|
399
|
+
else
|
400
|
+
err.backtrace.each { |loc|
|
401
|
+
m = loc.match(/(.*?):(\d*)([\.:].*)/)
|
402
|
+
if m
|
403
|
+
absolute_path = m[1]
|
404
|
+
lineno = m[2].to_i
|
405
|
+
message = m[3]
|
406
|
+
message << " :: " << mess if mess
|
407
|
+
stack_error(source, message, absolute_path, lineno)
|
408
|
+
mess = nil
|
409
|
+
end
|
410
|
+
}
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def self.process_error(code = :BT_FUNC_STATUS_MEMORY_ERROR)
|
415
|
+
err = BTCurrentThread.take_error
|
416
|
+
if err
|
417
|
+
klass, message, backtrace = err.exception_params
|
418
|
+
err.release
|
419
|
+
else
|
420
|
+
klass, message, backtrace = nil, nil, []
|
421
|
+
end
|
422
|
+
if klass
|
423
|
+
klass = eval(klass)
|
424
|
+
e = klass.new(message)
|
425
|
+
else
|
426
|
+
message = "#{code}" unless message
|
427
|
+
e = Error.new
|
428
|
+
end
|
429
|
+
e.set_backtrace(backtrace+caller_locations.collect(&:to_s))
|
430
|
+
e
|
431
|
+
end
|
432
|
+
end
|