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, |
2fc874ab |
47 | MARKER_ID_DYNAMIC, /* Dynamic IDs (range: 8-65535) */ |
d2007fbd |
48 | }; |
49 | |
750eb11a |
50 | static inline guint16 marker_get_id_from_info(struct marker_data *data, |
d2007fbd |
51 | struct marker_info *info) |
52 | { |
750eb11a |
53 | return ((unsigned long)info - (unsigned long)data->markers->data) |
d2007fbd |
54 | / sizeof(struct marker_info); |
55 | } |
56 | |
750eb11a |
57 | static inline struct marker_info *marker_get_info_from_id( |
58 | struct marker_data *data, guint16 id) |
d2007fbd |
59 | { |
750eb11a |
60 | if (unlikely(data->markers->len <= id)) |
d2007fbd |
61 | return NULL; |
750eb11a |
62 | return &g_array_index(data->markers, struct marker_info, id); |
d2007fbd |
63 | } |
64 | |
3c165eaf |
65 | /* |
66 | * Returns the head of the marker info list for that name. |
67 | */ |
750eb11a |
68 | static inline struct marker_info *marker_get_info_from_name( |
69 | struct marker_data *data, GQuark name) |
3c165eaf |
70 | { |
abc34be7 |
71 | gpointer orig_key, value; |
abc34be7 |
72 | int res; |
73 | |
750eb11a |
74 | res = g_hash_table_lookup_extended(data->markers_hash, |
f64fedd7 |
75 | (gconstpointer)(gulong)name, &orig_key, &value); |
abc34be7 |
76 | if (!res) |
77 | return NULL; |
750eb11a |
78 | return marker_get_info_from_id(data, (guint16)(gulong)value); |
3c165eaf |
79 | } |
80 | |
750eb11a |
81 | static inline char *marker_get_format_from_name(struct marker_data *data, |
c09a11e9 |
82 | GQuark name) |
83 | { |
84 | gpointer orig_key, value; |
85 | int res; |
86 | |
750eb11a |
87 | res = g_hash_table_lookup_extended(data->markers_format_hash, |
f64fedd7 |
88 | (gconstpointer)(gulong)name, &orig_key, &value); |
c09a11e9 |
89 | if (!res) |
90 | return NULL; |
91 | return (char *)value; |
92 | } |
93 | |
14b1ac27 |
94 | static inline struct marker_field *marker_get_field(struct marker_info *info, |
95 | guint i) |
96 | { |
97 | return &g_array_index(info->fields, struct marker_field, i); |
98 | } |
99 | |
100 | static inline unsigned int marker_get_num_fields(struct marker_info *info) |
101 | { |
102 | return info->fields->len; |
103 | } |
104 | |
105 | /* |
106 | * for_each_marker_field - iterate over fields of a marker |
107 | * @field: struct marker_field * to use as iterator |
108 | * @info: marker info pointer |
109 | */ |
110 | #define for_each_marker_field(field, info) \ |
111 | for (field = marker_get_field(info, 0); \ |
112 | field != marker_get_field(info, marker_get_num_fields(info)); \ |
113 | field++) |
114 | |
750eb11a |
115 | int marker_format_event(LttTrace *trace, GQuark channel, GQuark name, |
116 | const char *format); |
117 | int marker_id_event(LttTrace *trace, GQuark channel, GQuark name, guint16 id, |
3c165eaf |
118 | uint8_t int_size, uint8_t long_size, uint8_t pointer_size, |
119 | uint8_t size_t_size, uint8_t alignment); |
750eb11a |
120 | struct marker_data *allocate_marker_data(void); |
121 | void destroy_marker_data(struct marker_data *data); |
3c165eaf |
122 | |
123 | #endif //_LTT_MARKERS_H |