351d825a8d
* [0/N] git submodules * [1/N] Update cmake, gitignore, external - clang-tidy file - update .gitignore - update main CMakeLists.txt - update external/CMakeLists.txt - update rocprofiler_config_interfaces.cmake - update rocprofiler_formatting.cmake - update rocprofiler_interfaces.cmake - update rocprofiler_linting.cmake - update rocprofiler_options.cmake - update rocprofiler_utilities.cmake * [2/N] Update rocprofiler/config.h - update to work with new rocprofiler.h * [3/N] Update source/lib/rocprofiler/hsa - hsa-types.h: static asserts - hsa.cpp: copyTables scope - hsa.gen.cpp: ACTIVITY_DOMAIN_HSA_API -> ROCPROFILER_TRACER_ACTIVITY_DOMAIN_HSA_API - rename some files - add rocprofiler_ prefix to types and enums - HSA_API_TABLE_LOOKUP_DEFINITION macro - get_saved_table() -> get_table() * [4/N] Update source/lib/common - CMake: change target_link_libraries - defines.hpp: remove ppdefs defined in include/rocprofiler/defines.h * [5/N] Update source/lib/rocprofiler - updates due to changes in rocprofiler.h - rocprofiler_config.cpp: remove unions which are now defined in include/rocprofiler - CMakeLists.txt: rocprofiler.cpp and public hsa-runtime and hip libraries - rocprofiler.cpp: dummy implementations for: - rocprofiler_query_available_agents - rocprofiler_create_context - rocprofiler_start_context - rocprofiler_stop_context - rocprofiler_flush_buffer - rocprofiler_destroy_buffer * [6/N] Update license - replace stale LBNL license * [7/N] CMake format
139 wiersze
3.6 KiB
C++
139 wiersze
3.6 KiB
C++
// MIT License
|
|
//
|
|
// Copyright (c) 2023 ROCm Developer Tools
|
|
//
|
|
// 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
|
|
|
|
#ifndef ROCPROFILER_LOG_COLORS_AVAILABLE
|
|
# define ROCPROFILER_LOG_COLORS_AVAILABLE 1
|
|
#endif
|
|
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
|
|
namespace rocprofiler
|
|
{
|
|
namespace common
|
|
{
|
|
namespace log
|
|
{
|
|
bool&
|
|
monochrome();
|
|
|
|
inline bool&
|
|
monochrome()
|
|
{
|
|
static bool _v = []() {
|
|
auto _val = false;
|
|
const char* _env_cstr = nullptr;
|
|
#if defined(ROCPROFILER_LOG_COLORS_ENV)
|
|
_env_cstr = std::getenv(ROCPROFILER_LOG_COLORS_ENV);
|
|
#elif defined(ROCPROFILER_PROJECT_NAME)
|
|
auto _env_name = std::string{ROCPROFILER_PROJECT_NAME} + "_MONOCHROME";
|
|
for(auto& itr : _env_name)
|
|
itr = toupper(itr);
|
|
_env_cstr = std::getenv(_env_name.c_str());
|
|
#else
|
|
_env_cstr = std::getenv("ROCPROFILER_MONOCHROME");
|
|
#endif
|
|
|
|
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 common
|
|
} // namespace rocprofiler
|