Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
03236c7
lib: emit the Handle and UUID renderers only where a struct prepends one
TApplencourt Sep 9, 2026
99eb637
lib: let a type say how its bytes should be read
TApplencourt Sep 10, 2026
d35fc28
lib: render every member, so a UUID pair needs no renderer of its own
TApplencourt Sep 10, 2026
3191587
lib: declare rendering per member, in meta_parameters_struct
TApplencourt Sep 10, 2026
fb9e2b5
lib: one loader, plain renderer functions, and a check on every row
TApplencourt Sep 10, 2026
52fccbf
lib: name the rendering pieces for what they are
TApplencourt Sep 11, 2026
7994ff8
lib: one check for a member a renderer cannot read
TApplencourt Sep 11, 2026
4118a8a
lib: call it Bytes, and count duplicates instead of catching them
TApplencourt Sep 11, 2026
392c972
lib: let the struct printer decide when there is nothing to emit
TApplencourt Sep 11, 2026
5748f60
Simplify README
TApplencourt Sep 11, 2026
4a3372d
lib: trim the initializer note to the contract
TApplencourt Sep 11, 2026
d09a9fc
lib: declare how a function's byte-array parameters print
TApplencourt Sep 11, 2026
6b06d9d
lib: read a traced field's parameter from the model
TApplencourt Sep 11, 2026
429a825
lib: an editor's pass over the rendering comments and docs
TApplencourt Sep 11, 2026
b70fa7c
lib: drop the prepend hook the declared renderers replaced
TApplencourt Sep 11, 2026
8d9deb4
lib: check every backend's rendering rows, and every member of a decl…
TApplencourt Sep 11, 2026
ed40b51
lib: name the tracepoint decorations once, and say what each helper does
TApplencourt Sep 11, 2026
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
33 changes: 33 additions & 0 deletions backends/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Backends

## `meta_parameters_struct` and `meta_parameters_function`

`<backend>_meta_parameters.yaml` can carry two more sections of the same kind
as `meta_parameters` itself: facts the header knows that the C declaration does
not carry. These two say how to print bytes whose meaning no C type states --
`meta_parameters_struct` for a struct's byte-array members,
`meta_parameters_function` for a function's byte-array parameters.

```yaml
meta_parameters_struct:
ze_uuid_t:
- [ uuid_reversed, id ]
ze_kernel_uuid_t:
- [ uuid_reversed, kid ]
- [ uuid_reversed, mid ]
ze_ipc_mem_handle_t:
- [ blob, data ]

meta_parameters_function:
cuDeviceGetLuid:
- [ uuid, luid ]
```

A member with no row falls back to the default print: `char[N]` prints as a C
string, stopping at the first null char.

| Renderer | Prints |
| --- | --- |
| `uuid` | dashed hex, first byte first (cuda, hip) |
| `uuid_reversed` | dashed hex, last byte first (ze, zes) |
| `blob` | every byte escaped, stopping at none |
16 changes: 16 additions & 0 deletions backends/cuda/cuda_meta_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1078,3 +1078,19 @@ meta_parameters:
- [InArray, globalDim, tensorRank]
- [InArray, globalStrides, tensorRank]
- [InArray, elementStrides, tensorRank]

meta_parameters_function:
cuDeviceGetLuid:
- [ uuid, luid ]

meta_parameters_struct:
CUuuid:
- [ uuid, bytes ]
CUmemFabricHandle_v1:
- [ blob, data ]
CUipcEventHandle_v1:
- [ blob, reserved ]
CUipcMemHandle_v1:
- [ blob, reserved ]
CUmemPoolPtrExportData_v1:
- [ blob, reserved ]
4 changes: 3 additions & 1 deletion backends/cuda/cuda_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

# The driver and its export tables are one API but two LTTng providers, so the
# commands are grouped by the provider that will carry them.
META_PARAMETERS = load_meta_parameters('cuda_meta_parameters.yaml', 'cuda_exports_meta_parameters.yaml')

