395f01b689
* Move include/rocprofiler-sdk/cxx/details/delimit.hpp to tokenize.hpp
* Update docs/how-to/using-rocprofv3.rst
- fix code block indents
- reorder rocprofv3 options, limit them to important options
- add docs for `--runtime-trace`
* Update rocprofv3.py
- parser argument groups
- new `--runtime-trace` option
- new `--summary` option
- new `--summary-per-domain` option
- new `--summary-groups` option
- new `--summary-output-file` option
- new `--summary-units` option
* Update lib/rocprofiler-sdk/hsa/async_copy.cpp
- fix async copy operation names: add "MEMORY_COPY_" prefix
* lib/rocprofiler-sdk-tool: update statistics.{hpp,cpp}
- statistics<>::get_percent function
- stats_entry_t struct
- stats_formatter struct
- percentage struct
- std::to_string(::rocprofiler::tool::percentage)
* lib/rocprofiler-sdk-tool: update domain_type.{hpp,cpp}
- reorder domain_type enum values
* lib/rocprofiler-sdk-tool: update generateCSV.{hpp,cpp}
- separate writing CSV from accumulating statistics
- a lot of functionality was moved to statistics.{hpp,cpp}
* lib/rocprofiler-sdk-tool: update output_file.{hpp,cpp}
- output_stream_t struct
- get_output_stream(...) returns output_stream_t instance
* lib/rocprofiler-sdk-tool: update generateJSON.cpp
- update get_output_stream usage to output_stream_t
* lib/rocprofiler-sdk-tool: update generateOTF2.cpp
- header include order tweak
* lib/rocprofiler-sdk-tool: update buffered_output.hpp
- stats_data_t was renamed to stats_entry_t
* lib/rocprofiler-sdk-tool: update generatePerfetto.cpp
- header include tweak
* lib/rocprofiler-sdk-tool: update tmp_file_buffer.hpp
- emit warning message if write_ring_buffer fails after offloading instead of aborting
- prefer placement new instead of assignment in write_ring_buffer
* lib/rocprofiler-sdk-tool: add generateStats.{hpp,cpp}
- functions for accumulating statistics
* Update tests/rocprofv3/tracing-hip-in-libraries/CMakeLists.txt
- accommodate tweak to CSV output file name for HIP and HSA traces
* lib/rocprofiler-sdk-tool: update config.{hpp,cpp}
- new config variables
- stats_summary
- stats_summary_per_domain
- summary_output
- stats_summary_unit_value
- stats_summary_unit
- stats_summary_file
- stats_summary_groups
- support output keys for hostname: %hostname% / %h
* lib/rocprofiler-sdk-tool: update tool.cpp
- support summary output
* Documentation fixes
* Test for summary output
* Update tests/bin/transpose to use more ROCTx
- also support building with the roctracer ROCTx
* Remove roctxMark from OTF2 + fix kernel-rename tests
- following more ROCTx calls in transpose, kernel-rename validation had to be updated
* JSON metadata + JSON summary
- add serialization support for config
- add serialization support for statistics
- additions to json spec
- rocprofiler-sdk-tool/metadata/config
- rocprofiler-sdk-tool/metadata/command
- rocprofiler-sdk-tool/summary
- config output_keys support for NVIDIA %q{<ENV-VAR>} syntax
- config output_keys support keys within keys
* rocprofv3 --summary-groups warning if no domain matches
- emit warning if a regex in for summary groups did not match any domain names
* Compile fix for lib/rocprofiler-sdk-tool/tool.cpp
- get_config().scratch_memory_trace
- pass contributions to write_json
* Update rocprofv3.py to preload rocprofiler-sdk-roctx
- appended to LD_PRELOAD when args.marker_trace is enabled
* Fix ReST link errors about subtitle underline being too short
* Patch tokenization of config::stats_summary_groups
- guard against array values of empty strings
* Tweak rocprofv3 summary test
- input-summary.yaml (used by rocprofv3-test-summary-inp-yaml-execute) only provides one summary group regex
* Disable LD_PRELOAD of librocprofiler-sdk-roctx.so
- this causes problems in the sanitizers, will be addressed in another PR
230 строки
8.8 KiB
C++
230 строки
8.8 KiB
C++
// MIT License
|
|
//
|
|
// Copyright (c) 2023 Advanced Micro Devices, Inc.
|
|
//
|
|
// 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 "lib/common/environment.hpp"
|
|
#include "lib/common/filesystem.hpp"
|
|
#include "lib/common/mpl.hpp"
|
|
|
|
#include <rocprofiler-sdk/cxx/serialization.hpp>
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
namespace rocprofiler
|
|
{
|
|
namespace tool
|
|
{
|
|
namespace fs = common::filesystem;
|
|
using common::get_env;
|
|
|
|
struct config;
|
|
|
|
enum class config_context
|
|
{
|
|
global = 0,
|
|
att_plugin,
|
|
cli_plugin,
|
|
ctf_plugin,
|
|
file_plugin,
|
|
perfetto_plugin,
|
|
};
|
|
|
|
void
|
|
initialize();
|
|
|
|
template <config_context ContextT = config_context::global>
|
|
config&
|
|
get_config();
|
|
|
|
std::string
|
|
format_name(std::string_view _name, const config& = get_config<>());
|
|
|
|
std::string
|
|
format(std::string _fpath, const std::string& _tag = {});
|
|
|
|
int
|
|
get_mpi_size();
|
|
|
|
int
|
|
get_mpi_rank();
|
|
|
|
struct config
|
|
{
|
|
config();
|
|
|
|
bool demangle = get_env("ROCPROF_DEMANGLE_KERNELS", true);
|
|
bool truncate = get_env("ROCPROF_TRUNCATE_KERNELS", false);
|
|
bool kernel_trace = get_env("ROCPROF_KERNEL_TRACE", false);
|
|
bool hsa_core_api_trace = get_env("ROCPROF_HSA_CORE_API_TRACE", false);
|
|
bool hsa_amd_ext_api_trace = get_env("ROCPROF_HSA_AMD_EXT_API_TRACE", false);
|
|
bool hsa_image_ext_api_trace = get_env("ROCPROF_HSA_IMAGE_EXT_API_TRACE", false);
|
|
bool hsa_finalizer_ext_api_trace = get_env("ROCPROF_HSA_FINALIZER_EXT_API_TRACE", false);
|
|
bool marker_api_trace = get_env("ROCPROF_MARKER_API_TRACE", false);
|
|
bool memory_copy_trace = get_env("ROCPROF_MEMORY_COPY_TRACE", false);
|
|
bool scratch_memory_trace = get_env("ROCPROF_SCRATCH_MEMORY_TRACE", false);
|
|
bool counter_collection = get_env("ROCPROF_COUNTER_COLLECTION", false);
|
|
bool hip_runtime_api_trace = get_env("ROCPROF_HIP_RUNTIME_API_TRACE", false);
|
|
bool hip_compiler_api_trace = get_env("ROCPROF_HIP_COMPILER_API_TRACE", false);
|
|
bool list_metrics = get_env("ROCPROF_LIST_METRICS", false);
|
|
bool list_metrics_output_file = get_env("ROCPROF_OUTPUT_LIST_METRICS_FILE", false);
|
|
bool stats = get_env("ROCPROF_STATS", false);
|
|
bool stats_summary = get_env("ROCPROF_STATS_SUMMARY", false);
|
|
bool stats_summary_per_domain = get_env("ROCPROF_STATS_SUMMARY_PER_DOMAIN", false);
|
|
bool csv_output = false;
|
|
bool json_output = false;
|
|
bool pftrace_output = false;
|
|
bool otf2_output = false;
|
|
bool summary_output = false;
|
|
bool kernel_rename = get_env("ROCPROF_KERNEL_RENAME", false);
|
|
int mpi_size = get_mpi_size();
|
|
int mpi_rank = get_mpi_rank();
|
|
size_t perfetto_shmem_size_hint = get_env("ROCPROF_PERFETTO_SHMEM_SIZE_HINT_KB", 64);
|
|
size_t perfetto_buffer_size = get_env("ROCPROF_PERFETTO_BUFFER_SIZE_KB", 1024000);
|
|
uint64_t stats_summary_unit_value = 1;
|
|
std::string stats_summary_unit = get_env("ROCPROF_STATS_SUMMARY_UNITS", "nsec");
|
|
std::string output_path = get_env("ROCPROF_OUTPUT_PATH", fs::current_path().string());
|
|
std::string output_file =
|
|
get_env("ROCPROF_OUTPUT_FILE_NAME", fmt::format("%hostname%/{}", getpid()));
|
|
std::string tmp_directory = get_env("ROCPROF_TMPDIR", output_path);
|
|
std::string stats_summary_file = get_env("ROCPROF_STATS_SUMMARY_OUTPUT", "stderr");
|
|
|
|
std::string kernel_filter_include =
|
|
get_env("ROCPROF_KERNEL_FILTER_INCLUDE_REGEX", std::string{".*"});
|
|
std::string kernel_filter_exclude =
|
|
get_env("ROCPROF_KERNEL_FILTER_EXCLUDE_REGEX", std::string{});
|
|
std::string perfetto_buffer_fill_policy =
|
|
get_env("ROCPROF_PERFETTO_BUFFER_FILL_POLICY", std::string{"discard"});
|
|
std::string perfetto_backend = get_env("ROCPROF_PERFETTO_BACKEND", std::string{"inprocess"});
|
|
std::unordered_set<uint32_t> kernel_filter_range = {};
|
|
std::set<std::string> counters = {};
|
|
std::vector<std::string> stats_summary_groups = {};
|
|
|
|
template <typename ArchiveT>
|
|
void save(ArchiveT&) const;
|
|
|
|
template <typename ArchiveT>
|
|
void load(ArchiveT&)
|
|
{}
|
|
};
|
|
|
|
template <typename ArchiveT>
|
|
void
|
|
config::save(ArchiveT& ar) const
|
|
{
|
|
#define CFG_SERIALIZE_MEMBER(VAR) ar(cereal::make_nvp(#VAR, VAR))
|
|
#define CFG_SERIALIZE_NAMED_MEMBER(NAME, VAR) ar(cereal::make_nvp(NAME, VAR))
|
|
|
|
CFG_SERIALIZE_MEMBER(demangle);
|
|
CFG_SERIALIZE_MEMBER(truncate);
|
|
CFG_SERIALIZE_MEMBER(kernel_trace);
|
|
CFG_SERIALIZE_MEMBER(hsa_core_api_trace);
|
|
CFG_SERIALIZE_MEMBER(hsa_amd_ext_api_trace);
|
|
CFG_SERIALIZE_MEMBER(hsa_image_ext_api_trace);
|
|
CFG_SERIALIZE_MEMBER(hsa_finalizer_ext_api_trace);
|
|
CFG_SERIALIZE_MEMBER(marker_api_trace);
|
|
CFG_SERIALIZE_MEMBER(memory_copy_trace);
|
|
CFG_SERIALIZE_MEMBER(scratch_memory_trace);
|
|
CFG_SERIALIZE_MEMBER(counter_collection);
|
|
CFG_SERIALIZE_MEMBER(hip_runtime_api_trace);
|
|
CFG_SERIALIZE_MEMBER(hip_compiler_api_trace);
|
|
CFG_SERIALIZE_MEMBER(kernel_rename);
|
|
|
|
CFG_SERIALIZE_NAMED_MEMBER("summary", stats_summary);
|
|
CFG_SERIALIZE_NAMED_MEMBER("summary_per_domain", stats_summary_per_domain);
|
|
CFG_SERIALIZE_NAMED_MEMBER("summary_groups", stats_summary_groups);
|
|
CFG_SERIALIZE_NAMED_MEMBER("summary_unit", stats_summary_unit);
|
|
CFG_SERIALIZE_NAMED_MEMBER("summary_file", stats_summary_file);
|
|
|
|
CFG_SERIALIZE_MEMBER(perfetto_shmem_size_hint);
|
|
CFG_SERIALIZE_MEMBER(perfetto_buffer_size);
|
|
CFG_SERIALIZE_MEMBER(perfetto_buffer_fill_policy);
|
|
CFG_SERIALIZE_MEMBER(perfetto_backend);
|
|
|
|
CFG_SERIALIZE_NAMED_MEMBER("raw_tmp_directory", tmp_directory);
|
|
CFG_SERIALIZE_NAMED_MEMBER("raw_output_path", output_path);
|
|
CFG_SERIALIZE_NAMED_MEMBER("raw_output_file", output_file);
|
|
CFG_SERIALIZE_NAMED_MEMBER("tmp_directory", format(tmp_directory));
|
|
CFG_SERIALIZE_NAMED_MEMBER("output_path", format(output_path));
|
|
CFG_SERIALIZE_NAMED_MEMBER("output_file", format(output_file));
|
|
|
|
CFG_SERIALIZE_MEMBER(counters);
|
|
CFG_SERIALIZE_MEMBER(kernel_filter_include);
|
|
CFG_SERIALIZE_MEMBER(kernel_filter_exclude);
|
|
CFG_SERIALIZE_MEMBER(kernel_filter_range);
|
|
|
|
#undef CFG_SERIALIZE_MEMBER
|
|
#undef CFG_SERIALIZE_NAMED_MEMBER
|
|
}
|
|
|
|
template <config_context ContextT>
|
|
config&
|
|
get_config()
|
|
{
|
|
if constexpr(ContextT == config_context::global)
|
|
{
|
|
static auto* _v = new config{};
|
|
return *_v;
|
|
}
|
|
else
|
|
{
|
|
// context specific config copied from global config
|
|
static auto* _v = new config{get_config<config_context::global>()};
|
|
return *_v;
|
|
}
|
|
}
|
|
|
|
struct output_key
|
|
{
|
|
output_key(std::string _key, std::string _val, std::string _desc = {});
|
|
|
|
template <typename Tp,
|
|
typename Up = Tp,
|
|
std::enable_if_t<!common::mpl::is_string_type<Up>::value, int> = 0>
|
|
output_key(std::string _key, Tp&& _val, std::string _desc = {});
|
|
|
|
operator std::pair<std::string, std::string>() const;
|
|
|
|
std::string key = {};
|
|
std::string value = {};
|
|
std::string description = {};
|
|
};
|
|
|
|
template <typename Tp, typename Up, std::enable_if_t<!common::mpl::is_string_type<Up>::value, int>>
|
|
output_key::output_key(std::string _key, Tp&& _val, std::string _desc)
|
|
: key{std::move(_key)}
|
|
, value{fmt::format("{}", std::forward<Tp>(_val))}
|
|
, description{std::move(_desc)}
|
|
{}
|
|
|
|
std::vector<output_key>
|
|
output_keys(std::string _tag = {});
|
|
} // namespace tool
|
|
} // namespace rocprofiler
|