The code to print events is now part of textDump.c. If part of it is useful
[lttv.git] / ltt / branches / poly / misc / EventAPI.h
1 #define LTT_PACKED_STRUCT __attribute__ ((packed))
2 #define TRACER_MAGIC_NUMBER 0x00D6B7ED /* That day marks an important historical event ... */
3
4 void initFacilities();
5 void freeFacilities(); //not implimented yet
6
7
8 //following part is for event reading API
9 typedef struct _trace_header_event {
10 //information of the machine type
11 uint32_t arch_type; /* Type of architecture */
12 uint32_t arch_variant; /* Variant of the given type of architecture */
13 uint32_t system_type; /* Operating system type */
14 uint32_t magic_number; /* Magic number to identify a trace */
15
16 //format of fields
17 uint8_t time_size; /* time size */
18 uint8_t time_granul; /* time granularity */
19 uint8_t id_size; /* size of combined facility/event ids */
20
21 //other elements
22 uint32_t ip_addr; /* IP of the machine */
23 uint8_t nbCpu; /* number of CPU */
24 uint8_t cpuID; /* cpu id */
25 uint32_t buffer_size; /* Size of blocks */
26 } LTT_PACKED_STRUCT trace_header_event;
27
28
29 typedef struct _block_header {
30 struct timeval time; /* Time stamp of this block */
31 uint32_t tsc; /* TSC of this block, if applicable */
32 uint32_t time_delta; /* Time between now and prev event */
33 uint32_t event_count; /* event count */
34 } LTT_PACKED_STRUCT block_header;
35
36
37 typedef struct _block_footer {
38 uint32_t unused_bytes; /* unused bytes at the end of the block */
39 struct timeval time; /* Time stamp of this block */
40 uint32_t tsc; /* TSC of this block, if applicable */
41 uint32_t time_delta; /* Time between now and prev event */
42 } LTT_PACKED_STRUCT block_footer;
43
44
45 typedef struct _ltt_descriptor{
46 int fd; /* file descriptor */
47 off_t file_size; /* file size */
48 int nbBlocks; /* number of blocks in the file */
49 int which_block; /* which block the current block is */
50 int which_event; /* which event of the current block is currently processed */
51 uint32_t current_event_time; /* time of the current event */
52 trace_header_event * trace_header; /* the first event in the first block */
53 block_header * a_block_header; /* block header of the block*/
54 block_footer * a_block_footer; /* block footer of the block*/
55 void * first_event_pos; /* the position of the first event in blockBuf */
56 void * cur_event_pos; /* the position of the current event in blockBuf */
57 void * buffer; /* the buffer to contain the content of the block */
58 int byte_rev; /* Byte-reverse trace data */
59 double TSCPerUsec; /* Cycles per usec */
60 } ltt_descriptor;
61
62 typedef struct _field_handle{
63 char * name; /* field name */
64 data_type field_type; /* field type : integer, float, string, enum, array, sequence */
65 int size; /* number of bytes for a primitive type */
66 data_type element_type; /* element type for array or sequence */
67 int nbElements; /* number of fields for a struct, and of elements for array or sequence */
68 int sequence_size; /* the length size of uint which stores the number of elements of the sequence */
69 char * fmt; /* printf format string for primitive type */
70 off_t offset; /* offset from the beginning of the current event */
71 off_t end_field; /* end of the field: offset of the next field */
72 } field_handle;
73
74 typedef struct _event_handle{
75 char * name; /* event name */
76 int id; /* event code */
77 int size_fixed; /* indicate whether or not the event has string or sequence */
78 sequence base_field; /* base field */
79 int latest_block; /* the latest block which uses the event handle */
80 int latest_event; /* the latest event which uses the event handle */
81 } event_handle;
82
83
84 typedef struct _facility_handle{
85 char * name; /* facility name */
86 int nbEvents; /* number of events in the facility */
87 unsigned long checksum; /* checksum of the facility */
88 event_handle ** events; /* array of event types */
89 } facility_handle;
90
91
92 typedef struct _event_struct{
93 int recid; /* event position in the combined log */
94 struct timeval time; /* detailed absolute time */
95 uint32_t tsc; /* TSC of this event */
96 facility_handle * fHandle; /* facility handle */
97 int event_id; /* id of a event belonging to the facility */
98 // event_handle * event_type; /* event handle */
99 uint32_t ip_addr; /* IP address of the system */
100 uint8_t CPU_id; /* CPU id */
101 int tid; /* thread id */
102 int pid; /* process id */
103 sequence * base_field; /* base field */
104 void * data; /* event binary data */
105 } event_struct;
106
107
108 typedef struct _kernel_facility{
109 char * name; /* kernel name */
110 unsigned long checksum; /* checksum of the facility */
111 int nbEvents; /* number of events in the facility */
112 int firstId; /* the ID of the first event of the facility */
113 } kernel_facility;
114
115
116 void parseEventAndTypeDefinition(char * facilityName);
117 void generateFacilityHandle(char * facName, unsigned long checksum, sequence * events);
118 int getTypeSize(data_type dt, int index);
119
120
121 int getFacilitiesNumber(int * numFac, int * numEvents); //get the number of the registered faciliyies
122 int getFacilitiesFromKernel(kernel_facility ** kFacilities);
123 int readFile(int fd, void * buf, size_t size, char * mesg);
124 int readBlock(ltt_descriptor * lttdes, int whichBlock);
125 void updateLttdes(ltt_descriptor * lttdes);
126 void getTSCPerUsec(ltt_descriptor * lttdes);
127 void getEventTime(ltt_descriptor * lttdes, uint32_t time_delta, struct timeval * pTime);
128
129 ltt_descriptor * trace_open_log(char * fileName);
130 int trace_seek(ltt_descriptor * lttdes, off_t offset, int whence);
131 int trace_seek_time(ltt_descriptor * lttdes, uint32_t offset, int whence);
132 int trace_read(ltt_descriptor * lttdes, event_struct * ev);
133
134 int trace_lookup_facility(int evId, facility_handle ** facilityHandle);
135 int trace_lookup_event(int event_id, facility_handle * facHandle, event_handle ** eventHandle);
136 int trace_lookup_field(sequence * baseField, int position, field_handle ** field);
137
138 int trace_get_char(field_handle * field, void * data);
139 int trace_get_uchar(field_handle * field, void * data);
140 unsigned long trace_get_enum(field_handle * field, void * data);
141 short int trace_get_short(field_handle * field, void * data);
142 unsigned short int trace_get_ushort(field_handle * field, void * data);
143 int trace_get_integer(field_handle * field, void * data);
144 unsigned int trace_get_uinteger(field_handle * field, void * data);
145 long trace_get_long(field_handle * field, void * data);
146 unsigned long trace_get_ulong(field_handle * field, void * data);
147 float trace_get_float(field_handle * field, void * data);
148 double trace_get_double(field_handle * field, void * data);
149 char * trace_get_string(field_handle * field, void * data);
150
151 int trace_get_time_block_position(ltt_descriptor * lttdes, uint32_t seekTime, int beginBlock, int endBlock);
152 void trace_update_basefield(ltt_descriptor * lttdes, sequence * baseField );
153
154
155 #define EVENT_ID_SIZE() sizeof(int8_t)
156 #define TIME_DELTA_SIZE() sizeof(uint32_t)
157 //event id and time delta
158 #define EVENT_HEADER_SIZE() (sizeof(int8_t) + sizeof(uint32_t))
159
160 /* Time operation macros */
161 /* (T3 = T2 - T1) */
162 #define DBTimeSub(T3, T2, T1) \
163 do \
164 {\
165 T3.tv_sec = T2.tv_sec - T1.tv_sec; \
166 T3.tv_usec = T2.tv_usec - T1.tv_usec; \
167 if(T3.tv_usec < 0)\
168 {\
169 T3.tv_sec--;\
170 T3.tv_usec += 1000000;\
171 }\
172 } while(0)
173
174 /* (T3 = T2 + T1) */
175 #define DBTimeAdd(T3, T2, T1) \
176 do \
177 {\
178 T3.tv_sec = T2.tv_sec + T1.tv_sec; \
179 T3.tv_usec = T2.tv_usec + T1.tv_usec; \
180 if(T3.tv_usec >= 1000000)\
181 {\
182 T3.tv_sec += T3.tv_usec / 1000000;\
183 T3.tv_usec = T3.tv_usec % 1000000;\
184 }\
185 } while(0)
This page took 0.033738 seconds and 4 git commands to generate.