COMMANDS = build_command_index(
{ lttng_ust_cuda: cuda_api.functions, lttng_ust_cuda_exports: cuda_exports_api.functions },
context: CONTEXT,
spec: load_meta_parameters('cuda_meta_parameters.yaml', 'cuda_exports_meta_parameters.yaml')
spec: META_PARAMETERS[:meta_parameters]
)

CUDA_POINTER_NAMES = COMMANDS.pointer_names
Expand Down
2 changes: 1 addition & 1 deletion backends/cuda/gen_babeltrace_cuda_lib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'gen_cuda_library_base'
require_relative '../../utils/gen_babeltrace_lib_helper'

print_babeltrace_lib(NAMING)
print_babeltrace_lib(NAMING, META_PARAMETERS)
9 changes: 6 additions & 3 deletions backends/cuda/gen_cuda_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ module CUDA

EOF

print_handle_uuid_modules
puts
print_bytes_module(NAMING, META_PARAMETERS)

puts <<EOF
typedef :uint32, #{to_ffi_name('cuuint32_t')}
Expand All @@ -50,7 +49,11 @@ module CUDA
print_typedefs(
NAMING,
enum: ->(name, t) { print_enum(NAMING, name, API.enum(t.type, opaque_ok: true) || t.type) },
struct: ->(name, t) { print_struct_prepending_uuid(NAMING, name, API.struct(t.type)) },
struct: lambda { |name, t|
struct = API.struct(t.type)
print_struct_with_namespace(NAMING, name, struct,
body: struct_to_s_definition(NAMING, struct, META_PARAMETERS[:meta_parameters_struct][name]))
},
pointer: nil,
integer: nil
)
Expand Down
2 changes: 1 addition & 1 deletion backends/hip/gen_babeltrace_hip_lib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'gen_hip_library_base'
require_relative '../../utils/gen_babeltrace_lib_helper'

print_babeltrace_lib(NAMING)
print_babeltrace_lib(NAMING, META_PARAMETERS)
7 changes: 5 additions & 2 deletions backends/hip/gen_hip_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module HIP

EOF

print_handle_uuid_modules
print_bytes_module(NAMING, META_PARAMETERS)

puts <<EOF

Expand All @@ -32,7 +32,10 @@ module HIP
# layout to emit.
print_typedefs(NAMING, struct: lambda { |name, t|
struct = API.struct(t.type, opaque_ok: true)
print_struct_prepending_uuid(NAMING, name, struct) if struct
next unless struct

print_struct_with_namespace(NAMING, name, struct,
body: struct_to_s_definition(NAMING, struct, META_PARAMETERS[:meta_parameters_struct][name]))
})

puts <<~EOF
Expand Down
10 changes: 10 additions & 0 deletions backends/hip/hip_meta_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,13 @@ meta_parameters:
- [ReturnString]
amd_dbgapi_get_git_hash:
- [ReturnString]

meta_parameters_struct:
hipUUID:
- [ uuid, bytes ]
hipIpcMemHandle_t:
- [ blob, reserved ]
hipIpcEventHandle_t:
- [ blob, reserved ]
hipMemPoolPtrExportData:
- [ blob, reserved ]
4 changes: 3 additions & 1 deletion backends/hip/hip_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

CONTEXT = BackendContext.for(API, result_name: 'hipResult', init_functions: /.*/)

META_PARAMETERS = load_meta_parameters('hip_meta_parameters.yaml')

COMMANDS = build_command_index(
{ lttng_ust_hip: API.functions },
context: CONTEXT, spec: load_meta_parameters('hip_meta_parameters.yaml')
context: CONTEXT, spec: META_PARAMETERS[:meta_parameters]
)

HIP_POINTER_NAMES = COMMANDS.pointer_names
2 changes: 1 addition & 1 deletion backends/itt/gen_babeltrace_itt_lib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'gen_itt_library_base'
require_relative '../../utils/gen_babeltrace_lib_helper'

print_babeltrace_lib(NAMING)
print_babeltrace_lib(NAMING, META_PARAMETERS)
2 changes: 2 additions & 0 deletions backends/itt/gen_itt_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module ITT

EOF

print_bytes_module(NAMING, META_PARAMETERS)

