Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow #43

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft

Flow #43

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
include babeltrace_zeinterval_event_getter_and_setter
  • Loading branch information
TApplencourt committed Jul 22, 2022
commit e0c5e3280ad01515d30bbd91aad2acb3456c42d2
62 changes: 42 additions & 20 deletions utils/gen_babeltrace_event_getter_and_setter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@

def set_scalar(field_name, index, bt2_class, name)
puts <<EOF
bt_field *#{name}_field = bt_field_structure_borrow_member_field_by_index(#{field_name},#{index});
bt_field_#{bt2_class}_set_value(#{name}_field, #{name});
bt_field *#{name}_field = bt_field_structure_borrow_member_field_by_index(#{field_name}_field,#{index});
bt_field_#{get_cetter(bt2_class)}_set_value(#{name}_field, #{name});
EOF
end
end

def set_array_dynamic(field_name, index, bt2_class, name, field)
puts <<EOF
bt_field *#{name}_field = bt_field_structure_borrow_member_field_by_index(#{field_name},#{index});
bt_field *#{name}_field = bt_field_structure_borrow_member_field_by_index(#{field_name}_field,#{index});
bt_field_array_dynamic_set_length(#{name}_field, #{name}_length);
for (unsigned i=0; i < #{name}_length; i++) {
bt_field *#{name}_element_field = bt_field_structure_borrow_member_field_by_index(#{name}_field, i);
bt_field_#{field[:class]}_set_value(#{name}_field, #{name}[i]);
bt_field_#{get_cetter(field[:class])}_set_value(#{name}_element_field, #{name}[i]);
}
EOF
end

def set_field(name, field, index)
case field[:class]
def set_field(name, field, index)
case field[:class]
when "array_dynamic"
set_array_dynamic(name, index, field[:class], field[:name], field[:field])
else
set_scalar(name, index, field[:class], field[:name])
end
end

def get_cetter(klass)
case klass
when "signed"
"integer_signed"
when "unsigned"
"integer_unsigned"
else
klass
end
end

def get_c_type(field)
return field[:cast_type] if field.key?(:cast_type)
bits = field.fetch(:class_properties, {}).fetch(:field_value_range, 32)
Expand All @@ -43,7 +54,7 @@ def get_c_type(field)
when "unsigned"
"uint#{bits}_t"
when "string"
"const char*"
"const char*"
else
field[:class]
end
Expand All @@ -53,19 +64,21 @@ def create_signature_tuple(event)
event.flat_map { |field|
case field[:class]
when "array_dynamic"
[ ["*#{get_c_type(field[:field])}", field[:name] ],
["size_t", "#{field[:name]}_length"] ]
[ ["#{get_c_type(field[:field])}*", field[:name] ] ]
# ["size_t", "#{field[:name]}_length"] ]
else
[ [ get_c_type(field), field[:name] ] ]
end
}
end

common_context_field_setter = babeltrace_model[:stream_classes].map { |stream_class|
name = stream_class[:name].gsub(':','_')

l = create_signature_tuple(stream_class[:common_context])
signature_str = l.map { |e| e.join(' ') }.join(', ')
puts <<EOF
void bt_event_set_common_context_fields(bt_event* event, #{signature_str}) {
void bt_event_set_#{name}_common_context_fields(bt_event* event, #{signature_str}) {
EOF
puts <<EOF
bt_field *common_context_field = bt_event_borrow_common_context_field(event);
Expand All @@ -76,26 +89,35 @@ def create_signature_tuple(event)
puts <<EOF
}
EOF
["default", l]
[name, l]
}.to_h

name = :payload
babeltrace_model[:event_classes].each { |event_class|
name_stream_class = event_class.fetch("stream_class", common_context_field_setter.keys[0])
l_common = common_context_field_setter[name_stream_class]
l_payload = create_signature_tuple(event_class[:payload])

l_common = common_context_field_setter["default"]
l_payload = create_signature_tuple(event_class[name])
l_signature_str = (l_common + l_payload).map { |e| e.join(' ') }.join(', ')

l_common_call_str = l_common.map { |e, n| n}.join(', ')

l_call_str = (l_common + l_payload).map { |e, n| n}.join(', ')

puts <<EOF
void bt_event_set_#{event_class[:name].gsub(':','_')}(bt_event* event, #{l_signature_str}) {
bt_event_set_common_context_fields(event, #{l_common_call_str});
bt_field *#{name}_field = bt_event_#{name}_field(event);
bt_event_set_#{name_stream_class}_common_context_fields(event, #{l_common_call_str});
bt_field *payload_field = bt_event_borrow_payload_field(event);
EOF
event_class[name].each.with_index { |payload, i|
set_field("#{name}_field", payload, i)
event_class[:payload].each.with_index { |payload, i|
set_field("payload", payload, i)
}
puts <<EOF
}

bt_message* bt_message_create_#{event_class[:name].gsub(':','_')}(bt_event_class *event_class, bt_self_message_iterator *message_iterator, bt_stream *stream, #{l_signature_str}) {
bt_message *message = bt_message_event_create(message_iterator, event_class, stream);
bt_event *downstream_event = bt_message_event_borrow_event(message);
bt_event_set_#{event_class[:name].gsub(':','_')}(downstream_event, #{l_call_str});
return message;
}
EOF
}
6 changes: 6 additions & 0 deletions xprof/interval_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
:class: array_dynamic
:field:
:class: unsigned
:class_properties:
:field_value_range: 64
- :name: lttng:device
:payload:
- :name: name
Expand Down Expand Up @@ -85,6 +87,8 @@
:class: string
- :name: flow_id
:class: unsigned
:class_properties:
:field_value_range: 64
- :name: lttng:device_name
:payload:
- :name: name
Expand All @@ -97,3 +101,5 @@
:class: string
- :name: size
:class: unsigned
:class_properties:
:field_value_range: 64
2 changes: 1 addition & 1 deletion xprof/tally_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TallyCoreBase {
// ` symbol lookup error: ./ici/lib/libXProf.so: undefined symbol: _ZTI13TallyCoreBase`
virtual const std::vector<std::string> to_string() = 0;

const auto to_string_size() {
auto to_string_size() {
std::vector<long> v;
for (auto &e : to_string())
v.push_back(static_cast<long>(e.size()));
Expand Down
6 changes: 6 additions & 0 deletions ze/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ babeltrace_zeinterval_dispatchers.c: $(top_srcdir)/utils/gen_babeltrace_dispatch
babeltrace_zeinterval_emitter.h: $(top_srcdir)/utils/gen_babeltrace_emitter.rb $(top_srcdir)/xprof/interval_model.yaml
SRC_DIR=$(srcdir) $(RUBY) $^ zeinterval > $@

babeltrace_zeinterval_event_getter_and_setter.hpp: $(top_srcdir)/utils/gen_babeltrace_event_getter_and_setter.rb $(top_srcdir)/xprof/interval_model.yaml
SRC_DIR=$(srcdir) $(RUBY) $^ zeinterval > $@

babeltrace_zeinterval.h: $(top_srcdir)/xprof/interval.h.erb
$(ERB) namespace="zeinterval" $< > $@

Expand All @@ -294,6 +297,7 @@ CLEANFILES += \
babeltrace_zeinterval_callbacks.h \
babeltrace_zeinterval_dispatchers.c \
babeltrace_zeinterval_emitter.h \
babeltrace_zeinterval_event_getter_and_setter.hpp \
babeltrace_zeinterval.h \
babeltrace_zeinterval.c \
xprof_utils.hpp \
Expand All @@ -303,6 +307,7 @@ BUILT_SOURCES += \
babeltrace_zeinterval_callbacks.h \
babeltrace_zeinterval.h \
babeltrace_zeinterval_emitter.h \
babeltrace_zeinterval_event_getter_and_setter.hpp \
xprof_utils.hpp

nodist_libZEInterval_la_SOURCES = \
Expand All @@ -312,6 +317,7 @@ nodist_libZEInterval_la_SOURCES = \
babeltrace_zeinterval_dispatchers.c \
babeltrace_zeinterval_callbacks.cpp \
babeltrace_zeinterval_emitter.h \
babeltrace_zeinterval_event_getter_and_setter.hpp \
xprof_utils.hpp \
xprof_utils.cpp

Expand Down
17 changes: 11 additions & 6 deletions ze/zeinterval_callbacks.cpp.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "babeltrace_zeinterval.h"
#include "zeinterval_callbacks.hpp"
#include "xprof_utils.hpp"
#include "babeltrace_zeinterval_event_getter_and_setter.hpp"
#include <babeltrace2/babeltrace.h>

#include <ze_api.h>
Expand Down Expand Up @@ -83,10 +84,11 @@ static void create_and_enqueue_host_message(const char* hostname, const process_
const uint64_t ts, const uint64_t duration, const bool err) {

/* Message creation */
bt_message *message = create_host_message(hostname, process_id, thread_id, name, ts, duration, err,
bt_message *message = bt_message_create_lttng_host(
zeinterval_iter_g->dispatch->host_event_class,
zeinterval_self_message_iterator_g,
zeinterval_iter_g->dispatch->stream, BACKEND_ZE);
zeinterval_iter_g->dispatch->stream,
hostname, process_id, thread_id, ts, BACKEND_ZE, name, duration, err);

zeinterval_callbacks_state* state = (zeinterval_callbacks_state*) zeinterval_iter_g->callbacks_state;
state->downstream_message_queue.push(message);
Expand All @@ -95,11 +97,13 @@ static void create_and_enqueue_host_message(const char* hostname, const process_
static void create_and_enqueue_host_flow_message(const char* hostname, const process_id_t process_id, const thread_id_t thread_id, const char* name,
const uint64_t ts, const uint64_t duration, const bool err, const std::set<flow_id_t> flow_ids) {

std::vector<flow_id_t> flow_ids_vec(flow_ids.begin(), flow_ids.end());
/* Message creation */
bt_message *message = create_host_message(hostname, process_id, thread_id, name, ts, duration, err,
bt_message *message = bt_message_create_lttng_host_flow(
zeinterval_iter_g->dispatch->host_flow_event_class,
zeinterval_self_message_iterator_g,
zeinterval_iter_g->dispatch->stream, BACKEND_ZE, flow_ids);
zeinterval_iter_g->dispatch->stream,
hostname, process_id, thread_id, ts, BACKEND_ZE, name, duration, err, flow_ids.size(), flow_ids_vec.data());

zeinterval_callbacks_state* state = (zeinterval_callbacks_state*) zeinterval_iter_g->callbacks_state;
state->downstream_message_queue.push(message);
Expand Down Expand Up @@ -157,10 +161,11 @@ static void create_and_enqueue_traffic_message(const char* hostname, const proce
const uint64_t size) {

/* Message creation */
bt_message *message = create_traffic_message(hostname, process_id, thread_id, name, size,
bt_message *message = bt_message_create_lttng_traffic(
zeinterval_iter_g->dispatch->traffic_event_class,
zeinterval_self_message_iterator_g,
zeinterval_iter_g->dispatch->stream, BACKEND_ZE);
zeinterval_iter_g->dispatch->stream,
hostname, process_id, thread_id, 0, BACKEND_ZE, name, size);

zeinterval_callbacks_state* state = (zeinterval_callbacks_state*) zeinterval_iter_g->callbacks_state;
state->downstream_message_queue.push(message);
Expand Down