diff --git a/projects/rocprofiler-register/.gitmodules b/projects/rocprofiler-register/.gitmodules new file mode 100644 index 0000000000..687f5afc05 --- /dev/null +++ b/projects/rocprofiler-register/.gitmodules @@ -0,0 +1,6 @@ +[submodule "external/glog"] + path = external/glog + url = https://github.com/google/glog.git +[submodule "external/fmt"] + path = external/fmt + url = https://github.com/fmtlib/fmt.git diff --git a/projects/rocprofiler-register/CMakeLists.txt b/projects/rocprofiler-register/CMakeLists.txt index ef4e70fe66..699529b6fa 100644 --- a/projects/rocprofiler-register/CMakeLists.txt +++ b/projects/rocprofiler-register/CMakeLists.txt @@ -93,6 +93,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR enable_testing() include(CTest) +add_subdirectory(external) add_subdirectory(source) if(ROCPROFILER_REGISTER_BUILD_TESTS) diff --git a/projects/rocprofiler-register/cmake/rocprofiler_register_formatting.cmake b/projects/rocprofiler-register/cmake/rocprofiler_register_formatting.cmake index ffc23f0243..05e3c74a4a 100644 --- a/projects/rocprofiler-register/cmake/rocprofiler_register_formatting.cmake +++ b/projects/rocprofiler-register/cmake/rocprofiler_register_formatting.cmake @@ -35,7 +35,8 @@ if(ROCPROFILER_REGISTER_CLANG_FORMAT_EXE set(rocp_source_files) set(rocp_header_files) set(rocp_python_files) - set(rocp_cmake_files ${PROJECT_SOURCE_DIR}/CMakeLists.txt) + set(rocp_cmake_files ${PROJECT_SOURCE_DIR}/CMakeLists.txt + ${PROJECT_SOURCE_DIR}/external/CMakeLists.txt) foreach(_DIR cmake samples source tests) foreach(_TYPE header_files source_files cmake_files python_files) @@ -96,7 +97,7 @@ if(ROCPROFILER_REGISTER_CLANG_FORMAT_EXE endif() endforeach() - foreach(_TYPE source python) + foreach(_TYPE source python cmake) if(TARGET format-rocprofiler-register-${_TYPE}) add_dependencies(format format-rocprofiler-register-${_TYPE}) endif() diff --git a/projects/rocprofiler-register/cmake/rocprofiler_register_linting.cmake b/projects/rocprofiler-register/cmake/rocprofiler_register_linting.cmake index 1a34218e6f..c8398bcd93 100644 --- a/projects/rocprofiler-register/cmake/rocprofiler_register_linting.cmake +++ b/projects/rocprofiler-register/cmake/rocprofiler_register_linting.cmake @@ -27,8 +27,10 @@ macro(ROCPROFILER_REGISTER_ACTIVATE_CLANG_TIDY) ) endif() - set(CMAKE_CXX_CLANG_TIDY ${ROCPROFILER_REGISTER_CLANG_TIDY_COMMAND} - -header-filter=${PROJECT_SOURCE_DIR}/.*) + set(CMAKE_CXX_CLANG_TIDY + ${ROCPROFILER_REGISTER_CLANG_TIDY_COMMAND} + -header-filter=${PROJECT_SOURCE_DIR}/source/.* + --warnings-as-errors=*,-misc-header-include-cycle) # Create a preprocessor definition that depends on .clang-tidy content so the # compile command will change when .clang-tidy changes. This ensures that a diff --git a/projects/rocprofiler-register/cmake/rocprofiler_register_options.cmake b/projects/rocprofiler-register/cmake/rocprofiler_register_options.cmake index e25debc4ae..65d2e0878e 100644 --- a/projects/rocprofiler-register/cmake/rocprofiler_register_options.cmake +++ b/projects/rocprofiler-register/cmake/rocprofiler_register_options.cmake @@ -29,6 +29,8 @@ rocprofiler_register_add_option(ROCPROFILER_REGISTER_ENABLE_CLANG_TIDY rocprofiler_register_add_option( ROCPROFILER_REGISTER_BUILD_DEVELOPER "Extra build flags for development like -Werror" ${ROCPROFILER_REGISTER_BUILD_CI} ADVANCED) +rocprofiler_register_add_option(ROCPROFILER_REGISTER_BUILD_GLOG "Build GLOG" ON) +rocprofiler_register_add_option(ROCPROFILER_REGISTER_BUILD_FMT "Build FMT" ON) # In the future, we will do this even with clang-tidy enabled if(ROCPROFILER_REGISTER_BUILD_CI AND NOT ROCPROFILER_REGISTER_ENABLE_CLANG_TIDY) diff --git a/projects/rocprofiler-register/external/CMakeLists.txt b/projects/rocprofiler-register/external/CMakeLists.txt new file mode 100644 index 0000000000..af77572f22 --- /dev/null +++ b/projects/rocprofiler-register/external/CMakeLists.txt @@ -0,0 +1,33 @@ +set(BUILD_TESTING OFF) + +if(ROCPROFILER_REGISTER_BUILD_GLOG) + # checkout submodule if not already checked out or clone repo if no .gitmodules file + rocprofiler_register_checkout_git_submodule( + RECURSIVE + RELATIVE_PATH glog + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + REPO_URL https://github.com/google/glog.git + REPO_BRANCH "master") + + # May want to use GFLAGS in the future + set(WITH_GFLAGS OFF) + set(BUILD_SHARED_LIBS OFF) + add_subdirectory(glog EXCLUDE_FROM_ALL) +else() + find_package(glog REQUIRED) +endif() + +if(ROCPROFILER_REGISTER_BUILD_FMT) + # checkout submodule if not already checked out or clone repo if no .gitmodules file + rocprofiler_register_checkout_git_submodule( + RECURSIVE + RELATIVE_PATH fmt + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + REPO_URL https://github.com/fmtlib/fmt.git + REPO_BRANCH "master") + + set(FMT_TEST OFF) + add_subdirectory(fmt EXCLUDE_FROM_ALL) +else() + find_package(fmt REQUIRED) +endif() diff --git a/projects/rocprofiler-register/external/fmt b/projects/rocprofiler-register/external/fmt new file mode 160000 index 0000000000..6c845f57e5 --- /dev/null +++ b/projects/rocprofiler-register/external/fmt @@ -0,0 +1 @@ +Subproject commit 6c845f57e5db589208ff0c2808238587cafafa82 diff --git a/projects/rocprofiler-register/external/glog b/projects/rocprofiler-register/external/glog new file mode 160000 index 0000000000..3a0d4d22c5 --- /dev/null +++ b/projects/rocprofiler-register/external/glog @@ -0,0 +1 @@ +Subproject commit 3a0d4d22c5ae0b9a2216988411cfa6bf860cc372 diff --git a/projects/rocprofiler-register/scripts/run-ci.py b/projects/rocprofiler-register/scripts/run-ci.py index f531a6c4c7..c4d9b4eb13 100755 --- a/projects/rocprofiler-register/scripts/run-ci.py +++ b/projects/rocprofiler-register/scripts/run-ci.py @@ -91,7 +91,7 @@ def generate_custom(args, cmake_args, ctest_args): set(CTEST_UPDATE_TYPE git) set(CTEST_UPDATE_VERSION_ONLY TRUE) set(CTEST_GIT_COMMAND {GIT_CMD}) - set(CTEST_GIT_INIT_SUBMODULES FALSE) + set(CTEST_GIT_INIT_SUBMODULES TRUE) set(CTEST_OUTPUT_ON_FAILURE TRUE) set(CTEST_USE_LAUNCHERS TRUE) diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/CMakeLists.txt b/projects/rocprofiler-register/source/lib/rocprofiler-register/CMakeLists.txt index f1464bad77..d2ce9959b8 100644 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/CMakeLists.txt +++ b/projects/rocprofiler-register/source/lib/rocprofiler-register/CMakeLists.txt @@ -20,8 +20,9 @@ target_include_directories( target_link_libraries( rocprofiler-register PUBLIC rocprofiler-register::headers - PRIVATE rocprofiler-register::build-flags rocprofiler-register::memcheck - rocprofiler-register::stdcxxfs rocprofiler-register::dl) + PRIVATE fmt::fmt-header-only glog::glog rocprofiler-register::build-flags + rocprofiler-register::memcheck rocprofiler-register::stdcxxfs + rocprofiler-register::dl) set_target_properties( rocprofiler-register diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/CMakeLists.txt b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/CMakeLists.txt index 19f7c15568..ef1160ec66 100644 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/CMakeLists.txt +++ b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/CMakeLists.txt @@ -3,8 +3,7 @@ # set(rocprofiler_register_details_sources dl.cpp utility.cpp) -set(rocprofiler_register_details_headers environment.hpp join.hpp dl.hpp log.hpp - utility.hpp) +set(rocprofiler_register_details_headers environment.hpp dl.hpp utility.hpp) target_sources(rocprofiler-register PRIVATE ${rocprofiler_register_details_sources} ${rocprofiler_register_details_headers}) diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/dl.cpp b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/dl.cpp index 3ae00a688e..5c45c4ec8b 100644 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/dl.cpp +++ b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/dl.cpp @@ -23,7 +23,6 @@ #define GNU_SOURCE 1 #include "dl.hpp" -#include "join.hpp" #include "utility.hpp" #include @@ -34,6 +33,7 @@ #include #include +#include #include #include #include @@ -54,7 +54,7 @@ std::vector get_segment_addresses(pid_t _pid) { auto _data = std::vector{}; - auto _fname = common::join('/', "/proc", _pid, "maps"); + auto _fname = fmt::format("/{}/{}/{}", "proc", _pid, "maps"); auto ifs = std::ifstream{ _fname }; if(!ifs) { diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/environment.hpp b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/environment.hpp index 03bcf47089..4250ed4de0 100644 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/environment.hpp +++ b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/environment.hpp @@ -20,7 +20,8 @@ #pragma once -#include "log.hpp" +#include "fmt/core.h" +#include "glog/logging.h" #include #include @@ -31,52 +32,6 @@ #include #include -#if !defined(ROCPROFILER_REGISTER_ENVIRON_LOG_NAME) -# if defined(ROCPROFILER_REGISTER_COMMON_LIBRARY_NAME) -# define ROCPROFILER_REGISTER_ENVIRON_LOG_NAME \ - "[" ROCPROFILER_REGISTER_COMMON_LIBRARY_NAME "]" -# else -# define ROCPROFILER_REGISTER_ENVIRON_LOG_NAME "[environ]" -# endif -#endif - -#if !defined(ROCPROFILER_REGISTER_ENVIRON_LOG_START) -# if defined(ROCPROFILER_REGISTER_COMMON_LIBRARY_LOG_START) -# define ROCPROFILER_REGISTER_ENVIRON_LOG_START \ - ROCPROFILER_REGISTER_COMMON_LIBRARY_LOG_START -# elif defined(ROCPROFILER_REGISTER_LOG_COLORS_AVAILABLE) -# define ROCPROFILER_REGISTER_ENVIRON_LOG_START \ - fprintf(stderr, "%s", ::rocprofiler_register::log::color::dmesg()); -# else -# define ROCPROFILER_REGISTER_ENVIRON_LOG_START -# endif -#endif - -#if !defined(ROCPROFILER_REGISTER_ENVIRON_LOG_END) -# if defined(ROCPROFILER_REGISTER_COMMON_LIBRARY_LOG_END) -# define ROCPROFILER_REGISTER_ENVIRON_LOG_END \ - ROCPROFILER_REGISTER_COMMON_LIBRARY_LOG_END -# elif defined(ROCPROFILER_REGISTER_LOG_COLORS_AVAILABLE) -# define ROCPROFILER_REGISTER_ENVIRON_LOG_END \ - fprintf(stderr, "%s", ::rocprofiler_register::log::color::end()); -# else -# define ROCPROFILER_REGISTER_ENVIRON_LOG_END -# endif -#endif - -#define ROCPROFILER_REGISTER_ENVIRON_LOG(CONDITION, ...) \ - if(CONDITION) \ - { \ - fflush(stderr); \ - ROCPROFILER_REGISTER_ENVIRON_LOG_START \ - fprintf(stderr, \ - "[rocprofiler-register]" ROCPROFILER_REGISTER_ENVIRON_LOG_NAME "[%i] ", \ - getpid()); \ - fprintf(stderr, __VA_ARGS__); \ - ROCPROFILER_REGISTER_ENVIRON_LOG_END \ - fflush(stderr); \ - } - namespace rocprofiler_register { namespace common @@ -110,14 +65,13 @@ get_env_impl(std::string_view env_id, int _default) return std::stoi(env_var); } catch(std::exception& _e) { - fprintf(stderr, - "[rocprofiler_register][get_env] Exception thrown converting " - "getenv(\"%s\") = " - "%s to integer :: %s. Using default value of %i\n", - env_id.data(), - env_var, - _e.what(), - _default); + LOG(ERROR) << fmt::format( + "[rocprofiler_register][get_env] Exception thrown converting getenv({}) " + "= {} to integer :: {}. Using default value of {}", + env_id.data(), + env_var, + _e.what(), + _default); } return _default; } @@ -176,14 +130,11 @@ struct env_config std::string env_value = {}; int override = 0; - auto operator()(bool _verbose = false) const + auto operator()() const { if(env_name.empty()) return -1; - ROCPROFILER_REGISTER_ENVIRON_LOG(_verbose, - "setenv(\"%s\", \"%s\", %i)\n", - env_name.c_str(), - env_value.c_str(), - override); + LOG(INFO) << fmt::format( + "setenv({}, {}, {})", env_name.c_str(), env_value.c_str(), override); return setenv(env_name.c_str(), env_value.c_str(), override); } }; diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/join.hpp b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/join.hpp deleted file mode 100644 index 0086560dcf..0000000000 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/join.hpp +++ /dev/null @@ -1,184 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include - -#if !defined(ROCPROFILER_REGISTER_FOLD_EXPRESSION) -# define ROCPROFILER_REGISTER_FOLD_EXPRESSION(...) ((__VA_ARGS__), ...) -#endif - -namespace rocprofiler_register -{ -namespace common -{ -namespace -{ -template -struct is_string_impl : std::false_type -{ }; - -template <> -struct is_string_impl : std::true_type -{ }; - -template <> -struct is_string_impl : std::true_type -{ }; - -template <> -struct is_string_impl : std::true_type -{ }; - -template <> -struct is_string_impl : std::true_type -{ }; - -template -struct is_string : is_string_impl>> -{ }; - -template -auto -as_string(ArgT&& _v, std::enable_if_t::value, int> = 0) -{ - if constexpr(std::is_pointer>::value) - { - return (_v == nullptr) ? std::string{ "\"\"" } - : (std::string{ "\"" } + _v + std::string{ "\"" }); - } - else - { - return std::string{ "\"" } + _v + std::string{ "\"" }; - } -} - -template -auto -as_string(ArgT&& _v, std::enable_if_t::value, long> = 0) -{ - return _v; -} - -template -auto -join(DelimT&& _delim, Args&&... _args) -{ - using delim_type = std::remove_cv_t>; - - std::stringstream _ss{}; - _ss << std::boolalpha; - - if constexpr(std::is_same::value) - { - const char _delim_c[2] = { _delim, '\0' }; - ROCPROFILER_REGISTER_FOLD_EXPRESSION(_ss << _delim_c << _args); - auto _ret = _ss.str(); - return (_ret.length() > 1) ? _ret.substr(1) : std::string{}; - } - else - { - ROCPROFILER_REGISTER_FOLD_EXPRESSION(_ss << _delim << _args); - auto _ret = _ss.str(); - auto&& _len = std::string{ _delim }.length(); - return (_ret.length() > _len) ? _ret.substr(_len) : std::string{}; - } -} - -struct QuoteStrings -{ }; - -template -auto -join(QuoteStrings&&, DelimT&& _delim, Args&&... _args) -{ - using delim_type = std::remove_cv_t>; - - std::stringstream _ss{}; - _ss << std::boolalpha; - - if constexpr(std::is_same::value) - { - const char _delim_c[2] = { _delim, '\0' }; - ROCPROFILER_REGISTER_FOLD_EXPRESSION(_ss << _delim_c << as_string(_args)); - auto _ret = _ss.str(); - return (_ret.length() > 1) ? _ret.substr(1) : std::string{}; - } - else - { - ROCPROFILER_REGISTER_FOLD_EXPRESSION(_ss << _delim << as_string(_args)); - auto _ret = _ss.str(); - auto&& _len = std::string{ _delim }.length(); - return (_ret.length() > _len) ? _ret.substr(_len) : std::string{}; - } -} - -template -auto -join(std::array&& _delim, Args&&... _args) -{ - return join("", - std::get<0>(_delim), - join(std::get<1>(_delim), std::forward(_args)...), - std::get<2>(_delim)); -} - -template -auto -join(QuoteStrings&&, std::array&& _delim, Args&&... _args) -{ - return join(QuoteStrings{}, - "", - std::get<0>(_delim), - join(std::get<1>(_delim), std::forward(_args)...), - std::get<2>(_delim)); -} - -template -auto -join(std::tuple&& _delim, Args&&... _args) -{ - return join("", - std::get<0>(_delim), - join(std::get<1>(_delim), std::forward(_args)...), - std::get<2>(_delim)); -} - -template -auto -join(QuoteStrings&&, std::tuple&& _delim, Args&&... _args) -{ - return join(QuoteStrings{}, - "", - std::get<0>(_delim), - join(std::get<1>(_delim), std::forward(_args)...), - std::get<2>(_delim)); -} -} // namespace -} // namespace common -} // namespace rocprofiler_register diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/log.hpp b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/log.hpp deleted file mode 100644 index bc9ecf7c75..0000000000 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/log.hpp +++ /dev/null @@ -1,518 +0,0 @@ -// MIT License -// -// Copyright (c) 2020, The Regents of the University of California, -// through Lawrence Berkeley National Laboratory (subject to receipt of any -// required approvals from the U.S. Dept. of Energy). All rights reserved. -// -// 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 rhs -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR rhsWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR rhs DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include - -#ifndef ROCPROFILER_REGISTER_LOG_COLORS_AVAILABLE -# define ROCPROFILER_REGISTER_LOG_COLORS_AVAILABLE 1 -#endif - -#ifndef ROCPROFILER_REGISTER_PROJECT_NAME -# define ROCPROFILER_REGISTER_PROJECT_NAME "rocprofiler-register" -#endif - -#ifndef ROCP_REG_FILE_NAME -# define ROCP_REG_FILE_NAME \ - ::std::string{ __FILE__ } \ - .substr(::std::string_view{ __FILE__ }.find_last_of('/') + 1) \ - .c_str() -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace rocprofiler_register -{ -namespace log -{ -bool& -monochrome(); - -inline bool& -monochrome() -{ - static bool _v = []() { - auto _val = false; - const char* _env_cstr = nullptr; - _env_cstr = std::getenv("ROCPROFILER_REGISTER_MONOCHROME"); - - if(!_env_cstr) _env_cstr = std::getenv("MONOCHROME"); - - if(_env_cstr) - { - auto _env = std::string{ _env_cstr }; - - // check if numeric - if(_env.find_first_not_of("0123456789") == std::string::npos) - { - return _env.length() > 1 || _env[0] != '0'; - } - - for(auto& itr : _env) - itr = tolower(itr); - - // check for matches to acceptable forms of false - for(const auto& itr : { "off", "false", "no", "n", "f" }) - { - if(_env == itr) return false; - } - - // check for matches to acceptable forms of true - for(const auto& itr : { "on", "true", "yes", "y", "t" }) - { - if(_env == itr) return true; - } - } - return _val; - }(); - return _v; -} - -namespace color -{ -static constexpr auto info_value = "\033[01;34m"; -static constexpr auto warning_value = "\033[01;33m"; -static constexpr auto fatal_value = "\033[01;31m"; -static constexpr auto source_value = "\033[01;32m"; -static constexpr auto dmesg_value = "\033[01;37m"; -static constexpr auto end_value = "\033[0m"; - -inline const char* -info() -{ - return (log::monochrome()) ? "" : info_value; -} - -inline const char* -warning() -{ - return (log::monochrome()) ? "" : warning_value; -} - -inline const char* -fatal() -{ - return (log::monochrome()) ? "" : fatal_value; -} - -inline const char* -source() -{ - return (log::monochrome()) ? "" : source_value; -} - -inline const char* -dmesg() -{ - return (log::monochrome()) ? "" : dmesg_value; -} - -inline const char* -end() -{ - return (log::monochrome()) ? "" : end_value; -} -} // namespace color -} // namespace log -} // namespace rocprofiler_register - -namespace rocprofiler_register -{ -namespace log -{ -struct base -{ -public: - static base indent(size_t, size_t = 2) { return base{}; } - - template - auto operator<<(Tp&&) - { - return base{}; - } -}; - -struct logger : public base -{ - logger() = default; - - explicit logger(bool _exit) - : m_exit{ _exit } - { } - - ~logger() - { - if(m_done) - { - std::cerr << color::end() << "\n"; - if(m_exit) abort(); - } - } - - logger(logger&& rhs) noexcept - { - m_exit = rhs.m_exit; - m_done = rhs.m_done; - rhs.m_done = false; - } - - logger& operator=(logger&& rhs) noexcept - { - m_exit = rhs.m_exit; - m_done = rhs.m_done; - rhs.m_done = false; - return *this; - } - - logger&& indent(size_t _n, size_t _tab_size = 4) - { - for(size_t i = 0; i < _n; i++) - for(size_t j = 0; j < _tab_size; j++) - std::cerr << " "; - return std::move(*this); - } - - template - logger&& operator<<(Tp&& _v) - { - std::cerr << std::forward(_v); - return std::move(*this); - } - -private: - bool m_exit = false; - bool m_done = true; -}; - -template -inline auto& -get_color_hist() -{ - static thread_local std::vector> _v{}; - return _v; -} - -template -inline auto -push_color_hist(Tp* _v, const char* _c) -{ - if(!monochrome()) get_color_hist().emplace_back(_v, _c); - return _c; -} - -template -inline std::string -pop_color_hist(Tp* _v) -{ - if(monochrome()) return std::string{}; - - auto& _hist = get_color_hist(); - for(auto itr = _hist.rbegin(); itr != _hist.rend(); ++itr) - { - Tp* _addr = itr->first; - if(_addr == _v) - { - auto fitr = _hist.begin(); - std::advance(fitr, std::distance(_hist.rbegin(), itr)); - _hist.erase(fitr); - } - } - for(auto itr = _hist.rbegin(); itr != _hist.rend(); ++itr) - { - if(itr->first == _v) return itr->second; - } - return color::end(); -} - -template -std::basic_ostream& -info(std::basic_ostream& os) -{ - return (os << push_color_hist(&os, color::info())); -} - -template -std::basic_ostream& -warning(std::basic_ostream& os) -{ - return (os << push_color_hist(&os, color::warning())); -} - -template -std::basic_ostream& -fatal(std::basic_ostream& os) -{ - return (os << push_color_hist(&os, color::fatal())); -} - -template -std::basic_ostream& -source(std::basic_ostream& os) -{ - return (os << push_color_hist(&os, color::source())); -} - -template -std::basic_ostream& -end(std::basic_ostream& os) -{ - return (os << push_color_hist(&os, color::end())); -} - -template -std::basic_ostream& -pop(std::basic_ostream& os) -{ - return (os << pop_color_hist(&os)); -} - -template -std::basic_ostream& -reset(std::basic_ostream& os) -{ - pop_color_hist(&os); - return (os << color::end()); -} - -template -std::basic_ostream& -flush(std::basic_ostream& os) -{ - return (os << pop << std::flush); -} - -template -std::basic_ostream& -endl(std::basic_ostream& os) -{ - return (os << pop << "\n" << std::flush); -} - -template -struct stream_base -{ - stream_base(StreamT& _os, const char* _color) - : m_os{ _os } - { - m_os << push_color_hist(&_os, _color); - } - - ~stream_base() { m_os << pop_color_hist(&m_os); } - - stream_base(const stream_base&) = delete; - stream_base& operator=(const stream_base&) = delete; - - stream_base(stream_base&& rhs) noexcept = default; - stream_base& operator=(stream_base&& rhs) noexcept = default; - - template - stream_base& operator<<(Tp&& _v) - { - m_os << std::forward(_v); - return *this; - } - - template - stream_base& operator<<(Tp& _v) - { - m_os << _v; - return *this; - } - - stream_base& put(char _c) - { - m_os.put(_c); - return *this; - } - - stream_base& endl() - { - m_os << std::endl; - return *this; - } - - template - stream_base& write(Args&&... _args) - { - m_os.write(std::forward(_args)...); - return *this; - } - - stream_base& flush() - { - m_os << std::flush; - return *this; - } - - auto tellp() { return m_os.tellp(); } - - template - stream_base& seekp(Args&&... _args) - { - m_os.seekp(std::forward(_args)...); - return *this; - } - -private: - StreamT& m_os; -}; - -template -stream_base -stream(StreamT& _os, const char* _color) -{ - return stream_base{ _os, _color }; -} - -template -stream_base -info_stream(StreamT& _os) -{ - return stream_base{ _os, color::info() }; -} - -template -stream_base -source_stream(StreamT& _os) -{ - return stream_base{ _os, color::source() }; -} - -template -stream_base -warning_stream(StreamT& _os) -{ - return stream_base{ _os, color::warning() }; -} - -template -stream_base -fatal_stream(StreamT& _os) -{ - return stream_base{ _os, color::fatal() }; -} - -inline std::string -string(const char* _color, std::string_view _v) -{ - return std::string{ _color } + std::string{ _v } + std::string{ color::end() }; -} - -inline std::string -string(const char* _color, std::stringstream& _v) -{ - return std::string{ _color } + _v.str() + std::string{ color::end() }; -} - -inline std::string -string(const char* _color, std::stringstream&& _v) -{ - return std::string{ _color } + _v.str() + std::string{ color::end() }; -} - -template -inline auto -info_string(Tp&& _v) -{ - return string(color::info(), std::forward(_v)); -} - -template -inline auto -source_string(Tp&& _v) -{ - return string(color::source(), std::forward(_v)); -} - -template -inline auto -warning_string(Tp&& _v) -{ - return string(color::warning(), std::forward(_v)); -} - -template -inline auto -fatal_string(Tp&& _v) -{ - return string(color::fatal(), std::forward(_v)); -} -} // namespace log -} // namespace rocprofiler_register - -#if !defined(ROCPROFILER_REGISTER_LOG) -# define ROCPROFILER_REGISTER_LOG(COLOR, EXIT_CODE) \ - (::rocprofiler_register::log::logger(EXIT_CODE) \ - << ::rocprofiler_register::log::color::end() \ - << ::rocprofiler_register::log::color::source() << "[" \ - << ROCPROFILER_REGISTER_PROJECT_NAME << "][" << ROCP_REG_FILE_NAME << ":" \ - << __LINE__ << "][" << getpid() << "] " \ - << ::rocprofiler_register::log::color::end() << COLOR) -#endif - -#if defined(NDEBUG) -# if !defined(ROCPROFILER_REGISTER_INFO) -# define ROCPROFILER_REGISTER_INFO (::rocprofiler_register::log::base()) -# endif -# if !defined(ROCPROFILER_REGISTER_ASSERT) -# define ROCPROFILER_REGISTER_ASSERT(COND) (::rocprofiler_register::log::base()) -# endif -#else -# if !defined(ROCPROFILER_REGISTER_INFO) -# define ROCPROFILER_REGISTER_INFO \ - ROCPROFILER_REGISTER_LOG(::rocprofiler_register::log::color::info(), false) -# endif -# if !defined(ROCPROFILER_REGISTER_ASSERT) -# define ROCPROFILER_REGISTER_ASSERT(COND) \ - (COND) ? ::rocprofiler_register::log::base() : ROCPROFILER_REGISTER_FATAL -# endif -#endif - -#if !defined(ROCPROFILER_REGISTER_WARNING) -# define ROCPROFILER_REGISTER_WARNING \ - ROCPROFILER_REGISTER_LOG(::rocprofiler_register::log::color::warning(), false) -#endif - -#if !defined(ROCPROFILER_REGISTER_FATAL) -# define ROCPROFILER_REGISTER_FATAL \ - ROCPROFILER_REGISTER_LOG(::rocprofiler_register::log::color::fatal(), true) -#endif - -#if !defined(ROCPROFILER_REGISTER_PREFER) -# define ROCPROFILER_REGISTER_PREFER(COND) \ - (COND) ? ::rocprofiler_register::log::base() : ROCPROFILER_REGISTER_WARNING -#endif - -#if !defined(ROCPROFILER_REGISTER_REQUIRE) -# define ROCPROFILER_REGISTER_REQUIRE(COND) \ - (COND) ? ::rocprofiler_register::log::base() : ROCPROFILER_REGISTER_FATAL -#endif diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/utility.cpp b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/utility.cpp index 7a72ba729d..cc9e9fc6b1 100644 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/details/utility.cpp +++ b/projects/rocprofiler-register/source/lib/rocprofiler-register/details/utility.cpp @@ -92,9 +92,9 @@ delimit(const std::string& line, std::string_view delimiters) size_t _nmax = 0; for(char itr : line) { - for(size_t j = 0; j < delimiters.length(); ++j) + for(char delimiter : delimiters) { - if(itr == delimiters.at(j)) ++_nmax; + if(itr == delimiter) ++_nmax; } } reserve(_result, _nmax); diff --git a/projects/rocprofiler-register/source/lib/rocprofiler-register/rocprofiler_register.cpp b/projects/rocprofiler-register/source/lib/rocprofiler-register/rocprofiler_register.cpp index 55cd1ab4c7..a2eb28fa7e 100644 --- a/projects/rocprofiler-register/source/lib/rocprofiler-register/rocprofiler_register.cpp +++ b/projects/rocprofiler-register/source/lib/rocprofiler-register/rocprofiler_register.cpp @@ -24,7 +24,7 @@ #include "details/dl.hpp" #include "details/environment.hpp" -#include "details/log.hpp" +#include "glog/logging.h" #include #include @@ -140,7 +140,7 @@ get_this_library_path() { auto _this_lib_path = binary::get_linked_path(rocprofiler_register_lib_name, { RTLD_NOLOAD | RTLD_LAZY }); - ROCPROFILER_REGISTER_REQUIRE(_this_lib_path) + LOG_IF(FATAL, !_this_lib_path) << rocprofiler_register_lib_name << " could not locate itself in the list of loaded libraries"; return fs::path{ *_this_lib_path }.parent_path().string(); @@ -223,16 +223,15 @@ rocp_reg_scan_for_tools() } if(rocprofiler_register_verbose >= rocprofiler_register_info_level) - ROCPROFILER_REGISTER_INFO << "loaded " << _rocp_reg_lib_path_fname.string() - << " library at " << _rocp_reg_lib_path.string(); + LOG(INFO) << "loaded " << _rocp_reg_lib_path_fname.string() << " library at " + << _rocp_reg_lib_path.string(); - ROCPROFILER_REGISTER_REQUIRE(rocprofiler_lib_handle) - << _rocp_reg_lib << " failed to load\n"; + LOG_IF(FATAL, !rocprofiler_lib_handle) << _rocp_reg_lib << " failed to load\n"; *(void**) (&rocprofiler_lib_config_fn) = dlsym(rocprofiler_lib_handle, rocprofiler_lib_register_entrypoint); - ROCPROFILER_REGISTER_REQUIRE(rocprofiler_lib_config_fn) + LOG_IF(FATAL, !rocprofiler_lib_config_fn) << _rocp_reg_lib << " did not contain '" << rocprofiler_lib_register_entrypoint << "' symbol\n"; }