# itt defines its callbacks at the end of the file, so a struct member typed as
# one would name a callback FFI has not seen yet. Those members are emitted as
# a plain :pointer, which is the same machine type.
Expand Down
4 changes: 3 additions & 1 deletion backends/itt/itt_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
__itt_metadata_add
]

META_PARAMETERS = load_meta_parameters('itt_meta_parameters.yaml')

COMMANDS = build_command_index(
{ lttng_ust_itt: API.functions },
context: CONTEXT, spec: load_meta_parameters('itt_meta_parameters.yaml'),
context: CONTEXT, spec: META_PARAMETERS[:meta_parameters],
select: ->(func) { traced_functions.include?(func.name) }
)
2 changes: 1 addition & 1 deletion backends/mpi/gen_babeltrace_mpi_lib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'gen_mpi_library_base'
require_relative '../../utils/gen_babeltrace_lib_helper'

print_babeltrace_lib(NAMING)
print_babeltrace_lib(NAMING, META_PARAMETERS)
2 changes: 1 addition & 1 deletion backends/mpi/gen_mpi_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module MPI

EOF

print_handle_uuid_modules
print_bytes_module(NAMING, META_PARAMETERS)

print_typedefs(NAMING)

Expand Down
4 changes: 3 additions & 1 deletion backends/mpi/mpi_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@

CONTEXT = BackendContext.for(API, result_name: 'mpiResult', init_functions: init_functions)

META_PARAMETERS = load_meta_parameters('mpi_meta_parameters.yaml')

COMMANDS = build_command_index(
{ lttng_ust_mpi: API.functions },
context: CONTEXT, spec: load_meta_parameters('mpi_meta_parameters.yaml')
context: CONTEXT, spec: META_PARAMETERS[:meta_parameters]
)

# MPI spells its functions MPI_Comm_rank, already snake_case, so the macro name
Expand Down
2 changes: 1 addition & 1 deletion backends/omp/gen_babeltrace_omp_lib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'gen_omp_library_base'
require_relative '../../utils/gen_babeltrace_lib_helper'

print_babeltrace_lib(NAMING)
print_babeltrace_lib(NAMING, META_PARAMETERS)
2 changes: 2 additions & 0 deletions backends/omp/gen_omp_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module OMP

EOF

print_bytes_module(NAMING, META_PARAMETERS)

