11/*
22 *
3- * Copyright (C) 2023-2024 Intel Corporation
3+ * Copyright (C) 2023-2025 Intel Corporation
44 *
55 * SPDX-License-Identifier: MIT
66 *
@@ -47,6 +47,11 @@ class zetMetricTracerTest : public ::testing::Test {
4747 lzt::generate_device_list_with_activatable_metric_group_handles (
4848 devices, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EXP_TRACER_BASED,
4949 tracer_supporting_devices_list);
50+
51+ if (tracer_supporting_devices_list.size () == 0 ) {
52+ GTEST_SKIP ()
53+ << " no devices that have metric groups of type tracer were found" ;
54+ }
5055 }
5156
5257 void TearDown () override { lzt::destroy_context (context); }
@@ -67,10 +72,6 @@ TEST_F(
6772 zetMetricTracerTest,
6873 GivenActivatedMetricGroupsWhenTracerIsCreatedWithOneOrMultipleMetricsGroupsThenTracerCreateSucceeds) {
6974
70- if (tracer_supporting_devices_list.size () == 0 ) {
71- GTEST_SKIP ()
72- << " No devices that have metric groups of type Tracer were found" ;
73- }
7475 for (auto &device_with_metric_group_handles :
7576 tracer_supporting_devices_list) {
7677 device = device_with_metric_group_handles.device ;
@@ -122,10 +123,6 @@ TEST_F(
122123 zetMetricTracerTest,
123124 GivenTracerIsCreatedWithOneOrMoreActivatedMetricGroupWhenTracerIsEnabledSynchronouslyThenExpectTracerEnableToSucceed) {
124125
125- if (tracer_supporting_devices_list.size () == 0 ) {
126- GTEST_SKIP ()
127- << " No devices that have metric groups of type Tracer were found" ;
128- }
129126 for (auto &device_with_metric_group_handles :
130127 tracer_supporting_devices_list) {
131128 device = device_with_metric_group_handles.device ;
@@ -191,10 +188,6 @@ TEST_F(
191188 constexpr int32_t retry_wait_milliseconds = 5 ;
192189 ze_result_t result;
193190
194- if (tracer_supporting_devices_list.size () == 0 ) {
195- GTEST_SKIP ()
196- << " No devices that have metric groups of type Tracer were found" ;
197- }
198191 for (auto &device_with_metric_group_handles :
199192 tracer_supporting_devices_list) {
200193 device = device_with_metric_group_handles.device ;
@@ -361,10 +354,6 @@ TEST_P(
361354 LOG_INFO << " testing zetMetricTracerReadDataExp with " << test_mode
362355 << " tracer Enable and Disable" ;
363356
364- if (tracer_supporting_devices_list.size () == 0 ) {
365- GTEST_SKIP ()
366- << " No devices that have metric groups of type Tracer were found" ;
367- }
368357 for (auto &device_with_metric_group_handles :
369358 tracer_supporting_devices_list) {
370359 device = device_with_metric_group_handles.device ;
@@ -552,10 +541,6 @@ TEST_F(zetMetricTracerTest,
552541
553542 ze_result_t result;
554543
555- if (tracer_supporting_devices_list.size () == 0 ) {
556- GTEST_SKIP ()
557- << " No devices that have metric groups of type Tracer were found" ;
558- }
559544 for (auto &device_with_metric_group_handles :
560545 tracer_supporting_devices_list) {
561546 device = device_with_metric_group_handles.device ;
@@ -602,10 +587,6 @@ TEST_F(zetMetricTracerTest,
602587
603588 ze_result_t result;
604589
605- if (tracer_supporting_devices_list.size () == 0 ) {
606- GTEST_SKIP ()
607- << " No devices that have metric groups of type Tracer were found" ;
608- }
609590 for (auto &device_with_metric_group_handles :
610591 tracer_supporting_devices_list) {
611592 device = device_with_metric_group_handles.device ;
@@ -700,10 +681,6 @@ TEST_F(
700681 zetMetricTracerTest,
701682 GivenDecoderIsCreatedAndWorkloadExecutedAndTracerIsEnabledThenDecoderSucceedsDecodingMetrics) {
702683
703- if (tracer_supporting_devices_list.size () == 0 ) {
704- GTEST_SKIP ()
705- << " No devices that have metric groups of type Tracer were found" ;
706- }
707684 for (auto &device_with_metric_group_handles :
708685 tracer_supporting_devices_list) {
709686 device = device_with_metric_group_handles.device ;
@@ -946,4 +923,196 @@ TEST_F(
946923 }
947924}
948925
926+ TEST_F (zetMetricTracerTest,
927+ GivenDecoderIsCreatedWhenTracerIsDestroyedThenDecoderRemainsActive) {
928+ ze_result_t result;
929+
930+ for (auto &device_with_metric_group_handles :
931+ tracer_supporting_devices_list) {
932+ device = device_with_metric_group_handles.device ;
933+ lzt::display_device_properties (device);
934+ ASSERT_GT (device_with_metric_group_handles
935+ .activatable_metric_group_handle_list .size (),
936+ 0u );
937+ lzt::activate_metric_groups (
938+ device,
939+ device_with_metric_group_handles.activatable_metric_group_handle_list
940+ .size (),
941+ device_with_metric_group_handles.activatable_metric_group_handle_list
942+ .data ());
943+ zet_metric_tracer_exp_handle_t metric_tracer_handle = nullptr ;
944+ lzt::metric_tracer_create (lzt::get_default_context (), device,
945+ device_with_metric_group_handles
946+ .activatable_metric_group_handle_list .size (),
947+ device_with_metric_group_handles
948+ .activatable_metric_group_handle_list .data (),
949+ &tracer_descriptor, nullptr ,
950+ &metric_tracer_handle);
951+ lzt::metric_tracer_enable (metric_tracer_handle, true );
952+ zet_metric_decoder_exp_handle_t metric_decoder_handle = nullptr ;
953+ lzt::metric_decoder_create (metric_tracer_handle, &metric_decoder_handle);
954+ lzt::metric_tracer_disable (metric_tracer_handle, true );
955+ lzt::metric_tracer_destroy (metric_tracer_handle);
956+ uint32_t decodable_metric_count =
957+ lzt::metric_decoder_get_decodable_metrics_count (metric_decoder_handle);
958+ std::vector<zet_metric_handle_t > decodable_metric_handles (
959+ decodable_metric_count);
960+ lzt::metric_decoder_get_decodable_metrics (metric_decoder_handle,
961+ &decodable_metric_handles);
962+ decodable_metric_count = decodable_metric_handles.size ();
963+ for (uint32_t i = 0 ; i < decodable_metric_count; i++) {
964+ bool valid_type;
965+ zet_metric_properties_t decodable_metric_properties;
966+ lzt::get_metric_properties (decodable_metric_handles[i],
967+ &decodable_metric_properties);
968+ size_t metric_name_string_length;
969+ metric_name_string_length =
970+ strnlen (decodable_metric_properties.name , ZET_MAX_METRIC_NAME);
971+ EXPECT_GT (metric_name_string_length, 0 )
972+ << " the name string for this metric is of zero length" ;
973+ EXPECT_LT (metric_name_string_length, ZET_MAX_METRIC_NAME)
974+ << " the name string for this metric is not null terminated" ;
975+ valid_type =
976+ lzt::verify_value_type (decodable_metric_properties.resultType );
977+ EXPECT_TRUE (valid_type)
978+ << " metric properties for metric " << decodable_metric_properties.name
979+ << " has an incorrect resultType field "
980+ << decodable_metric_properties.resultType ;
981+ valid_type =
982+ lzt::verify_metric_type (decodable_metric_properties.metricType );
983+ EXPECT_TRUE (valid_type)
984+ << " metric properties for metric " << decodable_metric_properties.name
985+ << " has an invalid metricType field "
986+ << decodable_metric_properties.metricType ;
987+ }
988+ lzt::metric_decoder_destroy (metric_decoder_handle);
989+ lzt::deactivate_metric_groups (device);
990+ }
991+ }
992+
993+ TEST_F (zetMetricTracerTest,
994+ GivenDecoderIsCreatedThenEnsureAllMetricEntriesTimeStampsAreValid) {
995+
996+ for (auto &device_with_metric_group_handles :
997+ tracer_supporting_devices_list) {
998+ device = device_with_metric_group_handles.device ;
999+ lzt::display_device_properties (device);
1000+
1001+ ze_command_queue_handle_t commandQueue = lzt::create_command_queue (device);
1002+ zet_command_list_handle_t commandList = lzt::create_command_list (device);
1003+ void *a_buffer, *b_buffer, *c_buffer;
1004+ ze_group_count_t tg;
1005+ ze_kernel_handle_t function = get_matrix_multiplication_kernel (
1006+ device, &tg, &a_buffer, &b_buffer, &c_buffer, 128 );
1007+ lzt::append_launch_function (commandList, function, &tg, nullptr , 0 ,
1008+ nullptr );
1009+ lzt::close_command_list (commandList);
1010+
1011+ ze_event_pool_handle_t notification_event_pool;
1012+ notification_event_pool = lzt::create_event_pool (
1013+ lzt::get_default_context (), 1 , ZE_EVENT_POOL_FLAG_HOST_VISIBLE);
1014+ ze_event_handle_t notification_event;
1015+ ze_event_desc_t notification_event_descriptor = {
1016+ ZE_STRUCTURE_TYPE_EVENT_DESC, nullptr , 0 , ZE_EVENT_SCOPE_FLAG_HOST,
1017+ ZE_EVENT_SCOPE_FLAG_DEVICE};
1018+ notification_event = lzt::create_event (notification_event_pool,
1019+ notification_event_descriptor);
1020+
1021+ ASSERT_GT (device_with_metric_group_handles
1022+ .activatable_metric_group_handle_list .size (),
1023+ 0u );
1024+ lzt::activate_metric_groups (
1025+ device,
1026+ device_with_metric_group_handles.activatable_metric_group_handle_list
1027+ .size (),
1028+ device_with_metric_group_handles.activatable_metric_group_handle_list
1029+ .data ());
1030+ uint64_t host_timestamp_start, device_timestamp_start;
1031+ std::tie (host_timestamp_start, device_timestamp_start) =
1032+ lzt::get_global_timestamps (device);
1033+ LOG_DEBUG << " host_timestamp_start = " << host_timestamp_start
1034+ << " device_timestamp_start = " << device_timestamp_start;
1035+
1036+ zet_metric_tracer_exp_handle_t metric_tracer_handle;
1037+ lzt::metric_tracer_create (lzt::get_default_context (), device,
1038+ device_with_metric_group_handles
1039+ .activatable_metric_group_handle_list .size (),
1040+ device_with_metric_group_handles
1041+ .activatable_metric_group_handle_list .data (),
1042+ &tracer_descriptor, notification_event,
1043+ &metric_tracer_handle);
1044+ lzt::metric_tracer_enable (metric_tracer_handle, true );
1045+ LOG_DEBUG << " execute workload" ;
1046+ lzt::execute_command_lists (commandQueue, 1 , &commandList, nullptr );
1047+ LOG_DEBUG << " synchronize with completion of workload" ;
1048+ lzt::synchronize (commandQueue, std::numeric_limits<uint64_t >::max ());
1049+ LOG_DEBUG << " synchronize on the tracer notification event" ;
1050+ lzt::event_host_synchronize (notification_event,
1051+ std::numeric_limits<uint64_t >::max ());
1052+ lzt::metric_tracer_disable (metric_tracer_handle, true );
1053+ /* read data */
1054+ size_t raw_data_size = 0 ;
1055+ raw_data_size = lzt::metric_tracer_read_data_size (metric_tracer_handle);
1056+ std::vector<uint8_t > raw_data (raw_data_size, 0 );
1057+ lzt::metric_tracer_read_data (metric_tracer_handle, &raw_data);
1058+ zet_metric_decoder_exp_handle_t metric_decoder_handle = nullptr ;
1059+
1060+ lzt::metric_decoder_create (metric_tracer_handle, &metric_decoder_handle);
1061+ uint32_t decodable_metric_count =
1062+ lzt::metric_decoder_get_decodable_metrics_count (metric_decoder_handle);
1063+ std::vector<zet_metric_handle_t > decodable_metric_handles (
1064+ decodable_metric_count);
1065+ lzt::metric_decoder_get_decodable_metrics (metric_decoder_handle,
1066+ &decodable_metric_handles);
1067+ decodable_metric_count = decodable_metric_handles.size ();
1068+ /* Decode Data */
1069+ uint32_t metric_entry_count = 0 ;
1070+ uint32_t set_count = 0 ;
1071+ lzt::metric_tracer_decode_get_various_counts (
1072+ metric_decoder_handle, &raw_data_size, &raw_data,
1073+ decodable_metric_count, &decodable_metric_handles, &set_count,
1074+ &metric_entry_count);
1075+ std::vector<uint32_t > metric_entries_per_set_count (set_count);
1076+ std::vector<zet_metric_entry_exp_t > metric_entries (metric_entry_count);
1077+ lzt::metric_tracer_decode (metric_decoder_handle, &raw_data_size, &raw_data,
1078+ decodable_metric_count, &decodable_metric_handles,
1079+ &set_count, &metric_entries_per_set_count,
1080+ &metric_entry_count, &metric_entries);
1081+
1082+ if (metric_entry_count != 0 ) {
1083+ uint64_t metric_entry_timestamp_start = 0 ;
1084+ uint64_t metric_entry_timestamp_end = 0 ;
1085+ metric_entry_timestamp_start = metric_entries[0 ].timeStamp ;
1086+ LOG_DEBUG << " metric entry timestamp start "
1087+ << metric_entry_timestamp_start;
1088+ metric_entry_timestamp_end =
1089+ metric_entries[metric_entry_count - 1 ].timeStamp ;
1090+ LOG_DEBUG << " metric entry timestamp end " << metric_entry_timestamp_end;
1091+
1092+ uint64_t host_timestamp_end, device_timestamp_end;
1093+ std::tie (host_timestamp_end, device_timestamp_end) =
1094+ lzt::get_global_timestamps (device);
1095+ LOG_DEBUG << " host_timestamp_end = " << host_timestamp_end
1096+ << " device_timestamp_end = " << device_timestamp_end;
1097+ EXPECT_GT (metric_entry_timestamp_start, device_timestamp_start)
1098+ << " first metric entry timestamp should be greater than first "
1099+ " device timestamp" ;
1100+ EXPECT_LT (metric_entry_timestamp_end, device_timestamp_end)
1101+ << " last metric entry timestamp should be lesser than last device "
1102+ " timestamp" ;
1103+ }
1104+ lzt::metric_decoder_destroy (metric_decoder_handle);
1105+ lzt::metric_tracer_destroy (metric_tracer_handle);
1106+ lzt::deactivate_metric_groups (device);
1107+ lzt::free_memory (a_buffer);
1108+ lzt::free_memory (b_buffer);
1109+ lzt::free_memory (c_buffer);
1110+ lzt::reset_command_list (commandList);
1111+ lzt::destroy_event (notification_event);
1112+ lzt::destroy_event_pool (notification_event_pool);
1113+ lzt::destroy_command_queue (commandQueue);
1114+ lzt::destroy_command_list (commandList);
1115+ }
1116+ }
1117+
9491118} // namespace
0 commit comments