CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
144 lines
4.1 KiB
C++
144 lines
4.1 KiB
C++
// Copyright (c) Advanced Micro Devices, Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include "log.hpp"
|
|
#include "fwd.hpp"
|
|
|
|
#include <spdlog/fmt/fmt.h>
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <iomanip>
|
|
#include <regex>
|
|
#include <vector>
|
|
|
|
namespace
|
|
{
|
|
std::vector<log_entry> log_entries = {};
|
|
|
|
auto
|
|
get_color_regex(std::string _v)
|
|
{
|
|
auto _p = _v.find("[");
|
|
if(_p != std::string::npos) _v.insert(_p, 1, '\\');
|
|
return fmt::format("\\{}", _v);
|
|
}
|
|
|
|
auto _color_regex =
|
|
std::regex{ fmt::format("({}|{}|{}|{}|{})", get_color_regex(tim::log::color::info()),
|
|
get_color_regex(tim::log::color::source()),
|
|
get_color_regex(tim::log::color::warning()),
|
|
get_color_regex(tim::log::color::fatal()),
|
|
get_color_regex(tim::log::color::end())),
|
|
std::regex_constants::optimize };
|
|
} // namespace
|
|
|
|
log_entry::log_entry(std::string _msg)
|
|
: m_message{ std::move(_msg) }
|
|
, m_backtrace{ tim::get_unw_stack<4, 1>() }
|
|
{
|
|
if(log_ofs) *log_ofs << as_string("", "", "") << "\n";
|
|
}
|
|
|
|
log_entry::log_entry(source_location _loc, std::string _msg)
|
|
: m_location{ _loc }
|
|
, m_message{ std::move(_msg) }
|
|
, m_backtrace{ tim::get_unw_stack<4, 1>() }
|
|
{
|
|
if(log_ofs) *log_ofs << as_string("", "", "") << "\n";
|
|
}
|
|
|
|
std::string
|
|
log_entry::as_string(const char* _color, const char* _src, const char* _end) const
|
|
{
|
|
std::stringstream _ss;
|
|
if(m_location.function && m_location.file)
|
|
{
|
|
_ss << "[" << _src << m_location.file << ":" << m_location.line << _end << "]["
|
|
<< _src << m_location.function << _end << "]";
|
|
}
|
|
|
|
bool _remove_color = (strlen(_color) + strlen(_src) + strlen(_end) == 0);
|
|
|
|
_ss << " " << _color << std::regex_replace(m_message, std::regex{ "\n" }, " ... ")
|
|
<< _end;
|
|
|
|
return (_remove_color) ? std::regex_replace(_ss.str(), _color_regex, "") : _ss.str();
|
|
}
|
|
|
|
log_entry&
|
|
log_entry::add_log_entry(log_entry&& _v)
|
|
{
|
|
return log_entries.emplace_back(std::move(_v));
|
|
}
|
|
|
|
void
|
|
print_log_entries(std::ostream& _os, std::int64_t _count,
|
|
const std::function<bool(const log_entry&)>& _condition,
|
|
const std::function<void()>& _prelude, const char* _color,
|
|
bool _color_entries)
|
|
{
|
|
size_t i0 = (_count < 0) ? 0 : std::max<std::int64_t>(log_entries.size() - _count, 0);
|
|
size_t _w = std::log10(log_entries.size()) + 1;
|
|
|
|
if(dynamic_cast<std::ofstream*>(&_os) ||
|
|
(&_os != &std::cout && &_os != &std::cerr && &_os != &std::clog))
|
|
{
|
|
_color = "";
|
|
_color_entries = false;
|
|
}
|
|
|
|
const char* _end =
|
|
(strlen(_color) > 0 || _color_entries) ? tim::log::color::end() : "";
|
|
|
|
if(_prelude)
|
|
{
|
|
for(size_t i = i0; i < log_entries.size(); ++i)
|
|
{
|
|
if(!_condition || _condition(log_entries.at(i)))
|
|
{
|
|
_prelude();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// the requested number of log entries
|
|
auto _last = std::string{};
|
|
size_t _last_i = 0;
|
|
size_t _last_n = 0;
|
|
for(size_t i = i0; i < log_entries.size(); ++i)
|
|
{
|
|
auto& itr = log_entries.at(i);
|
|
|
|
if(!_condition || _condition(itr))
|
|
{
|
|
auto _msg = ((_color_entries) ? itr.as_string() : itr.as_string("", "", ""));
|
|
if(_msg != _last)
|
|
{
|
|
if(_last_n > 0 && !_last.empty())
|
|
{
|
|
_os << "[" << _color << std::setw(_w) << _last_i << "/"
|
|
<< log_entries.size() << _end << "] ... repeated " << _last_n
|
|
<< " times ...\n";
|
|
}
|
|
_last_n = 0;
|
|
_last_i = i;
|
|
_last = _msg;
|
|
_os << "[" << _color << std::setw(_w) << i << "/" << log_entries.size()
|
|
<< _end << "]" << _msg << "\n";
|
|
}
|
|
else
|
|
{
|
|
++_last_n;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(_last_n > 0)
|
|
{
|
|
_os << "[" << _color << std::setw(_w) << _last_i << "/" << log_entries.size()
|
|
<< _end << "] ... repeated " << _last_n << " times ...\n";
|
|
}
|
|
}
|