HawkTracer
0.10.0
|
Event is a data structure that carries an information about the system at specific point of time. This could be e.g. resource usge at specific point of time, or duration of operation.
User can define event that holds almost any data, however all the event types must inherit from the base event class. That comes with following implications:
To implement all the properties above, we created a base C
data struct which must be included in all custom events:
As mentioned above, user can include almost any information in the event. In order to achieve that, we've introduced a concept of Event inheritance. It's similar to C++
inheritance but requires a few extra information that helps us serializing and deserializing events. The library provides macro HT_DECLARE_EVENT_KLASS() to simplify the inheritance process.
The tutorial Tutorial: Define custom event type presents how to define custom event types.
Before using the event type, it must be registered in the system. It's done by calling HT_REGISTER_EVENT_KLASS() at the beginning of your program.
When user defines new event type, apart from the C type, she needs to define generic type of the field. The type can be one of:
STRUCT
- an event structure (it can't be any data structure, it must be an event type which is registered in the system)STRING
- null-terminated sequence of charactersINTEGER
- signed integer numberFLOAT
- floating point numberDOUBLE
- double-precision floating point numberPOINTER
- a pointerUNSIGNED_INTEGER
- unsigned integer numberOne of the common scenarios for using HawkTracer is to measure time spent in a specific scope by the application. E.g. user wants to know how long does it take to execute the code inside the if
block
We could have 2 events, one at the beginning of the if
statement, and other at the end of the block, but that's very inconvenient. Also, if one of the internal methods throws an exception, we never receive the second event. To simplify this task, HawkTracer provides a few macros (see scoped_tracepoint.h and string_scoped_tracepoint.h) and event types (#HT_CallstackStringEvent, #HT_CallstackIntEvent):
The code above will generate an event of #HT_CallstackStringEvent which holds following information:
"if (...)"
)Additionally, the macro pushes the event to a specified timeline.