Encapsulates information of the caller that can be collected. This is platform-specific, in this case, C++. What we receive from the C++ preprocessor is the source file name of the calling code, the line number within the source file name and the name of the method the call is placed in. Furthermore, we collect the std::type_info*
in case the call was not placed in a static or namespace function.
The method has a list of interface functions that gets such source information and some derived variants of it. In addition, thread and timer information is stored and managed.
As far as possible, 'lazy' techniques come to practice with this class. This means, only the things that are queried in-between to invocations of method Set are calculated.
class Lox
Definition at line 52 of file scopeinfo.inl.
Inner Type Index: | |
struct | FrameRecord |
struct | ParsedFileName |
Information of a single source file. Stored in field parsedFileNameCache. More... | |
struct | SourcePathTrimRule |
struct | ValueDescriptorPFN |
Serves as template parameter TValueDescriptor of field parsedFileNameCache. More... | |
Public Type Index: | |
using | ThreadDictionary = HashMap<MonoAllocator, threads::ThreadID, String32> |
A map we use to translate thread IDs to thread names. | |
Public Field Index: | |
NString | loxName |
The name of the Lox we are attached to. | |
Public Method Index: | |
ALIB_API | ScopeInfo (const NString &name, MonoAllocator &allocator) |
const NString | GetFileName () |
const NString | GetFileNameWithoutExtension () |
const NString | GetFullPath () |
int | GetLineNumber () |
const NString | GetLoxName () |
const NCString | GetMethod () |
const NCString & | GetOrigFile () |
threads::ThreadID | GetThreadID () |
const alib::String & | GetThreadNameAndID (threads::ThreadID *id) |
std::thread::id | GetThreadNativeID () |
Ticks | GetTimeStamp () |
void | GetTrimmedPath (AString &target) |
const std::type_info * | GetTypeInfo () |
void | PopNestedScope () |
Releases latest scope information. | |
ALIB_API void | Set (const lang::CallerInfo &ci) |
void | SetFileNameCacheCapacity (integer numberOfLists, integer entriesPerList) |
ALIB_API void | SetSourcePathTrimRule (const NCString &path, lang::Inclusion includeString, int trimOffset, lang::Case sensitivity, const NString &trimReplacement, lang::Reach reach, Priority priority) |
Protected Static Field Index: | |
static ALIB_API std::vector< SourcePathTrimRule > | GlobalSPTRs |
List of trim definitions for portions of source paths to be ignored. | |
static ALIB_API bool | GlobalSPTRsReadFromConfig = false |
Flag to determine if global rules have been read from config already. | |
Protected Field Index: | |
bool | AutoDetectTrimableSourcePath = true |
StdVectorMono< FrameRecord > | callStack |
A stack of scopes (allows recursive calls/nested logging). | |
int | callStackSize = -1 |
The current depth of recursive invocations. | |
std::vector< SourcePathTrimRule > | LocalSPTRs |
List of trim definitions for portions of source paths to be ignored. | |
LRUCacheTable< MonoAllocator, ValueDescriptorPFN, std::hash< NString > > | parsedFileNameCache |
Least recently used cache of parsed file name. | |
Thread * | thread = nullptr |
The thread passed with Set. | |
ThreadDictionary | threadDictionary |
String | threadName |
The name of the thread that executed the log. | |
std::thread::id | threadNativeIDx |
The C++ native ID. | |
Protected Method Index: | |
integer | getPathLength () |
ALIB_API void | trimPath () |
A map we use to translate thread IDs to thread names.
Definition at line 57 of file scopeinfo.inl.
|
protected |
If true, next time a source path cannot be trimmed successfully with custom trim information provided with Lox::SetSourcePathTrimRule some trim information is automatically created by comparing such source file's path with the path of the executable of the current process.
Definition at line 99 of file scopeinfo.inl.
|
protected |
A stack of scopes (allows recursive calls/nested logging).
Definition at line 180 of file scopeinfo.inl.
|
protected |
The current depth of recursive invocations.
Definition at line 183 of file scopeinfo.inl.
|
staticprotected |
List of trim definitions for portions of source paths to be ignored.
Definition at line 85 of file scopeinfo.inl.
|
staticprotected |
Flag to determine if global rules have been read from config already.
Definition at line 92 of file scopeinfo.inl.
|
protected |
List of trim definitions for portions of source paths to be ignored.
Definition at line 88 of file scopeinfo.inl.
NString loxName |
The name of the Lox we are attached to.
Definition at line 190 of file scopeinfo.inl.
|
protected |
Least recently used cache of parsed file name.
Definition at line 156 of file scopeinfo.inl.
|
protected |
The thread passed with Set.
Definition at line 106 of file scopeinfo.inl.
|
protected |
Dictionary to translate thread IDs into something maybe nicer/shorter. The dictionary may be filled by the user of the library using Lox.MapThreadName.
Definition at line 113 of file scopeinfo.inl.
|
protected |
The name of the thread that executed the log.
Definition at line 109 of file scopeinfo.inl.
|
protected |
The C++ native ID.
Definition at line 103 of file scopeinfo.inl.
ScopeInfo | ( | const NString & | name, |
MonoAllocator & | allocator ) |
Constructs a scope info.
name | The name of the Lox that this object belongs to. Will be converted to upper case. |
allocator | The monotonic allocator of "our" Lox, used for long-term allocations |
Definition at line 38 of file scopeinfo.cpp.
|
inline |
Receives the source file name excluding the path (usually provided by the preprocessor).
Definition at line 317 of file scopeinfo.inl.
|
inline |
Receives the source file name excluding the path and without an extension (usually provided by the preprocessor).
Definition at line 341 of file scopeinfo.inl.
|
inline |
Receives the path of the source file (not trimmed, see GetTrimmedPath).
Definition at line 283 of file scopeinfo.inl.
|
inline |
Receives the source file line number (usually provided by the preprocessor).
Definition at line 368 of file scopeinfo.inl.
|
inline |
Receives the name of the Lox we are belonging to (this is a 1:1 relationship).
Definition at line 264 of file scopeinfo.inl.
|
inline |
Receives the method name (usually provided by the preprocessor).
Definition at line 359 of file scopeinfo.inl.
|
inline |
Receives the original filename and path of the source file (usually provided by the preprocessor).
Definition at line 274 of file scopeinfo.inl.
|
inlineprotected |
Gets position of path/filename separator. This is evaluated only once after an invocation of Set.
Definition at line 458 of file scopeinfo.inl.
|
inline |
Receives the thread ID of the caller.
Definition at line 397 of file scopeinfo.inl.
|
inline |
Receives information about the thread that the current call was invoked with.
id | Output parameter receiving the ALib thread ID. If nullptr, it will be ignored. |
Definition at line 417 of file scopeinfo.inl.
|
inline |
Receives the thread ID of the caller.
Definition at line 408 of file scopeinfo.inl.
|
inline |
The timestamp of the last invocation of Set.
Definition at line 377 of file scopeinfo.inl.
|
inline |
Writes the path of the source file, trimmed according to trim-information provided with SetSourcePathTrimRule or detected according to AutoDetectTrimableSourcePath.
target | The target string to append the trimmed path to. |
Definition at line 303 of file scopeinfo.inl.
|
inline |
Receives the type information of the caller. If called from global function or static method, this will be nullptr
.
Definition at line 387 of file scopeinfo.inl.
|
inline |
Releases latest scope information.
Definition at line 227 of file scopeinfo.inl.
void Set | ( | const lang::CallerInfo & | ci | ) |
Stores C++ specific caller parameters and some other values like the time stamp. Also, flags thread information as not received, yet. Counts the recursion counter up.
ci | The caller information. |
Definition at line 118 of file scopeinfo.cpp.
Changes the capacity of the LRUCacheTable for parsed file names by calling LRUCacheTable::Reserve.
numberOfLists | The number of LRU-lists to use. |
entriesPerList | The maximum length of each cache list. |
Definition at line 214 of file scopeinfo.inl.
void SetSourcePathTrimRule | ( | const NCString & | path, |
lang::Inclusion | includeString, | ||
int | trimOffset, | ||
lang::Case | sensitivity, | ||
const NString & | trimReplacement, | ||
lang::Reach | reach, | ||
Priority | priority ) |
Does the job for Lox::SetSourcePathTrimRule and Lox::ClearSourcePathTrimRules.
path | The path to search for. If not starting with '*' , a prefix is searched. |
includeString | Determines if path should be included in the trimmed path or not. |
trimOffset | Adjusts the portion of path that is trimmed. 999999 to clear! |
sensitivity | Determines if the comparison of path with a source file's path is performed case-sensitive or not. |
trimReplacement | Replacement string for trimmed portion of the path. |
reach | Denotes whether the rule is applied locally (to this Lox only) or applies to all instances of class Lox. Defaults to Reach::Global. |
priority | The priority of the setting. |
Definition at line 142 of file scopeinfo.cpp.
|
protected |
Tries to trim the source file's path. Sets variable SourceFile::trimmedPath to either the successfully trimmed path or to the non-trimmed one. This way, it is executed only once, at it is 'lazily' invoked by GetTrimmedPath()
Definition at line 206 of file scopeinfo.cpp.