P4C
The P4 Compiler
Loading...
Searching...
No Matches
EventLogger Class Reference

#include <event_logger.h>

Inheritance diagram for EventLogger:
[legend]

Public Types

enum class  AllocPhase { PhvAllocation , TablePlacement }
 

Public Member Functions

void debug (unsigned level, const std::string &file, const std::string &message)
 
void decision (unsigned level, const std::string &file, const std::string &description, const std::string &what, const std::string &why)
 
void deinit ()
 
void enable ()
 
void error (const P4::ErrorMessage &msg)
 
void init (const std::string &outdir, const std::string &filename)
 
void iterationChange (unsigned iteration, AllocPhase phase)
 
void parserError (const P4::ParserErrorMessage &msg)
 
void pipeChange (int pipeId)
 
void warning (const P4::ErrorMessage &msg)
 

Static Public Member Functions

static EventLoggerget ()
 
static P4::DebugHook getDebugHook ()
 

Protected Member Functions

 EventLogger (const EventLogger &other)=delete
 
 EventLogger (EventLogger &&other)=delete
 
virtual std::ostream & getDebugStream (unsigned level, const std::string &file) const
 
int getFileNameId (const std::string &name)
 
int getManagerId (const std::string &name)
 
virtual std::string getStartTimestamp () const
 
virtual int getTimeDifference () const
 
void logProperties ()
 
template<typename T >
void logSink (const T *obj)
 
void nullInit ()
 
EventLoggeroperator= (const EventLogger &other)=delete
 
void passChange (const std::string &manager, const std::string &pass, unsigned seq)
 

Protected Attributes

const time_t BEGIN_TIME = std::time(nullptr)
 
bool enabled = false
 
int fileId = 0
 
std::vector< std::string > fileNames
 
std::map< std::string, int > fileNameToIds
 
bool initialized = false
 
std::string lastManager = ""
 
std::string lastPass = ""
 
unsigned lastSeq = 0
 
int managerId = 0
 
std::vector< std::string > managerNames
 
std::map< std::string, int > managerNameToIds
 

Detailed Description

Custom logger for emitting EventLog for P4I Almost every message in the compiler should be logged via this interface. This class manages backward compatibility of logs.

Warning
By default this class dumps all messages to null sink. To log them into actual logfile, you need to call method init()

Member Function Documentation

◆ debug()

void EventLogger::debug ( unsigned level,
const std::string & file,
const std::string & message )

This function is expected to be called from LOG_DEBUGn macros

◆ decision()

void EventLogger::decision ( unsigned level,
const std::string & file,
const std::string & description,
const std::string & what,
const std::string & why )

This function is expected to be called from LOG_DECISIONn macros

◆ deinit()

void EventLogger::deinit ( )

Used in testing to manually reset spdlog at will

◆ enable()

void EventLogger::enable ( )
inline

Enable logging to events into output file

Without this call, only properties and schema version are emitted. Logger should be initialized each time other jsons are emitted but should be enabled only if such option is set to TRUE.

◆ error()

void EventLogger::error ( const P4::ErrorMessage & msg)

This function is expected to be called from ErrorReporter as a custom sink for error messages

◆ getDebugHook()

static P4::DebugHook EventLogger::getDebugHook ( )
inlinestatic

Get callback for logging changes in pass managers

◆ getDebugStream()

std::ostream & EventLogger::getDebugStream ( unsigned level,
const std::string & file ) const
protectedvirtual

Gets output stream to which LOGn messages are normally emitted (backwards compatibility)

◆ getFileNameId()

int EventLogger::getFileNameId ( const std::string & name)
protected

Returns index of name in fileNames array

If name is not in the array yet, it adds it to the end. Uses fileNameToIds to do the lookup in constant time.

◆ getManagerId()

int EventLogger::getManagerId ( const std::string & name)
protected

Returns index of name in managerNames array

If name is not in the array yet, it adds it to the end. Uses managerNameToIds to do the lookup in constant time.

◆ getStartTimestamp()

std::string EventLogger::getStartTimestamp ( ) const
protectedvirtual

Serializes BEGIN_TIME to string Placed into method because of testing

◆ getTimeDifference()

int EventLogger::getTimeDifference ( ) const
protectedvirtual

Each message requires current timestamp in form of number of seconds since 1970-01-01 00:00

◆ init()

void EventLogger::init ( const std::string & outdir,
const std::string & filename )

This function initializes the logger to emit messages to a file

Parameters
outdirPath to directory in which manifest.json is located
filenamePath to logfile, relative to manifest.json
Note
Until this function is called, all events go to null sink

◆ iterationChange()

void EventLogger::iterationChange ( unsigned iteration,
AllocPhase phase )

This function should be called when new PhvAllocation or TablePlacement phase is started. Iteration number should be the same as in name of appropriate logfiles.

◆ logProperties()

void EventLogger::logProperties ( )
protected

This function is called from constructor, bootstrapping event log with schema version so P4I can use correct parser

◆ logSink()

template<typename T >
void EventLogger::logSink ( const T * obj)
inlineprotected

This is sink function for all logging functions. It accepts object to be serialized, serializes it to JSON and then calls underlying logger to dump it to output.

◆ parserError()

void EventLogger::parserError ( const P4::ParserErrorMessage & msg)

This function is expected to be called from ErrorReporter as a custom sink for parser error messages

◆ passChange()

void EventLogger::passChange ( const std::string & manager,
const std::string & pass,
unsigned seq )
protected

This function is called through debug hooks from each pass manager

◆ pipeChange()

void EventLogger::pipeChange ( int pipeId)

This function should be called when backend is executed on a particular pipe

◆ warning()

void EventLogger::warning ( const P4::ErrorMessage & msg)

This function is expected to be called from ErrorReporter as a custom sink for warning messages