Fix path to post-processing merge script (#187)
- Path to merge script not found unless user explicitly sources "share/rocprofiler-systems/setup-env.sh" to setup PATHs.
- Instead, let's derive the path when the application loads and use it when executing the helper script
- Rename script to rocprof-sys-merge-output.sh.
- Change install folder to <prefix>/libexec/rocprofiler-systems based on dev-ops feedback.
- Updated PATH variable in the modulefile and source scrtipt.
- For SWDEV-528101
[ROCm/rocprofiler-systems commit: adc66956b0]
This commit is contained in:
committed by
GitHub
orang tua
31dc2414e3
melakukan
6fe19b681a
@@ -371,7 +371,7 @@ configure_file(
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/scripts/merge-multiprocess-output.sh
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/bin/merge-multiprocess-output.sh
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}/rocprof-sys-merge-output.sh
|
||||
COPYONLY)
|
||||
|
||||
install(
|
||||
@@ -393,8 +393,8 @@ install(
|
||||
|
||||
install(
|
||||
PROGRAMS
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/bin/merge-multiprocess-output.sh
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/bin/
|
||||
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}/rocprof-sys-merge-output.sh
|
||||
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}
|
||||
COMPONENT setup)
|
||||
|
||||
# ------------------------------------------------------------------------------#
|
||||
|
||||
@@ -11,7 +11,7 @@ set ROOT [file normalize [file dirname [file normalize ${ModulesCurrentModulefil
|
||||
setenv @PROJECT_NAME_UNDERSCORED@_ROOT "${ROOT}"
|
||||
prepend-path CMAKE_PREFIX_PATH "${ROOT}"
|
||||
prepend-path PATH "${ROOT}/bin"
|
||||
prepend-path PATH "${ROOT}/@CMAKE_INSTALL_DATAROOTDIR@/@PROJECT_NAME@/bin"
|
||||
prepend-path PATH "${ROOT}/@CMAKE_INSTALL_LIBEXECDIR@/@PROJECT_NAME@"
|
||||
prepend-path LD_LIBRARY_PATH "${ROOT}/@CMAKE_INSTALL_LIBDIR@"
|
||||
prepend-path PYTHONPATH "${ROOT}/@CMAKE_INSTALL_PYTHONDIR@"
|
||||
setenv @PROJECT_NAME_UNDERSCORED@_DIR "${ROOT}/@CMAKE_INSTALL_DATAROOTDIR@/cmake/@PROJECT_NAME@"
|
||||
|
||||
@@ -15,7 +15,7 @@ fi
|
||||
|
||||
@PROJECT_NAME_UNDERSCORED@_ROOT=${BASEDIR}
|
||||
PATH=${BASEDIR}/bin:${PATH}
|
||||
PATH=${BASEDIR}/@CMAKE_INSTALL_DATAROOTDIR@/@PROJECT_NAME@/bin:${PATH}
|
||||
PATH=${BASEDIR}/@CMAKE_INSTALL_LIBEXECDIR@/@PROJECT_NAME@:${PATH}
|
||||
LD_LIBRARY_PATH=${BASEDIR}/@CMAKE_INSTALL_LIBDIR@:${LD_LIBRARY_PATH}
|
||||
PYTHONPATH=${BASEDIR}/@CMAKE_INSTALL_PYTHONDIR@:${PYTHONPATH}
|
||||
CMAKE_PREFIX_PATH=${BASEDIR}:${CMAKE_PREFIX_PATH}
|
||||
|
||||
@@ -246,6 +246,7 @@ prepare_environment_for_run(std::vector<char*>& _env)
|
||||
join(":", LIBPTHREAD_SO,
|
||||
get_realpath(get_internal_libpath("librocprof-sys-dl.so"))),
|
||||
true);
|
||||
update_env(_env, "ROCPROFSYS_SCRIPT_DIR", get_internal_script_path());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +260,20 @@ get_internal_libpath(const std::string& _lib)
|
||||
return rocprofsys::common::join("/", _dir, "..", "lib", _lib);
|
||||
}
|
||||
|
||||
std::string
|
||||
get_internal_script_path(void)
|
||||
{
|
||||
auto _exe = std::string_view{ realpath("/proc/self/exe", nullptr) };
|
||||
auto _pos = _exe.find_last_of('/');
|
||||
auto _dir = std::string{ "./" };
|
||||
if(_pos != std::string_view::npos) _dir = _exe.substr(0, _pos);
|
||||
|
||||
auto _script_dir = get_realpath(
|
||||
rocprofsys::common::join("/", _dir, "..", "libexec", "rocprofiler-systems"));
|
||||
|
||||
return _script_dir;
|
||||
}
|
||||
|
||||
void
|
||||
print_updated_environment(std::vector<char*> _env, std::string_view _prefix)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,9 @@ prepare_environment_for_run(std::vector<char*>&);
|
||||
std::string
|
||||
get_internal_libpath(const std::string& _lib);
|
||||
|
||||
std::string
|
||||
get_internal_script_path(void);
|
||||
|
||||
template <typename Tp>
|
||||
void
|
||||
update_env(std::vector<char*>&, std::string_view, Tp&&, bool _append = false,
|
||||
|
||||
+9
-1
@@ -352,8 +352,14 @@ main(int argc, char** argv)
|
||||
lib_search_paths.emplace_back(
|
||||
JOIN('/', _omni_lib_path, "rocprofiler-systems", "lib64"));
|
||||
|
||||
auto _omni_internal_libexec_path =
|
||||
JOIN('/', filepath::dirname(filepath::dirname(_omni_exe_path)), "libexec",
|
||||
"rocprofiler-systems");
|
||||
|
||||
ROCPROFSYS_ADD_LOG_ENTRY(argv[0], "::", "rocprofsys bin path: ", _omni_exe_path);
|
||||
ROCPROFSYS_ADD_LOG_ENTRY(argv[0], "::", "rocprofsys lib path: ", _omni_lib_path);
|
||||
ROCPROFSYS_ADD_LOG_ENTRY(
|
||||
argv[0], "::", "rocprofsys libexec path: ", _omni_internal_libexec_path);
|
||||
|
||||
for(const auto& itr : rocprofsys_get_link_map(nullptr))
|
||||
{
|
||||
@@ -1442,7 +1448,6 @@ main(int argc, char** argv)
|
||||
env_vars.emplace_back(TIMEMORY_JOIN('=', "ROCPROFSYS_MPI_FINALIZE", "OFF"));
|
||||
env_vars.emplace_back(TIMEMORY_JOIN('=', "ROCPROFSYS_USE_CODE_COVERAGE",
|
||||
(coverage_mode != CODECOV_NONE) ? "ON" : "OFF"));
|
||||
|
||||
addr_space = rocprofsys_get_address_space(bpatch, _cmdc, _cmdv, env_vars,
|
||||
binary_rewrite, _pid, mutname);
|
||||
|
||||
@@ -1970,6 +1975,9 @@ main(int argc, char** argv)
|
||||
(binary_rewrite && use_mpi) ? "ON" : "OFF"));
|
||||
if(use_mpi) env_vars.emplace_back(TIMEMORY_JOIN('=', "ROCPROFSYS_USE_PID", "ON"));
|
||||
|
||||
env_vars.emplace_back(
|
||||
TIMEMORY_JOIN('=', "ROCPROFSYS_SCRIPT_PATH", _omni_internal_libexec_path));
|
||||
|
||||
for(auto& itr : env_vars)
|
||||
{
|
||||
auto _pos = itr.find('=');
|
||||
|
||||
@@ -124,9 +124,11 @@ get_initial_environment()
|
||||
|
||||
auto _dl_libpath = get_realpath(get_internal_libpath("librocprof-sys-dl.so"));
|
||||
auto _omni_libpath = get_realpath(get_internal_libpath("librocprof-sys.so"));
|
||||
auto _libexecpath = get_realpath(get_internal_script_path());
|
||||
|
||||
update_env(_env, "LD_PRELOAD", _dl_libpath, UPD_APPEND);
|
||||
update_env(_env, "LD_LIBRARY_PATH", tim::filepath::dirname(_dl_libpath), UPD_APPEND);
|
||||
update_env(_env, "ROCPROFSYS_SCRIPT_PATH", _libexecpath, UPD_REPLACE);
|
||||
|
||||
auto _mode = get_env<std::string>("ROCPROFSYS_MODE", "sampling", false);
|
||||
|
||||
@@ -136,7 +138,6 @@ get_initial_environment()
|
||||
if(!getenv("OMP_TOOL_LIBRARIES"))
|
||||
update_env(_env, "OMP_TOOL_LIBRARIES", _dl_libpath, UPD_APPEND);
|
||||
#endif
|
||||
|
||||
return _env;
|
||||
}
|
||||
|
||||
@@ -150,6 +151,20 @@ get_internal_libpath(const std::string& _lib)
|
||||
return rocprofsys::common::join("/", _dir, "..", "lib", _lib);
|
||||
}
|
||||
|
||||
std::string
|
||||
get_internal_script_path(void)
|
||||
{
|
||||
auto _exe = std::string_view{ realpath("/proc/self/exe", nullptr) };
|
||||
auto _pos = _exe.find_last_of('/');
|
||||
auto _dir = std::string{ "./" };
|
||||
if(_pos != std::string_view::npos) _dir = _exe.substr(0, _pos);
|
||||
|
||||
auto _script_dir =
|
||||
rocprofsys::common::join("/", _dir, "..", "libexec", "rocprofiler-systems");
|
||||
|
||||
return _script_dir;
|
||||
}
|
||||
|
||||
void
|
||||
print_updated_environment(std::vector<char*> _env)
|
||||
{
|
||||
|
||||
@@ -49,6 +49,9 @@ get_initial_environment();
|
||||
std::string
|
||||
get_internal_libpath(const std::string& _lib);
|
||||
|
||||
std::string
|
||||
get_internal_script_path(void);
|
||||
|
||||
template <typename Tp>
|
||||
void
|
||||
update_env(std::vector<char*>& _environ, std::string_view _env_var, Tp&& _env_val,
|
||||
|
||||
@@ -174,6 +174,20 @@ get_internal_libpath(const std::string& _lib)
|
||||
return filepath::realpath(rocprofsys::common::join("/", _dir, "..", "lib", _lib),
|
||||
nullptr, false);
|
||||
}
|
||||
std::string
|
||||
get_internal_script_path(void)
|
||||
{
|
||||
auto _exe = std::string_view{ realpath("/proc/self/exe", nullptr) };
|
||||
auto _pos = _exe.find_last_of('/');
|
||||
auto _dir = std::string{ "./" };
|
||||
if(_pos != std::string_view::npos) _dir = _exe.substr(0, _pos);
|
||||
|
||||
auto _script_dir =
|
||||
rocprofsys::common::join("/", _dir, "..", "libexec", "rocprofiler-systems");
|
||||
|
||||
return _script_dir;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool
|
||||
@@ -222,6 +236,9 @@ init_parser(parser_data& _data)
|
||||
_data.dl_libpath = get_realpath(get_internal_libpath("librocprof-sys-dl.so").c_str());
|
||||
_data.omni_libpath = get_realpath(get_internal_libpath("librocprof-sys.so").c_str());
|
||||
|
||||
auto _libexecpath = get_realpath(get_internal_script_path());
|
||||
update_env(_data, "ROCPROFSYS_SCRIPT_PATH", _libexecpath, UPD_REPLACE);
|
||||
|
||||
#if defined(ROCPROFSYS_USE_OMPT)
|
||||
if(!getenv("OMP_TOOL_LIBRARIES"))
|
||||
update_env(_data, "OMP_TOOL_LIBRARIES", _data.dl_libpath, UPD_PREPEND);
|
||||
|
||||
@@ -263,25 +263,6 @@ post_process(tim::manager* _timemory_manager, bool& _perfetto_output_error)
|
||||
_timemory_manager->add_file_output("protobuf", "perfetto", _filename);
|
||||
}
|
||||
ofs.close();
|
||||
|
||||
if(dmp::rank() == 0)
|
||||
{
|
||||
const char* file_path = _filename.c_str();
|
||||
auto folder_path = [](std::string_view _v) {
|
||||
return tim::filepath::dirname(std::string(_v));
|
||||
};
|
||||
// Execute the merge script
|
||||
std::string command =
|
||||
"merge-multiprocess-output.sh '" + folder_path(file_path) + "'";
|
||||
int result = system(command.c_str());
|
||||
if(result != 0)
|
||||
{
|
||||
ROCPROFSYS_VERBOSE(0,
|
||||
"Failed to execute merge-multiprocess-output.sh with "
|
||||
"folder path: %s\n",
|
||||
folder_path(file_path).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(dmp::rank() == 0)
|
||||
{
|
||||
@@ -290,6 +271,41 @@ post_process(tim::manager* _timemory_manager, bool& _perfetto_output_error)
|
||||
_filename.c_str());
|
||||
}
|
||||
|
||||
// Merge the output files, if rank 0
|
||||
if(dmp::rank() == 0)
|
||||
{
|
||||
auto _output_folder = filepath::dirname(_filename);
|
||||
auto _script_path = std::string{ "rocprof-sys-merge-output.sh" };
|
||||
auto _script_dir = get_env("ROCPROFSYS_SCRIPT_PATH", std::string{}, false);
|
||||
|
||||
if(!_script_dir.empty())
|
||||
{
|
||||
_script_path = rocprofsys::common::join("/", _script_dir, _script_path);
|
||||
}
|
||||
|
||||
// Test that the script exists
|
||||
if(!filepath::exists(_script_path))
|
||||
{
|
||||
ROCPROFSYS_VERBOSE(0, "Script not found: %s\n", _script_path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
auto _command = _script_path + " '" + _output_folder + "'";
|
||||
|
||||
// Execute the merge script
|
||||
int result = system(_command.c_str());
|
||||
|
||||
if(result != 0)
|
||||
{
|
||||
ROCPROFSYS_VERBOSE(0, "Failed to execute: %s\n", _command.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
ROCPROFSYS_VERBOSE(0, "Successfully executed: %s\n", _command.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto& _tmp_file = get_perfetto_tmp_file();
|
||||
if(_tmp_file)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user