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
This commit is contained in:
1 parent
92b7326910
commit
957bb7a4e5
39 files changed
+2530
-291
No files matched your search
@@ -56,7 +56,7 @@ namespace
|
||||
{
|
||||
using auto_lock_t = std::unique_lock<std::mutex>;
|
||||
auto print_lock = std::mutex{};
|
||||
size_t nqueues = 8;
|
||||
size_t nqueues = 4;
|
||||
size_t nthreads = 4;
|
||||
size_t nitr = 500;
|
||||
size_t nsync = 10;
|
||||
@@ -112,7 +112,8 @@ main(int argc, char** argv)
|
||||
|
||||
{
|
||||
auto vector_ops_thread = std::thread{run_vector_ops, nthreads, nqueues};
|
||||
auto transpose_thread = std::thread{run_transpose, nthreads, nitr, nsync};
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
||||
auto transpose_thread = std::thread{run_transpose, nthreads, nitr, nsync};
|
||||
|
||||
vector_ops_thread.join();
|
||||
transpose_thread.join();
|
||||
|
||||
+30
-22
@@ -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)
|
||||
|
||||
|
||||
+1
-201
@@ -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>
|
||||
@@ -4,13 +4,20 @@
|
||||
|
||||
set(PACKAGE_OUTPUT_DIR
|
||||
${ROCPROFILER_SDK_TESTS_BINARY_DIR}/pytest-packages/rocprofiler_sdk)
|
||||
set(PYTEST_UTILS_PYTHON_SOURCES __init__.py dotdict.py)
|
||||
|
||||
set(PYTEST_UTILS_PYTHON_SOURCES __init__.py dotdict.py perfetto_reader.py)
|
||||
set(TESTS_PYTHON_SOURCES __init__.py rocprofv3.py)
|
||||
|
||||
foreach(_FILE ${PYTEST_UTILS_PYTHON_SOURCES})
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/pytest_utils/${_FILE}
|
||||
${PACKAGE_OUTPUT_DIR}/pytest_utils/${_FILE} COPYONLY)
|
||||
endforeach()
|
||||
|
||||
foreach(_FILE ${TESTS_PYTHON_SOURCES})
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/${_FILE}
|
||||
${PACKAGE_OUTPUT_DIR}/tests/${_FILE} COPYONLY)
|
||||
endforeach()
|
||||
|
||||
file(
|
||||
WRITE "${PACKAGE_OUTPUT_DIR}/__init__.py"
|
||||
"#
|
||||
|
||||
@@ -0,0 +1,750 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import re
|
||||
import pandas as pd
|
||||
|
||||
from collections import OrderedDict
|
||||
from perfetto.trace_processor import TraceProcessor
|
||||
|
||||
|
||||
class PerfettoReader:
|
||||
"""Read in perfetto protobuf output"""
|
||||
|
||||
def __init__(self, filename, select=None, **kwargs):
|
||||
"""Arguments:
|
||||
filename (str or list/tuple of str):
|
||||
Valid arguments should be a list of files
|
||||
|
||||
verbose (int):
|
||||
Information about processes, threads, categories, performance, etc.
|
||||
|
||||
report (list of str):
|
||||
alternative for verbose. Accepts:
|
||||
|
||||
- category (report categories in files)
|
||||
- process (report process info in files)
|
||||
- threads (report thread info in files)
|
||||
- track_ids (report track id info in files)
|
||||
- profile (report timing info from processing)
|
||||
|
||||
exclude_category (list of str):
|
||||
Every slice has an associated category, e.g., slices from sampling may be
|
||||
in "sampling" category, slices from instrumentation may be in "instrumentation"
|
||||
category. The categories in protobuf is specific to the tool that generated the
|
||||
protobuf. Use this option to exclude the slices from specific categories
|
||||
|
||||
include_category (list of str):
|
||||
Every slice has an associated category, e.g., slices from sampling may be
|
||||
in "sampling" category, slices from instrumentation may be in "instrumentation"
|
||||
category. The categories in protobuf is specific to the tool that generated the
|
||||
protobuf. Use this option to restrict the slices to the specified categories
|
||||
|
||||
default_categories (list of str):
|
||||
Use this option as a safety value when include/exclude are used. These categories
|
||||
are used when include/exclude category filtering resulted in no data in the data
|
||||
frame. Accepts "all" if you want to fallback to just including all categories.
|
||||
|
||||
patterns (list of regex str):
|
||||
Use this option to specify how the function/file/line are extracted from labels.
|
||||
For example, the default patterns are:
|
||||
|
||||
r"(?P<func>.*) \\[(?P<file>\\S+):(?P<line>[0-9]+)\\]$"
|
||||
r"(?P<func>.*) \\[(?P<file>\\S+)\\]$"
|
||||
r"^(?P<file>\\S+):(?P<line>[0-9]+)$"
|
||||
|
||||
To extract the function/file/line from the labeling patterns:
|
||||
|
||||
func [file:line]
|
||||
func [file]
|
||||
file:line
|
||||
|
||||
respectively.
|
||||
|
||||
thread_index_regex (regex str):
|
||||
Use this option to determine thread IDs from the name of the threads. For example,
|
||||
Omnitrace labels certain process tracks "Thread X (S)" to indicate that the given
|
||||
process track are samples of Thread X. The default pattern is:
|
||||
|
||||
r"(T|t)hread (?P<thread_index>[0-9]+)( |$)"
|
||||
|
||||
to extract the "thread_index" field.
|
||||
|
||||
max_depth (int):
|
||||
Set this a positive non-zero number signifying the maximum call-stack depth to
|
||||
process. This can significantly reduce the processing time for large traces.
|
||||
"""
|
||||
|
||||
self.filename = filename if isinstance(filename, (list, tuple)) else [filename]
|
||||
self.metadata = {"hatchet_inclusive_suffix": ".inc"}
|
||||
self.default_metric = "time{}".format(self.metadata["hatchet_inclusive_suffix"])
|
||||
self.verbose = 0
|
||||
self.report = []
|
||||
self.exclude = []
|
||||
self.include = []
|
||||
self.categories = []
|
||||
self.default_categories = []
|
||||
self.df_categories = []
|
||||
self.dataframe = pd.DataFrame()
|
||||
self.process = pd.DataFrame()
|
||||
self.threads = pd.DataFrame()
|
||||
self.track_ids = []
|
||||
self.trace_processor = []
|
||||
self.compiled_patterns = []
|
||||
self.thread_index_regex = None
|
||||
self.max_depth = None
|
||||
self.configure(**kwargs)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
|
||||
# pre-compile the regex patterns for extracting the func, file, and line info
|
||||
# users can use their own pattens via patterns=[...]. An empty set of patterns
|
||||
# is valid for avoiding parsing func/file/line info
|
||||
_default_patterns = [
|
||||
# func [file:line]
|
||||
r"(?P<func>.*) \[(?P<file>\S+):(?P<line>[0-9]+)\]$",
|
||||
# func [file]
|
||||
r"(?P<func>.*) \[(?P<file>\S+)\]$",
|
||||
# file:line
|
||||
r"^(?P<file>\S+):(?P<line>[0-9]+)$",
|
||||
]
|
||||
_patterns = kwargs["patterns"] if "patterns" in kwargs else None
|
||||
|
||||
if _patterns is None:
|
||||
_patterns = _default_patterns
|
||||
elif kwargs.get("use_default_patterns", True):
|
||||
_patterns += _default_patterns
|
||||
|
||||
self.compiled_patterns = [re.compile(x) for x in _patterns]
|
||||
self.thread_index_regex = re.compile(
|
||||
kwargs.get("thread_index_regex", "(T|t)hread (?P<thread_index>[0-9]+)( |$)")
|
||||
)
|
||||
|
||||
def report_at_verbosity(key, lvl):
|
||||
if self.verbose >= lvl and key not in self.report:
|
||||
self.report.append(key)
|
||||
|
||||
self.verbose = self.verbose if "verbose" not in kwargs else kwargs["verbose"]
|
||||
self.report = kwargs["report"] if "report" in kwargs else self.report
|
||||
report_at_verbosity("category", 1)
|
||||
report_at_verbosity("process", 2)
|
||||
report_at_verbosity("threads", 2)
|
||||
report_at_verbosity("track_ids", 2)
|
||||
|
||||
_filenames = sorted(self.filename)
|
||||
self.filename = kwargs.get("filename", sorted(self.filename))
|
||||
|
||||
_new_filenames = [x for x in self.filename if x not in _filenames]
|
||||
|
||||
if len(self.filename) + len(_new_filenames) != len(self.trace_processor):
|
||||
self.trace_processor = [TraceProcessor(trace=(f)) for f in self.filename]
|
||||
elif _new_filenames:
|
||||
self.trace_processor += [TraceProcessor(trace=(f)) for f in _new_filenames]
|
||||
|
||||
self.max_depth = kwargs.get("max_depth", None)
|
||||
|
||||
def query_tp(self, query, index_name=lambda x: "tp_index"):
|
||||
"""Simplifies querying the trace processor and always adds a
|
||||
"tp_index" column for referencing which trace_processor
|
||||
generated the data
|
||||
"""
|
||||
|
||||
def _append_column(df, name, idx):
|
||||
"""Used to add a tp_index column to our data which is used to identify
|
||||
which trace-processor the query results came from"""
|
||||
if name and name not in df:
|
||||
df.insert(0, name, idx)
|
||||
return df
|
||||
|
||||
def _get_dataframe(tp):
|
||||
"""workaround for bug in TraceProcessor.QueryResultIterator.as_pandas_dataframe()"""
|
||||
query_itr = tp.query(f"{query}")
|
||||
# the perfetto trace processor query function looks like this:
|
||||
#
|
||||
# def query(self, sql: str):
|
||||
# response = self.http.execute_query(sql)
|
||||
# if response.error:
|
||||
# raise TraceProcessorException(response.error)
|
||||
# return TraceProcessor.QueryResultIterator(response.column_names,
|
||||
# response.batch)
|
||||
#
|
||||
# unfortunately, data type of response.column_names is RepeatedScalarContainer
|
||||
# and in a lot of versions of pandas, this type does not satisfy any of it's
|
||||
# checks for whether this is a valid Index-type for the columns:
|
||||
# isinstance(..., Index)
|
||||
# isinstance(..., ABCSeries)
|
||||
# is_iterator(...)
|
||||
# isinstance(..., list)
|
||||
#
|
||||
# and thus as_pandas_dataframe() raises a TypeError exception. Queries can
|
||||
# be VERY expensive for a large database (>> 10s of seconds) so instead of
|
||||
# try -> except -> re-query (necessary) -> convert to list -> re-call
|
||||
# as_pandas_dataframe() like so:
|
||||
#
|
||||
# try:
|
||||
# return query_itr.as_pandas_dataframe()
|
||||
# except TypeError:
|
||||
# query_itr = tp.query(...)
|
||||
# query_itr.__dict__["..."] = list(query_itr.__dict__["..."])
|
||||
# return query_itr.as_pandas_dataframe()
|
||||
#
|
||||
# which would effectively result in two queries every single time, we just
|
||||
# do it upfront if the dict entry that is known to cause the problem exists
|
||||
# and is of the type that we know causes problems
|
||||
#
|
||||
_buggy_dict_entry = "_QueryResultIterator__column_names"
|
||||
if (
|
||||
_buggy_dict_entry in query_itr.__dict__
|
||||
and type(query_itr.__dict__[_buggy_dict_entry]).__name__
|
||||
== "RepeatedScalarContainer"
|
||||
):
|
||||
query_itr.__dict__[_buggy_dict_entry] = list(
|
||||
query_itr.__dict__[_buggy_dict_entry]
|
||||
)
|
||||
|
||||
return query_itr.as_pandas_dataframe()
|
||||
|
||||
return pd.concat(
|
||||
[
|
||||
_append_column(
|
||||
_get_dataframe(tp),
|
||||
index_name(idx),
|
||||
idx,
|
||||
)
|
||||
for idx, tp in enumerate(self.trace_processor)
|
||||
]
|
||||
)
|
||||
|
||||
def extract_tp_data(self, **kwargs):
|
||||
"""Extracts all the necessary data from the trace processor"""
|
||||
self.configure(**kwargs)
|
||||
|
||||
self.dataframe = self.query_tp(
|
||||
"SELECT slice_id, track_id, category, depth, stack_id, parent_stack_id, ts, dur, name FROM slice"
|
||||
)
|
||||
|
||||
self.df_categories = sorted(list(self.dataframe["category"].unique()))
|
||||
|
||||
# check for update to include/exclude category
|
||||
self.exclude = kwargs.get("exclude_category", self.exclude)
|
||||
self.include = kwargs.get("include_category", self.include)
|
||||
|
||||
self.categories = self.df_categories[:]
|
||||
|
||||
# apply include first
|
||||
if self.include:
|
||||
self.categories = [x for x in self.categories if x in self.include]
|
||||
|
||||
# apply exclude after
|
||||
if self.exclude:
|
||||
self.categories = [x for x in self.categories if x not in self.exclude]
|
||||
|
||||
self.default_categories = kwargs.get(
|
||||
"default_categories", self.default_categories
|
||||
)
|
||||
_acceptable_default_categories = (
|
||||
'default_categories can be set to: "all", ["all"], or [list of categories...]'
|
||||
)
|
||||
|
||||
if not self.categories and self.default_categories:
|
||||
if not isinstance(self.default_categories, (tuple, list)):
|
||||
self.default_categories = [self.default_categories]
|
||||
|
||||
if "all" in self.default_categories:
|
||||
self.categories = self.df_categories[:]
|
||||
else:
|
||||
raise ValueError(
|
||||
f"invalid default_categories value: {self.default_categories}. {_acceptable_default_categories}"
|
||||
)
|
||||
|
||||
# filter out any categories that do not exist
|
||||
self.categories = sorted([x for x in self.categories if x in self.df_categories])
|
||||
|
||||
if not self.categories:
|
||||
raise ValueError(
|
||||
f"The application of include_category={self.include} followed by exclude_category={self.exclude} rendered an empty set of categories (available={self.df_categories}). Either clear one of the configs or assign the default_categories. {_acceptable_default_categories}"
|
||||
)
|
||||
|
||||
if "category" in self.report:
|
||||
_ignore = [x for x in self.df_categories if x not in self.categories]
|
||||
print(
|
||||
"categories: {}{}".format(
|
||||
", ".join(self.categories),
|
||||
" (ignored: {})".format(", ".join(_ignore)) if _ignore else "",
|
||||
)
|
||||
)
|
||||
|
||||
# reduce the dataframe to given specified category data
|
||||
# TODO: adjust the parent stack ids. if <user> category entry is child of <host> category entry, we lose <user> category entry
|
||||
self.dataframe = self.dataframe[self.dataframe["category"].isin(self.categories)]
|
||||
|
||||
if self.dataframe.empty:
|
||||
raise RuntimeError(
|
||||
"category filtering resulted in an empty dataframe. categories: include={}, exclude={}, available={}".format(
|
||||
self.include, self.exclude, self.df_categories
|
||||
)
|
||||
)
|
||||
|
||||
self.process = self.query_tp(
|
||||
"SELECT process.upid AS process_upid, process.id AS process_id, process.pid, process.name AS process_name, process_track.upid as track_upid, process_track.id AS track_id, process_track.parent_id as track_parent_id, process_track.name AS track_name from process JOIN process_track ON process_track.upid = process.upid WHERE process.pid > 0"
|
||||
)
|
||||
self.threads = self.query_tp(
|
||||
"SELECT thread.utid AS thread_utid, thread.id AS thread_id, thread.tid, thread.name as thread_name, thread.is_main_thread, thread_track.id AS track_id, thread_track.parent_id AS track_parent_id, thread_track.name AS track_name from thread JOIN thread_track ON thread_track.utid = thread.utid"
|
||||
)
|
||||
|
||||
# generate empty dictionaries for each trace processor
|
||||
self.track_ids = [{} for _ in range(len(self.trace_processor))]
|
||||
|
||||
# generate mapping from track IDs to process and thread info.
|
||||
# the "pid" and "tid" fields are the system value. we want to
|
||||
# assign a "rank" and "thread" value for "pid" and "tid",
|
||||
# respectively which start at zero and monotonically increase
|
||||
for thread in self.threads.itertuples():
|
||||
_thread_name = (
|
||||
thread.thread_name if thread.track_name is None else thread.track_name
|
||||
)
|
||||
for process in self.process.itertuples():
|
||||
if process.tp_index != thread.tp_index:
|
||||
continue
|
||||
_process_name = (
|
||||
process.process_name
|
||||
if process.track_name is None
|
||||
else process.track_name
|
||||
)
|
||||
if process.track_id == thread.track_parent_id:
|
||||
self.track_ids[thread.tp_index][thread.track_id] = {
|
||||
"tp_index": thread.tp_index,
|
||||
"pid": process.pid,
|
||||
"tid": thread.tid,
|
||||
"rank": -1,
|
||||
"thread": -1,
|
||||
"prio": 0 if thread.is_main_thread else 1,
|
||||
"process_name": _process_name,
|
||||
"thread_name": _thread_name,
|
||||
}
|
||||
break
|
||||
|
||||
# some track ids do not have an associated system thread id so handle them here.
|
||||
# for example, omnitrace post-processes sampling data collected on a thread
|
||||
# during finalization and is inserted into perfetto on the main thread
|
||||
# but not in the main thread track so perfetto does not associate the
|
||||
# track_id with a system thread id.
|
||||
for process in self.process.itertuples():
|
||||
if process.track_id in self.track_ids[process.tp_index].keys():
|
||||
continue
|
||||
_process_name = (
|
||||
process.track_name
|
||||
if process.process_name is None
|
||||
else process.process_name
|
||||
)
|
||||
_thread_name = (
|
||||
process.process_name if process.track_name is None else process.track_name
|
||||
)
|
||||
self.track_ids[process.tp_index][process.track_id] = {
|
||||
"tp_index": process.tp_index,
|
||||
"pid": process.pid,
|
||||
"tid": process.pid,
|
||||
"rank": -1,
|
||||
"thread": -1,
|
||||
"prio": 0 if process.track_parent_id is None else 2,
|
||||
"process_name": _process_name,
|
||||
"thread_name": _thread_name,
|
||||
}
|
||||
|
||||
if "track_ids" in self.report and self.verbose >= 3:
|
||||
print("\ntrack ids (original):")
|
||||
for idx, _track_ids in enumerate(self.track_ids):
|
||||
for key, itr in _track_ids.items():
|
||||
print(f" {idx:2}: {key:8} :: {itr}")
|
||||
print("")
|
||||
|
||||
# since the protobuf just has raw (system) PID and TIDs and there may be multiple PIDs and TIDs
|
||||
# in the same file, we need to map the system PIDs to rank IDs starting at zero and, for each
|
||||
# PID, map the system TIDs to thread-ids starting at zero
|
||||
pid_offset = 0
|
||||
for idx, _track_ids in enumerate(self.track_ids):
|
||||
_track_ids = dict(
|
||||
sorted(
|
||||
_track_ids.items(),
|
||||
key=lambda x: [x[1]["pid"], x[1]["prio"], x[1]["tid"]],
|
||||
)
|
||||
)
|
||||
pids = list(set([x["pid"] for _, x in _track_ids.items()]))
|
||||
|
||||
if self.verbose >= 3:
|
||||
tids = list(set([x["tid"] for _, x in _track_ids.items()]))
|
||||
print(f"pids: {pids}")
|
||||
print(f"tids: {tids}")
|
||||
|
||||
# assign the rank and then increment the rank offset by the number of PIDs in the file
|
||||
for pidx, pid in enumerate(pids):
|
||||
for _, itr in _track_ids.items():
|
||||
if itr["pid"] == pid:
|
||||
itr["rank"] = pidx + pid_offset
|
||||
pid_offset += len(pids)
|
||||
|
||||
for _, pid in enumerate(pids):
|
||||
# dictionary containing only the data for this pid
|
||||
_pid_track_ids = dict(
|
||||
[[x, y] for x, y in _track_ids.items() if y["pid"] == pid]
|
||||
)
|
||||
|
||||
assigned_track_ids = []
|
||||
|
||||
# filter out the main threads (priority == 0) for a given pid and set index to a value of zero
|
||||
main_thr_info = set(
|
||||
[x for x, y in _pid_track_ids.items() if y["prio"] == 0]
|
||||
)
|
||||
|
||||
# for known "main" threads, assign index to zero
|
||||
for track_id, track_id_data in _track_ids.items():
|
||||
if track_id in main_thr_info:
|
||||
track_id_data["thread"] = 0
|
||||
assigned_track_ids.append(track_id)
|
||||
|
||||
# starting value for assignment. set before next step
|
||||
offset = 1 if assigned_track_ids else 0
|
||||
|
||||
# search thread name to try to identify which thread it belongs to.
|
||||
# needs to come after offset assignment
|
||||
for track_id, track_id_data in _track_ids.items():
|
||||
if (
|
||||
track_id in assigned_track_ids
|
||||
or track_id not in _pid_track_ids.keys()
|
||||
):
|
||||
continue
|
||||
m = re.search(self.thread_index_regex, track_id_data["thread_name"])
|
||||
if m:
|
||||
track_id_data["thread"] = int(m.group("thread_index"))
|
||||
assigned_track_ids.append(track_id)
|
||||
|
||||
# filter out the non-main threads (priority > 0) for a given pid that haven't already been assigned an index
|
||||
chld_thr_info = set(
|
||||
[
|
||||
x
|
||||
for x, y in _pid_track_ids.items()
|
||||
if y["prio"] > 0 and x not in assigned_track_ids
|
||||
]
|
||||
)
|
||||
|
||||
# finally, assign remaining tracks thread indexes via incrementing offset value
|
||||
for track_id, track_id_data in _track_ids.items():
|
||||
if (
|
||||
track_id in assigned_track_ids
|
||||
or track_id not in _pid_track_ids.keys()
|
||||
):
|
||||
continue
|
||||
if track_id in chld_thr_info:
|
||||
track_id_data["thread"] = offset
|
||||
assigned_track_ids.append(track_id)
|
||||
offset += 1
|
||||
|
||||
# make sure the thread indexes are monotonically increasing
|
||||
# this may not be the case because of the assignment via regex matching
|
||||
_pid_track_ids = dict(
|
||||
[[x, y] for x, y in _track_ids.items() if y["pid"] == pid]
|
||||
)
|
||||
tidx_max = max([y["thread"] for x, y in _pid_track_ids.items()])
|
||||
tidx_uniq = len(
|
||||
set(
|
||||
[
|
||||
y["thread"]
|
||||
for x, y in _pid_track_ids.items()
|
||||
if y["thread"] >= 0
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
if self.verbose >= 3:
|
||||
print(f"\nTID :: max={tidx_max}, unique={tidx_uniq}\n")
|
||||
|
||||
# add one to comparison since one thread with a value of 0 would be a size of 1
|
||||
while tidx_max + 1 > tidx_uniq:
|
||||
for idx in range(tidx_max):
|
||||
# if this is empty, we need to decrement all thread indexes > idx
|
||||
_tidx_loc = [
|
||||
x for x, y in _pid_track_ids.items() if y["thread"] == idx
|
||||
]
|
||||
if not _tidx_loc:
|
||||
for itr in _pid_track_ids.keys():
|
||||
if _track_ids[itr]["thread"] > idx:
|
||||
_track_ids[itr]["thread"] -= 1
|
||||
break
|
||||
# exit the loop so that we recalculate tidx_max
|
||||
tidx_max = max([y["thread"] for x, y in _pid_track_ids.items()])
|
||||
|
||||
if "process" in self.report:
|
||||
print(f"\nprocess:\n{self.process.to_string()}\n")
|
||||
if "threads" in self.report:
|
||||
print(f"\nthreads:\n{self.threads.to_string()}\n")
|
||||
if "track_ids" in self.report:
|
||||
print("\ntrack ids:")
|
||||
for idx, _track_ids in enumerate(self.track_ids):
|
||||
for key, itr in _track_ids.items():
|
||||
print(f" {idx:2}: {key:8} :: {itr}")
|
||||
print("")
|
||||
|
||||
if self.verbose >= 3:
|
||||
print("\nTID mapping:")
|
||||
for idx, _track_ids in enumerate(self.track_ids):
|
||||
for track_id, itr in _track_ids.items():
|
||||
pid = itr["pid"]
|
||||
tid = itr["tid"]
|
||||
pidx = itr["rank"]
|
||||
tidx = itr["thread"]
|
||||
print(
|
||||
f" {idx:2}: [{track_id:4}] {pid:8} -> {pidx:8} :: {tid:8} -> {tidx:8}"
|
||||
)
|
||||
|
||||
print("")
|
||||
|
||||
def create_graph(self):
|
||||
"""Create graph and dataframe"""
|
||||
|
||||
def get_frame_attributes(_name):
|
||||
"""Get the standard set of dictionary entries for a Frame.
|
||||
Also, parses the prefix for func-file-line info
|
||||
which is typically in the form:
|
||||
<FUNC> [<FILE>:<LINE>]
|
||||
<FUNC> [<FILE>]
|
||||
"""
|
||||
|
||||
if not self.compiled_patterns:
|
||||
return {"type": "function", "name": _name}
|
||||
|
||||
def _process_regex(_data):
|
||||
"""Process the regex data for func/file/line info"""
|
||||
return _data.groupdict() if _data is not None else None
|
||||
|
||||
def _perform_regex(_name):
|
||||
"""Performs a search for standard configurations of function + file + line"""
|
||||
for _pattern in self.compiled_patterns:
|
||||
_tmp = _process_regex(re.search(_pattern, _name))
|
||||
if _tmp:
|
||||
return _tmp
|
||||
return None
|
||||
|
||||
_keys = {"type": "region", "name": _name}
|
||||
_extra = {"file": "<unknown>", "line": "0"}
|
||||
_pdict = _perform_regex(_name)
|
||||
if _pdict is not None:
|
||||
_func = _pdict.get("func", None)
|
||||
_file = _pdict.get("file", "<unknown>")
|
||||
_line = _pdict.get("line", "0")
|
||||
_head = _pdict.get("head", None)
|
||||
_tail = _pdict.get("tail", None)
|
||||
|
||||
_line_s = f":{_line}" if int(_line) > 0 else ""
|
||||
_tail_s = f"/{_tail}" if _tail is not None else ""
|
||||
_file_s = f"{_file}{_line_s}" if _file != "<unknown>" else _file
|
||||
|
||||
_extra["file"] = _file_s
|
||||
_extra["line"] = _line
|
||||
|
||||
if "head" in _pdict:
|
||||
_keys["name"] = _head.rstrip()
|
||||
if _func is not None:
|
||||
_extra["func"] = _func
|
||||
else:
|
||||
if _func is not None:
|
||||
_keys["name"] = _func
|
||||
else:
|
||||
_keys["name"] = _file_s
|
||||
|
||||
_keys["name"] = "{}{}".format(_keys["name"], _tail_s)
|
||||
|
||||
return (_keys, _extra)
|
||||
|
||||
# list_roots = []
|
||||
track_id_dict = OrderedDict()
|
||||
callpath_to_node = {}
|
||||
|
||||
def_metric = self.default_metric
|
||||
|
||||
df = self.dataframe
|
||||
_cols = [
|
||||
"tp_index",
|
||||
"track_id",
|
||||
"category",
|
||||
"slice_id",
|
||||
"stack_id",
|
||||
"parent_stack_id",
|
||||
"name",
|
||||
"depth",
|
||||
"ts",
|
||||
"dur",
|
||||
]
|
||||
_data = [df[x].to_list() for x in _cols]
|
||||
|
||||
assert min([len(x) for x in _data]) == max([len(x) for x in _data])
|
||||
|
||||
for _tp_index, _track_id in zip(
|
||||
_data[_cols.index("tp_index")], _data[_cols.index("track_id")]
|
||||
):
|
||||
assert _tp_index < len(self.track_ids)
|
||||
assert _track_id in self.track_ids[_tp_index].keys()
|
||||
|
||||
_track_info = self.track_ids[_tp_index][_track_id]
|
||||
_rank = _track_info["rank"]
|
||||
_thread = _track_info["thread"]
|
||||
|
||||
if _tp_index not in track_id_dict:
|
||||
track_id_dict[_tp_index] = OrderedDict()
|
||||
if _rank not in track_id_dict[_tp_index]:
|
||||
track_id_dict[_tp_index][_rank] = OrderedDict()
|
||||
if _thread not in track_id_dict[_tp_index][_rank]:
|
||||
track_id_dict[_tp_index][_rank][_thread] = OrderedDict()
|
||||
|
||||
track_id_dict[_tp_index][_rank][_thread] = {0: None}
|
||||
|
||||
for (
|
||||
_tp_index,
|
||||
_track_id,
|
||||
_category,
|
||||
_slice_id,
|
||||
_stack_id,
|
||||
_parent_stack_id,
|
||||
_name,
|
||||
_depth,
|
||||
_ts,
|
||||
_dur,
|
||||
) in zip(*_data):
|
||||
_track_info = self.track_ids[_tp_index][_track_id]
|
||||
_rank = _track_info["rank"]
|
||||
_thread = _track_info["thread"]
|
||||
|
||||
_track_id_dict = track_id_dict[_tp_index][_rank][_thread]
|
||||
|
||||
# removed because of filtering
|
||||
if _parent_stack_id not in _track_id_dict:
|
||||
continue
|
||||
|
||||
# reduce processing time
|
||||
if self.max_depth is not None and _depth > self.max_depth:
|
||||
continue
|
||||
|
||||
_metrics = {}
|
||||
_metrics["rank"] = _track_info["rank"]
|
||||
_metrics["thread"] = _track_info["thread"]
|
||||
_metrics["pid"] = _track_info["pid"]
|
||||
_metrics["tid"] = _track_info["tid"]
|
||||
_metrics["track_id"] = _track_id
|
||||
_metrics["slice_id"] = _slice_id
|
||||
_metrics["stack_id"] = _stack_id
|
||||
_metrics["parent_stack_id"] = _parent_stack_id
|
||||
_metrics["ts"] = _ts
|
||||
_metrics[def_metric] = float(_dur) * 1.0e-9 # nsec -> sec
|
||||
|
||||
_frame_attrs, _extra = get_frame_attributes(_name)
|
||||
_extra["tp_index"] = _tp_index
|
||||
_extra["category"] = _category
|
||||
_extra["depth"] = _depth
|
||||
|
||||
# look up the parent node specific to the TP index, rank, and thread
|
||||
# stack ID is assigned by perfetto and parent stack ID is the
|
||||
# stack ID of it's parent.
|
||||
# _parent_node = _track_id_dict[_parent_stack_id]
|
||||
|
||||
# hnode = Node(Frame(_frame_attrs, **_extra), None)
|
||||
|
||||
# if _parent_node:
|
||||
# _parent_node.add_child(hnode)
|
||||
# else:
|
||||
# list_roots.append(hnode)
|
||||
|
||||
# # make sure this stack ID is unique for the
|
||||
# # TP index, rank, and thread and is equal to a
|
||||
# # previously seen node with the same stack ID
|
||||
# if _stack_id not in _track_id_dict:
|
||||
# _track_id_dict[_stack_id] = hnode
|
||||
# elif _track_id_dict[_stack_id] != hnode:
|
||||
# _existing = _track_id_dict[_stack_id]
|
||||
# raise RuntimeError(
|
||||
# f"{_stack_id} already exists in track_id_dict[{_tp_index}][{_rank}][{_thread}]. failed to set:\n {hnode.frame} (current)\n {_existing.frame} (existing)"
|
||||
# )
|
||||
|
||||
_hash = hash((_tp_index, _slice_id))
|
||||
if _hash in callpath_to_node:
|
||||
raise ValueError(f"{_hash} already exists in callpath_to_node dict")
|
||||
|
||||
_frame_attrs.pop("type") # should not be a column in dataframe
|
||||
callpath_to_node[_hash] = dict(
|
||||
**_frame_attrs,
|
||||
**_metrics,
|
||||
**_extra,
|
||||
)
|
||||
|
||||
if not callpath_to_node:
|
||||
raise RuntimeError(
|
||||
"call-graph is empty. if category filtering was used, you may have filtered out all the root nodes and thus all of it's children"
|
||||
)
|
||||
|
||||
return (df, callpath_to_node)
|
||||
# graph, dataframe = graphframe_indexing_helper(
|
||||
# list_roots,
|
||||
# data=list(callpath_to_node.values()),
|
||||
# extensions=["rank", "thread"],
|
||||
# fill_value=0,
|
||||
# )
|
||||
|
||||
# inc_metrics = [self.default_metric]
|
||||
# exc_metrics = []
|
||||
# return (graph, dataframe, exc_metrics, inc_metrics, self.default_metric)
|
||||
|
||||
def read(self, **kwargs):
|
||||
"""Read perfetto json."""
|
||||
|
||||
self.configure(**kwargs)
|
||||
self.extract_tp_data(**kwargs)
|
||||
|
||||
(
|
||||
dataframe,
|
||||
callpath_to_node,
|
||||
) = self.create_graph()
|
||||
|
||||
# def _read(**kwargs):
|
||||
# return self.read(**kwargs)
|
||||
|
||||
# def _configure(**kwargs):
|
||||
# self.configure(**kwargs)
|
||||
|
||||
# def _query(*args, **kwargs):
|
||||
# assert self.trace_processor
|
||||
# return self.query_tp(*args, **kwargs)
|
||||
|
||||
return (
|
||||
dataframe,
|
||||
callpath_to_node,
|
||||
)
|
||||
# default_metric=def_metric,
|
||||
# metadata=self.metadata,
|
||||
# attributes={
|
||||
# "reader": self,
|
||||
# "read": _read,
|
||||
# "query": _query,
|
||||
# "configure": _configure,
|
||||
# "selected_categories": lambda: self.categories,
|
||||
# "available_categories": lambda: self.df_categories,
|
||||
# },
|
||||
# )
|
||||
@@ -0,0 +1,23 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
from __future__ import absolute_import
|
||||
@@ -0,0 +1,48 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
def test_perfetto_data(
|
||||
pftrace_data, json_data, categories=("hip", "hsa", "marker", "kernel", "memory_copy")
|
||||
):
|
||||
|
||||
mapping = {
|
||||
"hip": ("hip_api", "hip_api"),
|
||||
"hsa": ("hsa_api", "hsa_api"),
|
||||
"marker": ("marker_api", "marker_api"),
|
||||
"kernel": ("kernel_dispatch", "kernel_dispatches"),
|
||||
"memory_copy": ("memory_copy", "memory_copy"),
|
||||
}
|
||||
|
||||
# make sure they specified valid categories
|
||||
for itr in categories:
|
||||
assert itr in mapping.keys()
|
||||
|
||||
for pf_category, js_category in [
|
||||
itr for key, itr in mapping.items() if key in categories
|
||||
]:
|
||||
_pf_data = pftrace_data.loc[pftrace_data["category"] == pf_category]
|
||||
_js_data = json_data["rocprofiler-sdk-tool"]["buffer_records"][js_category]
|
||||
|
||||
assert len(_pf_data) == len(_js_data)
|
||||
@@ -22,7 +22,7 @@ add_test(
|
||||
NAME rocprofv3-test-hsa-multiqueue-execute
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --hsa-trace --kernel-trace -d
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace -o out --output-format json:csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace -o out --output-format json:csv:pftrace
|
||||
$<TARGET_FILE:multiqueue_testapp>)
|
||||
|
||||
set_tests_properties(
|
||||
@@ -38,7 +38,9 @@ add_test(
|
||||
--kernel-trace-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/multiqueue_testapp-trace/out_kernel_trace.csv
|
||||
--json-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/multiqueue_testapp-trace/out_results.json)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/multiqueue_testapp-trace/out_results.json
|
||||
--pftrace-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/multiqueue_testapp-trace/out_results.pftrace)
|
||||
|
||||
set(MULTIQUEUE_VALIDATION_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/multiqueue_testapp-trace/out_hsa_api_trace.csv
|
||||
|
||||
@@ -6,6 +6,7 @@ import json
|
||||
|
||||
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
|
||||
from rocprofiler_sdk.pytest_utils import collapse_dict_list
|
||||
from rocprofiler_sdk.pytest_utils.perfetto_reader import PerfettoReader
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
@@ -24,6 +25,11 @@ def pytest_addoption(parser):
|
||||
action="store",
|
||||
help="Path to JSON file.",
|
||||
)
|
||||
parser.addoption(
|
||||
"--pftrace-input",
|
||||
action="store",
|
||||
help="Path to Perfetto trace file.",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -55,3 +61,9 @@ def json_data(request):
|
||||
filename = request.config.getoption("--json-input")
|
||||
with open(filename, "r") as inp:
|
||||
return dotdict(collapse_dict_list(json.load(inp)))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pftrace_data(request):
|
||||
filename = request.config.getoption("--pftrace-input")
|
||||
return PerfettoReader(filename).read()[0]
|
||||
@@ -154,6 +154,14 @@ def test_hsa_api_trace_json(json_data):
|
||||
assert functions.count("hsa_signal_destroy") == num_hsa_signal_destroy_calls
|
||||
|
||||
|
||||
def test_perfetto_data(pftrace_data, json_data):
|
||||
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
|
||||
|
||||
rocprofv3.test_perfetto_data(
|
||||
pftrace_data, json_data, ("hip", "hsa", "marker", "kernel", "memory_copy")
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
|
||||
sys.exit(exit_code)
|
||||
@@ -27,6 +27,15 @@ add_test(
|
||||
--hsa-finalizer-trace --kernel-trace --memory-copy-trace --output-format JSON -d
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace -o out $<TARGET_FILE:hip-in-libraries>)
|
||||
|
||||
add_test(
|
||||
NAME rocprofv3-test-trace-hip-in-libraries-pftrace-execute
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --hip-runtime-trace
|
||||
--hip-compiler-trace --hsa-core-trace --hsa-amd-trace --hsa-image-trace
|
||||
--hsa-finalizer-trace --kernel-trace --memory-copy-trace --output-format pftrace
|
||||
-d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace -o out
|
||||
$<TARGET_FILE:hip-in-libraries>)
|
||||
|
||||
string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
|
||||
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
|
||||
|
||||
@@ -58,6 +67,19 @@ set_tests_properties(
|
||||
"HSA_CORE_API|HSA_AMD_EXT_API|HSA_IMAGE_EXT_API|HSA_FINALIZER_EXT_API|HIP_API|HIP_COMPILER_API|KERNEL_DISPATCH|CODE_OBJECT"
|
||||
)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-trace-hip-in-libraries-pftrace-execute
|
||||
PROPERTIES
|
||||
TIMEOUT
|
||||
100
|
||||
LABELS
|
||||
"integration-tests"
|
||||
ENVIRONMENT
|
||||
"${tracing-env}"
|
||||
FAIL_REGULAR_EXPRESSION
|
||||
"HSA_CORE_API|HSA_AMD_EXT_API|HSA_IMAGE_EXT_API|HSA_FINALIZER_EXT_API|HIP_API|HIP_COMPILER_API|KERNEL_DISPATCH|CODE_OBJECT"
|
||||
)
|
||||
|
||||
rocprofiler_configure_pytest_files(CONFIG pytest.ini COPY validate.py conftest.py)
|
||||
|
||||
add_test(
|
||||
@@ -79,9 +101,13 @@ add_test(
|
||||
--hsa-stats ${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_hsa_stats.csv
|
||||
--memory-copy-stats
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_memory_copy_stats.csv
|
||||
--json-input ${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_results.json)
|
||||
--json-input ${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_results.json
|
||||
--pftrace-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_results.pftrace)
|
||||
|
||||
set(VALIDATION_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_results.pftrace
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_results.json
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_memory_copy_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_hsa_api_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_hip_api_trace.csv
|
||||
@@ -90,8 +116,7 @@ set(VALIDATION_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_kernel_stats.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_hip_stats.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_hsa_stats.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_memory_copy_stats.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_results.json)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hip-in-libraries-trace/out_memory_copy_stats.csv)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-trace-hip-in-libraries-validate
|
||||
@@ -101,7 +126,7 @@ set_tests_properties(
|
||||
LABELS
|
||||
"integration-tests"
|
||||
DEPENDS
|
||||
"rocprofv3-test-trace-hip-in-libraries-execute;rocprofv3-test-trace-hip-in-libraries-json-execute"
|
||||
"rocprofv3-test-trace-hip-in-libraries-execute;rocprofv3-test-trace-hip-in-libraries-json-execute;rocprofv3-test-trace-hip-in-libraries-pftrace-execute"
|
||||
FAIL_REGULAR_EXPRESSION
|
||||
"AssertionError"
|
||||
ATTACHED_FILES_ON_FAIL
|
||||
|
||||
@@ -7,6 +7,7 @@ import json
|
||||
|
||||
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
|
||||
from rocprofiler_sdk.pytest_utils import collapse_dict_list
|
||||
from rocprofiler_sdk.pytest_utils.perfetto_reader import PerfettoReader
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
@@ -66,6 +67,11 @@ def pytest_addoption(parser):
|
||||
action="store",
|
||||
help="Path to JSON file.",
|
||||
)
|
||||
parser.addoption(
|
||||
"--pftrace-input",
|
||||
action="store",
|
||||
help="Path to Perfetto trace file.",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -198,3 +204,9 @@ def json_data(request):
|
||||
filename = request.config.getoption("--json-input")
|
||||
with open(filename, "r") as inp:
|
||||
return dotdict(collapse_dict_list(json.load(inp)))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pftrace_data(request):
|
||||
filename = request.config.getoption("--pftrace-input")
|
||||
return PerfettoReader(filename).read()[0]
|
||||
@@ -398,6 +398,15 @@ def test_memory_copy_trace(
|
||||
validate_stats(row)
|
||||
|
||||
|
||||
def test_perfetto_data(pftrace_data, json_data):
|
||||
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
|
||||
|
||||
# do not test for HSA since that may vary b/t two separate runs
|
||||
rocprofv3.test_perfetto_data(
|
||||
pftrace_data, json_data, ("hip", "marker", "kernel", "memory_copy")
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
|
||||
sys.exit(exit_code)
|
||||
@@ -20,7 +20,7 @@ add_test(
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --hsa-trace -i
|
||||
${CMAKE_CURRENT_BINARY_DIR}/input.txt -d ${CMAKE_CURRENT_BINARY_DIR}/out_cc_trace
|
||||
-o pmc3 --output-format JSON:CSV $<TARGET_FILE:simple-transpose>)
|
||||
-o pmc3 --output-format JSON:PFTRACE:CSV $<TARGET_FILE:simple-transpose>)
|
||||
|
||||
string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
|
||||
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
|
||||
@@ -39,6 +39,8 @@ foreach(_DIR "pmc_1" "pmc_2" "pmc_3" "pmc_4")
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --json-input
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/out_cc_trace/${_DIR}/pmc3_results.json"
|
||||
--pftrace-input
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/out_cc_trace/${_DIR}/pmc3_results.pftrace"
|
||||
--hsa-input
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/out_cc_trace/${_DIR}/pmc3_hsa_api_trace.csv"
|
||||
--agent-input
|
||||
|
||||
@@ -8,6 +8,7 @@ import pandas as pd
|
||||
|
||||
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
|
||||
from rocprofiler_sdk.pytest_utils import collapse_dict_list
|
||||
from rocprofiler_sdk.pytest_utils.perfetto_reader import PerfettoReader
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
@@ -46,6 +47,11 @@ def pytest_addoption(parser):
|
||||
action="store",
|
||||
help="Path to JSON file.",
|
||||
)
|
||||
parser.addoption(
|
||||
"--pftrace-input",
|
||||
action="store",
|
||||
help="Path to Perfetto trace file.",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -184,3 +190,9 @@ def json_data(request):
|
||||
filename = request.config.getoption("--json-input")
|
||||
with open(filename, "r") as inp:
|
||||
return dotdict(collapse_dict_list(json.load(inp)))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pftrace_data(request):
|
||||
filename = request.config.getoption("--pftrace-input")
|
||||
return PerfettoReader(filename).read()[0]
|
||||
@@ -20,6 +20,14 @@ def test_validate_counter_collection_plus_tracing(
|
||||
assert len(counter_collection_data) > 0
|
||||
|
||||
|
||||
def test_perfetto_data(pftrace_data, json_data):
|
||||
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
|
||||
|
||||
rocprofv3.test_perfetto_data(
|
||||
pftrace_data, json_data, ("hip", "hsa", "marker", "kernel", "memory_copy")
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
|
||||
sys.exit(exit_code)
|
||||
@@ -15,7 +15,7 @@ add_test(
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> -M --hsa-trace --kernel-trace
|
||||
--memory-copy-trace --marker-trace -d ${CMAKE_CURRENT_BINARY_DIR}/%argt%-trace -o
|
||||
out --output-format csv,json $<TARGET_FILE:simple-transpose>)
|
||||
out --output-format pftrace,csv,json $<TARGET_FILE:simple-transpose>)
|
||||
|
||||
string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
|
||||
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
|
||||
@@ -57,15 +57,18 @@ add_test(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_marker_api_trace.csv
|
||||
--agent-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_agent_info.csv
|
||||
--json-input ${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_results.json)
|
||||
--json-input ${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_results.json
|
||||
--pftrace-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_results.pftrace)
|
||||
|
||||
set(VALIDATION_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_results.pftrace
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_results.json
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_memory_copy_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_hsa_api_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_kernel_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_marker_api_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_agent_info.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_results.json)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-trace/out_agent_info.csv)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-trace-validate
|
||||
@@ -87,8 +90,8 @@ add_test(
|
||||
NAME rocprofv3-test-systrace-execute
|
||||
COMMAND
|
||||
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --sys-trace -d
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-systrace -o out --output-format csv,json
|
||||
$<TARGET_FILE:simple-transpose>)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/%argt%-systrace -o out --output-format
|
||||
pftrace,csv,json $<TARGET_FILE:simple-transpose>)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-systrace-execute
|
||||
@@ -118,15 +121,18 @@ add_test(
|
||||
--agent-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_agent_info.csv
|
||||
--json-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_results.json)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_results.json
|
||||
--pftrace-input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_results.pftrace)
|
||||
|
||||
set(SYS_VALIDATION_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_results.pftrace
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_results.json
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_memory_copy_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_hsa_api_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_kernel_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_marker_api_trace.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_agent_info.csv
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_results.json)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-systrace/out_agent_info.csv)
|
||||
|
||||
set_tests_properties(
|
||||
rocprofv3-test-systrace-validate
|
||||
|
||||
@@ -6,6 +6,7 @@ import json
|
||||
|
||||
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
|
||||
from rocprofiler_sdk.pytest_utils import collapse_dict_list
|
||||
from rocprofiler_sdk.pytest_utils.perfetto_reader import PerfettoReader
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
@@ -44,6 +45,11 @@ def pytest_addoption(parser):
|
||||
action="store",
|
||||
help="Path to JSON file.",
|
||||
)
|
||||
parser.addoption(
|
||||
"--pftrace-input",
|
||||
action="store",
|
||||
help="Path to Perfetto trace file.",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -123,3 +129,9 @@ def json_data(request):
|
||||
filename = request.config.getoption("--json-input")
|
||||
with open(filename, "r") as inp:
|
||||
return dotdict(collapse_dict_list(json.load(inp)))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pftrace_data(request):
|
||||
filename = request.config.getoption("--pftrace-input")
|
||||
return PerfettoReader(filename).read()[0]
|
||||
@@ -263,6 +263,14 @@ def test_marker_api_trace_json(json_data):
|
||||
assert marker["end_timestamp"] >= marker["start_timestamp"]
|
||||
|
||||
|
||||
def test_perfetto_data(pftrace_data, json_data):
|
||||
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
|
||||
|
||||
rocprofv3.test_perfetto_data(
|
||||
pftrace_data, json_data, ("hip", "hsa", "marker", "kernel", "memory_copy")
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
|
||||
sys.exit(exit_code)
|
||||
+41
-39
@@ -1436,14 +1436,15 @@ write_json(call_stack_t* _call_stack)
|
||||
}
|
||||
|
||||
{
|
||||
namespace sdk = ::rocprofiler::sdk;
|
||||
using JSONOutputArchive = cereal::MinimalJSONOutputArchive;
|
||||
|
||||
constexpr auto json_prec = 32;
|
||||
constexpr auto json_indent = JSONOutputArchive::Options::IndentChar::space;
|
||||
auto json_opts = JSONOutputArchive::Options{json_prec, json_indent, 1};
|
||||
auto json_ar = JSONOutputArchive{*ofs, json_opts};
|
||||
auto buffer_names = rocprofiler::sdk::get_buffer_tracing_names();
|
||||
auto callbk_names = rocprofiler::sdk::get_callback_tracing_names();
|
||||
auto buffer_names = sdk::get_buffer_tracing_names();
|
||||
auto callbk_names = sdk::get_callback_tracing_names();
|
||||
auto validate_page_migration =
|
||||
(page_migration_status != ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL);
|
||||
|
||||
@@ -1655,8 +1656,10 @@ write_perfetto()
|
||||
}
|
||||
|
||||
{
|
||||
auto buffer_names = rocprofiler::sdk::get_buffer_tracing_names();
|
||||
auto callbk_name_info = rocprofiler::sdk::get_callback_tracing_names();
|
||||
namespace sdk = ::rocprofiler::sdk;
|
||||
|
||||
auto buffer_names = sdk::get_buffer_tracing_names();
|
||||
auto callbk_name_info = sdk::get_callback_tracing_names();
|
||||
|
||||
for(auto itr : hsa_api_bf_records)
|
||||
{
|
||||
@@ -1671,7 +1674,7 @@ write_perfetto()
|
||||
});
|
||||
if(ritr != hsa_api_cb_records.end()) _args = ritr->args;
|
||||
|
||||
TRACE_EVENT_BEGIN(rocprofiler::trait::name<rocprofiler::category::hsa_api>::value,
|
||||
TRACE_EVENT_BEGIN(sdk::perfetto_category<sdk::category::hsa_api>::name,
|
||||
::perfetto::StaticString(name.data()),
|
||||
track,
|
||||
itr.start_timestamp,
|
||||
@@ -1688,9 +1691,9 @@ write_perfetto()
|
||||
itr.correlation_id.internal,
|
||||
[&](::perfetto::EventContext ctx) {
|
||||
for(const auto& aitr : _args)
|
||||
add_perfetto_annotation(ctx, aitr.first, aitr.second);
|
||||
sdk::add_perfetto_annotation(ctx, aitr.first, aitr.second);
|
||||
});
|
||||
TRACE_EVENT_END(rocprofiler::trait::name<rocprofiler::category::hsa_api>::value,
|
||||
TRACE_EVENT_END(sdk::perfetto_category<sdk::category::hsa_api>::name,
|
||||
track,
|
||||
itr.end_timestamp,
|
||||
"end_ns",
|
||||
@@ -1710,7 +1713,7 @@ write_perfetto()
|
||||
});
|
||||
if(ritr != hip_api_cb_records.end()) _args = ritr->args;
|
||||
|
||||
TRACE_EVENT_BEGIN(rocprofiler::trait::name<rocprofiler::category::hip_api>::value,
|
||||
TRACE_EVENT_BEGIN(sdk::perfetto_category<sdk::category::hip_api>::name,
|
||||
::perfetto::StaticString(name.data()),
|
||||
track,
|
||||
itr.start_timestamp,
|
||||
@@ -1727,9 +1730,9 @@ write_perfetto()
|
||||
itr.correlation_id.internal,
|
||||
[&](::perfetto::EventContext ctx) {
|
||||
for(const auto& aitr : _args)
|
||||
add_perfetto_annotation(ctx, aitr.first, aitr.second);
|
||||
sdk::add_perfetto_annotation(ctx, aitr.first, aitr.second);
|
||||
});
|
||||
TRACE_EVENT_END(rocprofiler::trait::name<rocprofiler::category::hip_api>::value,
|
||||
TRACE_EVENT_END(sdk::perfetto_category<sdk::category::hip_api>::name,
|
||||
track,
|
||||
itr.end_timestamp,
|
||||
"end_ns",
|
||||
@@ -1741,7 +1744,7 @@ write_perfetto()
|
||||
auto name = buffer_names.at(itr.kind, itr.operation);
|
||||
auto& track = agent_tracks.at(itr.dst_agent_id.handle);
|
||||
|
||||
TRACE_EVENT_BEGIN(rocprofiler::trait::name<rocprofiler::category::memory_copy>::value,
|
||||
TRACE_EVENT_BEGIN(sdk::perfetto_category<sdk::category::memory_copy>::name,
|
||||
::perfetto::StaticString(name.data()),
|
||||
track,
|
||||
itr.start_timestamp,
|
||||
@@ -1758,7 +1761,7 @@ write_perfetto()
|
||||
agents_map.at(itr.dst_agent_id).logical_node_id,
|
||||
"copy_bytes",
|
||||
itr.bytes);
|
||||
TRACE_EVENT_END(rocprofiler::trait::name<rocprofiler::category::memory_copy>::value,
|
||||
TRACE_EVENT_END(sdk::perfetto_category<sdk::category::memory_copy>::name,
|
||||
track,
|
||||
itr.end_timestamp,
|
||||
"end_ns",
|
||||
@@ -1787,34 +1790,33 @@ write_perfetto()
|
||||
demangled.emplace(name, demangle(name));
|
||||
}
|
||||
|
||||
TRACE_EVENT_BEGIN(
|
||||
rocprofiler::trait::name<rocprofiler::category::kernel_dispatch>::value,
|
||||
::perfetto::StaticString(demangled.at(name).c_str()),
|
||||
track,
|
||||
itr.start_timestamp,
|
||||
::perfetto::Flow::ProcessScoped(itr.correlation_id.internal),
|
||||
"begin_ns",
|
||||
itr.start_timestamp,
|
||||
"kind",
|
||||
itr.kind,
|
||||
"agent",
|
||||
agents_map.at(info.agent_id).logical_node_id,
|
||||
"corr_id",
|
||||
itr.correlation_id.internal,
|
||||
"queue",
|
||||
info.queue_id.handle,
|
||||
"kernel_id",
|
||||
info.kernel_id,
|
||||
"private_segment_size",
|
||||
info.private_segment_size,
|
||||
"group_segment_size",
|
||||
info.group_segment_size,
|
||||
"workgroup_size",
|
||||
info.workgroup_size.x * info.workgroup_size.y * info.workgroup_size.z,
|
||||
"grid_size",
|
||||
info.grid_size.x * info.grid_size.y * info.grid_size.z);
|
||||
TRACE_EVENT_BEGIN(sdk::perfetto_category<sdk::category::kernel_dispatch>::name,
|
||||
::perfetto::StaticString(demangled.at(name).c_str()),
|
||||
track,
|
||||
itr.start_timestamp,
|
||||
::perfetto::Flow::ProcessScoped(itr.correlation_id.internal),
|
||||
"begin_ns",
|
||||
itr.start_timestamp,
|
||||
"kind",
|
||||
itr.kind,
|
||||
"agent",
|
||||
agents_map.at(info.agent_id).logical_node_id,
|
||||
"corr_id",
|
||||
itr.correlation_id.internal,
|
||||
"queue",
|
||||
info.queue_id.handle,
|
||||
"kernel_id",
|
||||
info.kernel_id,
|
||||
"private_segment_size",
|
||||
info.private_segment_size,
|
||||
"group_segment_size",
|
||||
info.group_segment_size,
|
||||
"workgroup_size",
|
||||
info.workgroup_size.x * info.workgroup_size.y * info.workgroup_size.z,
|
||||
"grid_size",
|
||||
info.grid_size.x * info.grid_size.y * info.grid_size.z);
|
||||
|
||||
TRACE_EVENT_END(rocprofiler::trait::name<rocprofiler::category::kernel_dispatch>::value,
|
||||
TRACE_EVENT_END(sdk::perfetto_category<sdk::category::kernel_dispatch>::name,
|
||||
track,
|
||||
itr.end_timestamp,
|
||||
"end_ns",
|
||||
|
||||
Reference in new issue
Block a user