Chi-Tech
|
#include <chi_log.h>
Data Structures | |
struct | Event |
struct | EventInfo |
class | RepeatingEvent |
Public Types | |
enum | LOG_LVL { LOG_0 = 1 , LOG_0WARNING = 2 , LOG_0ERROR = 3 , LOG_0VERBOSE_0 = 4 , LOG_0VERBOSE_1 = 5 , LOG_0VERBOSE_2 = 6 , LOG_ALL = 7 , LOG_ALLWARNING = 8 , LOG_ALLERROR = 9 , LOG_ALLVERBOSE_0 = 10 , LOG_ALLVERBOSE_1 = 11 , LOG_ALLVERBOSE_2 = 12 } |
enum | StdTags { MAX_MEMORY_USAGE = 0 } |
enum class | EventType { EVENT_CREATED = 0 , SINGLE_OCCURRENCE = 1 , EVENT_BEGIN = 2 , EVENT_END = 3 } |
enum class | EventOperation { NUMBER_OF_OCCURRENCES , TOTAL_DURATION = 1 , AVERAGE_DURATION = 2 , MAX_VALUE = 3 , AVERAGE_VALUE = 4 } |
Public Member Functions | |
LogStream | Log (LOG_LVL level=LOG_0) |
void | SetVerbosity (int int_level) |
int | GetVerbosity () const |
LogStream | Log0 () |
LogStream | Log0Warning () |
LogStream | Log0Error () |
LogStream | Log0Verbose0 () |
LogStream | Log0Verbose1 () |
LogStream | Log0Verbose2 () |
LogStream | LogAll () |
LogStream | LogAllWarning () |
LogStream | LogAllError () |
LogStream | LogAllVerbose0 () |
LogStream | LogAllVerbose1 () |
LogStream | LogAllVerbose2 () |
size_t | GetRepeatingEventTag (std::string event_name) |
size_t | GetExistingRepeatingEventTag (std::string event_name) |
void | LogEvent (size_t ev_tag, EventType ev_type, const std::shared_ptr< EventInfo > &ev_info) |
void | LogEvent (size_t ev_tag, EventType ev_type) |
std::string | PrintEventHistory (size_t ev_tag) |
double | ProcessEvent (size_t ev_tag, EventOperation ev_operation) |
Public Member Functions inherited from chi::TimingLog | |
TimingBlock & | CreateTimingBlock (const std::string &name, const std::string &parent_name="") |
TimingBlock & | CreateOrGetTimingBlock (const std::string &name, const std::string &parent_name="") |
TimingBlock & | GetTimingBlock (const std::string &name) |
Static Public Member Functions | |
static ChiLog & | GetInstance () noexcept |
Private Member Functions | |
ChiLog () noexcept | |
Private Attributes | |
DummyStream | dummy_stream_ |
int | verbosity_ |
std::vector< RepeatingEvent > | repeating_events |
Additional Inherited Members | |
Protected Attributes inherited from chi::TimingLog | |
std::map< std::string, std::unique_ptr< TimingBlock > > | timing_blocks_ |
Object for controlling logging.
There are three levels of verbosity in ChiTech: Zero(Default), One and Two. These can be set on the command line via the switch -v followed by a space and the number for the verbosity (0,1 or 2).
The lua command chiLogSetVerbosity(int_level)
achieves the same.
Printing a log under the auspices of a verbosity level again has numerous options. Firstly, any log can be a normal log, a warning or an error. Secondly, a log can be either location 0 or all the locations in a parallel process environment. The log option enums defined under LOG_LVL are
LOG_ALLVERBOSE_2, Used only if verbosity level equals 2
A log can be made by first connecting code with the logger. This is done by including the log header and then defining an extern reference to the global object.
A log is then written inside a piece of code as follows:
[0] This is printed on location 0 only [0] **WARNING** This is a warning [0] **!**ERROR**!** This is an error
Suppose a routine or segment of code gets called multiple times. Now suppose we want to know how many times this routine was called, how long it ran (total and on-avg), or we want to know at which timestamp it ran every time. We do this by using a repeating event. A repeating event is identified by a tag. Therefore the first step is to obtain a unique id for the event using ChiLog::GetRepeatingEventTag.
Events can now be logged using ChiLog::LogEvent(size_t ev_tag, ChiLog::EventType ev_type). As an example, consider we want to count the number of occurrences of an event. We trigger multiple occurences using
At the end of the block for which you wanted to log these events we can now extract the number of occurrences using
Below is a complete example:
6
Since chi::log is a global object this functionality is really powerful for use in modules or class objects where multiple methods can contribute to the same event track. For example an object can have an event tag as a member and initialize it at construction then all of the objects methods can contribute to the event.
In addition to the ChiLog::EventType the user can also supply a reference to a ChiLog::EventInfo structure. Be cautious with this though because each event stored a double and a string which can look like a memory leak if multiple events are pushed up with event information. Developers can supply either a double or a string or both to an event info constructor to instantiate an instance. The event arb_value is by default 0.0 and the event arb_info is by default an empty string. An example is shown below:
4.0
Event information can also be supplied by string values but then the average value is meaningless unless the average value is also supplied. For example:
1.33333
To get a string value of the event history developers can use ChiLog::PrintEventHistory along with the event tag. Just note that it will automatically be formatted for each location so no need to use chi::log to print it. Also, each event will be prepended with a program timestamp in seconds.
1.33333 [0] 3.813119000 EVENT_CREATED [0] 3.813120000 SINGLE_OCCURRENCE A [0] 3.813121000 SINGLE_OCCURRENCE B [0] 3.813122000 SINGLE_OCCURRENCE C
|
strong |
Enumerator | |
---|---|
NUMBER_OF_OCCURRENCES | Counts creation events, single occurrences and begins. |
TOTAL_DURATION | Integrates times between begins and ends. |
AVERAGE_DURATION | Computes average time between begins and ends. |
MAX_VALUE | Computes the maximum of the EventInfo arb_value. |
AVERAGE_VALUE | Computes the average of the EventInfo arb_value. |
|
strong |
enum chi::ChiLog::LOG_LVL |
Logging level
enum chi::ChiLog::StdTags |
|
privatenoexcept |
Default constructor
Definition at line 20 of file chi_log.cc.
size_t chi::ChiLog::GetExistingRepeatingEventTag | ( | std::string | event_name | ) |
Returns a unique tag to the latest version of an existing repeating event.
Definition at line 191 of file chi_log.cc.
|
staticnoexcept |
Access to the singleton
Definition at line 12 of file chi_log.cc.
size_t chi::ChiLog::GetRepeatingEventTag | ( | std::string | event_name | ) |
Returns a unique tag to a newly created repeating event.
Definition at line 176 of file chi_log.cc.
int chi::ChiLog::GetVerbosity | ( | ) | const |
Gets the current verbosity level.
Definition at line 172 of file chi_log.cc.
chi::LogStream chi::ChiLog::Log | ( | LOG_LVL | level = LOG_0 | ) |
Makes a log entry.
Definition at line 35 of file chi_log.cc.
void chi::ChiLog::LogEvent | ( | size_t | ev_tag, |
EventType | ev_type | ||
) |
Logs an event without any event information.
Definition at line 218 of file chi_log.cc.
void chi::ChiLog::LogEvent | ( | size_t | ev_tag, |
EventType | ev_type, | ||
const std::shared_ptr< EventInfo > & | ev_info | ||
) |
Logs an event with the supplied event information.
Definition at line 204 of file chi_log.cc.
std::string chi::ChiLog::PrintEventHistory | ( | size_t | ev_tag | ) |
Returns a string representation of the event history associated with the tag. Each event entry will be prepended by the location id and the program timestamp in seconds. This method uses the ChiLog::EventInfo::GetString method to append information. This allows derived classes to implement more sophisticated outputs.
Definition at line 234 of file chi_log.cc.
double chi::ChiLog::ProcessEvent | ( | size_t | ev_tag, |
EventOperation | ev_operation | ||
) |
Processes an event given an event operation. See ChiLog for further reference.
Definition at line 275 of file chi_log.cc.
void chi::ChiLog::SetVerbosity | ( | int | int_level | ) |
Sets the verbosity level.
Definition at line 165 of file chi_log.cc.
|
private |
|
private |