feature: Metrics properties show metric scopes in Tracelib

Related-To: NEO-15832

Signed-off-by: Shreyas Kunder <shreyas.kunder@intel.com>
This commit is contained in:
Shreyas Kunder
2025-09-09 22:29:20 +00:00
committed by Compute-Runtime-Automation
parent c08aa1d400
commit 5c6ae48d17
6 changed files with 97 additions and 1 deletions

View File

@@ -743,6 +743,19 @@ MetricImp *MultiDeviceMetricImp::getMetricAtSubDeviceIndex(uint32_t index) {
return nullptr;
}
ze_result_t MetricImp::getScopes(uint32_t *pCount, zet_intel_metric_scope_exp_handle_t *phScopes) {
if (*pCount == 0) {
*pCount = static_cast<uint32_t>(scopes.size());
return ZE_RESULT_SUCCESS;
}
*pCount = std::min(*pCount, static_cast<uint32_t>(scopes.size()));
for (uint32_t i = 0; i < *pCount; i++) {
phScopes[i] = scopes[i];
}
return ZE_RESULT_SUCCESS;
}
ze_result_t metricGroupGet(zet_device_handle_t hDevice, uint32_t *pCount, zet_metric_group_handle_t *phMetricGroups) {
auto device = Device::fromHandle(hDevice);
return device->getMetricDeviceContext().metricGroupGet(pCount, phMetricGroups);
@@ -1155,4 +1168,13 @@ ze_result_t metricAppendMarker(zet_command_list_handle_t hCommandList, zet_metri
return metricGroupImp->getMetricSource().appendMarker(hCommandList, hMetricGroup, value);
}
ze_result_t getMetricSupportedScopes(
zet_metric_handle_t *phMetric,
uint32_t *pScopesCount,
zet_intel_metric_scope_exp_handle_t *phMetricScopes) {
auto metricImp = static_cast<MetricImp *>(Metric::fromHandle(*phMetric));
return metricImp->getScopes(pScopesCount, phMetricScopes);
}
} // namespace L0

View File

@@ -201,6 +201,10 @@ class MetricDeviceContext {
return computeMetricScopesInitialized;
}
const std::vector<std::unique_ptr<MetricScopeImp>> &getMetricScopes() const {
return metricScopes;
}
protected:
bool areMetricGroupsFromSameSource(uint32_t count, zet_metric_group_handle_t *phMetricGroups, uint32_t *sourceType);
bool areMetricsFromSameSource(uint32_t count, zet_metric_handle_t *phMetrics, uint32_t *sourceType);
@@ -256,6 +260,10 @@ struct MetricImp : public Metric {
bool isPredefined = true;
bool isMultiDevice = false;
MultiDeviceMetricImp *rootDeviceMetricImp = nullptr;
std::vector<zet_intel_metric_scope_exp_handle_t> scopes = {};
public:
ze_result_t getScopes(uint32_t *pCount, zet_intel_metric_scope_exp_handle_t *phScopes);
};
struct MultiDeviceMetricImp : public MetricImp {
@@ -626,5 +634,6 @@ ze_result_t metricScopesGet(zet_context_handle_t hContext, zet_device_handle_t h
zet_intel_metric_scope_exp_handle_t *phMetricScopes);
ze_result_t metricScopeGetProperties(zet_intel_metric_scope_exp_handle_t hMetricScope, zet_intel_metric_scope_properties_exp_t *pMetricScopeProperties);
ze_result_t metricAppendMarker(zet_command_list_handle_t hCommandList, zet_metric_group_handle_t hMetricGroup, uint32_t value);
ze_result_t getMetricSupportedScopes(zet_metric_handle_t *phMetric, uint32_t *pScopesCount, zet_intel_metric_scope_exp_handle_t *phMetricScopes);
} // namespace L0

View File

@@ -581,6 +581,51 @@ TEST_F(MetricIpSamplingStreamerTest, whenGetConcurrentMetricGroupsIsCalledThenCo
}
}
using MetricIpSamplingMetricSupportedScopeTest = MetricIpSamplingStreamerTest;
class MockMetricImp : public MetricImp {
public:
using MetricImp::MetricImp;
void setScopes(const std::vector<zet_intel_metric_scope_exp_handle_t> &newScopes) {
scopes = newScopes;
}
};
TEST_F(MetricIpSamplingMetricSupportedScopeTest, givenMetricWhenGettingSupportedMetricScopesThenExpectedCountAndHandlesAreReturned) {
EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi());
EXPECT_EQ(testDevices[0]->getMetricDeviceContext().getMetricScopes().size(), 0u);
zet_metric_group_handle_t metricGroupHandle = MetricIpSamplingStreamerTest::getMetricGroup(testDevices[0]);
uint32_t metricCount = 0;
EXPECT_EQ(zetMetricGet(metricGroupHandle, &metricCount, nullptr), ZE_RESULT_SUCCESS);
metricCount = 1;
zet_metric_handle_t phMetric{};
EXPECT_EQ(zetMetricGet(metricGroupHandle, &metricCount, &phMetric), ZE_RESULT_SUCCESS);
zet_intel_metric_scope_properties_exp_t scopeProperties{};
scopeProperties.stype = ZET_STRUCTURE_TYPE_INTEL_METRIC_SCOPE_PROPERTIES_EXP;
scopeProperties.pNext = nullptr;
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopesHandles;
MockMetricScope *mockMetricScope = new MockMetricScope(scopeProperties, false);
metricScopesHandles.push_back(mockMetricScope->toHandle());
auto metricImp = static_cast<MockMetricImp *>(Metric::fromHandle(phMetric));
metricImp->setScopes(metricScopesHandles);
uint32_t metricScopesCount = 0;
EXPECT_EQ(zetIntelMetricSupportedScopesGetExp(&phMetric, &metricScopesCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricScopesCount, 1u);
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopesHandle(metricScopesCount);
EXPECT_EQ(zetIntelMetricSupportedScopesGetExp(&phMetric, &metricScopesCount, metricScopesHandle.data()), ZE_RESULT_SUCCESS);
EXPECT_NE(metricScopesHandle[0], nullptr);
delete mockMetricScope;
}
using MetricIpSamplingCalcOpMultiDevTest = MetricIpSamplingCalculateMultiDevFixture;
HWTEST2_F(MetricIpSamplingCalcOpMultiDevTest, givenIpSamplingMetricGroupThenCreateAndDestroyCalcOpIsSuccessful, EustallSupportedPlatforms) {