2023-09-26 11:50:57 -07:00
|
|
|
#include "metrics_test.h"
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
|
|
#include "lib/rocprofiler/counters/metrics.hpp"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
2023-10-16 13:41:40 -07:00
|
|
|
namespace counters = ::rocprofiler::counters;
|
|
|
|
|
|
2023-09-26 11:50:57 -07:00
|
|
|
auto
|
2023-10-10 18:10:23 -05:00
|
|
|
loadTestData(const std::unordered_map<std::string, std::vector<std::vector<std::string>>>& map)
|
2023-09-26 11:50:57 -07:00
|
|
|
{
|
|
|
|
|
std::unordered_map<std::string, std::vector<counters::Metric>> ret;
|
2023-10-10 18:10:23 -05:00
|
|
|
for(const auto& [gfx, dataMap] : map)
|
2023-09-26 11:50:57 -07:00
|
|
|
{
|
|
|
|
|
auto& metric_vec = ret.emplace(gfx, std::vector<counters::Metric>{}).first->second;
|
2023-10-10 18:10:23 -05:00
|
|
|
for(const auto& data_vec : dataMap)
|
2023-09-26 11:50:57 -07:00
|
|
|
{
|
2023-10-16 13:41:40 -07:00
|
|
|
metric_vec.emplace_back(data_vec.at(0),
|
|
|
|
|
data_vec.at(1),
|
|
|
|
|
data_vec.at(2),
|
|
|
|
|
data_vec.at(4),
|
|
|
|
|
data_vec.at(3),
|
|
|
|
|
"",
|
|
|
|
|
0);
|
2023-09-26 11:50:57 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2023-10-10 18:10:23 -05:00
|
|
|
TEST(metrics, base_load)
|
2023-09-26 11:50:57 -07:00
|
|
|
{
|
2023-10-16 13:41:40 -07:00
|
|
|
auto rocp_data = counters::getBaseHardwareMetrics();
|
2023-09-26 11:50:57 -07:00
|
|
|
auto test_data = loadTestData(basic_gfx908);
|
2023-10-16 13:41:40 -07:00
|
|
|
ASSERT_EQ(rocp_data.count("gfx908"), 1);
|
2023-09-26 11:50:57 -07:00
|
|
|
ASSERT_EQ(test_data.count("gfx908"), 1);
|
2023-10-16 13:41:40 -07:00
|
|
|
auto rocp_data_v = rocp_data.at("gfx908");
|
|
|
|
|
auto test_data_v = test_data.at("gfx908");
|
|
|
|
|
EXPECT_EQ(rocp_data_v.size(), test_data_v.size());
|
|
|
|
|
auto find = [&rocp_data_v](const auto& v) -> std::optional<counters::Metric> {
|
|
|
|
|
for(const auto& ditr : rocp_data_v)
|
|
|
|
|
if(ditr.name() == v.name()) return ditr;
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
};
|
|
|
|
|
auto equal = [](const auto& lhs, const auto& rhs) {
|
|
|
|
|
return std::tie(lhs.name(), lhs.block(), lhs.event(), lhs.description()) ==
|
|
|
|
|
std::tie(rhs.name(), rhs.block(), rhs.event(), rhs.description());
|
|
|
|
|
};
|
|
|
|
|
for(const auto& itr : test_data_v)
|
|
|
|
|
{
|
|
|
|
|
auto val = find(itr);
|
|
|
|
|
if(!val)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_TRUE(val) << "failed to find " << fmt::format("{}", itr);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
EXPECT_TRUE(equal(itr, *val)) << fmt::format("\n\t{} \n\t\t!= \n\t{}", itr, *val);
|
|
|
|
|
}
|
2023-09-26 11:50:57 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 18:10:23 -05:00
|
|
|
TEST(metrics, derived_load)
|
2023-09-26 11:50:57 -07:00
|
|
|
{
|
2023-10-16 13:41:40 -07:00
|
|
|
auto rocp_data = counters::getDerivedHardwareMetrics();
|
|
|
|
|
auto test_data = loadTestData(derived_gfx908);
|
|
|
|
|
ASSERT_EQ(rocp_data.count("gfx908"), 1);
|
2023-09-26 11:50:57 -07:00
|
|
|
ASSERT_EQ(test_data.count("gfx908"), 1);
|
2023-10-16 13:41:40 -07:00
|
|
|
auto rocp_data_v = rocp_data.at("gfx908");
|
|
|
|
|
auto test_data_v = test_data.at("gfx908");
|
|
|
|
|
EXPECT_EQ(rocp_data_v.size(), test_data_v.size());
|
|
|
|
|
auto find = [&rocp_data_v](const auto& v) -> std::optional<counters::Metric> {
|
|
|
|
|
for(const auto& ditr : rocp_data_v)
|
|
|
|
|
if(ditr.name() == v.name()) return ditr;
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
};
|
|
|
|
|
auto equal = [](const auto& lhs, const auto& rhs) {
|
|
|
|
|
return std::tie(
|
|
|
|
|
lhs.name(), lhs.block(), lhs.event(), lhs.description(), lhs.expression()) ==
|
|
|
|
|
std::tie(rhs.name(), rhs.block(), rhs.event(), rhs.description(), rhs.expression());
|
|
|
|
|
};
|
|
|
|
|
for(const auto& itr : test_data_v)
|
|
|
|
|
{
|
|
|
|
|
auto val = find(itr);
|
|
|
|
|
if(!val)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_TRUE(val) << "failed to find " << fmt::format("{}", itr);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
EXPECT_TRUE(equal(itr, *val)) << fmt::format("\n\t{} \n\t\t!= \n\t{}", itr, *val);
|
|
|
|
|
}
|
2023-10-10 18:10:23 -05:00
|
|
|
}
|