Added submodules for glog/fmt (#9)
* Added submodules for glog/fmt
Removes existing printing/formatting code.
* Update external/CMakeLists.txt
Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com>
* Update external/CMakeLists.txt
Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com>
* Update external/CMakeLists.txt
- checkout submodule if not already checked out or clone repo if no .gitmodules file
- find_package(... REQUIRED)
* Disable tests from external directory
* Update external/CMakeLists.txt
- fix type: BRANCH -> REPO_BRANCH
* Update cmake/rocprofiler_register_formatting.cmake
- Include external/CMakeLists.txt in format-cmake target
- include format-cmake in format target
* Fix cmake options
- ROCPROFILE_REGISTER_* -> ROCPROFILER_REGISTER_*
* Update rocprofiler_register_linting.cmake
- fix header filter to exclude external headers
- enable warning-as-errors except for misc-header-include-cycle because that originates in fmt headers
* Fix clang-tidy error in utility.cpp
- a bit out of place in this PR but caught due to --warning-as-errors addition
---------
Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com>
[ROCm/rocprofiler-register commit: 33b19051d2]
Tento commit je obsažen v:
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+33
@@ -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()
|
||||
+1
Submodul projects/rocprofiler-register/external/fmt přidán v 6c845f57e5
+1
Submodul projects/rocprofiler-register/external/glog přidán v 3a0d4d22c5
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-2
@@ -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})
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#define GNU_SOURCE 1
|
||||
|
||||
#include "dl.hpp"
|
||||
#include "join.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
@@ -34,6 +33,7 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <elf.h>
|
||||
#include <fmt/core.h>
|
||||
#include <link.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -54,7 +54,7 @@ std::vector<segment_address_ranges>
|
||||
get_segment_addresses(pid_t _pid)
|
||||
{
|
||||
auto _data = std::vector<segment_address_ranges>{};
|
||||
auto _fname = common::join('/', "/proc", _pid, "maps");
|
||||
auto _fname = fmt::format("/{}/{}/{}", "proc", _pid, "maps");
|
||||
auto ifs = std::ifstream{ _fname };
|
||||
if(!ifs)
|
||||
{
|
||||
|
||||
+12
-61
@@ -20,7 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "log.hpp"
|
||||
#include "fmt/core.h"
|
||||
#include "glog/logging.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
@@ -31,52 +32,6 @@
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
#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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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 <array>
|
||||
#include <initializer_list>
|
||||
#include <ios>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
#if !defined(ROCPROFILER_REGISTER_FOLD_EXPRESSION)
|
||||
# define ROCPROFILER_REGISTER_FOLD_EXPRESSION(...) ((__VA_ARGS__), ...)
|
||||
#endif
|
||||
|
||||
namespace rocprofiler_register
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template <typename Tp>
|
||||
struct is_string_impl : std::false_type
|
||||
{ };
|
||||
|
||||
template <>
|
||||
struct is_string_impl<std::string> : std::true_type
|
||||
{ };
|
||||
|
||||
template <>
|
||||
struct is_string_impl<std::string_view> : std::true_type
|
||||
{ };
|
||||
|
||||
template <>
|
||||
struct is_string_impl<const char*> : std::true_type
|
||||
{ };
|
||||
|
||||
template <>
|
||||
struct is_string_impl<char*> : std::true_type
|
||||
{ };
|
||||
|
||||
template <typename Tp>
|
||||
struct is_string : is_string_impl<std::remove_cv_t<std::decay_t<Tp>>>
|
||||
{ };
|
||||
|
||||
template <typename ArgT>
|
||||
auto
|
||||
as_string(ArgT&& _v, std::enable_if_t<is_string<ArgT>::value, int> = 0)
|
||||
{
|
||||
if constexpr(std::is_pointer<std::decay_t<ArgT>>::value)
|
||||
{
|
||||
return (_v == nullptr) ? std::string{ "\"\"" }
|
||||
: (std::string{ "\"" } + _v + std::string{ "\"" });
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::string{ "\"" } + _v + std::string{ "\"" };
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ArgT>
|
||||
auto
|
||||
as_string(ArgT&& _v, std::enable_if_t<!is_string<ArgT>::value, long> = 0)
|
||||
{
|
||||
return _v;
|
||||
}
|
||||
|
||||
template <typename DelimT, typename... Args>
|
||||
auto
|
||||
join(DelimT&& _delim, Args&&... _args)
|
||||
{
|
||||
using delim_type = std::remove_cv_t<std::remove_reference_t<DelimT>>;
|
||||
|
||||
std::stringstream _ss{};
|
||||
_ss << std::boolalpha;
|
||||
|
||||
if constexpr(std::is_same<delim_type, char>::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 <typename DelimT, typename... Args>
|
||||
auto
|
||||
join(QuoteStrings&&, DelimT&& _delim, Args&&... _args)
|
||||
{
|
||||
using delim_type = std::remove_cv_t<std::remove_reference_t<DelimT>>;
|
||||
|
||||
std::stringstream _ss{};
|
||||
_ss << std::boolalpha;
|
||||
|
||||
if constexpr(std::is_same<delim_type, char>::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 <typename... Args>
|
||||
auto
|
||||
join(std::array<std::string_view, 3>&& _delim, Args&&... _args)
|
||||
{
|
||||
return join("",
|
||||
std::get<0>(_delim),
|
||||
join(std::get<1>(_delim), std::forward<Args>(_args)...),
|
||||
std::get<2>(_delim));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto
|
||||
join(QuoteStrings&&, std::array<std::string_view, 3>&& _delim, Args&&... _args)
|
||||
{
|
||||
return join(QuoteStrings{},
|
||||
"",
|
||||
std::get<0>(_delim),
|
||||
join(std::get<1>(_delim), std::forward<Args>(_args)...),
|
||||
std::get<2>(_delim));
|
||||
}
|
||||
|
||||
template <typename DelimB, typename DelimT, typename DelimE, typename... Args>
|
||||
auto
|
||||
join(std::tuple<DelimB, DelimT, DelimE>&& _delim, Args&&... _args)
|
||||
{
|
||||
return join("",
|
||||
std::get<0>(_delim),
|
||||
join(std::get<1>(_delim), std::forward<Args>(_args)...),
|
||||
std::get<2>(_delim));
|
||||
}
|
||||
|
||||
template <typename DelimB, typename DelimT, typename DelimE, typename... Args>
|
||||
auto
|
||||
join(QuoteStrings&&, std::tuple<DelimB, DelimT, DelimE>&& _delim, Args&&... _args)
|
||||
{
|
||||
return join(QuoteStrings{},
|
||||
"",
|
||||
std::get<0>(_delim),
|
||||
join(std::get<1>(_delim), std::forward<Args>(_args)...),
|
||||
std::get<2>(_delim));
|
||||
}
|
||||
} // namespace
|
||||
} // namespace common
|
||||
} // namespace rocprofiler_register
|
||||
@@ -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 <rocprofiler-register/version.h>
|
||||
|
||||
#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 <cstdlib>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
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 <typename Tp>
|
||||
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 <typename Tp>
|
||||
logger&& operator<<(Tp&& _v)
|
||||
{
|
||||
std::cerr << std::forward<Tp>(_v);
|
||||
return std::move(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_exit = false;
|
||||
bool m_done = true;
|
||||
};
|
||||
|
||||
template <typename Tp>
|
||||
inline auto&
|
||||
get_color_hist()
|
||||
{
|
||||
static thread_local std::vector<std::pair<Tp*, const char*>> _v{};
|
||||
return _v;
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
inline auto
|
||||
push_color_hist(Tp* _v, const char* _c)
|
||||
{
|
||||
if(!monochrome()) get_color_hist<Tp>().emplace_back(_v, _c);
|
||||
return _c;
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
inline std::string
|
||||
pop_color_hist(Tp* _v)
|
||||
{
|
||||
if(monochrome()) return std::string{};
|
||||
|
||||
auto& _hist = get_color_hist<Tp>();
|
||||
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 <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
info(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << push_color_hist(&os, color::info()));
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
warning(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << push_color_hist(&os, color::warning()));
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
fatal(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << push_color_hist(&os, color::fatal()));
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
source(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << push_color_hist(&os, color::source()));
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
end(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << push_color_hist(&os, color::end()));
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
pop(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << pop_color_hist(&os));
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
reset(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
pop_color_hist(&os);
|
||||
return (os << color::end());
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
flush(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << pop << std::flush);
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
endl(std::basic_ostream<CharT, Traits>& os)
|
||||
{
|
||||
return (os << pop << "\n" << std::flush);
|
||||
}
|
||||
|
||||
template <typename StreamT>
|
||||
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 <typename Tp>
|
||||
stream_base& operator<<(Tp&& _v)
|
||||
{
|
||||
m_os << std::forward<Tp>(_v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
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 <typename... Args>
|
||||
stream_base& write(Args&&... _args)
|
||||
{
|
||||
m_os.write(std::forward<Args>(_args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
stream_base& flush()
|
||||
{
|
||||
m_os << std::flush;
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto tellp() { return m_os.tellp(); }
|
||||
|
||||
template <typename... Args>
|
||||
stream_base& seekp(Args&&... _args)
|
||||
{
|
||||
m_os.seekp(std::forward<Args>(_args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
StreamT& m_os;
|
||||
};
|
||||
|
||||
template <typename StreamT>
|
||||
stream_base<StreamT>
|
||||
stream(StreamT& _os, const char* _color)
|
||||
{
|
||||
return stream_base<StreamT>{ _os, _color };
|
||||
}
|
||||
|
||||
template <typename StreamT>
|
||||
stream_base<StreamT>
|
||||
info_stream(StreamT& _os)
|
||||
{
|
||||
return stream_base<StreamT>{ _os, color::info() };
|
||||
}
|
||||
|
||||
template <typename StreamT>
|
||||
stream_base<StreamT>
|
||||
source_stream(StreamT& _os)
|
||||
{
|
||||
return stream_base<StreamT>{ _os, color::source() };
|
||||
}
|
||||
|
||||
template <typename StreamT>
|
||||
stream_base<StreamT>
|
||||
warning_stream(StreamT& _os)
|
||||
{
|
||||
return stream_base<StreamT>{ _os, color::warning() };
|
||||
}
|
||||
|
||||
template <typename StreamT>
|
||||
stream_base<StreamT>
|
||||
fatal_stream(StreamT& _os)
|
||||
{
|
||||
return stream_base<StreamT>{ _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 <typename Tp>
|
||||
inline auto
|
||||
info_string(Tp&& _v)
|
||||
{
|
||||
return string(color::info(), std::forward<Tp>(_v));
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
inline auto
|
||||
source_string(Tp&& _v)
|
||||
{
|
||||
return string(color::source(), std::forward<Tp>(_v));
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
inline auto
|
||||
warning_string(Tp&& _v)
|
||||
{
|
||||
return string(color::warning(), std::forward<Tp>(_v));
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
inline auto
|
||||
fatal_string(Tp&& _v)
|
||||
{
|
||||
return string(color::fatal(), std::forward<Tp>(_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
|
||||
+2
-2
@@ -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);
|
||||
|
||||
+6
-7
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "details/dl.hpp"
|
||||
#include "details/environment.hpp"
|
||||
#include "details/log.hpp"
|
||||
#include "glog/logging.h"
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
Odkázat v novém úkolu
Zablokovat Uživatele