Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "common/preset_registry.hpp"

#include "common/env_vars.hpp"
#include "common/path.hpp"
#include "embedded_presets.hpp"

#include <spdlog/fmt/fmt.h>
Expand All @@ -28,21 +29,21 @@ find_preset_directory()
if(preset_dir_env && std::strlen(preset_dir_env) > 0)
{
auto dir = std::string{ preset_dir_env };
if(common::path::exists(dir)) return dir;
if(path::is_directory(dir)) return dir;
}

auto root = common::path::get_rocprofsys_root();
if(!root.empty())
{
auto candidate = fmt::format("{}/share/rocprofiler-systems/presets", root);
if(common::path::exists(candidate)) return candidate;
if(path::is_directory(candidate)) return candidate;
}

const auto* rocm_path = std::getenv("ROCM_PATH");
if(rocm_path && std::strlen(rocm_path) > 0)
{
auto candidate = fmt::format("{}/share/rocprofiler-systems/presets", rocm_path);
if(common::path::exists(candidate)) return candidate;
if(path::is_directory(candidate)) return candidate;
}

return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <array>
#include <string>
#include <string_view>
#include <sys/stat.h>
#include <unordered_map>

using settings = ::tim::settings;
Expand Down Expand Up @@ -407,17 +406,6 @@ remove(std::string inp, const std::set<std::string>& entries)

//--------------------------------------------------------------------------------------//

bool
file_exists(const std::string& _fname)
{
struct stat _buffer;
if(stat(_fname.c_str(), &_buffer) == 0)
return (S_ISREG(_buffer.st_mode) != 0 || S_ISLNK(_buffer.st_mode) != 0);
return false;
}

//--------------------------------------------------------------------------------------//

