SDK: remove majority of exceptions (#176)

* SDK: remove majority of exceptions

- replace with ROCP_FATAL, ROCP_CI_LOG(WARNING), etc.
- improve logging of symbolic link
- add --readlink and --realpath (hidden options) to rocprofv3 to follow symlinks for preloaded libraries

* Add rocprofv3 --rocm-root argument

* Fix registration resolved_exists

* Fix rocprofv3_avail.py

* Update logging for rocprofiler_configure search

- relax failure conditions

* Misc clang-tidy fixes

* Fix merge

* Fix merge

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
Co-authored-by: Bhardwaj, Gopesh <Gopesh.Bhardwaj@amd.com>
Este commit está contenido en:
Madsen, Jonathan
2025-02-18 10:44:37 -06:00
cometido por GitHub
padre fd99654433
commit 470f347e50
Se han modificado 17 ficheros con 270 adiciones y 140 borrados
+64 -8
Ver fichero
@@ -77,6 +77,7 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <thread>
#include <unordered_set>
#include <vector>
@@ -101,6 +102,49 @@ namespace
{
namespace fs = ::rocprofiler::common::filesystem;
bool
resolved_exists(std::string_view fname)
{
if(fs::is_symlink(fname))
{
// NOTE: Use of ROCP_CI_LOG(WARNING) causes segfault. Likely bc glog is not fully
// initialized
auto _errc = std::error_code{};
auto _symlinked = fs::read_symlink(fname, _errc);
if(_errc && _symlinked.empty())
{
ROCP_WARNING << fmt::format("Symbolic link '{}' returned error code {} :: {}",
fname,
_errc.value(),
_errc.message());
return false;
}
else if(_errc && !_symlinked.empty())
{
ROCP_WARNING << fmt::format("Symbolic link '{}' -> '{}' returned error code {} :: {}",
fname,
_symlinked.string(),
_errc.value(),
_errc.message());
return false;
}
if(_symlinked.is_relative()) _symlinked = fs::path{fname}.parent_path() / _symlinked;
ROCP_TRACE << fmt::format("Symbolic link:\n\t{}\n\t\t-> {}", fname, _symlinked.string());
if(!fs::exists(_symlinked))
{
ROCP_WARNING << fmt::format("{} is broken symbolic link", fname);
return false;
}
return resolved_exists(fs::absolute(_symlinked).string());
}
return fs::exists(fname);
}
// invoke all rocprofiler_configure symbols
bool
invoke_client_configures();
@@ -257,14 +301,17 @@ find_clients()
{
ROCP_INFO << "[ROCP_TOOL_LIBRARIES] searching " << itr << " for rocprofiler_configure";
if(fs::exists(itr))
if(fs::exists(itr) && resolved_exists(itr))
{
auto elfinfo = common::elf_utils::read(itr);
if(!elfinfo.has_symbol(std::regex{"^rocprofiler_configure$"}))
{
ROCP_FATAL << "[ROCP_TOOL_LIBRARIES] rocprofiler-sdk tool library '" << itr
<< "' did not contain rocprofiler_configure symbol (search method: "
"ELF parsing)";
ROCP_CI_LOG(WARNING) << fmt::format(
"[ROCP_TOOL_LIBRARIES] rocprofiler-sdk tool library '{}' did not "
"contain rocprofiler_configure symbol (search method: ELF parsing). "
"Attempting dlopen anyway since the library was explicitly listed in "
"ROCP_TOOL_LIBRARIES",
itr);
}
}
@@ -295,10 +342,10 @@ find_clients()
{
auto _sym = rocprofiler_configure_dlsym(handle);
// FATAL bc they explicitly said this was a tool library
ROCP_FATAL_IF(!_sym)
ROCP_CI_LOG_IF(WARNING, !_sym)
<< "[ROCP_TOOL_LIBRARIES] rocprofiler-sdk tool library '" << itr
<< "' did not contain rocprofiler_configure symbol (search method: dlsym)";
if(is_unique_configure_func(_sym)) emplace_client(itr, handle, _sym);
if(_sym && is_unique_configure_func(_sym)) emplace_client(itr, handle, _sym);
}
}
}
@@ -323,13 +370,22 @@ find_clients()
{
ROCP_INFO << "searching " << itr << " for rocprofiler_configure";
if(fs::exists(itr))
if(fs::exists(itr) && resolved_exists(itr))
{
auto elfinfo = common::elf_utils::read(itr);
if(!elfinfo.has_symbol(std::regex{"^rocprofiler_configure$"})) continue;
if(!elfinfo.has_symbol(std::regex{"^rocprofiler_configure$"}))
{
ROCP_INFO << fmt::format(
"Shared library '{}' did not contain the 'rocprofiler_configure' symbol "
"(search method: ELF parsing) required by rocprofiler-sdk for tools",
itr);
continue;
}
}
else
{
ROCP_INFO << fmt::format(
"Shared library '{}' either does not exist or is a broken symbolic link", itr);
continue;
}