CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
176 lines
4.3 KiB
C++
176 lines
4.3 KiB
C++
// Copyright (c) Advanced Micro Devices, Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
// IMPORTANT NOTE:
|
|
// this may be a header file but will lead to ODR violations if included
|
|
// more than once. The reason it is in a header file is so that the python
|
|
// bindings can also build these symbols. The absence of inline is intentional!
|
|
|
|
#include "library/coverage.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cstddef>
|
|
#include <set>
|
|
#include <string>
|
|
#include <tuple>
|
|
#include <vector>
|
|
|
|
namespace rocprofsys
|
|
{
|
|
namespace coverage
|
|
{
|
|
namespace
|
|
{
|
|
template <typename Tp, typename... Args>
|
|
inline std::set<Tp, Args...>
|
|
get_uncovered(const std::set<Tp, Args...>& _covered,
|
|
const std::set<Tp, Args...>& _possible)
|
|
{
|
|
std::set<Tp, Args...> _v{};
|
|
for(auto&& itr : _possible)
|
|
{
|
|
if(_covered.count(itr) == 0) _v.emplace(itr);
|
|
}
|
|
return _v;
|
|
}
|
|
//
|
|
template <typename Tp, typename... Args>
|
|
inline std::vector<Tp, Args...>
|
|
get_uncovered(const std::vector<Tp, Args...>& _covered,
|
|
const std::vector<Tp, Args...>& _possible)
|
|
{
|
|
std::vector<Tp, Args...> _v{};
|
|
for(auto&& itr : _possible)
|
|
{
|
|
if(!std::any_of(_covered.begin(), _covered.end(),
|
|
[itr](auto&& _entry) { return _entry == itr; }))
|
|
_v.emplace_back(itr);
|
|
}
|
|
return _v;
|
|
}
|
|
} // namespace
|
|
|
|
code_coverage::data&
|
|
code_coverage::data::operator+=(const data& rhs)
|
|
{
|
|
for(auto&& itr : rhs.addresses)
|
|
addresses.emplace(itr);
|
|
for(auto&& itr : rhs.modules)
|
|
modules.emplace(itr);
|
|
for(auto&& itr : rhs.modules)
|
|
modules.emplace(itr);
|
|
return *this;
|
|
}
|
|
|
|
code_coverage::data
|
|
code_coverage::data::operator+(const data& rhs) const
|
|
{
|
|
return data{ *this } += rhs;
|
|
}
|
|
|
|
double
|
|
code_coverage::operator()(Category _c) const
|
|
{
|
|
switch(_c)
|
|
{
|
|
case STANDARD: return static_cast<double>(count) / static_cast<double>(size);
|
|
case ADDRESS:
|
|
return static_cast<double>(covered.addresses.size()) /
|
|
static_cast<double>(possible.addresses.size());
|
|
case MODULE:
|
|
return static_cast<double>(covered.modules.size()) /
|
|
static_cast<double>(possible.modules.size());
|
|
case FUNCTION:
|
|
return static_cast<double>(covered.functions.size()) /
|
|
static_cast<double>(possible.functions.size());
|
|
}
|
|
return 0.0;
|
|
}
|
|
|
|
code_coverage::int_set_t
|
|
code_coverage::get_uncovered_addresses() const
|
|
{
|
|
return get_uncovered(covered.addresses, possible.addresses);
|
|
}
|
|
|
|
code_coverage::str_set_t
|
|
code_coverage::get_uncovered_modules() const
|
|
{
|
|
return get_uncovered(covered.modules, possible.modules);
|
|
}
|
|
|
|
code_coverage::str_set_t
|
|
code_coverage::get_uncovered_functions() const
|
|
{
|
|
return get_uncovered(covered.functions, possible.functions);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
|
|
coverage_data&
|
|
coverage_data::operator+=(const coverage_data& rhs)
|
|
{
|
|
count += rhs.count;
|
|
return *this;
|
|
}
|
|
|
|
coverage_data
|
|
coverage_data::operator+(const coverage_data& rhs) const
|
|
{
|
|
return coverage_data{ *this } += rhs;
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator==(const coverage_data& rhs) const
|
|
{
|
|
return std::tie(module, function, address) ==
|
|
std::tie(rhs.module, rhs.function, rhs.address);
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator==(const data_tuple_t& rhs) const
|
|
{
|
|
return std::tie(module, function, address) ==
|
|
std::tie(std::get<0>(rhs), std::get<1>(rhs), std::get<2>(rhs));
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator!=(const coverage_data& rhs) const
|
|
{
|
|
return !(*this == rhs);
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator<(const coverage_data& rhs) const
|
|
{
|
|
if(count != rhs.count) return count < rhs.count;
|
|
if(module != rhs.module) return module < rhs.module;
|
|
if(function != rhs.function) return function < rhs.function;
|
|
if(address != rhs.address) return address < rhs.address;
|
|
if(line != rhs.line) return line < rhs.line;
|
|
return source < rhs.source;
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator<=(const coverage_data& rhs) const
|
|
{
|
|
return (*this == rhs || *this < rhs);
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator>(const coverage_data& rhs) const
|
|
{
|
|
return (*this != rhs && !(*this < rhs));
|
|
}
|
|
|
|
bool
|
|
coverage_data::operator>=(const coverage_data& rhs) const
|
|
{
|
|
return !(*this < rhs);
|
|
}
|
|
//
|
|
} // namespace coverage
|
|
} // namespace rocprofsys
|