metababel 1.0.3 → 1.0.4
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/README.md +2 -2
- data/bin/btx_gen_source_callbacks +113 -0
- data/bin/metababel +13 -0
- data/lib/metababel/bt2_trace_class_generator.rb +14 -10
- data/lib/metababel/version.rb +1 -1
- data/template/downstream.c.erb +9 -0
- data/template/downstream.h.erb +5 -0
- data/template/filter.c.erb +12 -12
- data/template/source.c.erb +12 -12
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94a55badce2025551858542b3ad05ec6f2fadfa18ea7a3d32e43dfc8fa588505
|
|
4
|
+
data.tar.gz: 861f4853f64c5de23d47f6678e8a369b49b1e5f84cd4ad1944b077a32e5a8a87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10357d19a20bb264699f6f586f49fd2d5229a7da0ea7dd51234d5b5733bee78340c83f564a2084a26a99db9d13073332ad211c67def4b469c6251e2f219b4efa
|
|
7
|
+
data.tar.gz: 92a55fb2d187388088d13d30a827548b1543bec100f81ff4fa58a7dae41d77ad52f53268b33abd93a1149ea9479c838354b3d1b1773e6dbdf8f2b54a0ae1351b
|
data/README.md
CHANGED
|
@@ -38,8 +38,8 @@ stateDiagram-v2
|
|
|
38
38
|
|
|
39
39
|
```mermaid
|
|
40
40
|
stateDiagram-v2
|
|
41
|
-
[*] -->
|
|
42
|
-
|
|
41
|
+
[*] --> BTX_FILTER_STATE_INITIALIZING
|
|
42
|
+
BTX_FILTER_STATE_INITIALIZING --> BTX_FILTER_PROCESSING
|
|
43
43
|
state BTX_FILTER_PROCESSING {
|
|
44
44
|
[*] --> BTX_FILTER_PROCESSING_STATE_READING
|
|
45
45
|
[*] --> BTX_FILTER_PROCESSING_STATE_SENDING
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'erb'
|
|
6
|
+
require 'time'
|
|
7
|
+
|
|
8
|
+
REGEXT_PRETTY = /
|
|
9
|
+
=\s # We are interested to the right of the equal sign
|
|
10
|
+
(
|
|
11
|
+
""| # Empty string
|
|
12
|
+
".*?[^\\]"| # String who can contain space and quoted string
|
|
13
|
+
[^\s,]+ # Anything except space and comma
|
|
14
|
+
)
|
|
15
|
+
/x.freeze
|
|
16
|
+
|
|
17
|
+
SOURCE_TEMPLATE = <<~TEXT.freeze
|
|
18
|
+
/* Code generated by #{__FILE__} */
|
|
19
|
+
|
|
20
|
+
#include <metababel/metababel.h>
|
|
21
|
+
|
|
22
|
+
void btx_push_usr_messages(void *btx_handle, void *usr_data, btx_source_status_t *status) {
|
|
23
|
+
<%- if not data.empty? and not data.first[:hostname].nil? -%>
|
|
24
|
+
btx_downstream_set_environment_hostname(btx_handle, "<%= data.first[:hostname] %>");
|
|
25
|
+
<%- end -%>
|
|
26
|
+
|
|
27
|
+
<%- data.each do | entry | -%>
|
|
28
|
+
<%- entry.fetch(:times,1).times do -%>
|
|
29
|
+
btx_push_message_<%= entry[:name] %>(btx_handle<%= ', ' if not entry[:field_values].empty? %><%= entry[:field_values].join(", ") %>);
|
|
30
|
+
<%- end -%>
|
|
31
|
+
<%- end -%>
|
|
32
|
+
|
|
33
|
+
*status = BTX_SOURCE_END;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void btx_register_usr_callbacks(void *btx_handle) {
|
|
37
|
+
btx_register_callbacks_push_usr_messages(btx_handle, &btx_push_usr_messages);
|
|
38
|
+
}
|
|
39
|
+
TEXT
|
|
40
|
+
|
|
41
|
+
def parse_event(line)
|
|
42
|
+
h = { hostname: nil,
|
|
43
|
+
name: nil,
|
|
44
|
+
field_values: [] }
|
|
45
|
+
# Parse a token one at a time
|
|
46
|
+
head, tail = line.split(nil, 2)
|
|
47
|
+
# Timestamp?
|
|
48
|
+
if head.start_with?('[')
|
|
49
|
+
t = Time.parse(head[1...-1])
|
|
50
|
+
# Need to convert in nasosecond
|
|
51
|
+
h[:field_values] << ((t.to_i * 1_000_000_000) + t.nsec)
|
|
52
|
+
# discard next token, the offset "(+x.xxxxxxxx)", which
|
|
53
|
+
# always follows the bracketed timestamp
|
|
54
|
+
_, head, tail = tail.split(nil, 3)
|
|
55
|
+
end
|
|
56
|
+
# Hostname?
|
|
57
|
+
unless head.end_with?(':')
|
|
58
|
+
h[:hostname] = head
|
|
59
|
+
head, tail = tail.split(nil, 2)
|
|
60
|
+
end
|
|
61
|
+
h[:name] = head.chop.gsub(/[^0-9A-Za-z-]/, '_')
|
|
62
|
+
# Handle the fields
|
|
63
|
+
h[:field_values] += tail.scan(REGEXT_PRETTY).flatten
|
|
64
|
+
h
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def parse_log(input_path)
|
|
68
|
+
File.open(input_path, 'r') do |file|
|
|
69
|
+
file.each_line.map do |line|
|
|
70
|
+
parse_event(line)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def render_and_save(data, output_path)
|
|
76
|
+
renderer = ERB.new(SOURCE_TEMPLATE, trim_mode: '-')
|
|
77
|
+
output = renderer.result(binding)
|
|
78
|
+
File.write(output_path, output, mode: 'w')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
DOCS = <<-DOCS.freeze
|
|
82
|
+
Usage: #{$0}.rb [options]
|
|
83
|
+
|
|
84
|
+
Example:
|
|
85
|
+
ruby #{$0} -y stream_classes.yaml -i btx_log.txt -o callbacks.c
|
|
86
|
+
DOCS
|
|
87
|
+
|
|
88
|
+
# Display help if no arguments.
|
|
89
|
+
ARGV << '-h' if ARGV.empty?
|
|
90
|
+
|
|
91
|
+
options = {}
|
|
92
|
+
|
|
93
|
+
OptionParser.new do |opts|
|
|
94
|
+
opts.banner = DOCS
|
|
95
|
+
|
|
96
|
+
opts.on('-h', '--help', 'Prints this help') do
|
|
97
|
+
puts opts
|
|
98
|
+
exit
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
opts.on('-i', '--log PATH', '[Mandatory] Path to btx_log.txt.') do |p|
|
|
102
|
+
options[:input_path] = p
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
opts.on('-o', '--output PATH', '[Mandatory] Path to the bt2 SOURCE file.') do |p|
|
|
106
|
+
options[:output_path] = p
|
|
107
|
+
end
|
|
108
|
+
end.parse!
|
|
109
|
+
|
|
110
|
+
raise OptionParser::MissingArgument if options[:output_path].nil?
|
|
111
|
+
|
|
112
|
+
data = options.key?(:input_path) ? parse_log(options[:input_path]) : []
|
|
113
|
+
render_and_save(data, options[:output_path])
|
data/bin/metababel
CHANGED
|
@@ -412,7 +412,20 @@ class ContextBuilder
|
|
|
412
412
|
t.get_declarator(variable: '_trace_class', self_component: '_self_component')
|
|
413
413
|
end
|
|
414
414
|
|
|
415
|
+
downstream_environements = if t.environment.nil?
|
|
416
|
+
[]
|
|
417
|
+
else
|
|
418
|
+
t.environment.entries.map do |e|
|
|
419
|
+
args = {}
|
|
420
|
+
body = "\n" + Babeltrace2Gen.context(indent: 1) do
|
|
421
|
+
e.get_setter(trace: '_trace', arg_variables: args)
|
|
422
|
+
end
|
|
423
|
+
[args['outputs'].first, body]
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
|
|
415
427
|
{ body_declarator_classes: body_declarator_classes,
|
|
428
|
+
downstream_environements: downstream_environements,
|
|
416
429
|
downstream_events: downstream_events,
|
|
417
430
|
stream_classes: t.stream_classes,
|
|
418
431
|
event_name: event_name }
|
|
@@ -100,8 +100,6 @@ module Babeltrace2Gen
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def get_declarator(variable:, self_component:)
|
|
103
|
-
raise NotImplementedError, "':environment' keyword not supported in downstream model" if environment
|
|
104
|
-
|
|
105
103
|
pr "#{variable} = bt_trace_class_create(#{self_component});"
|
|
106
104
|
bt_set_conditionally(@assigns_automatic_stream_class_id) do |v|
|
|
107
105
|
pr "bt_trace_class_set_assigns_automatic_stream_class_id(#{variable}, #{v});"
|
|
@@ -985,15 +983,20 @@ module Babeltrace2Gen
|
|
|
985
983
|
end
|
|
986
984
|
|
|
987
985
|
def get_getter(trace:, arg_variables:)
|
|
988
|
-
var_name =
|
|
989
|
-
arg_variables.fetch_append('outputs', bt_get_variable)
|
|
990
|
-
bt_func_get = self.class.instance_variable_get(:@bt_func)
|
|
986
|
+
var_name = bt_get_variable(arg_variables).name
|
|
991
987
|
pr "const bt_value *#{var_name}_value = bt_trace_borrow_environment_entry_value_by_name_const(#{trace}, \"#{var_name}\");"
|
|
992
|
-
pr "#{var_name} = #{
|
|
988
|
+
pr "#{var_name} = bt_value_#{@type}_get(#{var_name}_value);"
|
|
993
989
|
end
|
|
994
990
|
|
|
995
|
-
def
|
|
996
|
-
|
|
991
|
+
def get_setter(trace:, arg_variables:)
|
|
992
|
+
var_name = bt_get_variable(arg_variables).name
|
|
993
|
+
bt_type_set = self.class.instance_variable_get(:@bt_type_set)
|
|
994
|
+
pr "bt_trace_set_environment_entry_#{bt_type_set}(#{trace}, \"#{var_name}\", #{var_name});"
|
|
995
|
+
end
|
|
996
|
+
|
|
997
|
+
def bt_get_variable(arg_variables={})
|
|
998
|
+
var = GeneratedArg.new(self.class.instance_variable_get(:@bt_type), @name)
|
|
999
|
+
arg_variables.fetch_append('outputs', var)
|
|
997
1000
|
end
|
|
998
1001
|
end
|
|
999
1002
|
|
|
@@ -1005,13 +1008,14 @@ module Babeltrace2Gen
|
|
|
1005
1008
|
extend BTFromH
|
|
1006
1009
|
|
|
1007
1010
|
@bt_type = 'const char*'
|
|
1008
|
-
@
|
|
1011
|
+
@bt_type_set = 'string'
|
|
1009
1012
|
end
|
|
1010
1013
|
|
|
1011
1014
|
class BTEntryClass::IntegerSigned < BTEntryClass
|
|
1012
1015
|
extend BTFromH
|
|
1013
1016
|
|
|
1014
1017
|
@bt_type = 'int64_t'
|
|
1015
|
-
|
|
1018
|
+
# Sadly it's ` bt_trace_set_environment_entry_integer() ` and not ` bt_trace_set_environment_entry_integer_signed()`
|
|
1019
|
+
@bt_type_set = 'integer'
|
|
1016
1020
|
end
|
|
1017
1021
|
end
|
data/lib/metababel/version.rb
CHANGED
data/template/downstream.c.erb
CHANGED
|
@@ -173,3 +173,12 @@ void btx_push_message_<%= e.name_sanitized %>(
|
|
|
173
173
|
btx_downstream_push_message(_message_iterator_private_data, _message);
|
|
174
174
|
}
|
|
175
175
|
<% end %>
|
|
176
|
+
|
|
177
|
+
<% downstream_environements.each do |arg, body| %>
|
|
178
|
+
void btx_downstream_set_environment_<%= arg.name%>(void *btx_handle,
|
|
179
|
+
<%= arg.type%> <%= arg.name%>) {
|
|
180
|
+
common_data_t *common_data = (common_data_t *)btx_handle;
|
|
181
|
+
bt_trace *_trace = common_data->downstream_trace;
|
|
182
|
+
<%= body %>
|
|
183
|
+
}
|
|
184
|
+
<% end %>
|
data/template/downstream.h.erb
CHANGED
|
@@ -42,6 +42,11 @@ void btx_register_on_downstream_message_callback(
|
|
|
42
42
|
void *btx_handle, on_downstream_message_callback_f *callback);
|
|
43
43
|
<% end %>
|
|
44
44
|
|
|
45
|
+
<% downstream_environements.each do |arg, body| %>
|
|
46
|
+
void btx_downstream_set_environment_<%= arg.name%>(void *btx_handle,
|
|
47
|
+
<%= arg.type%> <%= arg.name%>);
|
|
48
|
+
<% end %>
|
|
49
|
+
|
|
45
50
|
#ifdef __cplusplus
|
|
46
51
|
}
|
|
47
52
|
#endif
|
data/template/filter.c.erb
CHANGED
|
@@ -347,18 +347,6 @@ filter_initialize(bt_self_component_filter *self_component_filter,
|
|
|
347
347
|
common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
|
|
348
348
|
common_data->params = params;
|
|
349
349
|
|
|
350
|
-
/* Read parameters */
|
|
351
|
-
btx_populate_params(common_data);
|
|
352
|
-
bt_value_get_ref(common_data->params);
|
|
353
|
-
|
|
354
|
-
/* Register User Callbacks */
|
|
355
|
-
btx_register_usr_callbacks((void *)common_data);
|
|
356
|
-
/* Call initialize_processing*/
|
|
357
|
-
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
358
|
-
/* Call read callbacks */
|
|
359
|
-
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
360
|
-
common_data->btx_params);
|
|
361
|
-
|
|
362
350
|
/* Set the component's user data to our private data structure */
|
|
363
351
|
bt_self_component_set_data(
|
|
364
352
|
bt_self_component_filter_as_self_component(self_component_filter),
|
|
@@ -406,6 +394,18 @@ filter_initialize(bt_self_component_filter *self_component_filter,
|
|
|
406
394
|
btx_streams_get_ref(common_data->downstream_trace); // ??
|
|
407
395
|
bt_trace_class_put_ref(trace_class);
|
|
408
396
|
|
|
397
|
+
/* Read parameters */
|
|
398
|
+
btx_populate_params(common_data);
|
|
399
|
+
bt_value_get_ref(common_data->params);
|
|
400
|
+
|
|
401
|
+
/* Register User Callbacks */
|
|
402
|
+
btx_register_usr_callbacks((void *)common_data);
|
|
403
|
+
/* Call initialize_processing*/
|
|
404
|
+
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
405
|
+
/* Call read callbacks */
|
|
406
|
+
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
407
|
+
common_data->btx_params);
|
|
408
|
+
|
|
409
409
|
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
410
410
|
}
|
|
411
411
|
|
data/template/source.c.erb
CHANGED
|
@@ -96,18 +96,6 @@ source_initialize(bt_self_component_source *self_component_source,
|
|
|
96
96
|
common_data->btx_params = (btx_params_t *)calloc(1, sizeof(btx_params_t));
|
|
97
97
|
common_data->params = params;
|
|
98
98
|
|
|
99
|
-
/* Read parameters */
|
|
100
|
-
btx_populate_params(common_data);
|
|
101
|
-
bt_value_get_ref(common_data->params);
|
|
102
|
-
|
|
103
|
-
/* Register User Callbacks */
|
|
104
|
-
btx_register_usr_callbacks((void *)common_data);
|
|
105
|
-
/* Call initialize_processing*/
|
|
106
|
-
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
107
|
-
/* Call read callbacks */
|
|
108
|
-
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
109
|
-
common_data->btx_params);
|
|
110
|
-
|
|
111
99
|
/* Upcast `self_component_source` to the `bt_self_component` type */
|
|
112
100
|
bt_self_component *self_component =
|
|
113
101
|
bt_self_component_source_as_self_component(self_component_source);
|
|
@@ -134,6 +122,18 @@ source_initialize(bt_self_component_source *self_component_source,
|
|
|
134
122
|
bt_self_component_source_add_output_port(self_component_source, "out", NULL,
|
|
135
123
|
NULL);
|
|
136
124
|
|
|
125
|
+
/* Read parameters */
|
|
126
|
+
btx_populate_params(common_data);
|
|
127
|
+
bt_value_get_ref(common_data->params);
|
|
128
|
+
|
|
129
|
+
/* Register User Callbacks */
|
|
130
|
+
btx_register_usr_callbacks((void *)common_data);
|
|
131
|
+
/* Call initialize_processing*/
|
|
132
|
+
btx_call_callbacks_initialize_component(common_data, &common_data->usr_data);
|
|
133
|
+
/* Call read callbacks */
|
|
134
|
+
btx_call_callbacks_read_params(common_data, common_data->usr_data,
|
|
135
|
+
common_data->btx_params);
|
|
136
|
+
|
|
137
137
|
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
|
|
138
138
|
}
|
|
139
139
|
|
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.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Applencourt
|
|
@@ -10,16 +10,18 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2024-
|
|
13
|
+
date: 2024-02-16 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description:
|
|
16
16
|
email:
|
|
17
17
|
executables:
|
|
18
18
|
- metababel
|
|
19
|
+
- btx_gen_source_callbacks
|
|
19
20
|
extensions: []
|
|
20
21
|
extra_rdoc_files: []
|
|
21
22
|
files:
|
|
22
23
|
- README.md
|
|
24
|
+
- bin/btx_gen_source_callbacks
|
|
23
25
|
- bin/metababel
|
|
24
26
|
- lib/metababel.rb
|
|
25
27
|
- lib/metababel/bt2_generator_utils.rb
|
|
@@ -57,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
57
59
|
- !ruby/object:Gem::Version
|
|
58
60
|
version: '0'
|
|
59
61
|
requirements: []
|
|
60
|
-
|
|
61
|
-
rubygems_version: 2.7.6.3
|
|
62
|
+
rubygems_version: 3.3.3
|
|
62
63
|
signing_key:
|
|
63
64
|
specification_version: 4
|
|
64
65
|
summary: Helper for creation Babeltrace plugins
|