namespace
{
constexpr std::string_view _rocm_op_prefix = "ROCPROFSYS_ROCM_";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ dump_log_abort(int _v);
std::string
remove(std::string inp, const std::set<std::string>& entries);

bool
file_exists(const std::string&);

// ROCm operation-list settings follow the env-var shape
// ROCPROFSYS_ROCM_<DOMAIN>_OPERATIONS. These helpers are the single source of
// truth for that mapping; do not reconstruct the prefix/suffix elsewhere.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common/env_vars.hpp"
#include "common/environment.hpp"
#include "common/json_config.hpp"
#include "common/path.hpp"

#include <nlohmann/json.hpp>
#include <spdlog/fmt/fmt.h>
Expand Down Expand Up @@ -251,7 +252,7 @@ generate_config(std::string _config_file, const std::set<std::string>& _config_f
auto _open = [&_nout, &fmt_opts](std::ofstream& _ofs, const std::string& _fname,
const std::string& _type) -> std::ofstream& {
++_nout;
if(file_exists(_fname))
if(rocprofsys::path::is_regular_file(_fname))
{
if(fmt_opts.force_config)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ parse_args(int argc, char** argv, std::vector<std::string>& _env,
_generate_configs = true;
auto _dir = p.get<std::string>("generate-configs");
if(!_dir.empty()) _config_folder = std::move(_dir);
if(!filepath::exists(_config_folder)) filepath::makedir(_config_folder);
if(!path::is_directory(_config_folder)) filepath::makedir(_config_folder);
});
parser
.add_argument({ "--no-defaults" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <timemory/components/timing/wall_clock.hpp>
#include <timemory/environment/types.hpp>
#include <timemory/log/macros.hpp>
#include <timemory/utility/filepath.hpp>
#include <timemory/utility/types.hpp>

#include <algorithm>
Expand All @@ -34,7 +33,6 @@

namespace
{
namespace filepath = ::tim::filepath;
using rocprofsys::get_env;
using strview_init_t = std::initializer_list<std::string_view>;
using strview_set_t = std::set<std::string_view>;
Expand Down Expand Up @@ -415,15 +413,16 @@ get_internal_libs_data_impl()
{ "librocprof-sys-dl.so", "librocprof-sys-user.so", "librocprof-sys-rt.so" })
{
auto libpath = fmt::format("{}/{}/{}", rocprofsys_root, lib_dir, lib_fname);
if(filepath::exists(libpath))
if(rocprofsys::path::is_regular_file(libpath))
{
_libs.emplace_back(rocprofsys::path::realpath(libpath));
}
}
}

rocprofsys::utility::filter_sort_unique(
_libs, [](const auto& itr) { return itr.empty() || !filepath::exists(itr); });
rocprofsys::utility::filter_sort_unique(_libs, [](const auto& itr) {
return itr.empty() || !rocprofsys::path::is_regular_file(itr);
});

auto _data = library_module_map_t{};
for(const auto& itr : _libs)
Expand Down Expand Up @@ -527,7 +526,10 @@ find_library(std::string_view _lib_v)
for(const auto& itr : get_library_search_paths())
{
auto _path = fmt::format("{}/{}", itr, _lib_v);
if(filepath::exists(_path)) return std::optional<std::string>{ _path };
if(rocprofsys::path::is_regular_file(_path))
{
return std::optional<std::string>{ _path };
}
}

return std::optional<std::string>{};
Expand All @@ -544,7 +546,10 @@ find_libraries(std::string_view _lib_v)
for(const auto& itr : get_library_search_paths())
{
auto _path = fmt::format("{}/{}", itr, _lib_v);
if(filepath::exists(_path)) _libs.emplace_back(_path);
if(rocprofsys::path::is_regular_file(_path))
{
_libs.emplace_back(_path);
}
}

return _libs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,8 @@ get_absolute_exe_filepath(std::string exe_name);
std::string
get_absolute_lib_filepath(std::string lib_name);

bool
exists(const std::string& name);

bool
is_file(std::string _name);
std::string
absolute(std::string _path);

std::string
get_cwd();
Expand Down Expand Up @@ -292,7 +289,8 @@ main(int argc, char** argv)
auto rocprofsys_root_from_env = rocprofsys::get_env<std::string>(
"rocprofiler_systems_ROOT",
rocprofsys::get_env<std::string>(rocprofsys::env_vars::ROOT, ""));
if(!rocprofsys_root_from_env.empty() && exists(rocprofsys_root_from_env))
if(!rocprofsys_root_from_env.empty() &&
path::is_directory(absolute(rocprofsys_root_from_env)))
{
bin_search_paths.emplace_back(rocprofsys_root_from_env + "/bin");
bin_search_paths.emplace_back(rocprofsys_root_from_env +
Expand All @@ -312,7 +310,7 @@ main(int argc, char** argv)
}

auto _rocprofsys_exe_filepath = path::realpath(get_absolute_exe_filepath(argv[0]));
if(!exists(_rocprofsys_exe_filepath))
if(!path::is_regular_file(absolute(_rocprofsys_exe_filepath)))
_rocprofsys_exe_filepath =
path::realpath(get_absolute_exe_filepath(rocprofsys_get_exe_realpath()));
bin_search_paths.emplace_back(path::parent_path(_rocprofsys_exe_filepath));
Expand Down Expand Up @@ -2765,20 +2763,23 @@ absolute(std::string _path)
std::string
get_absolute_filepath(std::string _name, const strvec_t& _search_paths)
{
if(!_name.empty() && (!exists(_name) || !is_file(_name)))
if(!_name.empty() && !path::is_regular_file(absolute(_name)))
{
auto _orig = _name;
for(auto itr : _search_paths)
{
if(!path::is_directory(itr) || is_file(itr)) itr = path::parent_path(itr);
if(!path::is_directory(itr))
{
itr = path::parent_path(itr);
}

auto _exists = false;
ROCPROFSYS_ADD_LOG_ENTRY("searching", itr, "for", _name);
for(const auto& pitr :
{ absolute(fmt::format("{}/{}", itr, _name)),
absolute(fmt::format("{}/{}", itr, path::filename(_name))) })
{
_exists = exists(pitr) && is_file(pitr);
_exists = path::is_regular_file(pitr);
if(_exists)
{
_name = pitr;
Expand All @@ -2790,7 +2791,7 @@ get_absolute_filepath(std::string _name, const strvec_t& _search_paths)
if(_exists) break;
}

if(!exists(_name))
if(!path::is_regular_file(absolute(_name)))
{
auto _search_paths_v = fmt::format("{}", fmt::join(bin_search_paths, ", "));
verbprintf(
Expand Down Expand Up @@ -2843,7 +2844,7 @@ get_absolute_lib_filepath(std::string lib_name)
{
auto _orig_name = lib_name;
lib_name = get_absolute_filepath(std::move(lib_name), lib_search_paths);
if(_orig_name == lib_name && !exists(lib_name) &&
if(_orig_name == lib_name && !path::is_regular_file(absolute(lib_name)) &&
lib_name.find(".so") == std::string::npos &&
lib_name.find(".a") == std::string::npos)
{
Expand All @@ -2852,20 +2853,6 @@ get_absolute_lib_filepath(std::string lib_name)
return lib_name;
}

bool
exists(const std::string& name)
{
return filepath::exists(absolute(name));
}

bool
is_file(std::string _name)
{
_name = path::realpath(_name);
struct stat buffer;
return (stat(_name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode) != 0);
}

std::string
get_cwd()
{
Expand Down Expand Up @@ -2895,10 +2882,10 @@ find_dyn_api_rt()
rocprofsys::get_env<std::string>("DYNINSTAPI_RT_LIB", _dyn_api_rt_base + ".so");
auto _dyn_api_rt_abs = get_absolute_lib_filepath(_dyn_api_rt_env);

if(!exists(_dyn_api_rt_abs))
if(!path::is_regular_file(absolute(_dyn_api_rt_abs)))
_dyn_api_rt_abs = get_absolute_lib_filepath(_dyn_api_rt_base + ".a");

if(exists(_dyn_api_rt_abs))
if(path::is_regular_file(absolute(_dyn_api_rt_abs)))
{
rocprofsys::set_env<string_t>("DYNINSTAPI_RT_LIB", _dyn_api_rt_abs, 1);
rocprofsys::set_env<string_t>("DYNINST_REWRITER_PATHS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include "common/path.hpp"
#include "core/common_types.hpp"
#include "core/demangler.hpp"
#include "function_signature.hpp"
Expand All @@ -12,7 +13,6 @@
#include "module_function.hpp"

#include <spdlog/fmt/ranges.h>
#include <timemory/utility/filepath.hpp>

#include <dlfcn.h>
#include <string>
Expand Down Expand Up @@ -130,13 +130,13 @@ struct rocprofsys_snippet_vec
//======================================================================================//
//
static inline bool
rocprofsys_get_is_executable(std::string_view _cmd, bool _default_v)
rocprofsys_get_is_executable(const std::string& _cmd, bool _default_v)
{
bool _is_executable = _default_v;

if(_cmd.empty())
if(!_cmd.empty())
{
if(!tim::filepath::exists(std::string{ _cmd }))
if(!rocprofsys::path::is_regular_file(_cmd))
{
verbprintf(
0,
Expand Down
5 changes: 2 additions & 3 deletions projects/rocprofiler-systems/source/lib/binary/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <timemory/unwind/bfd.hpp>
#include <timemory/unwind/dlinfo.hpp>
#include <timemory/unwind/types.hpp>
#include <timemory/utility/filepath.hpp>
#include <timemory/utility/procfs/maps.hpp>

#include "logger/debug.hpp"
Expand Down Expand Up @@ -138,7 +137,7 @@ get_binary_info(const std::vector<std::string>& _files,
auto _filter = [&_satisfies_binary_filter](const procfs::maps& _v) {
if(_v.pathname.empty()) return false;
auto _path = path::realpath(_v.pathname);
return (filepath::exists(_path) && _satisfies_binary_filter(_path));
return (path::is_regular_file(_path) && _satisfies_binary_filter(_path));
};

auto _data = std::vector<binary_info>{};
Expand All @@ -148,7 +147,7 @@ get_binary_info(const std::vector<std::string>& _files,
for(const auto& itr : _files)
{
auto _filename = path::realpath(itr);
if(filepath::exists(_filename) && _satisfies_binary_filter(_filename) &&
if(path::is_regular_file(_filename) && _satisfies_binary_filter(_filename) &&
_exists.find(_filename) == _exists.end())
{
_data.emplace_back(parse_line_info(_filename, _process_dwarf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
#include "logger/debug.hpp"
#include <spdlog/fmt/fmt.h>

#include <timemory/utility/filepath.hpp>

#include <algorithm>
#include <array>
#include <cctype>
#include <charconv>
#include <cstdint>
#include <cstdio>
#include <optional>
Comment thread
lloginov-amd marked this conversation as resolved.
Resolved
#include <set>
#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -484,7 +483,7 @@ discover_llvm_libdir_for_ompt()

auto has_libomptarget = [](const std::string& dir) {
const std::string so = dir + "/libomptarget.so";
return ::tim::filepath::exists(so);
return path::is_regular_file(so);
};

// Pick the first candidate that contains libomptarget.so
Expand Down
Loading
Loading