Commit 47f38850 authored by Thomas Applencourt's avatar Thomas Applencourt
Browse files

Refractor gen_clinterval_callbacks.rb

parent 71804e83
Pipeline #13164 failed with stage
......@@ -180,6 +180,7 @@ nodist_libBabeltraceCL_la_SOURCES = \
libBabeltraceCL_la_SOURCES = \
babeltrace_cl.c \
babeltrace_cl.h
libBabeltraceCL_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./
libBabeltraceCL_la_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Werror $(BABELTRACE2_CFLAGS)
libBabeltraceCL_la_LDFLAGS = $(BABELTRACE2_LIBS) -avoid-version -module
......@@ -209,8 +210,8 @@ libTestingCLProf_la_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Werror $(BABEL
libTestingCLProf_la_CXXFLAGS = -std=c++17 -Wall -Wextra -Wno-unused-parameter -Werror $(BABELTRACE2_CFLAGS)
libTestingCLProf_la_LDFLAGS = $(BABELTRACE2_LIBS) -avoid-version -module
clinterval_callbacks.cpp: $(srcdir)/clinterval_callbacks.cpp.erb $(srcdir)/gen_clinterval.rb opencl_model.yaml babeltrace_cl_callbacks.h tracer_opencl.h
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_clinterval.rb
clinterval_callbacks.cpp: $(srcdir)/clinterval_callbacks.cpp.erb $(srcdir)/gen_clinterval_callbacks.rb opencl_babeltrace_model.yaml
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_clinterval_callbacks.rb > clinterval_callbacks.cpp
clinterval_callbacks.h: $(srcdir)/gen_babeltrace_cl_callbacks.rb opencl_babeltrace_model.yaml
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_babeltrace_cl_callbacks.rb clinterval > clinterval_callbacks.h
......@@ -359,7 +360,7 @@ EXTRA_DIST = \
babeltrace_opencl.in \
extract_enqueues \
clprof.c.erb \
gen_clinterval.rb \
gen_clinterval_callbacks.rb \
clinterval_callbacks.cpp.erb \
clinterval_callbacks.hpp\
xprof_utils.hpp \
......
......@@ -124,11 +124,11 @@ static void clinterval_<%= dbt_event.name %>_callback(
int64_t ns_from_origin;
bt_clock_snapshot_get_ns_from_origin(bt_clock, &ns_from_origin);
<%if dbt_event.name.end_with?(START) %>
<%if dbt_event.name_unsanitized.end_with?(START) %>
state->host_start[hpt_function_name_t(hostname,process_id, thread_id, "<%= dbt_event.name_striped %>")] = ns_from_origin;
<%elsif dbt_event.name.end_with?(STOP) %>
<%elsif dbt_event.name_unsanitized.end_with?(STOP) %>
const uint64_t start_g = state->host_start[hpt_function_name_t(hostname,process_id, thread_id, "<%= dbt_event.name_striped %>")];
<% if dbt_event.fields.key?('errcode_ret_val') %>
<% if dbt_event.fields_name.include?('errcode_ret_val') %>
create_and_enqueue_host_message(hostname.c_str(), process_id, thread_id, "<%= dbt_event.name_striped %>", start_g, ns_from_origin-start_g, errcode_ret_val);
<% else %>
create_and_enqueue_host_message(hostname.c_str(), process_id, thread_id, "<%= dbt_event.name_striped %>", start_g, ns_from_origin-start_g, 0);
......@@ -143,7 +143,7 @@ static void clinterval_<%= dbt_event.name %>_callback(
%>
<%# To do handle Alloc and cl_mem_host_ptr %>
<%if dbt_event.name.include?("clEnqueue") and dbt_event.fields.key?("size") %>
<%if dbt_event.name_striped.include?("clEnqueue") and dbt_event.fields_name.include?("size") %>
create_and_enqueue_traffic_message(hostname.c_str(), process_id, thread_id, "<%= dbt_event.name_striped %>",size);
<% end %>
......@@ -192,9 +192,9 @@ static void clinterval_<%= dbt_event.name %>_callback(
<% end%>
<%# Map [ Tuple [ Hostnane, process, cl_command_queue ], Tuple [ device, subdevice] ] %>
<% if dbt_event.name.end_with?(START) and dbt_event.name.include?('clCreateCommandQueue') %>
<% if dbt_event.name_unsanitized.end_with?(START) and dbt_event.name_striped.include?('clCreateCommandQueue') %>
state->start_device[hpt_t(hostname,process_id, thread_id) ] = (thapi_device_id) device;
<%elsif dbt_event.name.end_with?(STOP) and dbt_event.name.include?('clCreateCommandQueue') %>
<%elsif dbt_event.name_unsanitized.end_with?(STOP) and dbt_event.name_striped.include?('clCreateCommandQueue') %>
const thapi_device_id device = state->start_device[hpt_t(hostname,process_id, thread_id) ];
const thapi_device_id root_device = state->device_to_rootdevice[hp_device_t(hostname,process_id, device) ];
if (root_device != 0) {
......@@ -221,8 +221,8 @@ static void clinterval_<%= dbt_event.name %>_callback(
const hostname_t hostname{borrow_hostname(bt_evt)};
const process_id_t process_id = borrow_process_id(bt_evt);
state->kernel_to_name[hp_kernel_t(hostname,process_id,kernel)] = hostname_t(function_name);
<% elsif dbt_event.name.end_with?(START) and dbt_event.fields['command_queue'] %>
<% if dbt_event.fields['kernel'] %>
<% elsif dbt_event.name.end_with?(START) and dbt_event.fields_name.include?('command_queue') %>
<% if dbt_event.fields_name.include?('kernel') %>
const thapi_function_name name{ state->kernel_to_name[hp_kernel_t(hostname,process_id,kernel)]};
<% else %>
constexpr char name[] = "<%= dbt_event.name_striped %>";
......
require 'erb'
require 'yaml'
if ENV["SRC_DIR"]
SRC_DIR = ENV["SRC_DIR"]
else
SRC_DIR = "."
end
opencl_model = YAML::load_file("opencl_model.yaml")
SUFFIXES = opencl_model["suffixes"]
START = SUFFIXES["start"]
STOP = SUFFIXES["stop"]
# Todo. This list is not complete
$cl_type_to_bl_type = {
"cl_platform_id" => "integer_unsigned",
"cl_device_id" => "integer_unsigned",
"cl_context" => "integer_unsigned",
"cl_command_queue" => "integer_unsigned",
"cl_mem" => "integer_unsigned",
"cl_program" => "integer_unsigned",
"cl_kernel" => "integer_unsigned",
"cl_event" => "integer_unsigned",
"cl_sampler" => "integer_unsigned",
"cl_GLsync" => "integer_unsigned",
"CLeglImageKHR" => "integer_unsigned",
"CLeglDisplayKHR" => "integer_unsigned",
"CLeglSyncKHR" => "integer_unsigned",
"cl_accelerator_intel" => "integer_unsigned",
"unsigned int" => "integer_unsigned",
"int" => "integer_signed",
"intptr_t" => "integer_signed",
"uintptr_t" => "integer_unsigned",
"size_t" => "integer_unsigned",
"cl_int" => "integer_signed",
"cl_uint" => "integer_unsigned",
"cl_long" => "integer_signed",
"cl_ulong" => "integer_unsigned",
"cl_short" => "integer_signed",
"cl_ushort" => "integer_unsigned",
"cl_char" => "string",
"cl_uchar" => "string",
"cl_half" => "real_single",
"cl_float" => "real_single",
"cl_double" => "real_double",
'cl_errcode' => 'integer_signed',
'string' => 'string'
}
class DBT_event
def initialize(name_unsanitized, fields)
@name_unsanitized = name_unsanitized
@fields = fields
end
def name_unsanitized
@name_unsanitized
end
def fields
@fields
end
def name
@name_unsanitized.gsub(':','_')
end
def name_striped
@name_unsanitized[/:(.*?)_?(?:#{START}|#{STOP})?$/,1]
end
Payload = Struct.new(:lttng_type,:name)
def payloads
@fields.map { |name, f_info|
cl_type = f_info["type"]
l = Payload.new($cl_type_to_bl_type.fetch(cl_type,'string'),name)
if f_info['array']
[Payload.new('integer_unsigned',"_#{name}_length"),l]
else
l
end
}.flatten
end
def callback_signature
head = ['const bt_event *bt_evt', 'const bt_clock_snapshot *bt_clock']
l = @fields.map { | name, f_info|
t = f_info['type'].gsub('cl_errcode','cl_int')
if f_info['pointer'] or f_info['array'] or f_info['string']
t = "#{t} *"
end
if f_info['array']
["size_t _#{name}_length", "#{t} #{name}"]
else
["#{t} #{name}"]
end
}.flatten
a = head+l
a.join(",\n")
end
end
$dbt_events = opencl_model['events'].map { |dbt_event|
name_unsanitized, fields = dbt_event
DBT_event.new(name_unsanitized, fields)
}
def write_file_via_template(file)
template = File.read(File.join(SRC_DIR, "#{file}.erb"))
template_rendered = ERB.new(template).result(binding).gsub(/^\s*$\n/,'')
File.write("#{file}", template_rendered)
end
$sink_type = ARGV[0]
$l_file_generated=['clinterval_callbacks.cpp']
if $sink_type == 'dust'
write_file_via_template('dust.c')
else
$l_file_generated.each{ |f|
write_file_via_template(f)
}
end
require 'erb'
require 'yaml'
SRC_DIR = ENV['SRC_DIR'] || '.'
START = 'entry'
STOP = 'exit'
class DBT_event
attr_reader :fields, :name_unsanitized
def initialize(klass)
@name_unsanitized = klass[:name]
@fields = klass[:payload]
end
def fields_name
@fields.map { |f| f[:name] }
end
def name
@name_unsanitized.gsub(':', '_')
end
def name_striped
# #{namespace}:#{foo}_#{START} -> #{foo}
# #{namespace}:#{foo} -> #{foo}
@name_unsanitized[/:(.*?)_?(?:#{START}|#{STOP})?$/, 1]
end
def callback_signature
decls = []
@fields.each do |f|
decls.push ['size_t', "_#{f[:name]}_length"] if f[:class] == 'array_static'
decls.push [f[:cast_type], f[:name]]
end
(['const bt_event *bt_evt', 'const bt_clock_snapshot *bt_clock'] + decls.map { |t, n| "#{t} #{n}" }).join(",\n ")
end
end
opencl_babeltrace_model = YAML.load_file('opencl_babeltrace_model.yaml')
$dbt_events = opencl_babeltrace_model[:event_classes].map { |klass|
DBT_event.new(klass)
}
template = File.read(File.join(SRC_DIR, "clinterval_callbacks.cpp.erb"))
puts ERB.new(template).result(binding).gsub(/^\s*$\n/, '')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment