Add ROCPROFSYS_PATH variable to environment (#1103)

* Add ROCPROFSYS_ROOT to the env for sample

* Add env for causal

* Add env for instrument

* Check for null and address memory leak

Signed-off-by: David Galiffi <David.Galiffi@amd.com>

---------

Signed-off-by: David Galiffi <David.Galiffi@amd.com>
Этот коммит содержится в:
David Galiffi
2025-09-24 13:52:34 -04:00
коммит произвёл GitHub
родитель 8912930840
Коммит 4d959460e1
5 изменённых файлов: 72 добавлений и 42 удалений
+21 -14
Просмотреть файл
@@ -247,31 +247,38 @@ prepare_environment_for_run(std::vector<char*>& _env)
get_realpath(get_internal_libpath("librocprof-sys-dl.so"))),
true);
update_env(_env, "ROCPROFSYS_SCRIPT_DIR", get_internal_script_path());
update_env(_env, "ROCPROFSYS_ROOT", get_rocprofsys_root());
}
}
std::string
get_rocprofsys_root(void)
{
char* _tmp = realpath("/proc/self/exe", nullptr);
std::string _exe = (_tmp) ? std::string{ _tmp } : std::string{};
if(_tmp) free(_tmp);
auto _pos = _exe.find_last_of('/');
auto _dir = std::string{ "./" };
if(_pos != std::string::npos) _dir = _exe.substr(0, _pos);
return rocprofsys::common::join("/", _dir, "..");
}
std::string
get_internal_libpath(const std::string& _lib)
{
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);
return rocprofsys::common::join("/", _dir, "..", "lib", _lib);
auto _root = get_rocprofsys_root();
return rocprofsys::common::join("/", _root, "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;
auto _root = get_rocprofsys_root();
return rocprofsys::common::join("/", _root, "libexec", "rocprofiler-systems");
}
void
+3
Просмотреть файл
@@ -52,6 +52,9 @@ prepare_command_for_run(char*, std::vector<char*>&);
void
prepare_environment_for_run(std::vector<char*>&);
std::string
get_rocprofsys_root(void);
std::string
get_internal_libpath(const std::string& _lib);
+21 -13
Просмотреть файл
@@ -125,7 +125,9 @@ 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());
auto _rootpath = get_realpath(get_rocprofsys_root());
update_env(_env, "ROCPROFSYS_ROOT", _rootpath, UPD_REPLACE);
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);
@@ -138,27 +140,33 @@ get_initial_environment()
}
std::string
get_internal_libpath(const std::string& _lib)
get_rocprofsys_root(void)
{
auto _exe = std::string_view{ realpath("/proc/self/exe", nullptr) };
char* _tmp = realpath("/proc/self/exe", nullptr);
std::string _exe = (_tmp) ? std::string{ _tmp } : std::string{};
if(_tmp) free(_tmp);
auto _pos = _exe.find_last_of('/');
auto _dir = std::string{ "./" };
if(_pos != std::string_view::npos) _dir = _exe.substr(0, _pos);
return rocprofsys::common::join("/", _dir, "..", "lib", _lib);
if(_pos != std::string::npos) _dir = _exe.substr(0, _pos);
return rocprofsys::common::join("/", _dir, "..");
}
std::string
get_internal_libpath(const std::string& _lib)
{
auto _root = get_rocprofsys_root();
return rocprofsys::common::join("/", _root, "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;
auto _root = get_rocprofsys_root();
return rocprofsys::common::join("/", _root, "libexec", "rocprofiler-systems");
}
void
+3
Просмотреть файл
@@ -46,6 +46,9 @@ print_updated_environment(std::vector<char*> _env);
std::vector<char*>
get_initial_environment();
std::string
get_rocprofsys_root(void);
std::string
get_internal_libpath(const std::string& _lib);
+24 -15
Просмотреть файл
@@ -164,28 +164,34 @@ remove_env(parser_data& _data, std::string_view _env_var)
}
}
std::string
get_rocprofsys_root(void)
{
char* _tmp = realpath("/proc/self/exe", nullptr);
std::string _exe = (_tmp) ? std::string{ _tmp } : std::string{};
if(_tmp) free(_tmp);
auto _pos = _exe.find_last_of('/');
auto _dir = std::string{ "./" };
if(_pos != std::string::npos) _dir = _exe.substr(0, _pos);
return rocprofsys::common::join("/", _dir, "..");
}
std::string
get_internal_libpath(const std::string& _lib)
{
auto _exe = filepath::realpath("/proc/self/exe", nullptr, false);
auto _pos = _exe.find_last_of('/');
auto _dir = filepath::get_cwd();
if(_pos != std::string_view::npos) _dir = _exe.substr(0, _pos);
return filepath::realpath(rocprofsys::common::join("/", _dir, "..", "lib", _lib),
nullptr, false);
auto _root = get_rocprofsys_root();
return rocprofsys::common::join("/", _root, "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;
auto _root = get_rocprofsys_root();
return rocprofsys::common::join("/", _root, "libexec", "rocprofiler-systems");
}
} // namespace
@@ -239,6 +245,9 @@ init_parser(parser_data& _data)
auto _libexecpath = get_realpath(get_internal_script_path());
update_env(_data, "ROCPROFSYS_SCRIPT_PATH", _libexecpath, UPD_REPLACE);
auto _rootpath = get_realpath(get_rocprofsys_root());
update_env(_data, "ROCPROFSYS_ROOT", _rootpath, UPD_REPLACE);
return _data;
}