initial port of the mainwindow
[lttv.git] / ltt / marker.h
1 #ifndef _LTT_MARKERS_H
2 #define _LTT_MARKERS_H
3
4 /*
5 * Marker support header.
6 *
7 * Mathieu Desnoyers, August 2007
8 * License: LGPL.
9 */
10
11 #include <glib.h>
12 #include <ltt/trace.h>
13 #include <ltt/compiler.h>
14 #include <ltt/marker-field.h>
15 #include <ltt/trace.h>
16
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
21
22 struct marker_info;
23
24 struct marker_info {
25 GQuark name;
26 char *format;
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. */
35 struct marker_info *next; /* Linked list of markers with the same name */
36 };
37
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
44 enum marker_id {
45 MARKER_ID_SET_MARKER_ID = 0, /* Static IDs available (range 0-7) */
46 MARKER_ID_SET_MARKER_FORMAT,
47 };
48
49 static inline guint16 marker_get_id_from_info(struct marker_data *data,
50 struct marker_info *info)
51 {
52 return ((unsigned long)info - (unsigned long)data->markers->data)
53 / sizeof(struct marker_info);
54 }
55
56 static inline struct marker_info *marker_get_info_from_id(
57 struct marker_data *data, guint16 id)
58 {
59 if (unlikely(data->markers->len <= id))
60 return NULL;
61 return &g_array_index(data->markers, struct marker_info, id);
62 }
63
64 /*
65 * Returns the head of the marker info list for that name.
66 */
67 static inline struct marker_info *marker_get_info_from_name(
68 struct marker_data *data, GQuark name)
69 {
70 gpointer orig_key, value;
71 int res;
72
73 res = g_hash_table_lookup_extended(data->markers_hash,
74 (gconstpointer)(gulong)name, &orig_key, &value);
75 if (!res)
76 return NULL;
77 return marker_get_info_from_id(data, (guint16)(gulong)value);
78 }
79
80 static inline char *marker_get_format_from_name(struct marker_data *data,
81 GQuark name)
82 {
83 gpointer orig_key, value;
84 int res;
85
86 res = g_hash_table_lookup_extended(data->markers_format_hash,
87 (gconstpointer)(gulong)name, &orig_key, &value);
88 if (!res)
89 return NULL;
90 return (char *)value;
91 }
92
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
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,
117 uint8_t int_size, uint8_t long_size, uint8_t pointer_size,
118 uint8_t size_t_size, uint8_t alignment);
119 struct marker_data *allocate_marker_data(void);
120 void destroy_marker_data(struct marker_data *data);
121
122 #endif //_LTT_MARKERS_H
This page took 0.031736 seconds and 4 git commands to generate.