3#ifndef poplar_DebugContext_hpp
4#define poplar_DebugContext_hpp
6#include "ProfileValue.hpp"
7#include "SerializationFormat.hpp"
14#define SUPPORTS_LOCATION_BUILTINS \
15 (__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \
16 __has_builtin(__builtin_LINE))
18#define SUPPORTS_LOCATION_BUILTINS 1
20#define SUPPORTS_LOCATION_BUILTINS 0
27 const char *functionName{
""};
28 const char *fileName{
""};
29 unsigned lineNumber{};
34 constexpr SourceLocation(
const char *functionName,
const char *fileName,
36 : functionName{functionName}, fileName{fileName},
37 lineNumber{lineNumber}, valid{
true} {}
38 constexpr const char *getFunctionName()
const {
return functionName; }
39 constexpr const char *getFileName()
const {
return fileName; }
40 constexpr unsigned getLineNumber()
const {
return lineNumber; }
41 constexpr bool isValid()
const {
return valid; }
42#if SUPPORTS_LOCATION_BUILTINS
43 static SourceLocation Current(
const char *functionName = __builtin_FUNCTION(),
44 const char *fileName = __builtin_FILE(),
45 unsigned lineNumber = __builtin_LINE()) {
46 return {functionName, fileName, lineNumber};
92 std::unique_ptr<core::DebugInfo> impl;
111 core::DebugInfo &getImpl()
const {
return *impl; }
119 const std::string &fileName,
143 std::unique_ptr<core::DebugNameAndId> impl;
147 std::string parentPath =
"");
159 core::DebugNameAndId &getImpl()
const {
return *impl; }
222 std::unique_ptr<core::DebugContext> impl;
244 core::DebugContext &getImpl()
const {
return *impl; }
DebugContext gathers the common external parameters of the context of an operation.
Definition: DebugContext.hpp:221
std::string getPathName() const
Gets the pathname of this object as the concatenation of the parent name received in the constructor ...
DebugInfo stores and persists a set of data that describes the context of an operation.
Definition: DebugContext.hpp:91
bool setValue(std::string name, ProfileValue value)
Adds custom data to this object if "name" is not already set.
DebugId getId() const
Gets the unique identifier of this DebugInfo object.
std::string getPathName() const
Gets the pathname of this object (as received from DebugContext).
static void closeStreamer()
Closes the streamer: all data is flushed to disk and the file is ready to be read.
static void initializeStreamer(const std::string &fileName, const DebugSerializationFormat &format=DebugSerializationFormat::CBOR)
Initializes the streamer, unless it is already initialized (for example through env variables).
DebugInfo(const DebugContext &debugContext, std::string layer)
Constructor.
DebugNameAndId bundles a name and a DebugId to facilitate their propagation through function calls.
Definition: DebugContext.hpp:142
std::string getPathName() const
Gets the pathname of this object as the concatenation of the parent name received in the constructor ...
ProfileValue represents a read-only JSON-like tree of values that are used to store the output of the...
Definition: ProfileValue.hpp:39
This class mimics std::source_location that is unavailable as we don't yet support C++20.
Definition: DebugContext.hpp:26
Poplar classes and functions.
Definition: ArrayRef.hpp:14
std::ostream & operator<<(std::ostream &os, const DebugNameAndId &dnai)
Display the path name of the DebugNameAndId.
std::uint64_t DebugId
A unique identifier for the debug context.
Definition: DebugContext.hpp:59
DebugSerializationFormat
Definition: DebugContext.hpp:53
@ JSON
Serialise in JSON format.
@ CBOR
Serialise in CBOR format.