3c165eaf |
1 | #ifndef _LTT_MARKERS_H |
2 | #define _LTT_MARKERS_H |
3 | |
d2007fbd |
4 | /* |
5 | * Marker support header. |
6 | * |
3c165eaf |
7 | * Mathieu Desnoyers, August 2007 |
d2007fbd |
8 | * License: LGPL. |
9 | */ |
10 | |
3c165eaf |
11 | #include <glib.h> |
d2007fbd |
12 | #include <ltt/trace.h> |
13 | #include <ltt/compiler.h> |
bb38a290 |
14 | #include <ltt/marker-field.h> |
29af7cfd |
15 | #include <ltt/trace.h> |
3c165eaf |
16 | |
3c165eaf |
17 | #define LTT_ATTRIBUTE_NETWORK_BYTE_ORDER (1<<1) |
18 | |
19 | /* static ids 0-7 reserved for internal use. */ |
20 | #define MARKER_CORE_IDS 8 |
3c165eaf |
21 | |
22 | struct marker_info; |
d2007fbd |
23 | |
24 | struct marker_info { |
3c165eaf |
25 | GQuark name; |
26 | char *format; |
2fc874ab |
27 | long size; /* size if known statically, else -1 */ |
28 | guint8 largest_align; /* Size of the largest alignment needed in the |
29 | payload. */ |
30 | GArray *fields; /* Array of struct marker_field */ |
31 | guint8 int_size, long_size, pointer_size, size_t_size; |
32 | guint8 alignment; /* Size on which the architecture alignment must be |
33 | done. Useful to encapsulate x86_32 events on |
34 | x86_64 kernels. */ |
3c165eaf |
35 | struct marker_info *next; /* Linked list of markers with the same name */ |
36 | }; |
37 | |
750eb11a |
38 | struct marker_data { |
39 | GArray *markers; //indexed by marker id |
40 | GHashTable *markers_hash; //indexed by name hash |
41 | GHashTable *markers_format_hash; //indexed by name hash |
42 | }; |
43 | |
d2007fbd |
44 | enum marker_id { |
45 | MARKER_ID_SET_MARKER_ID = 0, /* Static IDs available (range 0-7) */ |
46 | MARKER_ID_SET_MARKER_FORMAT, |
d2007fbd |
47 | }; |
48 | |
750eb11a |
49 | static inline guint16 marker_get_id_from_info(struct marker_data *data, |
d2007fbd |
50 | struct marker_info *info) |
51 | { |
750eb11a |
52 | return ((unsigned long)info - (unsigned long)data->markers->data) |
d2007fbd |
53 | / sizeof(struct marker_info); |
54 | } |
55 | |
750eb11a |
56 | static inline struct marker_info *marker_get_info_from_id( |
57 | struct marker_data *data, guint16 id) |
d2007fbd |
58 | { |
750eb11a |
59 | if (unlikely(data->markers->len <= id)) |
d2007fbd |
60 | return NULL; |
750eb11a |
61 | return &g_array_index(data->markers, struct marker_info, id); |
d2007fbd |
62 | } |
63 | |
3c165eaf |
64 | /* |
65 | * Returns the head of the marker info list for that name. |
66 | */ |
750eb11a |
67 | static inline struct marker_info *marker_get_info_from_name( |
68 | struct marker_data *data, GQuark name) |
3c165eaf |
69 | { |
abc34be7 |
70 | gpointer orig_key, value; |
abc34be7 |
71 | int res; |
72 | |
750eb11a |
73 | res = g_hash_table_lookup_extended(data->markers_hash, |
f64fedd7 |
74 | (gconstpointer)(gulong)name, &orig_key, &value); |
abc34be7 |
75 | if (!res) |
76 | return NULL; |
750eb11a |
77 | return marker_get_info_from_id(data, (guint16)(gulong)value); |
3c165eaf |
78 | } |
79 | |
750eb11a |
80 | static inline char *marker_get_format_from_name(struct marker_data *data, |
c09a11e9 |
81 | GQuark name) |
82 | { |
83 | gpointer orig_key, value; |
84 | int res; |
85 | |
750eb11a |
86 | res = g_hash_table_lookup_extended(data->markers_format_hash, |
f64fedd7 |
87 | (gconstpointer)(gulong)name, &orig_key, &value); |
c09a11e9 |
88 | if (!res) |
89 | return NULL; |
90 | return (char *)value; |
91 | } |
92 | |
14b1ac27 |
93 | static inline struct marker_field *marker_get_field(struct marker_info *info, |
94 | guint i) |
95 | { |
96 | return &g_array_index(info->fields, struct marker_field, i); |
97 | } |
98 | |
99 | static inline unsigned int marker_get_num_fields(struct marker_info *info) |
100 | { |
101 | return info->fields->len; |
102 | } |
103 | |
104 | /* |
105 | * for_each_marker_field - iterate over fields of a marker |
106 | * @field: struct marker_field * to use as iterator |
107 | * @info: marker info pointer |
108 | */ |
109 | #define for_each_marker_field(field, info) \ |
110 | for (field = marker_get_field(info, 0); \ |
111 | field != marker_get_field(info, marker_get_num_fields(info)); \ |
112 | field++) |
113 | |
750eb11a |
114 | int marker_format_event(LttTrace *trace, GQuark channel, GQuark name, |
115 | const char *format); |
116 | int marker_id_event(LttTrace *trace, GQuark channel, GQuark name, guint16 id, |
3c165eaf |
117 | uint8_t int_size, uint8_t long_size, uint8_t pointer_size, |
118 | uint8_t size_t_size, uint8_t alignment); |
750eb11a |
119 | struct marker_data *allocate_marker_data(void); |
120 | void destroy_marker_data(struct marker_data *data); |
3c165eaf |
121 | |
122 | #endif //_LTT_MARKERS_H |