metababel 1.0.2 → 1.0.3
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 +4 -4
- data/bin/metababel +18 -15
- data/lib/metababel/bt2_trace_class_generator.rb +27 -0
- data/lib/metababel/version.rb +1 -1
- data/template/component.c.erb +13 -1
- data/template/component.h.erb +1 -0
- data/template/filter.c.erb +1 -1
- data/template/sink.c.erb +1 -1
- data/template/source.c.erb +4 -10
- data/template/upstream.c.erb +20 -31
- data/template/upstream.h.erb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29d62dad7a8e18caa6eae836db0caf7b0e7dd5012c6d83492e51140d9c4ab110
|
|
4
|
+
data.tar.gz: 9781c211009fbb238c4a96b3faf0341607da2b202155179f58aa545d75f45809
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0fef46f9f4461770e2b1994e087788a53dfe3b198d8a529e9e0486320a788f6eac20b4230605f612dbd7cdcbc69746b93e9605f06086353f78a70f6da5774f0
|
|
7
|
+
data.tar.gz: '0791014239ed111d63148bdb45c2a8d48f45ad0e51a2440fc9171e2220465add097e1f7a4340fef82aca2f4f2b303e1083803ab9d76a6252cfbf9795fc72dfbe'
|
data/bin/metababel
CHANGED
|
@@ -62,8 +62,11 @@ class BaseDispatch
|
|
|
62
62
|
alias eql? ==
|
|
63
63
|
|
|
64
64
|
def hash
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
# Remove cycle in dependency, and memos
|
|
66
|
+
blacklist = %i[@dispatch_types @matched_dispatchers @body_args]
|
|
67
|
+
instance_variables.filter_map do |i|
|
|
68
|
+
instance_variable_get(i).hash unless blacklist.include?(i)
|
|
69
|
+
end.reduce(:^)
|
|
67
70
|
end
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -103,8 +106,8 @@ class Dispatcher < BaseDispatch
|
|
|
103
106
|
@index_stream_class = index_stream_class
|
|
104
107
|
@index_event_class = index_event_class
|
|
105
108
|
@default_clock_class = default_clock_class
|
|
106
|
-
@dispatch_types = []
|
|
107
109
|
@name = event.name
|
|
110
|
+
@dispatch_types = []
|
|
108
111
|
end
|
|
109
112
|
|
|
110
113
|
def body_args
|
|
@@ -230,13 +233,12 @@ def parse_argv
|
|
|
230
233
|
end
|
|
231
234
|
|
|
232
235
|
def get_dispatch_type(em, default_clock_class, context)
|
|
233
|
-
|
|
234
236
|
begin
|
|
235
237
|
dispatchers = em.domain ? OpenStruct.new(context).instance_eval(em.domain) : context['all']
|
|
236
238
|
rescue StandardError
|
|
237
239
|
raise "Please ensure the domain '#{em.domain}' uses valid ruby expressions and all set_id have been previously defined. Current defined set_ids: #{context.keys}."
|
|
238
240
|
end
|
|
239
|
-
|
|
241
|
+
raise 'Metababel Hash Set problem' unless (dispatchers - dispatchers).empty?
|
|
240
242
|
raise "Nil or empty event set for '#{em.set_id}'." unless dispatchers.is_a?(Set)
|
|
241
243
|
|
|
242
244
|
matched_dispatchers, signatures = dispatchers.filter_map do |dispatcher|
|
|
@@ -251,19 +253,20 @@ def get_dispatch_type(em, default_clock_class, context)
|
|
|
251
253
|
# Verify the uniqueness of signatures.
|
|
252
254
|
# Note that `s.type` takes into account the `cast_type`
|
|
253
255
|
# (see TestMatchingConflictingSignatures for more details)
|
|
254
|
-
unique_signatures = signatures.uniq
|
|
256
|
+
unique_signatures = signatures.map { |s| "(#{s.map(&:type).join(', ')})" }.uniq
|
|
255
257
|
unless unique_signatures.size == 1
|
|
256
|
-
signatures_str = unique_signatures.
|
|
258
|
+
signatures_str = unique_signatures.join(', ')
|
|
257
259
|
raise "Conflicting signatures for '#{em.set_id}', found #{unique_signatures.size} signatures, only one allowed: '#{signatures_str}'"
|
|
258
260
|
end
|
|
259
261
|
|
|
260
262
|
# Modify the dispatcher to add the new dispatchType
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
dispatch_type_args
|
|
264
|
-
|
|
265
|
-
|
|
263
|
+
timestamp = default_clock_class ? [GeneratedArg.new('int64_t', '_timestamp')] : []
|
|
264
|
+
event_class_name = [GeneratedArg.new('const char *', '_event_class_name')]
|
|
265
|
+
dispatch_type_args = matched_dispatchers.zip(signatures).map do |m, s|
|
|
266
|
+
[m.name, timestamp + event_class_name + s]
|
|
267
|
+
end.to_h
|
|
266
268
|
|
|
269
|
+
name = em.set_id
|
|
267
270
|
dispatch_type = DispatchType.new(
|
|
268
271
|
name, dispatch_type_args, "matching_#{sanitize(name)}", matched_dispatchers
|
|
269
272
|
)
|
|
@@ -354,7 +357,7 @@ class ContextBuilder
|
|
|
354
357
|
|
|
355
358
|
def callback_types
|
|
356
359
|
@callback_types ||= begin
|
|
357
|
-
callback_types = ['
|
|
360
|
+
callback_types = ['automatic']
|
|
358
361
|
if @cli_options.key?(:matching)
|
|
359
362
|
event_classes = trace_matcher.stream_classes.map(&:event_classes).flatten(1).filter do |em|
|
|
360
363
|
raise "Key ':set_id' required for matching events." unless em.set_id
|
|
@@ -427,7 +430,7 @@ class ContextBuilder
|
|
|
427
430
|
dispatchers, automatic_dispatch_types = t.filter_map_event_classes_with_index do |e, index_stream_class, index_event_class, default_clock_class|
|
|
428
431
|
dispatcher = Dispatcher.new(e, event_name, 'getter', index_stream_class, index_event_class,
|
|
429
432
|
default_clock_class)
|
|
430
|
-
dispatch_type = DispatchType.new(e.name, dispatcher.args, '
|
|
433
|
+
dispatch_type = DispatchType.new(e.name, { e.name => dispatcher.args }, 'automatic', [dispatcher])
|
|
431
434
|
dispatcher.dispatch_types << dispatch_type
|
|
432
435
|
|
|
433
436
|
[dispatcher, dispatch_type]
|
|
@@ -459,7 +462,7 @@ end
|
|
|
459
462
|
|
|
460
463
|
def wrote_upstream(cb)
|
|
461
464
|
erb_render_and_save(cb.get_context(%w[upstream]), 'upstream.h', cb.folder)
|
|
462
|
-
erb_render_and_save(cb.get_context(%w[upstream]), 'upstream.c', cb.folder)
|
|
465
|
+
erb_render_and_save(cb.get_context(%w[upstream callback_types]), 'upstream.c', cb.folder)
|
|
463
466
|
end
|
|
464
467
|
|
|
465
468
|
def wrote_downstream(cb)
|
|
@@ -632,6 +632,7 @@ module Babeltrace2Gen
|
|
|
632
632
|
|
|
633
633
|
class BTFieldClass::Array::Static < BTFieldClass::Array
|
|
634
634
|
extend BTFromH
|
|
635
|
+
using HashRefinements
|
|
635
636
|
attr_reader :length
|
|
636
637
|
|
|
637
638
|
def initialize(parent:, element_field_class:, length:)
|
|
@@ -645,8 +646,34 @@ module Babeltrace2Gen
|
|
|
645
646
|
pr "bt_field_class *#{element_field_class_variable};"
|
|
646
647
|
@element_field_class.get_declarator(trace_class: trace_class, variable: element_field_class_variable)
|
|
647
648
|
pr "#{variable} = bt_field_class_array_static_create(#{trace_class}, #{element_field_class_variable}, #{@length});"
|
|
649
|
+
pr "bt_field_class_put_ref(#{element_field_class_variable});"
|
|
650
|
+
end
|
|
651
|
+
end
|
|
652
|
+
|
|
653
|
+
def get_setter(field:, arg_variables:)
|
|
654
|
+
usr_var = bt_get_variable(arg_variables, is_array: true)
|
|
655
|
+
pr "for(uint64_t _i=0; _i < #{@length} ; _i++)"
|
|
656
|
+
scope do
|
|
657
|
+
v = "#{field}_e"
|
|
658
|
+
pr "bt_field* #{v} = bt_field_array_borrow_element_field_by_index(#{field}, _i);"
|
|
659
|
+
arg_variables.fetch_append('internal', GeneratedArg.new('', "#{usr_var.name}[_i]"))
|
|
660
|
+
@element_field_class.get_setter(field: v, arg_variables: arg_variables)
|
|
661
|
+
end
|
|
662
|
+
end
|
|
663
|
+
|
|
664
|
+
def get_getter(field:, arg_variables:)
|
|
665
|
+
length = @length
|
|
666
|
+
usr_var = bt_get_variable(arg_variables, is_array: true)
|
|
667
|
+
pr "#{usr_var.name} = (#{usr_var.type}) malloc(#{length} * sizeof(#{usr_var.name}));"
|
|
668
|
+
pr "for(uint64_t _i=0; _i < #{length} ; _i++)"
|
|
669
|
+
scope do
|
|
670
|
+
v = "#{field}_e"
|
|
671
|
+
pr "const bt_field* #{v} = bt_field_array_borrow_element_field_by_index_const(#{field}, _i);"
|
|
672
|
+
arg_variables.fetch_append('internal', GeneratedArg.new('', "#{usr_var.name}[_i]"))
|
|
673
|
+
@element_field_class.get_getter(field: v, arg_variables: arg_variables)
|
|
648
674
|
end
|
|
649
675
|
end
|
|
676
|
+
|
|
650
677
|
end
|
|
651
678
|
|
|
652
679
|
class BTFieldClass::Array::Dynamic < BTFieldClass::Array
|
data/lib/metababel/version.rb
CHANGED
data/template/component.c.erb
CHANGED
|
@@ -14,7 +14,6 @@ void btx_populate_params(common_data_t *common_data) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
<% static_callback_types.each do |e| %>
|
|
17
|
-
|
|
18
17
|
void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
19
18
|
void *btx_handle, <%= e.name_sanitized %>_static_callback_f *callback) {
|
|
20
19
|
((common_data_t *)btx_handle)->static_callbacks-><%= e.name_sanitized %> =
|
|
@@ -32,3 +31,16 @@ void btx_call_callbacks_<%= e.name_sanitized %>(
|
|
|
32
31
|
<%= e.args.map{ |s| s.name }.join(", ") %>);
|
|
33
32
|
}
|
|
34
33
|
<% end %>
|
|
34
|
+
|
|
35
|
+
void btx_unregister_callbacks(common_data_t *common_data) {
|
|
36
|
+
name_to_dispatcher_t *current, *tmp;
|
|
37
|
+
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
38
|
+
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
39
|
+
<% callback_types.each do |id| %>
|
|
40
|
+
if (current->callbacks-><%= id %>)
|
|
41
|
+
utarray_free(current->callbacks-><%= id %>);
|
|
42
|
+
<% end %>
|
|
43
|
+
free(current->callbacks);
|
|
44
|
+
free(current);
|
|
45
|
+
}
|
|
46
|
+
}
|
data/template/component.h.erb
CHANGED
|
@@ -169,6 +169,7 @@ struct common_data_s {
|
|
|
169
169
|
<% end %>
|
|
170
170
|
|
|
171
171
|
void btx_register_usr_callbacks(void *btx_handle);
|
|
172
|
+
void btx_unregister_callbacks(common_data_t *common_data);
|
|
172
173
|
|
|
173
174
|
<% static_callback_types.each do |e| %>
|
|
174
175
|
typedef void <%= e.name_sanitized %>_static_callback_f(
|
data/template/filter.c.erb
CHANGED
|
@@ -488,7 +488,7 @@ static void filter_finalize(bt_self_component_filter *self_component_filter) {
|
|
|
488
488
|
bt_trace_put_ref(common_data->downstream_trace);
|
|
489
489
|
|
|
490
490
|
/* Delete name_to_dispatchers */
|
|
491
|
-
|
|
491
|
+
btx_unregister_callbacks(common_data);
|
|
492
492
|
|
|
493
493
|
/* We allocate it, we need to free it */
|
|
494
494
|
free(common_data->btx_params);
|
data/template/sink.c.erb
CHANGED
|
@@ -126,7 +126,7 @@ static void sink_finalize(bt_self_component_sink *self_component_sink) {
|
|
|
126
126
|
btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
|
|
127
127
|
|
|
128
128
|
// Delete name_to_dispatcher
|
|
129
|
-
|
|
129
|
+
btx_unregister_callbacks(common_data);
|
|
130
130
|
|
|
131
131
|
// We allocate it, we need to free it
|
|
132
132
|
free(common_data->btx_params);
|
data/template/source.c.erb
CHANGED
|
@@ -176,19 +176,13 @@ static void source_finalize(bt_self_component_source *self_component_source) {
|
|
|
176
176
|
btx_call_callbacks_finalize_component(common_data, common_data->usr_data);
|
|
177
177
|
|
|
178
178
|
btx_streams_put_ref(common_data->downstream_trace); // ??
|
|
179
|
-
|
|
179
|
+
/* We allocate it, we need to put ref */
|
|
180
180
|
bt_trace_put_ref(common_data->downstream_trace);
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
185
|
-
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
186
|
-
utarray_free(current->callbacks->generic);
|
|
187
|
-
free(current->callbacks);
|
|
188
|
-
free(current);
|
|
189
|
-
}
|
|
182
|
+
/* Delete name_to_dispatchers */
|
|
183
|
+
btx_unregister_callbacks(common_data);
|
|
190
184
|
|
|
191
|
-
|
|
185
|
+
/* We allocate it, we need to free it */
|
|
192
186
|
free(common_data->btx_params);
|
|
193
187
|
free(common_data->static_callbacks);
|
|
194
188
|
bt_value_put_ref(common_data->params);
|
data/template/upstream.c.erb
CHANGED
|
@@ -28,7 +28,7 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
|
|
|
28
28
|
bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &_timestamp);
|
|
29
29
|
<% end %>
|
|
30
30
|
<%# event_class_name, only required when there is at least one matching callback for this event. %>
|
|
31
|
-
<% if dispatcher.dispatch_types.map
|
|
31
|
+
<% if dispatcher.dispatch_types.map { |dt| dt.args[dispatcher.name] }.flatten.any? { |arg| arg.name == '_event_class_name' } %>
|
|
32
32
|
const char *_event_class_name = "<%= dispatcher.name %>";
|
|
33
33
|
<% end %>
|
|
34
34
|
|
|
@@ -42,7 +42,7 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
|
|
|
42
42
|
(*((<%= dispatch_type.name_sanitized %>_callback_f **)(_p)))(
|
|
43
43
|
(void *)common_data,
|
|
44
44
|
common_data
|
|
45
|
-
->usr_data<%= dispatch_type.args.map{ |a| a.name }.join_with_prefix(", ") %>);
|
|
45
|
+
->usr_data<%= dispatch_type.args[dispatcher.name].map{ |a| a.name }.join_with_prefix(", ") %>);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -54,56 +54,45 @@ static void btx_dispatch_<%= dispatcher.name_sanitized %>(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
<% end %>
|
|
57
|
-
|
|
58
|
-
void
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
static void bt_register_callbacks(void *btx_handle, const char *dispatcher_name,
|
|
59
|
+
void *btx_dispatch_p, const char *id,
|
|
60
|
+
void *callback) {
|
|
61
|
+
|
|
61
62
|
name_to_dispatcher_t *s = NULL;
|
|
63
|
+
|
|
62
64
|
name_to_dispatcher_t **name_to_dispatcher =
|
|
63
65
|
&((common_data_t *)btx_handle)->name_to_dispatcher;
|
|
64
|
-
HASH_FIND_STR(*name_to_dispatcher,
|
|
66
|
+
HASH_FIND_STR(*name_to_dispatcher, dispatcher_name, s);
|
|
67
|
+
|
|
65
68
|
if (!s) {
|
|
66
69
|
// We didn't find the dispatcher, so we need to create it.
|
|
67
70
|
s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
|
|
68
|
-
s->name =
|
|
69
|
-
s->dispatcher =
|
|
71
|
+
s->name = dispatcher_name;
|
|
72
|
+
s->dispatcher = btx_dispatch_p;
|
|
70
73
|
s->callbacks = (callbacks_t *)calloc(1, sizeof(callbacks_t));
|
|
71
74
|
// 2. Register it
|
|
72
75
|
HASH_ADD_KEYPTR(hh, *name_to_dispatcher, s->name, strlen(s->name), s);
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
<%
|
|
76
|
-
if (strcmp("<%=
|
|
78
|
+
<% callback_types.each_with_index do |id,i| %>
|
|
79
|
+
<%= i == 0 ? "if" : "else if" %>(strcmp("<%= id %>", id) == 0) {
|
|
77
80
|
// Add the callbacks to the array
|
|
78
|
-
if (!s->callbacks-><%=
|
|
79
|
-
utarray_new(s->callbacks-><%=
|
|
80
|
-
utarray_push_back(s->callbacks-><%=
|
|
81
|
+
if (!s->callbacks-><%= id %>)
|
|
82
|
+
utarray_new(s->callbacks-><%= id %>, &ut_ptr_icd);
|
|
83
|
+
utarray_push_back(s->callbacks-><%= id %>, &callback);
|
|
81
84
|
}
|
|
82
|
-
|
|
83
85
|
<% end %>
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
<% end %>
|
|
87
88
|
<% dispatch_types.each do |dispatch_type| %>
|
|
88
89
|
void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
|
|
89
90
|
void *btx_handle,
|
|
90
91
|
<%= dispatch_type.name_sanitized %>_callback_f *callback) {
|
|
91
92
|
<% dispatch_type.matched_dispatchers.each do |dispatcher| %>
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
bt_register_callbacks(btx_handle, "<%= dispatcher.name %>",
|
|
94
|
+
(void *)&btx_dispatch_<%= dispatcher.name_sanitized %>,
|
|
95
|
+
"<%= dispatch_type.id %>", (void *)callback);
|
|
94
96
|
<% end %>
|
|
95
97
|
}
|
|
96
|
-
|
|
97
98
|
<% end %>
|
|
98
|
-
void btx_delete_dispatchers(common_data_t *common_data) {
|
|
99
|
-
name_to_dispatcher_t *current, *tmp;
|
|
100
|
-
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
101
|
-
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
102
|
-
<% dispatch_types.map(&:id).uniq.each do |name| %>
|
|
103
|
-
if (current->callbacks-><%= name %>)
|
|
104
|
-
utarray_free(current->callbacks-><%= name %>);
|
|
105
|
-
<% end %>
|
|
106
|
-
free(current->callbacks);
|
|
107
|
-
free(current);
|
|
108
|
-
}
|
|
109
|
-
}
|
data/template/upstream.h.erb
CHANGED
|
@@ -13,13 +13,13 @@ typedef void(dispatcher_t)(callbacks_t *callbacks, common_data_t *common_data,
|
|
|
13
13
|
typedef void <%= dispatch_type.name_sanitized %>_callback_f(
|
|
14
14
|
void *btx_handle,
|
|
15
15
|
void *
|
|
16
|
-
usr_data<%= dispatch_type.args.map{ |s| s.type }.join_with_prefix(', ') %>);
|
|
16
|
+
usr_data<%= dispatch_type.args.values[0].map{ |s| s.type }.join_with_prefix(', ') %>);
|
|
17
17
|
|
|
18
18
|
void btx_register_callbacks_<%= dispatch_type.name_sanitized %>(
|
|
19
19
|
void *btx_handle, <%= dispatch_type.name_sanitized %>_callback_f *callback);
|
|
20
20
|
|
|
21
21
|
<% end %>
|
|
22
|
-
void
|
|
22
|
+
void btx_unregister_callbacks(common_data_t *common_data);
|
|
23
23
|
|
|
24
24
|
#ifdef __cplusplus
|
|
25
25
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metababel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Applencourt
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email:
|
|
@@ -57,7 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
57
57
|
- !ruby/object:Gem::Version
|
|
58
58
|
version: '0'
|
|
59
59
|
requirements: []
|
|
60
|
-
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 2.7.6.3
|
|
61
62
|
signing_key:
|
|
62
63
|
specification_version: 4
|
|
63
64
|
summary: Helper for creation Babeltrace plugins
|