Skip to content

Commit 1032dc2

Browse files
committed
Event timing v2
1 parent 57e4b4e commit 1032dc2

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

utils/gen_babeltrace_model_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def get_extra_fields_types_name(event)
22
event["fields"].collect { |field|
33
lttng = LTTng::TracepointField.new(*field)
44
name = lttng.name.to_s
5-
type = event["args"].find { |t, n| n == name || n == name.gsub(/_val\z/, "") }[0]
5+
type = event["args"].find { |t, n| n == name || n == name.gsub(/_vals?\z/, "") }[0]
66
case lttng.macro.to_s
77
when /ctf_sequence/
88
[["ctf_integer", "size_t", "_#{name}_length", nil],

ze/tracer_ze_helpers.include.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static struct _ze_event_h * _get_profiling_event(
375375
}
376376

377377
e_w->command_list = command_list;
378-
ze_event_pool_desc_t desc = {ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, NULL, ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE, 1};
378+
ze_event_pool_desc_t desc = {ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, NULL, ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_KERNEL_MAPPED_TIMESTAMP, 1};
379379
ze_result_t res = ZE_EVENT_POOL_CREATE_PTR(context, &desc, 0, NULL, &e_w->event_pool);
380380
if (res != ZE_RESULT_SUCCESS) {
381381
THAPI_DBGLOG("zeEventPoolCreate failed with %d, for command list: %p, context: %p", res, command_list, context);
@@ -399,6 +399,7 @@ static struct _ze_event_h * _get_profiling_event(
399399
}
400400

401401
static void _profile_event_results(ze_event_handle_t event);
402+
static void _profile_event_results_v2(ze_event_handle_t event, ze_command_list_handle_t);
402403

403404
static inline void _on_created_event(ze_event_handle_t event) {
404405
#ifdef THAPI_DEBUG
@@ -441,8 +442,10 @@ static inline void _on_destroy_event(ze_event_handle_t event) {
441442
return;
442443
}
443444

444-
if (!(ze_event->flags & _ZE_PROFILED))
445+
if (!(ze_event->flags & _ZE_PROFILED)) {
445446
_profile_event_results(event);
447+
_profile_event_results_v2(event, ze_event->command_list);
448+
}
446449
PUT_ZE_EVENT_WRAPPER(ze_event);
447450
}
448451

@@ -472,8 +475,10 @@ static inline void _on_reset_event(ze_event_handle_t event) {
472475
return;
473476
}
474477

475-
if (!(ze_event->flags & _ZE_PROFILED))
478+
if (!(ze_event->flags & _ZE_PROFILED)) {
476479
_profile_event_results(event);
480+
_profile_event_results_v2(event, ze_event->command_list);
481+
}
477482

478483
if (!(ze_event->flags & _ZE_IMMEDIATE_CMD))
479484
ADD_ZE_EVENT(ze_event);
@@ -505,6 +510,9 @@ static void _profile_event_results(ze_event_handle_t event) {
505510
if (tracepoint_enabled(lttng_ust_ze_profiling, event_profiling_results)) {
506511
status = ZE_EVENT_QUERY_STATUS_PTR(event);
507512
timestamp_status = ZE_EVENT_QUERY_KERNEL_TIMESTAMP_PTR(event, &res);
513+
printf("zeEventQueryKernelTimestamp | Start %ld | End %ld \n",
514+
res.global.kernelStart,
515+
res.global.kernelEnd);
508516
do_tracepoint(lttng_ust_ze_profiling, event_profiling_results,
509517
event, status, timestamp_status,
510518
res.global.kernelStart,
@@ -513,6 +521,42 @@ static void _profile_event_results(ze_event_handle_t event) {
513521
res.context.kernelEnd);
514522
}
515523
}
524+
static void _profile_event_results_v2(ze_event_handle_t event, ze_command_list_handle_t command_list) {
525+
526+
ze_result_t status = ZE_EVENT_QUERY_STATUS_PTR(event);
527+
528+
/* Find Device */
529+
ze_device_handle_t device;
530+
ZE_COMMAND_LIST_GET_DEVICE_HANDLE_PTR(command_list, &device);
531+
532+
// Qurery Timestamp. We should avoid malloc
533+
uint32_t pCount = 0;
534+
ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_PTR(event, device, &pCount, NULL);
535+
536+
ze_kernel_timestamp_result_t *kernelTimestamps =
537+
malloc(pCount * sizeof(ze_kernel_timestamp_result_t));
538+
ze_synchronized_timestamp_result_ext_t *synchronizedTimestamps =
539+
malloc(pCount * sizeof(ze_synchronized_timestamp_result_ext_t));
540+
ze_event_query_kernel_timestamps_results_ext_properties_t resultsProps;
541+
542+
resultsProps.stype = ZE_STRUCTURE_TYPE_EVENT_QUERY_KERNEL_TIMESTAMPS_RESULTS_EXT_PROPERTIES;
543+
resultsProps.pNext = NULL;
544+
resultsProps.pKernelTimestampsBuffer = kernelTimestamps;
545+
resultsProps.pSynchronizedTimestampsBuffer = synchronizedTimestamps;
546+
// Query the event timestamps
547+
ze_result_t timestamps_status = ZE_EVENT_QUERY_KERNEL_TIMESTAMPS_EXT_PTR(event, device, &pCount, &resultsProps);
548+
// Will do lttng static array. of size pCount and type synchronizedTimestamps
549+
for (uint32_t i = 0; i < pCount; i++) {
550+
printf("zeEventQueryKernelTimestampsExtSynchronizedTimestamps | Start %ld | End %ld \n",
551+
synchronizedTimestamps[i].global.kernelStart,
552+
synchronizedTimestamps[i].global.kernelEnd);
553+
printf("zeEventQueryKernelTimestampsExtGlobalKernelKernelTimestamps | Start %ld | End %ld \n",
554+
kernelTimestamps[i].global.kernelStart,
555+
kernelTimestamps[i].global.kernelEnd);
556+
}
557+
do_tracepoint(lttng_ust_ze_profiling, event_profiling_results_v2,
558+
event, status, timestamps_status, pCount, synchronizedTimestamps);
559+
}
516560

517561
static void _event_cleanup() {
518562
struct _ze_event_h *ze_event = NULL;

ze/ze_events.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ lttng_ust_ze_profiling:
132132
- [ ctf_integer, uint64_t, globalEnd, "globalEnd" ]
133133
- [ ctf_integer, uint64_t, contextStart, "contextStart" ]
134134
- [ ctf_integer, uint64_t, contextEnd, "contextEnd" ]
135+
- name: event_profiling_results_v2
136+
args:
137+
- [ ze_event_handle_t, hEvent ]
138+
- [ ze_result_t, status ]
139+
- [ ze_result_t, timestampsStatus ]
140+
- [ uint32_t, count ]
141+
- [ ze_synchronized_timestamp_result_ext_t *, pSynchronizedTimestamps ]
142+
fields:
143+
- [ ctf_integer_hex, uintptr_t, hEvent, "(uintptr_t)hEvent" ]
144+
- [ ctf_integer, ze_result_t, status, "status" ]
145+
- [ ctf_integer, ze_result_t, timestampsStatus, "timestampsStatus" ]
146+
- [ ctf_integer, uint32_t, count, "count" ]
147+
- [ ctf_sequence_text, uint8_t, pSynchronizedTimestamps_vals, pSynchronizedTimestamps, size_t, "sizeof(ze_synchronized_timestamp_result_ext_t)*count" ]
135148
lttng_ust_ze_properties:
136149
events:
137150
- name: driver

ze/ze_model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def upper_snake_case(str)
182182
ze_event_pool_desc_t _new_desc;
183183
if (_do_profile && desc && !(desc->flags & ZE_EVENT_POOL_FLAG_IPC)) {
184184
_new_desc = *desc;
185-
_new_desc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
185+
_new_desc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP | ZE_EVENT_POOL_FLAG_KERNEL_MAPPED_TIMESTAMP;
186186
_new_desc.flags |= ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
187187
desc = &_new_desc;
188188
}

0 commit comments

Comments
 (0)