Files
rocm-systems/projects/rocprofiler-systems/source/lib/omnitrace/include/library/coverage.hpp
T
Jonathan R. Madsen 72d0a7d08a Code Coverage Support (#46)
* Code-coverage support

* Examples update

- code-coverage example
- tweak transpose and parallel-overhead

* Coverage output + testing

- config::get_setting value(...)
- REGULAR_EXPRESSION -> REGEX in cmake func args
- coverage.hpp header
- coverage JSON
- coverage tests

* cmake formatting

* Library instrumentation w/o main + more

- fixed library instrumentation w/o main
- use TIMEMORY_PROJECT_NAME in output messages
- removed '--driver' option from omnitrace exe
- support coverage in trace mode
- OMNITRACE_KOKKOS_KERNEL_LOGGER
- support multiple calls to omnitrace_set_env after init if already called
- support multiple calls to omnitrace_set_mpi after init if same args
- support multiple calls to omnitrace_init if same mode
- unique_ptr_t for thread_data which calls finalize when thread_data is destroyed
- tweaked openmp tests
- improved finalization

* Replace CI --output-on-failure with -V

* Fix to OMNITRACE_DL_INVOKE

* omnitrace-exe and testing updates

- omnitrace::omnitrace-timemory interface library
- support for configs in omnitrace exe
- print-{available,instrumented,...} opts no longer exit w/o --simulate
- all tests apply --print-instrumented functions
- tweaked coverage tests
- print-* options print instructions not address range

* Remove OMNITRACE_DEBUG_FINALIZE=ON from CI

* Python cmake tweaks

* Tweak test ordering

* Upload CI artifacts if fail or success

* CI Python tweaks

- Use OMNITRACE_PYTHON_PREFIX and OMNITRACE_PYTHON_ENVS

* CI ELFULTILS_DOWNLOAD_VERSION

* test tweaks

- labels and more coverage tests

* tweak to omnitrace --config handling

* Update module/function constraint handling + PP

- tweak pre-processor definition handling
- removed free-standing module_constraint
- remove free-standing routine_constraint
- remove module_name.find("omnitrace") module constraint
- fully handle the output path of omnitrace *-instr files
- get_use_code_coverage config option
- print-coverage option
- coverage_module_functions

* use github.job not github.name

* Re-enable HSA_ENABLE_INTERRUPT

- remove coverage address report

[ROCm/rocprofiler-systems commit: 791375bb24]
2022-04-25 17:00:52 -05:00

168 lines
5.1 KiB
C++

// MIT License
//
// Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "timemory/mpl/concepts.hpp"
#include "timemory/tpls/cereal/cereal/cereal.hpp"
#include <timemory/tpls/cereal/cereal.hpp>
#include <cstddef>
#include <set>
#include <string>
#if !defined(OMNITRACE_SERIALIZE)
# define OMNITRACE_SERIALIZE(MEMBER_VARIABLE) \
ar(::tim::cereal::make_nvp(#MEMBER_VARIABLE, MEMBER_VARIABLE))
#endif
namespace omnitrace
{
namespace coverage
{
void
post_process();
//--------------------------------------------------------------------------------------//
//
/// \struct code_coverage
/// \brief Summary information about the code coverage
//
//--------------------------------------------------------------------------------------//
struct code_coverage
{
using int_set_t = std::set<size_t>;
using str_set_t = std::set<std::string>;
enum Category
{
STANDARD = 0,
ADDRESS,
MODULE,
FUNCTION
};
struct data
{
int_set_t addresses = {};
str_set_t modules = {};
str_set_t functions = {};
template <typename ArchiveT>
void serialize(ArchiveT& ar, const unsigned version);
};
double operator()(Category _c = STANDARD) const;
double get(Category _c = STANDARD) const { return (*this)(_c); }
int_set_t get_uncovered_addresses() const;
str_set_t get_uncovered_modules() const;
str_set_t get_uncovered_functions() const;
template <typename ArchiveT>
void serialize(ArchiveT& ar, const unsigned version);
size_t count = 0;
size_t size = 0;
data covered = {};
data possible = {};
};
//
template <typename ArchiveT>
void
code_coverage::serialize(ArchiveT& ar, const unsigned version)
{
OMNITRACE_SERIALIZE(count);
OMNITRACE_SERIALIZE(size);
OMNITRACE_SERIALIZE(covered);
OMNITRACE_SERIALIZE(possible);
if constexpr(tim::concepts::is_output_archive<ArchiveT>::value)
{
ar.setNextName("coverage");
ar.startNode();
ar(tim::cereal::make_nvp("total", get(STANDARD)));
ar(tim::cereal::make_nvp("addresses", get(ADDRESS)));
ar(tim::cereal::make_nvp("modules", get(MODULE)));
ar(tim::cereal::make_nvp("functions", get(FUNCTION)));
ar.finishNode();
}
(void) version;
}
//
template <typename ArchiveT>
void
code_coverage::data::serialize(ArchiveT& ar, const unsigned version)
{
OMNITRACE_SERIALIZE(addresses);
OMNITRACE_SERIALIZE(modules);
OMNITRACE_SERIALIZE(functions);
(void) version;
}
//--------------------------------------------------------------------------------------//
//
/// \struct coverage_data
/// \brief Detailed information about the code coverage
//
//--------------------------------------------------------------------------------------//
struct coverage_data
{
using data_tuple_t = std::tuple<std::string_view, std::string_view, size_t>;
template <typename ArchiveT>
void serialize(ArchiveT& ar, const unsigned version);
coverage_data& operator+=(const coverage_data& rhs);
bool operator==(const coverage_data& rhs) const;
bool operator==(const data_tuple_t& rhs) const;
bool operator!=(const coverage_data& rhs) const;
bool operator<(const coverage_data& rhs) const;
bool operator<=(const coverage_data& rhs) const;
bool operator>(const coverage_data& rhs) const;
bool operator>=(const coverage_data& rhs) const;
size_t count = 0;
size_t address = 0;
size_t line = 0;
std::string module = {};
std::string function = {};
std::string source = {};
};
//
template <typename ArchiveT>
void
coverage_data::serialize(ArchiveT& ar, const unsigned version)
{
OMNITRACE_SERIALIZE(count);
OMNITRACE_SERIALIZE(line);
OMNITRACE_SERIALIZE(address);
OMNITRACE_SERIALIZE(module);
OMNITRACE_SERIALIZE(function);
OMNITRACE_SERIALIZE(source);
(void) version;
}
//
} // namespace coverage
} // namespace omnitrace