Template Numerical Library version\ main:0b2c40f
Loading...
Searching...
No Matches
TNL::Benchmarks::JsonLogging Class Reference

Logger that outputs benchmark results as JSON lines (JSONL). More...

#include <TNL/Benchmarks/JsonLogging.h>

Inheritance diagram for TNL::Benchmarks::JsonLogging:
[legend]
Collaboration diagram for TNL::Benchmarks::JsonLogging:
[legend]

Public Member Functions

 JsonLogging (std::ostream &log, int verbose=1)
 Constructs JSON logger.
void logResult (const std::string &performer, const HeaderElements &headerElements, const RowElements &rowElements, const std::string &errorMessage="") override
 Logs a benchmark result as JSON.
void writeErrorMessage (const std::string &message) override
 Logs an error message as JSON.
void writeRow (const HeaderElements &headerElements, const RowElements &rowElements, const std::string &errorMessage)
 Writes a single result row as JSON.
Public Member Functions inherited from TNL::Benchmarks::Logging
 Logging (std::ostream &log, int verbose=1)
 Constructs logger with output stream.
const MetadataColumns & getMetadataColumns () const
 Gets current metadata columns.
int getVerbose () const
 Gets current verbosity level.
virtual void setMetadataColumns (const MetadataColumns &elements)
 Sets all metadata columns at once.
virtual void setMetadataElement (const typename MetadataColumns::value_type &element, int insertPosition=-1)
 Updates or adds a single metadata element.
void setVerbose (int verbose)
 Sets verbosity level.
void syncMetadata (Logging &other)
 Copies metadata from another logger instance.

Static Protected Member Functions

static std::string escape_json (const std::string &s)

Additional Inherited Members

Public Types inherited from TNL::Benchmarks::Logging
using HeaderElements = std::vector< std::string >
using MetadataColumns = std::vector< MetadataElement >
using MetadataElement = std::pair< std::string, std::string >
using RowElements = LoggingRowElements
Protected Attributes inherited from TNL::Benchmarks::Logging
bool header_changed = true
std::ostreamlog
MetadataColumns metadataColumns
int verbose = 0

Detailed Description

Logger that outputs benchmark results as JSON lines (JSONL).

Each result is written as a separate JSON object on its own line, making it easy to parse and process with standard tools. See https://jsonltools.com/what-is-jsonl for details.

Output format example:

{"operation": "multiply", "performer": "CPU", "time": "1.23e-04", ...}
{"operation": "multiply", "performer": "GPU", "time": "4.56e-05", ...}

Error messages are also logged as JSON objects with an "error" field.

Constructor & Destructor Documentation

◆ JsonLogging()

TNL::Benchmarks::JsonLogging::JsonLogging ( std::ostream & log,
int verbose = 1 )
inline

Constructs JSON logger.

Parameters
logOutput stream for JSONL data
verboseVerbosity level (passed to base class, not used by this class)

Member Function Documentation

◆ logResult()

void TNL::Benchmarks::JsonLogging::logResult ( const std::string & performer,
const HeaderElements & headerElements,
const RowElements & rowElements,
const std::string & errorMessage = "" )
inlineoverridevirtual

Logs a benchmark result as JSON.

Adds performer metadata and writes the result row.

Parameters
performerName of implementation being tested
headerElementsColumn names
rowElementsFormatted row values
errorMessageOptional error description

Implements TNL::Benchmarks::Logging.

◆ writeErrorMessage()

void TNL::Benchmarks::JsonLogging::writeErrorMessage ( const std::string & message)
inlineoverridevirtual

Logs an error message as JSON.

Outputs current metadata plus an "error" field containing the message.

Parameters
messageError description

Implements TNL::Benchmarks::Logging.

◆ writeRow()

void TNL::Benchmarks::JsonLogging::writeRow ( const HeaderElements & headerElements,
const RowElements & rowElements,
const std::string & errorMessage )
inline

Writes a single result row as JSON.

Outputs all metadata columns followed by result values, each as key-value pairs in the JSON object.

Parameters
headerElementsColumn names
rowElementsFormatted row values
errorMessageOptional error description

The documentation for this class was generated from the following file: