Adding Perfetto support (#867)
* Perfetto submodule * include/rocprofiler-sdk/cxx/perfetto.hpp - adapted from tests/common/perfetto.hpp - updated json-tool to use <rocprofiler-sdk/cxx/perfetto.hpp> * Update include/rocprofiler-sdk/cxx - add details/delimit.hpp - add details/join.hpp - extend details/mpl.hpp - extend details/operators.hpp * Update lib/rocprofiler-sdk/hsa/async_copy.cpp - update MEMORY_COPY direction names * Preliminary perfetto support * Update lib/rocprofiler-sdk-tool/generatePerfetto.cpp - fix getting roctx msg vs. buffer operation name * Temporary variable restructuring * Perfetto patches after rebasing onto main * Revert lib/rocprofiler-sdk/hsa/async_copy.cpp - revert name * Update lib/rocprofiler-sdk-tool/generatePerfetto.cpp - fix ReadTrace * Update tests/bin/hip-in-libraries - sleep_for * Support PFTRACE output format option in rocprofv3 * Change perfetto logging * Update rocprofv3 tests to generate pftrace output * Minor tweak to json-tool.cpp * Update requirements.txt for perfetto testing * Fix data race on amount_read in generatePerfetto.cpp * Add testing for pftrace output - relatively simple testing which verifies that the pftrace file has the same number of entries as JSON data for HIP/HSA/marker/kernel/memory_copy * Fix import in perfetto_reader.py * Fix data race in generatePerfetto.cpp
Cette révision appartient à :
révisé par
GitHub
Parent
92b7326910
révision
957bb7a4e5
@@ -84,32 +84,40 @@ if(NOT TARGET rocprofiler::rocprofiler-cereal)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# perfetto
|
||||
fetchcontent_declare(
|
||||
perfetto
|
||||
GIT_REPOSITORY https://android.googlesource.com/platform/external/perfetto
|
||||
GIT_TAG v42.0
|
||||
SOURCE_DIR ${PROJECT_BINARY_DIR}/external/perfetto BINARY_DIR
|
||||
${PROJECT_BINARY_DIR}/external/build/perfetto-build SUBBUILD_DIR
|
||||
${PROJECT_BINARY_DIR}/external/build/perfetto-subdir)
|
||||
if(NOT TARGET rocprofiler::rocprofiler-perfetto)
|
||||
# perfetto
|
||||
fetchcontent_declare(
|
||||
perfetto
|
||||
GIT_REPOSITORY https://android.googlesource.com/platform/external/perfetto
|
||||
GIT_TAG v44.0
|
||||
SOURCE_DIR ${PROJECT_BINARY_DIR}/external/perfetto BINARY_DIR
|
||||
${PROJECT_BINARY_DIR}/external/build/perfetto-build SUBBUILD_DIR
|
||||
${PROJECT_BINARY_DIR}/external/build/perfetto-subdir)
|
||||
|
||||
fetchcontent_getproperties(perfetto)
|
||||
fetchcontent_getproperties(perfetto)
|
||||
|
||||
if(NOT perfetto_POPULATED)
|
||||
fetchcontent_populate(perfetto)
|
||||
if(NOT perfetto_POPULATED)
|
||||
fetchcontent_populate(perfetto)
|
||||
endif()
|
||||
|
||||
add_library(rocprofiler-tests-perfetto STATIC)
|
||||
add_library(rocprofiler::tests-perfetto ALIAS rocprofiler-tests-perfetto)
|
||||
target_sources(
|
||||
rocprofiler-tests-perfetto
|
||||
PRIVATE ${PROJECT_BINARY_DIR}/external/perfetto/sdk/perfetto.h
|
||||
${PROJECT_BINARY_DIR}/external/perfetto/sdk/perfetto.cc)
|
||||
target_include_directories(
|
||||
rocprofiler-tests-perfetto SYSTEM
|
||||
INTERFACE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/external/perfetto/sdk>)
|
||||
set_target_properties(rocprofiler-tests-perfetto PROPERTIES POSITION_INDEPENDENT_CODE
|
||||
ON)
|
||||
else()
|
||||
add_library(rocprofiler-tests-perfetto INTERFACE)
|
||||
add_library(rocprofiler::tests-perfetto ALIAS rocprofiler-tests-perfetto)
|
||||
target_link_libraries(rocprofiler-tests-perfetto
|
||||
INTERFACE rocprofiler::rocprofiler-perfetto)
|
||||
endif()
|
||||
|
||||
add_library(rocprofiler-tests-perfetto STATIC)
|
||||
add_library(rocprofiler::tests-perfetto ALIAS rocprofiler-tests-perfetto)
|
||||
target_sources(
|
||||
rocprofiler-tests-perfetto
|
||||
PRIVATE ${PROJECT_BINARY_DIR}/external/perfetto/sdk/perfetto.h
|
||||
${PROJECT_BINARY_DIR}/external/perfetto/sdk/perfetto.cc)
|
||||
target_include_directories(
|
||||
rocprofiler-tests-perfetto SYSTEM
|
||||
INTERFACE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/external/perfetto/sdk>)
|
||||
set_target_properties(rocprofiler-tests-perfetto PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# common utilities
|
||||
cmake_path(GET CMAKE_CURRENT_SOURCE_DIR PARENT_PATH COMMON_LIBRARY_INCLUDE_DIR)
|
||||
|
||||
|
||||
@@ -22,204 +22,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#define ROCPROFILER_DEFINE_NAME_TRAIT(NAME, DESC, ...) \
|
||||
namespace rocprofiler \
|
||||
{ \
|
||||
template <> \
|
||||
struct perfetto_category<__VA_ARGS__> \
|
||||
{ \
|
||||
static constexpr auto value = NAME; \
|
||||
static constexpr auto description = DESC; \
|
||||
}; \
|
||||
}
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
template <typename Tp>
|
||||
struct perfetto_category;
|
||||
|
||||
namespace trait
|
||||
{
|
||||
template <typename... Tp>
|
||||
using name = perfetto_category<Tp...>;
|
||||
}
|
||||
} // namespace rocprofiler
|
||||
|
||||
#define ROCPROFILER_DEFINE_NS_API(NS, NAME) \
|
||||
namespace rocprofiler \
|
||||
{ \
|
||||
namespace NS \
|
||||
{ \
|
||||
struct NAME; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ROCPROFILER_DEFINE_CATEGORY(NS, VALUE, DESC) \
|
||||
ROCPROFILER_DEFINE_NS_API(NS, VALUE) \
|
||||
ROCPROFILER_DEFINE_NAME_TRAIT(#VALUE, DESC, NS::VALUE)
|
||||
|
||||
ROCPROFILER_DEFINE_CATEGORY(category, hsa_api, "HSA API function")
|
||||
ROCPROFILER_DEFINE_CATEGORY(category, hip_api, "HIP API function")
|
||||
ROCPROFILER_DEFINE_CATEGORY(category, marker_api, "Marker API region")
|
||||
ROCPROFILER_DEFINE_CATEGORY(category, kernel_dispatch, "GPU kernel dispatch")
|
||||
ROCPROFILER_DEFINE_CATEGORY(category, memory_copy, "Async memory copy")
|
||||
|
||||
#define ROCPROFILER_PERFETTO_CATEGORY(TYPE) \
|
||||
::perfetto::Category(::rocprofiler::perfetto_category<::rocprofiler::TYPE>::value) \
|
||||
.SetDescription(::rocprofiler::perfetto_category<::rocprofiler::TYPE>::description)
|
||||
|
||||
#define ROCPROFILER_PERFETTO_CATEGORIES \
|
||||
ROCPROFILER_PERFETTO_CATEGORY(category::hsa_api), \
|
||||
ROCPROFILER_PERFETTO_CATEGORY(category::hip_api), \
|
||||
ROCPROFILER_PERFETTO_CATEGORY(category::marker_api), \
|
||||
ROCPROFILER_PERFETTO_CATEGORY(category::kernel_dispatch), \
|
||||
ROCPROFILER_PERFETTO_CATEGORY(category::memory_copy)
|
||||
|
||||
#include <perfetto.h>
|
||||
|
||||
PERFETTO_DEFINE_CATEGORIES(ROCPROFILER_PERFETTO_CATEGORIES);
|
||||
|
||||
namespace concepts
|
||||
{
|
||||
template <typename Tp>
|
||||
struct is_string_type : std::false_type
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct is_string_type<std::string> : std::true_type
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct is_string_type<char*> : std::true_type
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct is_string_type<const char*> : std::true_type
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct is_string_type<std::string_view> : std::true_type
|
||||
{};
|
||||
|
||||
template <typename Tp>
|
||||
struct is_string_type<const Tp> : is_string_type<std::decay_t<Tp>>
|
||||
{};
|
||||
|
||||
template <typename Tp>
|
||||
struct is_string_type<Tp&> : is_string_type<std::decay_t<Tp>>
|
||||
{};
|
||||
|
||||
template <typename Tp>
|
||||
struct is_string_type<volatile Tp> : is_string_type<std::decay_t<Tp>>
|
||||
{};
|
||||
|
||||
template <typename Tp, size_t N>
|
||||
struct is_string_type<Tp[N]> : is_string_type<std::decay_t<Tp[N]>>
|
||||
{};
|
||||
|
||||
template <typename Tp, size_t N>
|
||||
struct is_string_type<const Tp[N]> : is_string_type<std::decay_t<Tp[N]>>
|
||||
{};
|
||||
|
||||
template <typename Tp, size_t N>
|
||||
struct is_string_type<volatile Tp[N]> : is_string_type<std::decay_t<Tp[N]>>
|
||||
{};
|
||||
|
||||
template <typename Tp>
|
||||
struct unqualified_type
|
||||
{
|
||||
using type = std::remove_reference_t<std::remove_cv_t<std::decay_t<Tp>>>;
|
||||
};
|
||||
|
||||
template <typename Tp>
|
||||
using unqualified_type_t = typename unqualified_type<Tp>::type;
|
||||
|
||||
template <typename Tp>
|
||||
struct can_stringify
|
||||
{
|
||||
private:
|
||||
static constexpr auto sfinae(int)
|
||||
-> decltype(std::declval<std::ostream&>() << std::declval<Tp>(), bool())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static constexpr auto sfinae(long) { return false; }
|
||||
|
||||
public:
|
||||
static constexpr bool value = sfinae(0);
|
||||
constexpr auto operator()() const { return sfinae(0); }
|
||||
};
|
||||
} // namespace concepts
|
||||
|
||||
using perfetto_event_context_t = ::perfetto::EventContext;
|
||||
|
||||
template <typename Np, typename Tp>
|
||||
auto
|
||||
add_perfetto_annotation(perfetto_event_context_t& ctx, Np&& _name, Tp&& _val)
|
||||
{
|
||||
using named_type = concepts::unqualified_type_t<Np>;
|
||||
using value_type = concepts::unqualified_type_t<Tp>;
|
||||
|
||||
static_assert(concepts::is_string_type<named_type>::value, "Error! name is not a string type");
|
||||
|
||||
auto _get_dbg = [&]() {
|
||||
auto* _dbg = ctx.event()->add_debug_annotations();
|
||||
_dbg->set_name(std::string_view{std::forward<Np>(_name)}.data());
|
||||
return _dbg;
|
||||
};
|
||||
|
||||
if constexpr(std::is_same<value_type, std::string_view>::value)
|
||||
{
|
||||
_get_dbg()->set_string_value(_val.data());
|
||||
}
|
||||
else if constexpr(concepts::is_string_type<value_type>::value)
|
||||
{
|
||||
_get_dbg()->set_string_value(std::forward<Tp>(_val));
|
||||
}
|
||||
else if constexpr(std::is_same<value_type, bool>::value)
|
||||
{
|
||||
_get_dbg()->set_bool_value(_val);
|
||||
}
|
||||
else if constexpr(std::is_enum<value_type>::value)
|
||||
{
|
||||
_get_dbg()->set_int_value(static_cast<int64_t>(_val));
|
||||
}
|
||||
else if constexpr(std::is_floating_point<value_type>::value)
|
||||
{
|
||||
_get_dbg()->set_double_value(static_cast<double>(_val));
|
||||
}
|
||||
else if constexpr(std::is_integral<value_type>::value)
|
||||
{
|
||||
if constexpr(std::is_unsigned<value_type>::value)
|
||||
{
|
||||
_get_dbg()->set_uint_value(_val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_get_dbg()->set_int_value(_val);
|
||||
}
|
||||
}
|
||||
else if constexpr(std::is_pointer<value_type>::value)
|
||||
{
|
||||
_get_dbg()->set_pointer_value(reinterpret_cast<uint64_t>(_val));
|
||||
}
|
||||
else if constexpr(concepts::can_stringify<value_type>::value)
|
||||
{
|
||||
auto _ss = std::stringstream{};
|
||||
_ss << std::forward<Tp>(_val);
|
||||
_get_dbg()->set_string_value(_ss.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(std::is_empty<value_type>::value, "Error! unsupported data type");
|
||||
}
|
||||
}
|
||||
#include <rocprofiler-sdk/cxx/perfetto.hpp>
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur