Support external (i.e. user-defined) trace annotations (#195)
* Support external (i.e. user-defined) trace annotations
- tweaked the python examples to be more balanced
- updated the user-api example to conform to user API changes
- moved the get/set for State and ThreadState to state.{hpp,cpp}
- introduced user-provided trace annotations
- added perfetto python category
- moved coverage impl files around
- created enumerations for mapping category enums to category types
- created enumerations for mapping annotation type enums to annotation values
- moved tracing::add_perfetto_annotations to tracing/annotation.hpp
- utility make_index_sequence_range
- libomnitrace-dl: omnitrace_push_category_region
- libomnitrace-dl: omnitrace_pop_category_region
- libomnitrace-user: omnitrace_user_push_annotated_region
- libomnitrace-user: omnitrace_user_pop_annotated_region
- libpyomnitrace: support extra annotations via annotate_trace config value
- filename
- line
- last attempted instr in bytecode (lasti)
- argcount
- num local variables
- stacksize
- omnitrace-python: -a / --annotate-traces option
* tweak ubuntu-focal workflow
* Fix installation of omnitrace-user headers
* ubuntu-focal-codecov workflow update
- Install texinfo
* Update timemory submodule
Αυτή η υποβολή περιλαμβάνεται σε:
υποβλήθηκε από
GitHub
γονέας
1b8f09aa2d
υποβολή
642b6b95ca
@@ -0,0 +1,194 @@
|
||||
// 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
|
||||
|
||||
// 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 omnitrace
|
||||
{
|
||||
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 omnitrace
|
||||
Αναφορά σε νέο ζήτημα
Block a user