15#ifndef AMINO_CORE_RUNTIME_SERVICES_H
16#define AMINO_CORE_RUNTIME_SERVICES_H
23#include "internal/ConfigMacros.h"
24#include "internal/Storage.h"
105 template <
typename T,
typename R =
void>
106 using enable_if_functor =
107 std::enable_if_t<!std::is_convertible<T const&, StringView>::value, R>;
135 template <
typename OStream>
139 template <
typename OStream>
151 bool allowConcurrentCalls =
false);
191 template <
typename MsgFunc>
192 AMINO_INTERNAL_FORCEINLINE enable_if_functor<MsgFunc>
194 using StringLike = std::remove_reference_t<
decltype(msgFunc())>;
196 (std::is_constructible<StringView, StringLike const&>::value ||
197 std::is_convertible<StringLike const&, StringView>::value),
198 "msgFunc must return a type convertible to StringView");
200 internal_log(
true, category, msgFunc());
205 assert(isEnabled &&
"Logging is disabled!");
206 internal_log(isEnabled, category, message);
211 template <
typename Msg>
212 AMINO_INTERNAL_FORCEINLINE
void logInfo(Msg
const& msg)
const {
217 template <
typename Msg>
218 AMINO_INTERNAL_FORCEINLINE
void logWarning(Msg
const& msg)
const {
223 template <
typename Msg>
224 AMINO_INTERNAL_FORCEINLINE enable_if_functor<Msg>
logError(
225 Msg
const& msg)
const {
263 template <
typename OStream>
264 static void callback(
268 auto& os = *
static_cast<OStream*
>(clientData);
269 auto prefix = getCategoryPrefix(category);
270 os.write(prefix.data(), prefix.size());
271 os.write(message.
data(), message.
size());
279 AMINO_CORE_SHARED_DECL
static StringView getCategoryPrefix(
284 AMINO_CORE_SHARED_DECL
288 template <
typename StringLike>
289 AMINO_INTERNAL_FORCEINLINE
290 std::enable_if_t<!std::is_convertible<StringLike, StringView>::value>
294 StringLike&& message)
const {
295 return internal_log(enabled, cat, StringView{message});
300 Internal::Storage_t<5> m_storage{};
Definition of macros for symbol visibility.
String view class (similar to std::string_view)
RuntimeMessageCategory
Category of the message logged at runtime (when executing a graph).
@ kInfo
The message provides information to the user.
Runtime service that is used by operators.
AMINO_CORE_SHARED_DECL bool isLogEnabled(RuntimeMessageCategory cat) const
Check if logging is enabled for a specific category.
AMINO_CORE_SHARED_DECL void logError(StringView msg) const
Log the given error message if logging of errors is enabled.
bool isLogErrorEnabled() const
Short-hand for isLogEnabled(RuntimeMessageCategory::kError)
void log(RuntimeMessageCategory category, StringView const &message) const
Log a message with a specific category.
RuntimeServices(RuntimeServices &&rhs) noexcept=delete
Copying and moving RuntimeServices is prohibited.
AMINO_CORE_SHARED_DECL RuntimeServices(LogCallback cb, void *clientData, RuntimeMessageCategory logLevel=RuntimeMessageCategory::kInfo, bool allowConcurrentCalls=false)
Constructs a RuntimeServices that calls the given callback when messages are logged.
AMINO_INTERNAL_FORCEINLINE enable_if_functor< Msg > logError(Msg const &msg) const
Short-hand for log(RuntimeMessageCategory::kError, msg)
RuntimeServices(const RuntimeServices &rhs)=delete
Copying and moving RuntimeServices is prohibited.
AMINO_CORE_SHARED_DECL ~RuntimeServices()
Destructor.
AMINO_INTERNAL_FORCEINLINE void logInfo(Msg const &msg) const
Short-hand for log(RuntimeMessageCategory::kInfo, msg)
AMINO_CORE_SHARED_DECL int profilerEventBegin(const char *eventName) const
Notify profiler about beginning of a new named event.
AMINO_INTERNAL_FORCEINLINE void logWarning(Msg const &msg) const
Short-hand for log(RuntimeMessageCategory::kWarning, msg)
void(*)(RuntimeMessageCategory category, Amino::StringView const &message, void *clientData) LogCallback
AMINO_INTERNAL_FORCEINLINE RuntimeServices(OStream *os)
Constructs a RuntimeServices that logs messages to the given output stream when messages are logged.
AMINO_INTERNAL_FORCEINLINE RuntimeServices(OStream *os, RuntimeMessageCategory logLevel)
Constructs a RuntimeServices that logs messages to the given output stream when messages are logged.
bool isLogWarningEnabled() const
Short-hand for isLogEnabled(RuntimeMessageCategory::kWarning)
bool isLogInfoEnabled() const
Short-hand for isLogEnabled(RuntimeMessageCategory::kInfo)
AMINO_CORE_SHARED_DECL int profilerEventBegin() const
Notify profiler about beginning of a new named event.
AMINO_CORE_SHARED_DECL void profilerEventEnd(int startEventID) const
Notify profiler about end of an event.
RuntimeServices & operator=(const RuntimeServices &rhs)=delete
Copying and moving RuntimeServices is prohibited.
static AMINO_CORE_SHARED_DECL RuntimeServices const & getDisabled()
Get reference to a "disabled" runtime services.
AMINO_INTERNAL_FORCEINLINE enable_if_functor< MsgFunc > log(RuntimeMessageCategory category, MsgFunc const &msgFunc) const
Log a message with a specific category.
RuntimeServices & operator=(RuntimeServices &&rhs) noexcept=delete
Copying and moving RuntimeServices is prohibited.
Helper class to ensure all profiler events have matching begin/end calls.
~ProfilerGuard()
Destructor.
ProfilerGuard(RuntimeServices const &rs, const char *eventName)
Constructor.
ProfilerGuard(RuntimeServices const &rs)
Constructor.
String view class (similar to std::string_view).
constexpr char const * data() const noexcept
Get the string view data.
constexpr size_t size() const noexcept
Get the size of the string view.