| 1 | #ifndef _LTT_EVENT_H |
| 2 | #define _LTT_EVENT_H |
| 3 | |
| 4 | #include <glib.h> |
| 5 | #include <stdint.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <endian.h> |
| 8 | #include <ltt/ltt.h> |
| 9 | #include <ltt/time.h> |
| 10 | |
| 11 | struct marker_field; |
| 12 | |
| 13 | struct LttField { |
| 14 | int offset; |
| 15 | int size; |
| 16 | }; |
| 17 | |
| 18 | /* |
| 19 | * Structure LttEvent and LttEventPosition must begin with the _exact_ same |
| 20 | * fields in the exact same order. LttEventPosition is a parent of LttEvent. |
| 21 | */ |
| 22 | struct LttEvent { |
| 23 | /* Begin of LttEventPosition fields */ |
| 24 | LttTracefile *tracefile; |
| 25 | unsigned int block; |
| 26 | unsigned int offset; |
| 27 | |
| 28 | /* Timekeeping */ |
| 29 | uint64_t tsc; /* Current timestamp counter */ |
| 30 | |
| 31 | /* End of LttEventPosition fields */ |
| 32 | guint32 timestamp; /* truncated timestamp */ |
| 33 | |
| 34 | guint16 event_id; |
| 35 | |
| 36 | LttTime event_time; |
| 37 | |
| 38 | void *data; /* event data */ |
| 39 | GArray *fields_offsets; /* current field offsets table */ |
| 40 | guint data_size; |
| 41 | guint event_size; /* event_size field of the header : |
| 42 | used to verify data_size from marker. */ |
| 43 | int count; /* the number of overflow of cycle count */ |
| 44 | gint64 overflow_nsec; /* precalculated nsec for overflows */ |
| 45 | }; |
| 46 | |
| 47 | struct LttEventPosition { |
| 48 | LttTracefile *tracefile; |
| 49 | unsigned int block; |
| 50 | unsigned int offset; |
| 51 | |
| 52 | /* Timekeeping */ |
| 53 | uint64_t tsc; /* Current timestamp counter */ |
| 54 | }; |
| 55 | |
| 56 | static inline guint16 ltt_event_id(const struct LttEvent *event) |
| 57 | { |
| 58 | return event->event_id; |
| 59 | } |
| 60 | |
| 61 | static inline LttTime ltt_event_time(const struct LttEvent *event) |
| 62 | { |
| 63 | return event->event_time; |
| 64 | } |
| 65 | |
| 66 | /* Obtain the position of the event within the tracefile. This |
| 67 | is used to seek back to this position later or to seek to another |
| 68 | position, computed relative to this position. The event position |
| 69 | structure is opaque and contains several fields, only two |
| 70 | of which are user accessible: block number and event index |
| 71 | within the block. */ |
| 72 | |
| 73 | void ltt_event_position(LttEvent *e, LttEventPosition *ep); |
| 74 | |
| 75 | LttEventPosition * ltt_event_position_new(); |
| 76 | |
| 77 | void ltt_event_position_get(LttEventPosition *ep, LttTracefile **tf, |
| 78 | guint *block, guint *offset, guint64 *tsc); |
| 79 | |
| 80 | void ltt_event_position_set(LttEventPosition *ep, LttTracefile *tf, |
| 81 | guint block, guint offset, guint64 tsc); |
| 82 | |
| 83 | gint ltt_event_position_compare(const LttEventPosition *ep1, |
| 84 | const LttEventPosition *ep2); |
| 85 | |
| 86 | void ltt_event_position_copy(LttEventPosition *dest, |
| 87 | const LttEventPosition *src); |
| 88 | |
| 89 | LttTracefile *ltt_event_position_tracefile(LttEventPosition *ep); |
| 90 | |
| 91 | /* These functions extract data from an event after architecture specific |
| 92 | * conversions. */ |
| 93 | |
| 94 | guint32 ltt_event_get_unsigned(LttEvent *e, struct marker_field *f); |
| 95 | |
| 96 | gint32 ltt_event_get_int(LttEvent *e, struct marker_field *f); |
| 97 | |
| 98 | guint64 ltt_event_get_long_unsigned(LttEvent *e, struct marker_field *f); |
| 99 | |
| 100 | gint64 ltt_event_get_long_int(LttEvent *e, struct marker_field *f); |
| 101 | |
| 102 | float ltt_event_get_float(LttEvent *e, struct marker_field *f); |
| 103 | |
| 104 | double ltt_event_get_double(LttEvent *e, struct marker_field *f); |
| 105 | |
| 106 | |
| 107 | /* The string obtained is only valid until the next read from |
| 108 | * the same tracefile. */ |
| 109 | |
| 110 | gchar *ltt_event_get_string(LttEvent *e, struct marker_field *f); |
| 111 | |
| 112 | static inline LttCycleCount ltt_event_cycle_count(const LttEvent *e) |
| 113 | { |
| 114 | return e->tsc; |
| 115 | } |
| 116 | |
| 117 | static inline struct LttField *ltt_event_field(const LttEvent *e, int index) |
| 118 | { |
| 119 | return &g_array_index(e->fields_offsets, struct LttField, index); |
| 120 | } |
| 121 | |
| 122 | #endif //_LTT_EVENT_H |