metababel 0.0.3 → 0.0.5
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 +58 -29
- data/lib/metababel/bt2_stream_classes_generator.rb +133 -67
- data/lib/metababel/bt2_values_generator.rb +19 -16
- data/lib/metababel/version.rb +1 -1
- data/template/component.c.erb +0 -1
- data/template/component.h.erb +3 -0
- data/template/downstream.c.erb +6 -6
- data/template/downstream.h.erb +2 -2
- data/template/filter.c.erb +250 -145
- data/template/sink.c.erb +34 -15
- data/template/upstream.c.erb +118 -8
- data/template/upstream.h.erb +36 -6
- metadata +2 -2
data/template/upstream.c.erb
CHANGED
|
@@ -4,24 +4,44 @@
|
|
|
4
4
|
#include <babeltrace2/babeltrace.h>
|
|
5
5
|
#include <metababel/btx_component.h>
|
|
6
6
|
#include <metababel/btx_upstream.h>
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
#include <stdlib.h>
|
|
7
9
|
|
|
8
|
-
<%
|
|
9
|
-
static void
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const bt_event *<%= event_name %>) {
|
|
10
|
+
<% event_class_dispatchers.each do |e| %>
|
|
11
|
+
static void btx_dispatch_<%= e.name_sanitized %>(
|
|
12
|
+
UT_array *callbacks, common_data_t *common_data,
|
|
13
|
+
const bt_message *upstream_message, bool *is_callback_called) {
|
|
13
14
|
|
|
14
15
|
<% e.args.each do |s| %>
|
|
15
16
|
<%= s.type %> <%= s.name %>;
|
|
16
17
|
<% end %>
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
<%# Since now event is a variable, we need to check if the body will render variables that accesses it. %>
|
|
20
|
+
<% if not e.body.empty? %>
|
|
21
|
+
const bt_event *<%= event_name %> = bt_message_event_borrow_event_const(upstream_message);
|
|
22
|
+
<%= "\n" + e.body %>
|
|
23
|
+
<% end %>
|
|
24
|
+
|
|
25
|
+
<% if e.default_clock_class %>
|
|
26
|
+
int64_t _timestamp;
|
|
27
|
+
const bt_clock_snapshot *clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(upstream_message);
|
|
28
|
+
bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &_timestamp);
|
|
29
|
+
<% end %>
|
|
18
30
|
// Call all the callbacks who where registered
|
|
19
31
|
// Their type are declared in 'upstream.h'
|
|
20
32
|
<%= e.name_sanitized %>_callback_f **p = NULL;
|
|
21
33
|
while ((p = utarray_next(callbacks, p))) {
|
|
22
|
-
(*p)((void *)common_data,
|
|
23
|
-
|
|
34
|
+
(*p)((void *)common_data,
|
|
35
|
+
common_data
|
|
36
|
+
->usr_data<%= ', _timestamp' if e.default_clock_class %><%= e.args.map{ |s| s.name }.join_with_prefix(", ") %>);
|
|
24
37
|
}
|
|
38
|
+
|
|
39
|
+
<% e.args_to_free.each do |s| %>
|
|
40
|
+
<%= "free(#{s.name});" %>
|
|
41
|
+
<% end %>
|
|
42
|
+
|
|
43
|
+
if (callbacks)
|
|
44
|
+
*is_callback_called = true;
|
|
25
45
|
}
|
|
26
46
|
|
|
27
47
|
void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
@@ -45,3 +65,93 @@ void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
|
45
65
|
utarray_push_back(s->callbacks, &callback);
|
|
46
66
|
}
|
|
47
67
|
<% end %>
|
|
68
|
+
|
|
69
|
+
<% stream_classes_matching_dispatchers.each do |s| %>
|
|
70
|
+
void btx_matching_dispatch_<%= s.name_sanitized %>(UT_array *callbacks,
|
|
71
|
+
common_data_t *common_data,
|
|
72
|
+
const bt_message *upstream_message,
|
|
73
|
+
bool *is_callback_called) {
|
|
74
|
+
|
|
75
|
+
<% s.args.each do |a| %>
|
|
76
|
+
<%= a.type %> <%= a.name %>;
|
|
77
|
+
<% end %>
|
|
78
|
+
const bt_event *<%= event_name %> = bt_message_event_borrow_event_const(upstream_message);
|
|
79
|
+
<%= s.body %>
|
|
80
|
+
const bt_event_class *event_class = bt_event_borrow_class_const(<%= event_name %>);
|
|
81
|
+
const char *event_class_name = bt_event_class_get_name(event_class);
|
|
82
|
+
|
|
83
|
+
condition_to_callback_t **p = NULL;
|
|
84
|
+
while ((p = utarray_next(callbacks, p))) {
|
|
85
|
+
<%= s.name_sanitized %>_callback_condition_f *condition =
|
|
86
|
+
(<%= s.name_sanitized %>_callback_condition_f *)((*p)->condition);
|
|
87
|
+
<%= s.name_sanitized %>_conditioned_callback_f *callback =
|
|
88
|
+
(<%= s.name_sanitized %>_conditioned_callback_f *)((*p)->callback);
|
|
89
|
+
<% if s.default_clock_class %>
|
|
90
|
+
int64_t _timestamp;
|
|
91
|
+
const bt_clock_snapshot *clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(upstream_message);
|
|
92
|
+
bt_clock_snapshot_get_ns_from_origin(clock_snapshot, &_timestamp);
|
|
93
|
+
<% end %>
|
|
94
|
+
bool is_condition_met = false;
|
|
95
|
+
condition(
|
|
96
|
+
(void *)common_data, common_data->usr_data, event_class_name,
|
|
97
|
+
&is_condition_met<%= ', _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.name }.join_with_prefix(", ") %>);
|
|
98
|
+
if (is_condition_met) {
|
|
99
|
+
callback(
|
|
100
|
+
(void *)common_data, common_data->usr_data,
|
|
101
|
+
event_class_name<%= ', _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.name }.join_with_prefix(", ") %>);
|
|
102
|
+
*is_callback_called = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void btx_register_matching_callback_<%= s.name_sanitized %>(
|
|
108
|
+
void *btx_handle, <%= s.name_sanitized %>_callback_condition_f *condition,
|
|
109
|
+
<%= s.name_sanitized %>_conditioned_callback_f *callback) {
|
|
110
|
+
// Look-up our dispatcher
|
|
111
|
+
name_to_dispatcher_t *s = NULL;
|
|
112
|
+
name_to_dispatcher_t **name_to_matching_dispatcher =
|
|
113
|
+
&((common_data_t *)btx_handle)->name_to_matching_dispatcher;
|
|
114
|
+
HASH_FIND_STR(*name_to_matching_dispatcher, "<%= s.name_sanitized %>", s);
|
|
115
|
+
if (!s) {
|
|
116
|
+
// We didn't find the dispatcher, so we need to:
|
|
117
|
+
// 1. Create it
|
|
118
|
+
s = (name_to_dispatcher_t *)malloc(sizeof(name_to_dispatcher_t));
|
|
119
|
+
s->name = "<%= s.name_sanitized %>";
|
|
120
|
+
s->dispatcher = (void *)&btx_matching_dispatch_<%= s.name_sanitized %>;
|
|
121
|
+
utarray_new(s->callbacks, &ut_ptr_icd);
|
|
122
|
+
// 2. Register it
|
|
123
|
+
HASH_ADD_KEYPTR(hh, *name_to_matching_dispatcher, s->name, strlen(s->name),
|
|
124
|
+
s);
|
|
125
|
+
}
|
|
126
|
+
// Add the callbacks to the array
|
|
127
|
+
condition_to_callback_t *m =
|
|
128
|
+
(condition_to_callback_t *)malloc(sizeof(condition_to_callback_t));
|
|
129
|
+
m->condition = (void *)condition;
|
|
130
|
+
m->callback = (void *)callback;
|
|
131
|
+
utarray_push_back(s->callbacks, &m);
|
|
132
|
+
}
|
|
133
|
+
<% end %>
|
|
134
|
+
|
|
135
|
+
void btx_delete_dispatchers(common_data_t *common_data) {
|
|
136
|
+
name_to_dispatcher_t *current, *tmp;
|
|
137
|
+
HASH_ITER(hh, common_data->name_to_dispatcher, current, tmp) {
|
|
138
|
+
HASH_DEL(common_data->name_to_dispatcher, current);
|
|
139
|
+
utarray_free(current->callbacks);
|
|
140
|
+
free(current);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
void btx_delete_matching_dispatchers(common_data_t *common_data) {
|
|
145
|
+
name_to_dispatcher_t *current, *tmp;
|
|
146
|
+
HASH_ITER(hh, common_data->name_to_matching_dispatcher, current, tmp) {
|
|
147
|
+
// Removes the item from the hash table.
|
|
148
|
+
HASH_DEL(common_data->name_to_matching_dispatcher, current);
|
|
149
|
+
// Deletes every condition, callback pair.
|
|
150
|
+
condition_to_callback_t **p = NULL;
|
|
151
|
+
while ((p = utarray_next(current->callbacks, p))) {
|
|
152
|
+
free(*p);
|
|
153
|
+
}
|
|
154
|
+
utarray_free(current->callbacks);
|
|
155
|
+
free(current);
|
|
156
|
+
}
|
|
157
|
+
}
|
data/template/upstream.h.erb
CHANGED
|
@@ -6,17 +6,47 @@ extern "C" {
|
|
|
6
6
|
|
|
7
7
|
// Dispatcher
|
|
8
8
|
typedef void(dispatcher_t)(UT_array *callbacks, common_data_t *common_data,
|
|
9
|
-
const
|
|
9
|
+
const bt_message *upstream_message, bool *is_callback_called);
|
|
10
10
|
|
|
11
|
-
<%
|
|
11
|
+
<% event_class_dispatchers.each do |e| %>
|
|
12
12
|
<%# The signature type of callbacks %>
|
|
13
|
-
typedef void
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
typedef void <%= e.name_sanitized %>_callback_f(
|
|
14
|
+
void *btx_handle,
|
|
15
|
+
void *usr_data<%= ', int64_t _timestamp' if e.default_clock_class %><%= e.args.map{ |s| s.type }.join_with_prefix(", ") %>);
|
|
16
16
|
<%# The Function who register the callbacks to the dispatcher %>
|
|
17
|
-
|
|
17
|
+
void btx_register_callbacks_<%= e.name_sanitized %>(
|
|
18
18
|
void *btx_handle, <%= e.name_sanitized %>_callback_f *callback);
|
|
19
19
|
<% end %>
|
|
20
|
+
|
|
21
|
+
void btx_delete_dispatchers(common_data_t *common_data);
|
|
22
|
+
|
|
23
|
+
// Matching dispatcher
|
|
24
|
+
|
|
25
|
+
struct condition_to_callback_s {
|
|
26
|
+
void *condition;
|
|
27
|
+
void *callback;
|
|
28
|
+
};
|
|
29
|
+
typedef struct condition_to_callback_s condition_to_callback_t;
|
|
30
|
+
|
|
31
|
+
<% stream_classes_matching_dispatchers.each do |s| %>
|
|
32
|
+
<%# The signature type of condition callbacks %>
|
|
33
|
+
typedef void <%= s.name_sanitized %>_callback_condition_f(
|
|
34
|
+
void *btx_handle, void *usr_data, const char *event_class_name,
|
|
35
|
+
bool *matched<%= ', int64_t _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.type }.join_with_prefix(", ") %>);
|
|
36
|
+
|
|
37
|
+
<%# The signature type of callbacks to be called if the condition is met %>
|
|
38
|
+
typedef void <%= s.name_sanitized %>_conditioned_callback_f(
|
|
39
|
+
void *btx_handle, void *usr_data,
|
|
40
|
+
const char *
|
|
41
|
+
event_class_name<%= ', int64_t _timestamp' if s.default_clock_class %><%= s.args.map{ |a| a.type }.join_with_prefix(", ") %>);
|
|
42
|
+
|
|
43
|
+
void btx_register_matching_callback_<%= s.name_sanitized %>(
|
|
44
|
+
void *btx_handle, <%= s.name_sanitized %>_callback_condition_f *condition,
|
|
45
|
+
<%= s.name_sanitized %>_conditioned_callback_f *callback);
|
|
46
|
+
<% end %>
|
|
47
|
+
|
|
48
|
+
void btx_delete_matching_dispatchers(common_data_t *common_data);
|
|
49
|
+
|
|
20
50
|
#ifdef __cplusplus
|
|
21
51
|
}
|
|
22
52
|
#endif
|
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: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
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: 2023-05
|
|
13
|
+
date: 2023-07-05 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email:
|