[rocprofiler-systems] Update logging to use spdlog library (#2428)

## Motivation

- Structured logging with proper log levels (TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Better performance through compile-time formatting
- Consistent formatting using fmt library
- Runtime log level control via arguments and environment variables
- Easier maintenance and debugging capabilities

## Technical Details

- Added spdlog as a submodule and integrated it into CMake build system
- Created new `rocprofiler-systems-logger` library wrapping spdlog functionality
- Replaced custom logging macros (`ROCPROFSYS_VERBOSE`, `ROCPROFSYS_DEBUG`, `ROCPROFSYS_FATAL`, `ROCPROFSYS_REQUIRE`, `ROCPROFSYS_CI_THROW`, etc.) with spdlog equivalents (`LOG_DEBUG`, `LOG_WARNING`, `LOG_CRITICAL`, etc.)
- Implemented log level control through command-line arguments and environment variables
- Converted assertion macros to proper error handling with exceptions and std::abort()
This commit is contained in:
Milan Radosavljevic
2026-01-14 21:27:51 +01:00
committed by GitHub
parent 499127c0b9
commit 318d13870f
111 changed files with 2657 additions and 2602 deletions
@@ -23,7 +23,6 @@
#include "library/coverage.hpp"
#include "api.hpp"
#include "core/config.hpp"
#include "core/debug.hpp"
#include "library/coverage/impl.hpp"
#include "library/thread_data.hpp"
@@ -31,6 +30,8 @@
#include <timemory/tpls/cereal/cereal.hpp>
#include <timemory/utility/popen.hpp>
#include "logger/debug.hpp"
#include <algorithm>
#include <map>
#include <mutex>
@@ -108,9 +109,7 @@ post_process()
if(_coverage.size == 0)
{
ROCPROFSYS_VERBOSE_F(
0,
"Warning! Code coverage enabled but no code coverage data is available!\n");
LOG_WARNING("Code coverage enabled but no code coverage data is available!");
return;
}
@@ -150,11 +149,9 @@ post_process()
}
else
{
ROCPROFSYS_VERBOSE_F(0,
"Warning! No matching coverage data for "
"%s :: %s (0x%x)\n",
func.first.data(), file.first.data(),
(unsigned int) addr.first);
LOG_WARNING("No matching coverage data for {} :: {} (0x{:X})",
func.first, file.first,
(unsigned int) addr.first);
}
}
}
@@ -208,21 +205,20 @@ post_process()
std::swap(_coverage_data, _tmp);
}
ROCPROFSYS_VERBOSE(0, "code coverage :: %6.2f%s\n", _coverage() * 100.0, "%");
ROCPROFSYS_VERBOSE(0, "module coverage :: %6.2f%s\n",
_coverage(code_coverage::MODULE) * 100.0, "%");
ROCPROFSYS_VERBOSE(0, "function coverage :: %6.2f%s\n",
_coverage(code_coverage::FUNCTION) * 100.0, "%");
if(get_verbose() >= 0) fprintf(stderr, "\n");
LOG_INFO("code coverage :: {:.2f}%", _coverage() * 100.0);
LOG_INFO("module coverage :: {:.2f}%", _coverage(code_coverage::MODULE) * 100.0);
LOG_INFO("function coverage :: {:.2f}%", _coverage(code_coverage::FUNCTION) * 100.0);
std::sort(_coverage_data.begin(), _coverage_data.end(),
std::greater<coverage_data>{});
auto _get_setting = [](const std::string& _v) {
auto&& _b = config::get_setting_value<bool>(_v);
ROCPROFSYS_CI_THROW(!_b, "Error! No configuration setting named '%s'",
_v.c_str());
if(!_b && get_is_continuous_integration())
{
throw std::runtime_error(
fmt::format("Error! No configuration setting named '{}'", _v));
}
return _b.value_or(true);
};
@@ -255,7 +251,8 @@ post_process()
}
else
{
ROCPROFSYS_THROW("Error opening coverage output file: %s", _fname.c_str());
throw std::runtime_error(
fmt::format("Error opening coverage output file: {}", _fname));
}
}
@@ -287,11 +284,10 @@ post_process()
}
else
{
ROCPROFSYS_THROW("Error opening coverage output file: %s", _fname.c_str());
throw std::runtime_error(
fmt::format("Error opening coverage output file: {}", _fname));
}
}
if(get_verbose() >= 0) fprintf(stderr, "\n");
}
} // namespace coverage
} // namespace rocprofsys
@@ -308,8 +304,8 @@ rocprofsys_register_source_hidden(const char* file, const char* func, size_t lin
using coverage_data = coverage::coverage_data;
ROCPROFSYS_BASIC_VERBOSE_F(4, "[0x%x] :: %-20s :: %20s:%zu :: %s\n",
(unsigned int) address, func, file, line, source);
LOG_DEBUG("[0x{:X}] :: {:20s} :: {:20s}:{} :: {}", (unsigned int) address, func, file,
line, source);
coverage::get_coverage_data().emplace_back(
coverage_data{ size_t{ 0 }, address, line, file, func,
@@ -339,8 +335,6 @@ rocprofsys_register_coverage_hidden(const char* file, const char* func, size_t a
else if(rocprofsys::get_state() >= rocprofsys::State::Finalized)
return;
ROCPROFSYS_BASIC_VERBOSE_F(3, "[0x%x] %-20s :: %20s\n", (unsigned int) address, func,
file);
(*coverage::get_coverage_count())[file][func][address] += 1;
}