11#include <rdma/fabric.h>
12#include <rdma/fi_ext.h>
13#include <rdma/providers/fi_log.h>
14#include <spdlog/common.h>
15#include "spdlog/spdlog.h"
23 constexpr auto fiLogLevelStrings = std::array<std::pair<std::string_view, ::fi_log_level>, 4>{
24 {{
"trace", FI_LOG_TRACE}, {
"debug", FI_LOG_DEBUG}, {
"info", FI_LOG_INFO}, {
"warn", FI_LOG_WARN}}
27 static int fiLogEnabled(
const struct fi_provider* prov,
enum fi_log_level level,
enum fi_log_subsys subsys, std::uint64_t
flags);
28 static int fiLogReady(
const struct fi_provider* prov,
enum fi_log_level level,
enum fi_log_subsys subsys, std::uint64_t
flags,
29 std::uint64_t* showtime);
30 void fiLog(
const struct fi_provider* prov,
enum fi_log_level level,
enum fi_log_subsys subsys,
char const*,
int line,
char const* msgIn);
40 if (_isInit.exchange(
true, std::memory_order_relaxed))
45 auto fiLogLevelCStr = ::getenv(
"FI_LOG_LEVEL");
46 if (fiLogLevelCStr !=
nullptr)
48 auto fiLogLevelStr = std::string{fiLogLevelCStr};
49 std::ranges::transform(fiLogLevelStr, fiLogLevelStr.begin(), [](
unsigned char const c) { return std::tolower(c); });
50 auto it = std::ranges::find_if(fiLogLevelStrings,
51 [fiLogLevelStr](std::pair<std::string_view, ::fi_log_level>
const& item) {
return fiLogLevelStr == item.first; });
52 if (it != fiLogLevelStrings.end())
62 auto ops = ::fi_ops_log{
63 .size =
sizeof(::fi_ops_log),
64 .enabled = &fiLogEnabled,
69 auto logging = ::fid_logging{
74 fiCall(::fi_import_log,
"Failed to initialize logging",
fiVersion(), 0, &logging);
78 friend int fiLogEnabled(
const struct fi_provider*,
enum fi_log_level,
enum fi_log_subsys, std::uint64_t);
81 fi_log_level level() const noexcept
87 bool isProviderLoggingEnabled(
const struct fi_provider*)
const noexcept
93 bool isSubsystemLoggingEnabled(
enum fi_log_subsys)
const noexcept
98 std::atomic_bool _isInit;
99 ::fi_log_level _level;
104 char const* fiLogSubsystemName(
enum fi_log_subsys subsys)
108 case FI_LOG_CORE:
return "core";
109 case FI_LOG_FABRIC:
return "fabric";
110 case FI_LOG_DOMAIN:
return "domain";
111 case FI_LOG_EP_CTRL:
return "ep_ctrl";
112 case FI_LOG_EP_DATA:
return "ep_data";
113 case FI_LOG_AV:
return "av";
114 case FI_LOG_CQ:
return "cq";
115 case FI_LOG_EQ:
return "eq";
116 case FI_LOG_MR:
return "mr";
117 case FI_LOG_CNTR:
return "cntr";
122 spdlog::level::level_enum fiLevelToSpdlogLevel(
enum fi_log_level level)
126 case FI_LOG_WARN:
return spdlog::level::warn;
127 case FI_LOG_TRACE:
return spdlog::level::trace;
128 case FI_LOG_INFO:
return spdlog::level::info;
129 case FI_LOG_DEBUG:
return spdlog::level::debug;
130 default:
return spdlog::level::warn;
134 int fiLogEnabled(
const struct fi_provider* prov,
enum fi_log_level level,
enum fi_log_subsys subsys, std::uint64_t)
136 return (level <= logging.level() || logging.level() == FI_LOG_TRACE) && logging.isProviderLoggingEnabled(prov) &&
137 logging.isSubsystemLoggingEnabled(subsys);
140 int fiLogReady(
const struct fi_provider*,
enum fi_log_level,
enum fi_log_subsys, std::uint64_t, std::uint64_t*)
145 void fiLog(
const struct fi_provider* prov,
enum fi_log_level level,
enum fi_log_subsys subsys,
char const*,
int line,
char const* msgIn)
147 auto msg = std::string{msgIn};
148 if (msg.ends_with(
'\n'))
154 {fmt::format(
"libfabric:{}:{}", fiLogSubsystemName(subsys), prov->name).c_str(), line,
""}, fiLevelToSpdlogLevel(level),
"{}", msg);
void fiInitLogging()
Initalize logging for libfabric. After this call, all libfabric internal logs will be written to the ...
std::uint32_t fiVersion() noexcept
Returns the libfabric version this library was compiled with.
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.
gInfo flags
Mark the grain as invalid.