# The Ruby bindings for OMPT carry only its enums.
print_typedefs(NAMING,
enum: ->(name, t) { print_enum(name, API.enum(t.type)) },
Expand Down
4 changes: 3 additions & 1 deletion backends/omp/ompt_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
YAMLCAst::Declaration.new(name: t.name.gsub(/_t\z/, '') + '_func', type: t.type.type)
end

META_PARAMETERS = load_meta_parameters('ompt_meta_parameters.yaml')

COMMANDS = build_command_index(
{ lttng_ust_ompt: OMPT_CALLBACKS },
context: CONTEXT, spec: load_meta_parameters('ompt_meta_parameters.yaml')
context: CONTEXT, spec: META_PARAMETERS[:meta_parameters]
)
2 changes: 1 addition & 1 deletion backends/opencl/opencl_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def void_parameters?
end
end

meta_parameters = load_meta_parameters('opencl_meta_parameters.yaml')
meta_parameters = load_meta_parameters('opencl_meta_parameters.yaml')[:meta_parameters]

# Both groups go to the one lttng_ust_opencl provider, so they are grouped by
# what actually separates them: an extension is reached through
Expand Down
2 changes: 1 addition & 1 deletion backends/ze/gen_babeltrace_ze_lib.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'gen_ze_library_base'
require_relative '../../utils/gen_babeltrace_lib_helper'

print_babeltrace_lib(NAMING)
print_babeltrace_lib(NAMING, META_PARAMETERS)
104 changes: 6 additions & 98 deletions backends/ze/gen_ze_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,92 +102,6 @@ def self.ZE_MINOR_VERSION(ver = VERSION_CURRENT)
ver & 0x0000ffff
end

module Handle
def to_s
s = '{ data: "'
s << self[:data].to_a.collect { |v| "\\\\x%02x" % ((v + 256)%256) }.join
s << '" }'
end
end

module UUID
def to_s
a = self[:id].to_a
s = "{ id: "
s << "%02x" % a[15]
s << "%02x" % a[14]
s << "%02x" % a[13]
s << "%02x" % a[12]
s << "-"
s << "%02x" % a[11]
s << "%02x" % a[10]
s << "-"
s << "%02x" % a[9]
s << "%02x" % a[8]
s << "-"
s << "%02x" % a[7]
s << "%02x" % a[6]
s << "-"
s << "%02x" % a[5]
s << "%02x" % a[4]
s << "%02x" % a[3]
s << "%02x" % a[2]
s << "%02x" % a[1]
s << "%02x" % a[0]
s << " }"
end
end

module KUUID
def to_s
a = self[:kid].to_a
s = "{ kid: "
s << "%02x" % a[15]
s << "%02x" % a[14]
s << "%02x" % a[13]
s << "%02x" % a[12]
s << "-"
s << "%02x" % a[11]
s << "%02x" % a[10]
s << "-"
s << "%02x" % a[9]
s << "%02x" % a[8]
s << "-"
s << "%02x" % a[7]
s << "%02x" % a[6]
s << "-"
s << "%02x" % a[5]
s << "%02x" % a[4]
s << "%02x" % a[3]
s << "%02x" % a[2]
s << "%02x" % a[1]
s << "%02x" % a[0]
a = self[:mid].to_a
s << ", mid: "
s << "%02x" % a[15]
s << "%02x" % a[14]
s << "%02x" % a[13]
s << "%02x" % a[12]
s << "-"
s << "%02x" % a[11]
s << "%02x" % a[10]
s << "-"
s << "%02x" % a[9]
s << "%02x" % a[8]
s << "-"
s << "%02x" % a[7]
s << "%02x" % a[6]
s << "-"
s << "%02x" % a[5]
s << "%02x" % a[4]
s << "%02x" % a[3]
s << "%02x" % a[2]
s << "%02x" % a[1]
s << "%02x" % a[0]
s << " }"
end
end

module Version
def to_s
"\#{self[:major]}.\#{self[:minor]}"
Expand All @@ -201,18 +115,9 @@ def to_i

EOF

def print_struct(name, struct)
prepends = []
if NAMING.class_name(name).match('UUID')
prepends << if NAMING.class_name(name).match('ZEKernelUUID')
'KUUID'
else
'UUID'
end
elsif NAMING.class_name(name).match(/Handle\z/)
prepends << 'Handle'
end
print_bytes_module(NAMING, META_PARAMETERS)

def print_struct(name, struct)
stype = traced_structure_type_names(name).first
initializer = <<EOF if stype

Expand All @@ -224,7 +129,10 @@ def initialize(*args)
end
EOF

print_struct_with_namespace(NAMING, name, struct, prepends: prepends, initializer: initializer, close: false)
to_s = struct_to_s_definition(NAMING, struct, META_PARAMETERS[:meta_parameters_struct][name])
print_struct_with_namespace(NAMING, name, struct,
body: [to_s, initializer].compact.join,
close: false)
end

API.int_scalars.each do |k, v|
Expand Down
19 changes: 19 additions & 0 deletions backends/ze/ze_meta_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,22 @@ meta_parameters:
zeCommandListUpdateMutableCommandKernelsExp:
- [ InArray, pCommandId, numKernels ]
- [ InArray, phKernels, numKernels ]

meta_parameters_struct:
ze_uuid_t:
- [ uuid_reversed, id ]
ze_driver_uuid_t:
- [ uuid_reversed, id ]
ze_device_uuid_t:
- [ uuid_reversed, id ]
ze_native_kernel_uuid_t:
- [ uuid_reversed, id ]
ze_kernel_uuid_t:
- [ uuid_reversed, kid ]
- [ uuid_reversed, mid ]
ze_device_luid_ext_t:
- [ uuid_reversed, id ]
ze_ipc_mem_handle_t:
- [ blob, data ]
ze_ipc_event_pool_handle_t:
- [ blob, data ]
Loading
Loading