allocate marker data
[lttv.git] / ltt / branches / poly / ltt / tracefile.c
CommitLineData
449cb9d7 1/* This file is part of the Linux Trace Toolkit viewer
3aee1200 2 * Copyright (C) 2005 Mathieu Desnoyers
449cb9d7 3 *
3aee1200 4 * Complete rewrite from the original version made by XangXiu Yang.
5 *
1b44b0b5 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License Version 2.1 as published by the Free Software Foundation.
449cb9d7 9 *
1b44b0b5 10 * This library is distributed in the hope that it will be useful,
449cb9d7 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1b44b0b5 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
449cb9d7 14 *
1b44b0b5 15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
449cb9d7 19 */
20
4e4d11b3 21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
6cd62ccf 25#include <stdio.h>
26#include <fcntl.h>
8d1e6362 27#include <string.h>
28#include <dirent.h>
6cd62ccf 29#include <sys/stat.h>
30#include <sys/types.h>
8d1e6362 31#include <errno.h>
32#include <unistd.h>
42db9bf1 33#include <math.h>
cdf90f40 34#include <glib.h>
3aee1200 35#include <malloc.h>
36#include <sys/mman.h>
dd3a6d39 37#include <string.h>
6cd62ccf 38
ef35d837 39// For realpath
40#include <limits.h>
41#include <stdlib.h>
42
43
6cd62ccf 44#include "parser.h"
a5dcde2f 45#include <ltt/ltt.h>
46#include "ltt-private.h"
963b5f2d 47#include <ltt/trace.h>
c02ea99f 48#include <ltt/event.h>
29af7cfd 49//#include <ltt/type.h>
1a2ceb63 50#include <ltt/ltt-types.h>
bb38a290 51#include <ltt/marker.h>
3aee1200 52
53/* Facility names used in this file */
54
55GQuark LTT_FACILITY_NAME_HEARTBEAT,
d1bb700c 56 LTT_EVENT_NAME_HEARTBEAT,
57 LTT_EVENT_NAME_HEARTBEAT_FULL;
3aee1200 58GQuark LTT_TRACEFILE_NAME_FACILITIES;
59
86005ded 60#ifndef g_open
61#define g_open open
62#endif
63
64
51b5991e 65#define __UNUSED__ __attribute__((__unused__))
6cd62ccf 66
a1062ddd 67#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
3aee1200 68
69#ifndef g_debug
a1062ddd 70#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
3aee1200 71#endif
a1062ddd 72
45e14832 73#define g_close close
8959a0c8 74
b77d1b57 75/* Those macros must be called from within a function where page_size is a known
76 * variable */
77#define PAGE_MASK (~(page_size-1))
78#define PAGE_ALIGN(addr) (((addr)+page_size-1)&PAGE_MASK)
79
6cd62ccf 80/* set the offset of the fields belonging to the event,
81 need the information of the archecture */
f104d082 82//void set_fields_offsets(LttTracefile *tf, LttEventType *event_type);
eed2ef37 83//size_t get_fields_offsets(LttTracefile *tf, LttEventType *event_type, void *data);
6cd62ccf 84
3aee1200 85/* get the size of the field type according to
86 * The facility size information. */
f104d082 87#if 0
3aee1200 88static inline void preset_field_type_size(LttTracefile *tf,
89 LttEventType *event_type,
90 off_t offset_root, off_t offset_parent,
91 enum field_status *fixed_root, enum field_status *fixed_parent,
92 LttField *field);
f104d082 93#endif //0
6cd62ccf 94
3aee1200 95/* map a fixed size or a block information from the file (fd) */
96static gint map_block(LttTracefile * tf, guint block_num);
97
98/* calculate nsec per cycles for current block */
791dffa6 99#if 0
100static guint32 calc_nsecs_per_cycle(LttTracefile * t);
101static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles);
102#endif //0
6cd62ccf 103
3aee1200 104/* go to the next event */
105static int ltt_seek_next_event(LttTracefile *tf);
6cd62ccf 106
3c165eaf 107//void ltt_update_event_size(LttTracefile *tf);
eed2ef37 108
3c165eaf 109static int open_tracefiles(LttTrace *trace, gchar *root_path,
110 gchar *relative_path);
111static int ltt_process_facility_tracefile(LttTracefile *tf);
112static void ltt_tracefile_time_span_get(LttTracefile *tf,
113 LttTime *start, LttTime *end);
114static void group_time_span_get(GQuark name, gpointer data, gpointer user_data);
115static gint map_block(LttTracefile * tf, guint block_num);
116static int ltt_seek_next_event(LttTracefile *tf);
117static void __attribute__((constructor)) init(void);
118static void ltt_update_event_size(LttTracefile *tf);
119//void precompute_offsets(LttFacility *fac, LttEventType *event);
2312de30 120
3aee1200 121#if 0
43da6a59 122/* Functions to parse system.xml file (using glib xml parser) */
51b5991e 123static void parser_start_element (GMarkupParseContext __UNUSED__ *context,
43da6a59 124 const gchar *element_name,
125 const gchar **attribute_names,
126 const gchar **attribute_values,
127 gpointer user_data,
128 GError **error)
129{
130 int i=0;
131 LttSystemDescription* des = (LttSystemDescription* )user_data;
132 if(strcmp("system", element_name)){
2a74fbf4 133 *error = g_error_new(G_MARKUP_ERROR,
134 G_LOG_LEVEL_WARNING,
135 "This is not system.xml file");
136 return;
43da6a59 137 }
138
139 while(attribute_names[i]){
140 if(strcmp("node_name", attribute_names[i])==0){
141 des->node_name = g_strdup(attribute_values[i]);
142 }else if(strcmp("domainname", attribute_names[i])==0){
143 des->domain_name = g_strdup(attribute_values[i]);
144 }else if(strcmp("cpu", attribute_names[i])==0){
145 des->nb_cpu = atoi(attribute_values[i]);
146 }else if(strcmp("arch_size", attribute_names[i])==0){
147 if(strcmp(attribute_values[i],"LP32") == 0) des->size = LTT_LP32;
148 else if(strcmp(attribute_values[i],"ILP32") == 0) des->size = LTT_ILP32;
149 else if(strcmp(attribute_values[i],"LP64") == 0) des->size = LTT_LP64;
150 else if(strcmp(attribute_values[i],"ILP64") == 0) des->size = LTT_ILP64;
151 else if(strcmp(attribute_values[i],"UNKNOWN") == 0) des->size = LTT_UNKNOWN;
152 }else if(strcmp("endian", attribute_names[i])==0){
153 if(strcmp(attribute_values[i],"LITTLE_ENDIAN") == 0)
154 des->endian = LTT_LITTLE_ENDIAN;
155 else if(strcmp(attribute_values[i],"BIG_ENDIAN") == 0)
156 des->endian = LTT_BIG_ENDIAN;
157 }else if(strcmp("kernel_name", attribute_names[i])==0){
158 des->kernel_name = g_strdup(attribute_values[i]);
159 }else if(strcmp("kernel_release", attribute_names[i])==0){
160 des->kernel_release = g_strdup(attribute_values[i]);
161 }else if(strcmp("kernel_version", attribute_names[i])==0){
162 des->kernel_version = g_strdup(attribute_values[i]);
163 }else if(strcmp("machine", attribute_names[i])==0){
164 des->machine = g_strdup(attribute_values[i]);
165 }else if(strcmp("processor", attribute_names[i])==0){
166 des->processor = g_strdup(attribute_values[i]);
167 }else if(strcmp("hardware_platform", attribute_names[i])==0){
168 des->hardware_platform = g_strdup(attribute_values[i]);
169 }else if(strcmp("operating_system", attribute_names[i])==0){
170 des->operating_system = g_strdup(attribute_values[i]);
171 }else if(strcmp("ltt_major_version", attribute_names[i])==0){
172 des->ltt_major_version = atoi(attribute_values[i]);
173 }else if(strcmp("ltt_minor_version", attribute_names[i])==0){
174 des->ltt_minor_version = atoi(attribute_values[i]);
175 }else if(strcmp("ltt_block_size", attribute_names[i])==0){
176 des->ltt_block_size = atoi(attribute_values[i]);
177 }else{
2a74fbf4 178 *error = g_error_new(G_MARKUP_ERROR,
179 G_LOG_LEVEL_WARNING,
180 "Not a valid attribute");
181 return;
43da6a59 182 }
183 i++;
184 }
185}
186
51b5991e 187static void parser_characters (GMarkupParseContext __UNUSED__ *context,
43da6a59 188 const gchar *text,
51b5991e 189 gsize __UNUSED__ text_len,
43da6a59 190 gpointer user_data,
51b5991e 191 GError __UNUSED__ **error)
43da6a59 192{
193 LttSystemDescription* des = (LttSystemDescription* )user_data;
194 des->description = g_strdup(text);
195}
3aee1200 196#endif //0
f104d082 197
3c165eaf 198#if 0
77175651 199LttFacility *ltt_trace_get_facility_by_num(LttTrace *t,
3aee1200 200 guint num)
201{
202 g_assert(num < t->facilities_by_num->len);
203
204 return &g_array_index(t->facilities_by_num, LttFacility, num);
205
206}
3c165eaf 207#endif //0
43da6a59 208
b56dcdf2 209guint ltt_trace_get_num_cpu(LttTrace *t)
210{
211 return t->num_cpu;
212}
213
43da6a59 214
b7576a11 215/* trace can be NULL
216 *
217 * Return value : 0 success, 1 bad tracefile
218 */
219int parse_trace_header(void *header, LttTracefile *tf, LttTrace *t)
220{
221 guint32 *magic_number = (guint32*)header;
222 struct ltt_trace_header_any *any = (struct ltt_trace_header_any *)header;
223
224 if(*magic_number == LTT_MAGIC_NUMBER)
225 tf->reverse_bo = 0;
226 else if(*magic_number == LTT_REV_MAGIC_NUMBER)
227 tf->reverse_bo = 1;
228 else /* invalid magic number, bad tracefile ! */
229 return 1;
230
231 /* Get float byte order : might be different from int byte order
232 * (or is set to 0 if the trace has no float (kernel trace)) */
233 tf->float_word_order = any->float_word_order;
f104d082 234 tf->has_alignment = any->has_alignment;
90440c06 235 tf->has_heartbeat = any->has_heartbeat;
b7576a11 236
237 if(t) {
238 t->arch_type = ltt_get_uint32(LTT_GET_BO(tf),
239 &any->arch_type);
240 t->arch_variant = ltt_get_uint32(LTT_GET_BO(tf),
241 &any->arch_variant);
242 t->arch_size = any->arch_size;
243 t->ltt_major_version = any->major_version;
244 t->ltt_minor_version = any->minor_version;
245 t->flight_recorder = any->flight_recorder;
3c165eaf 246 // t->compact_facilities = NULL;
b7576a11 247 }
248
249
250 switch(any->major_version) {
251
252 case 0:
3c165eaf 253 g_warning("Unsupported trace version : %hhu.%hhu",
254 any->major_version, any->minor_version);
255 return 1;
256 break;
257 case 1:
b7576a11 258 switch(any->minor_version) {
3c165eaf 259 case 0:
b7576a11 260 {
3c165eaf 261 struct ltt_trace_header_1_0 *vheader =
262 (struct ltt_trace_header_1_0 *)header;
823820eb 263 tf->buffer_header_size =
264 sizeof(struct ltt_block_start_header)
3c165eaf 265 + sizeof(struct ltt_trace_header_1_0);
62e4e7bf 266 tf->tsc_lsb_truncate = vheader->tsc_lsb_truncate;
267 tf->tscbits = vheader->tscbits;
268 tf->tsc_msb_cutoff = 32 - tf->tsc_lsb_truncate - tf->tscbits;
dd3a6d39 269 tf->tsc_mask = ((1ULL << (tf->tscbits))-1);
270 tf->tsc_mask = tf->tsc_mask << tf->tsc_lsb_truncate;
62e4e7bf 271 tf->tsc_mask_next_bit = (1ULL<<(tf->tscbits));
272 tf->tsc_mask_next_bit = tf->tsc_mask_next_bit << tf->tsc_lsb_truncate;
e939e5b2 273 if(t) {
274 t->start_freq = ltt_get_uint64(LTT_GET_BO(tf),
275 &vheader->start_freq);
a3999b49 276 t->freq_scale = ltt_get_uint32(LTT_GET_BO(tf),
277 &vheader->freq_scale);
e939e5b2 278 t->start_tsc = ltt_get_uint64(LTT_GET_BO(tf),
279 &vheader->start_tsc);
280 t->start_monotonic = ltt_get_uint64(LTT_GET_BO(tf),
281 &vheader->start_monotonic);
282 t->start_time.tv_sec = ltt_get_uint64(LTT_GET_BO(tf),
283 &vheader->start_time_sec);
284 t->start_time.tv_nsec = ltt_get_uint64(LTT_GET_BO(tf),
285 &vheader->start_time_usec);
286 t->start_time.tv_nsec *= 1000; /* microsec to nanosec */
287
288 t->start_time_from_tsc = ltt_time_from_uint64(
c7f86478 289 (double)t->start_tsc
290 * (1000000000.0 / tf->trace->freq_scale)
62e4e7bf 291 / (double)t->start_freq);
292 t->compact_event_bits = 0;
e939e5b2 293 }
294 }
295 break;
b7576a11 296 default:
986e2a7c 297 g_warning("Unsupported trace version : %hhu.%hhu",
3c165eaf 298 any->major_version, any->minor_version);
b7576a11 299 return 1;
300 }
301 break;
b7576a11 302 default:
303 g_warning("Unsupported trace version : %hhu.%hhu",
304 any->major_version, any->minor_version);
305 return 1;
306 }
307
308
309 return 0;
310}
311
312
313
6cd62ccf 314/*****************************************************************************
315 *Function name
963b5f2d 316 * ltt_tracefile_open : open a trace file, construct a LttTracefile
6cd62ccf 317 *Input params
963b5f2d 318 * t : the trace containing the tracefile
319 * fileName : path name of the trace file
3aee1200 320 * tf : the tracefile structure
6cd62ccf 321 *Return value
3aee1200 322 * : 0 for success, -1 otherwise.
6cd62ccf 323 ****************************************************************************/
324
3aee1200 325gint ltt_tracefile_open(LttTrace *t, gchar * fileName, LttTracefile *tf)
6cd62ccf 326{
963b5f2d 327 struct stat lTDFStat; /* Trace data file status */
3aee1200 328 struct ltt_block_start_header *header;
b77d1b57 329 int page_size = getpagesize();
6cd62ccf 330
331 //open the file
d3d34f49 332 tf->long_name = g_quark_from_string(fileName);
963b5f2d 333 tf->trace = t;
3865ea09 334 tf->fd = open(fileName, O_RDONLY);
6cd62ccf 335 if(tf->fd < 0){
2a74fbf4 336 g_warning("Unable to open input data file %s\n", fileName);
3aee1200 337 goto end;
6cd62ccf 338 }
339
340 // Get the file's status
341 if(fstat(tf->fd, &lTDFStat) < 0){
2a74fbf4 342 g_warning("Unable to get the status of the input data file %s\n", fileName);
3aee1200 343 goto close_file;
6cd62ccf 344 }
345
346 // Is the file large enough to contain a trace
823820eb 347 if(lTDFStat.st_size <
9ea7b94b 348 (off_t)(sizeof(struct ltt_block_start_header)
349 + sizeof(struct ltt_trace_header_any))){
8710c6c7 350 g_print("The input data file %s does not contain a trace\n", fileName);
3aee1200 351 goto close_file;
352 }
353
354 /* Temporarily map the buffer start header to get trace information */
355 /* Multiple of pages aligned head */
b77d1b57 356 tf->buffer.head = mmap(0,
9ea7b94b 357 PAGE_ALIGN(sizeof(struct ltt_block_start_header)
358 + sizeof(struct ltt_trace_header_any)), PROT_READ,
3aee1200 359 MAP_PRIVATE, tf->fd, 0);
3865ea09 360 if(tf->buffer.head == MAP_FAILED) {
3aee1200 361 perror("Error in allocating memory for buffer of tracefile");
362 goto close_file;
6cd62ccf 363 }
3865ea09 364 g_assert( ( (guint)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
3aee1200 365
366 header = (struct ltt_block_start_header*)tf->buffer.head;
6cd62ccf 367
51551c6f 368 if(parse_trace_header(header->trace, tf, NULL)) {
369 g_warning("parse_trace_header error");
370 goto unmap_file;
371 }
3aee1200 372
6cd62ccf 373 //store the size of the file
374 tf->file_size = lTDFStat.st_size;
f628823c 375 tf->buf_size = ltt_get_uint32(LTT_GET_BO(tf), &header->buf_size);
376 tf->num_blocks = tf->file_size / tf->buf_size;
377
378 if(munmap(tf->buffer.head,
9ea7b94b 379 PAGE_ALIGN(sizeof(struct ltt_block_start_header)
380 + sizeof(struct ltt_trace_header_any)))) {
f628823c 381 g_warning("unmap size : %u\n",
9ea7b94b 382 PAGE_ALIGN(sizeof(struct ltt_block_start_header)
383 + sizeof(struct ltt_trace_header_any)));
f628823c 384 perror("munmap error");
385 g_assert(0);
386 }
3aee1200 387 tf->buffer.head = NULL;
6cd62ccf 388
963b5f2d 389 //read the first block
3aee1200 390 if(map_block(tf,0)) {
391 perror("Cannot map block for tracefile");
392 goto close_file;
393 }
394
395 return 0;
6cd62ccf 396
3aee1200 397 /* Error */
398unmap_file:
f628823c 399 if(munmap(tf->buffer.head,
9ea7b94b 400 PAGE_ALIGN(sizeof(struct ltt_block_start_header)
401 + sizeof(struct ltt_trace_header_any)))) {
f628823c 402 g_warning("unmap size : %u\n",
9ea7b94b 403 PAGE_ALIGN(sizeof(struct ltt_block_start_header)
404 + sizeof(struct ltt_trace_header_any)));
f628823c 405 perror("munmap error");
406 g_assert(0);
407 }
3aee1200 408close_file:
3865ea09 409 close(tf->fd);
3aee1200 410end:
411 return -1;
6cd62ccf 412}
413
d3d34f49 414LttTrace *ltt_tracefile_get_trace(LttTracefile *tf)
415{
416 return tf->trace;
417}
418
3aee1200 419#if 0
6cd62ccf 420/*****************************************************************************
963b5f2d 421 *Open control and per cpu tracefiles
6cd62ccf 422 ****************************************************************************/
423
45e14832 424void ltt_tracefile_open_cpu(LttTrace *t, gchar * tracefile_name)
6cd62ccf 425{
963b5f2d 426 LttTracefile * tf;
427 tf = ltt_tracefile_open(t,tracefile_name);
4a6c8e36 428 if(!tf) return;
963b5f2d 429 t->per_cpu_tracefile_number++;
430 g_ptr_array_add(t->per_cpu_tracefiles, tf);
6cd62ccf 431}
432
45e14832 433gint ltt_tracefile_open_control(LttTrace *t, gchar * control_name)
6cd62ccf 434{
963b5f2d 435 LttTracefile * tf;
c02ea99f 436 LttEvent ev;
963b5f2d 437 LttFacility * f;
963b5f2d 438 void * pos;
439 FacilityLoad fLoad;
8d1e6362 440 unsigned int i;
963b5f2d 441
442 tf = ltt_tracefile_open(t,control_name);
2a74fbf4 443 if(!tf) {
444 g_warning("ltt_tracefile_open_control : bad file descriptor");
445 return -1;
446 }
963b5f2d 447 t->control_tracefile_number++;
448 g_ptr_array_add(t->control_tracefiles,tf);
449
450 //parse facilities tracefile to get base_id
542ceddd 451 if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){
963b5f2d 452 while(1){
c02ea99f 453 if(!ltt_tracefile_read(tf,&ev)) return 0; // end of file
40331ba8 454
c02ea99f 455 if(ev.event_id == TRACE_FACILITY_LOAD){
456 pos = ev.data;
45e14832 457 fLoad.name = (gchar*)pos;
47a166fc 458 fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
cbd41522 459 fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
963b5f2d 460
461 for(i=0;i<t->facility_number;i++){
462 f = (LttFacility*)g_ptr_array_index(t->facilities,i);
463 if(strcmp(f->name,fLoad.name)==0 && fLoad.checksum==f->checksum){
464 f->base_id = fLoad.base_code;
465 break;
466 }
467 }
2a74fbf4 468 if(i==t->facility_number) {
8d1e6362 469 g_warning("Facility: %s, checksum: %u is not found",
470 fLoad.name,(unsigned int)fLoad.checksum);
2a74fbf4 471 return -1;
472 }
c02ea99f 473 }else if(ev.event_id == TRACE_BLOCK_START){
40331ba8 474 continue;
c02ea99f 475 }else if(ev.event_id == TRACE_BLOCK_END){
40331ba8 476 break;
2a74fbf4 477 }else {
8d1e6362 478 g_warning("Not valid facilities trace file");
2a74fbf4 479 return -1;
480 }
963b5f2d 481 }
482 }
2a74fbf4 483 return 0;
6cd62ccf 484}
3aee1200 485#endif //0
6cd62ccf 486
487/*****************************************************************************
488 *Function name
963b5f2d 489 * ltt_tracefile_close: close a trace file,
6cd62ccf 490 *Input params
963b5f2d 491 * t : tracefile which will be closed
6cd62ccf 492 ****************************************************************************/
493
963b5f2d 494void ltt_tracefile_close(LttTracefile *t)
6cd62ccf 495{
f628823c 496 int page_size = getpagesize();
497
3aee1200 498 if(t->buffer.head != NULL)
f628823c 499 if(munmap(t->buffer.head, PAGE_ALIGN(t->buf_size))) {
500 g_warning("unmap size : %u\n",
501 PAGE_ALIGN(t->buf_size));
502 perror("munmap error");
503 g_assert(0);
504 }
505
3865ea09 506 close(t->fd);
963b5f2d 507}
6cd62ccf 508
6cd62ccf 509
963b5f2d 510/*****************************************************************************
511 *Get system information
512 ****************************************************************************/
3aee1200 513#if 0
45e14832 514gint getSystemInfo(LttSystemDescription* des, gchar * pathname)
963b5f2d 515{
45e14832 516 int fd;
517 GIOChannel *iochan;
518 gchar *buf = NULL;
519 gsize length;
43da6a59 520
521 GMarkupParseContext * context;
2a74fbf4 522 GError * error = NULL;
43da6a59 523 GMarkupParser markup_parser =
524 {
525 parser_start_element,
8d1e6362 526 NULL,
43da6a59 527 parser_characters,
528 NULL, /* passthrough */
529 NULL /* error */
530 };
963b5f2d 531
45e14832 532 fd = g_open(pathname, O_RDONLY, 0);
533 if(fd == -1){
2a74fbf4 534 g_warning("Can not open file : %s\n", pathname);
535 return -1;
6cd62ccf 536 }
963b5f2d 537
45e14832 538 iochan = g_io_channel_unix_new(fd);
539
43da6a59 540 context = g_markup_parse_context_new(&markup_parser, 0, des,NULL);
6cd62ccf 541
45e14832 542 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
543 while(g_io_channel_read_line(iochan, &buf, &length, NULL, &error)
544 != G_IO_STATUS_EOF) {
545
546 if(error != NULL) {
547 g_warning("Can not read xml file: \n%s\n", error->message);
548 g_error_free(error);
549 }
550 if(!g_markup_parse_context_parse(context, buf, length, &error)){
2a74fbf4 551 if(error != NULL) {
552 g_warning("Can not parse xml file: \n%s\n", error->message);
553 g_error_free(error);
554 }
555 g_markup_parse_context_free(context);
45e14832 556
557 g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
558 if(error != NULL) {
559 g_warning("Can not close file: \n%s\n", error->message);
560 g_error_free(error);
561 }
562
563 close(fd);
2a74fbf4 564 return -1;
43da6a59 565 }
963b5f2d 566 }
2a74fbf4 567 g_markup_parse_context_free(context);
45e14832 568
569 g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
570 if(error != NULL) {
571 g_warning("Can not close file: \n%s\n", error->message);
572 g_error_free(error);
573 }
574
575 g_close(fd);
576
577 g_free(buf);
2a74fbf4 578 return 0;
6cd62ccf 579}
3aee1200 580#endif //0
6cd62ccf 581
582/*****************************************************************************
963b5f2d 583 *The following functions get facility/tracefile information
6cd62ccf 584 ****************************************************************************/
3aee1200 585#if 0
45e14832 586gint getFacilityInfo(LttTrace *t, gchar* eventdefs)
6cd62ccf 587{
45e14832 588 GDir * dir;
589 const gchar * name;
8d1e6362 590 unsigned int i,j;
963b5f2d 591 LttFacility * f;
592 LttEventType * et;
45e14832 593 gchar fullname[DIR_NAME_SIZE];
594 GError * error = NULL;
595
596 dir = g_dir_open(eventdefs, 0, &error);
963b5f2d 597
45e14832 598 if(error != NULL) {
599 g_warning("Can not open directory: %s, %s\n", eventdefs, error->message);
600 g_error_free(error);
2a74fbf4 601 return -1;
602 }
963b5f2d 603
45e14832 604 while((name = g_dir_read_name(dir)) != NULL){
605 if(!g_pattern_match_simple("*.xml", name)) continue;
606 strcpy(fullname,eventdefs);
607 strcat(fullname,name);
608 ltt_facility_open(t,fullname);
609 }
610 g_dir_close(dir);
963b5f2d 611
963b5f2d 612 for(j=0;j<t->facility_number;j++){
8710c6c7 613 f = (LttFacility*)g_ptr_array_index(t->facilities, j);
963b5f2d 614 for(i=0; i<f->event_number; i++){
615 et = f->events[i];
40331ba8 616 setFieldsOffset(NULL, et, NULL, t);
963b5f2d 617 }
618 }
2a74fbf4 619 return 0;
963b5f2d 620}
3aee1200 621#endif //0
6cd62ccf 622
963b5f2d 623/*****************************************************************************
624 *A trace is specified as a pathname to the directory containing all the
625 *associated data (control tracefiles, per cpu tracefiles, event
626 *descriptions...).
627 *
628 *When a trace is closed, all the associated facilities, types and fields
629 *are released as well.
8d1e6362 630 */
631
632
633/****************************************************************************
634 * get_absolute_pathname
803229fa 635 *
8d1e6362 636 * return the unique pathname in the system
637 *
ef35d837 638 * MD : Fixed this function so it uses realpath, dealing well with
639 * forgotten cases (.. were not used correctly before).
803229fa 640 *
963b5f2d 641 ****************************************************************************/
45e14832 642void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname)
9f797243 643{
9f797243 644 abs_pathname[0] = '\0';
803229fa 645
ef35d837 646 if ( realpath (pathname, abs_pathname) != NULL)
647 return;
648 else
649 {
8d1e6362 650 /* error, return the original path unmodified */
ef35d837 651 strcpy(abs_pathname, pathname);
9f797243 652 return;
653 }
ef35d837 654 return;
9f797243 655}
656
3aee1200 657/* Search for something like : .*_.*
658 *
659 * The left side is the name, the right side is the number.
660 */
661
ae3d0f50 662int get_tracefile_name_number(gchar *raw_name,
3aee1200 663 GQuark *name,
ae3d0f50 664 guint *num,
62e4e7bf 665 guint *tid,
666 guint *pgid,
667 guint64 *creation)
6cd62ccf 668{
3aee1200 669 guint raw_name_len = strlen(raw_name);
670 gchar char_name[PATH_MAX];
3aee1200 671 int i;
672 int underscore_pos;
673 long int cpu_num;
674 gchar *endptr;
62e4e7bf 675 gchar *tmpptr;
3aee1200 676
677 for(i=raw_name_len-1;i>=0;i--) {
678 if(raw_name[i] == '_') break;
679 }
ae3d0f50 680 if(i==-1) { /* Either not found or name length is 0 */
62e4e7bf 681 /* This is a userspace tracefile */
682 strncpy(char_name, raw_name, raw_name_len);
683 char_name[raw_name_len] = '\0';
684 *name = g_quark_from_string(char_name);
685 *num = 0; /* unknown cpu */
686 for(i=0;i<raw_name_len;i++) {
687 if(raw_name[i] == '/') {
688 break;
689 }
690 }
691 i++;
692 for(;i<raw_name_len;i++) {
693 if(raw_name[i] == '/') {
694 break;
695 }
696 }
697 i++;
698 for(;i<raw_name_len;i++) {
699 if(raw_name[i] == '-') {
700 break;
701 }
702 }
703 if(i == raw_name_len) return -1;
704 i++;
705 tmpptr = &raw_name[i];
706 for(;i<raw_name_len;i++) {
707 if(raw_name[i] == '.') {
708 raw_name[i] = ' ';
709 break;
710 }
711 }
712 *tid = strtoul(tmpptr, &endptr, 10);
713 if(endptr == tmpptr)
714 return -1; /* No digit */
715 if(*tid == ULONG_MAX)
716 return -1; /* underflow / overflow */
717 i++;
718 tmpptr = &raw_name[i];
719 for(;i<raw_name_len;i++) {
720 if(raw_name[i] == '.') {
721 raw_name[i] = ' ';
722 break;
723 }
724 }
725 *pgid = strtoul(tmpptr, &endptr, 10);
726 if(endptr == tmpptr)
727 return -1; /* No digit */
728 if(*pgid == ULONG_MAX)
729 return -1; /* underflow / overflow */
730 i++;
731 tmpptr = &raw_name[i];
732 *creation = strtoull(tmpptr, &endptr, 10);
733 if(endptr == tmpptr)
734 return -1; /* No digit */
735 if(*creation == G_MAXUINT64)
736 return -1; /* underflow / overflow */
737 } else {
738 underscore_pos = i;
739
740 cpu_num = strtol(raw_name+underscore_pos+1, &endptr, 10);
741
742 if(endptr == raw_name+underscore_pos+1)
743 return -1; /* No digit */
744 if(cpu_num == LONG_MIN || cpu_num == LONG_MAX)
745 return -1; /* underflow / overflow */
746
747 strncpy(char_name, raw_name, underscore_pos);
748 char_name[underscore_pos] = '\0';
749
750 *name = g_quark_from_string(char_name);
751 *num = cpu_num;
752 }
69bd59ed 753
b333a76b 754
3aee1200 755 return 0;
756}
963b5f2d 757
3aee1200 758
3865ea09 759GData **ltt_trace_get_tracefiles_groups(LttTrace *trace)
77175651 760{
3865ea09 761 return &trace->tracefiles;
77175651 762}
763
764
3865ea09 765void compute_tracefile_group(GQuark key_id,
766 GArray *group,
767 struct compute_tracefile_group_args *args)
77175651 768{
769 int i;
770 LttTracefile *tf;
771
772 for(i=0; i<group->len; i++) {
773 tf = &g_array_index (group, LttTracefile, i);
774 if(tf->cpu_online)
3865ea09 775 args->func(tf, args->func_args);
77175651 776 }
777}
778
779
3aee1200 780void ltt_tracefile_group_destroy(gpointer data)
781{
782 GArray *group = (GArray *)data;
783 int i;
784 LttTracefile *tf;
785
786 for(i=0; i<group->len; i++) {
787 tf = &g_array_index (group, LttTracefile, i);
788 if(tf->cpu_online)
789 ltt_tracefile_close(tf);
790 }
791 g_array_free(group, TRUE);
6cd62ccf 792}
793
3aee1200 794gboolean ltt_tracefile_group_has_cpu_online(gpointer data)
49bf71b5 795{
3aee1200 796 GArray *group = (GArray *)data;
797 int i;
798 LttTracefile *tf;
799
800 for(i=0; i<group->len; i++) {
801 tf = &g_array_index (group, LttTracefile, i);
3c165eaf 802 if(tf->cpu_online)
803 return 1;
3aee1200 804 }
805 return 0;
49bf71b5 806}
807
808
3aee1200 809/* Open each tracefile under a specific directory. Put them in a
810 * GData : permits to access them using their tracefile group pathname.
811 * i.e. access control/modules tracefile group by index :
812 * "control/module".
3865ea09 813 *
814 * relative path is the path relative to the trace root
815 * root path is the full path
3aee1200 816 *
4a55f63e 817 * A tracefile group is simply an array where all the per cpu tracefiles sit.
3aee1200 818 */
819
3c165eaf 820int open_tracefiles(LttTrace *trace, gchar *root_path, gchar *relative_path)
f7afe191 821{
62e4e7bf 822 DIR *dir = opendir(root_path);
823 struct dirent *entry;
824 struct stat stat_buf;
825 int ret;
3865ea09 826
62e4e7bf 827 gchar path[PATH_MAX];
828 int path_len;
829 gchar *path_ptr;
3aee1200 830
3865ea09 831 int rel_path_len;
69bd59ed 832 gchar rel_path[PATH_MAX];
833 gchar *rel_path_ptr;
cb03932a 834 LttTracefile tmp_tf;
3865ea09 835
62e4e7bf 836 if(dir == NULL) {
837 perror(root_path);
838 return ENOENT;
839 }
3aee1200 840
62e4e7bf 841 strncpy(path, root_path, PATH_MAX-1);
842 path_len = strlen(path);
843 path[path_len] = '/';
844 path_len++;
845 path_ptr = path + path_len;
3aee1200 846
3865ea09 847 strncpy(rel_path, relative_path, PATH_MAX-1);
848 rel_path_len = strlen(rel_path);
849 rel_path[rel_path_len] = '/';
850 rel_path_len++;
851 rel_path_ptr = rel_path + rel_path_len;
852
62e4e7bf 853 while((entry = readdir(dir)) != NULL) {
854
855 if(entry->d_name[0] == '.') continue;
856
857 strncpy(path_ptr, entry->d_name, PATH_MAX - path_len);
858 strncpy(rel_path_ptr, entry->d_name, PATH_MAX - rel_path_len);
859
860 ret = stat(path, &stat_buf);
861 if(ret == -1) {
862 perror(path);
863 continue;
864 }
865
866 g_debug("Tracefile file or directory : %s\n", path);
867
74a588bb 868 if(strcmp(rel_path, "/eventdefs") == 0) continue;
869
62e4e7bf 870 if(S_ISDIR(stat_buf.st_mode)) {
3aee1200 871
62e4e7bf 872 g_debug("Entering subdirectory...\n");
873 ret = open_tracefiles(trace, path, rel_path);
874 if(ret < 0) continue;
875 } else if(S_ISREG(stat_buf.st_mode)) {
876 GQuark name;
ae3d0f50 877 guint num, tid, pgid;
62e4e7bf 878 guint64 creation;
3aee1200 879 GArray *group;
ae3d0f50 880 num = tid = pgid = 0;
62e4e7bf 881 creation = 0;
ae3d0f50 882 if(get_tracefile_name_number(rel_path, &name, &num, &tid, &pgid, &creation))
3aee1200 883 continue; /* invalid name */
3865ea09 884
62e4e7bf 885 g_debug("Opening file.\n");
cb03932a 886 if(ltt_tracefile_open(trace, path, &tmp_tf)) {
887 g_info("Error opening tracefile %s", path);
888
889 continue; /* error opening the tracefile : bad magic number ? */
890 }
891
3865ea09 892 g_debug("Tracefile name is %s and number is %u",
893 g_quark_to_string(name), num);
894
cb03932a 895 tmp_tf.cpu_online = 1;
896 tmp_tf.cpu_num = num;
d3d34f49 897 tmp_tf.name = name;
62e4e7bf 898 tmp_tf.tid = tid;
899 tmp_tf.pgid = pgid;
900 tmp_tf.creation = creation;
d1bb700c 901 if(tmp_tf.name == g_quark_from_string("/compact")
62e4e7bf 902 || tmp_tf.name == g_quark_from_string("/flight-compact"))
903 tmp_tf.compact = 1;
d1bb700c 904 else
62e4e7bf 905 tmp_tf.compact = 0;
3865ea09 906 group = g_datalist_id_get_data(&trace->tracefiles, name);
3aee1200 907 if(group == NULL) {
908 /* Elements are automatically cleared when the array is allocated.
909 * It makes the cpu_online variable set to 0 : cpu offline, by default.
910 */
911 group = g_array_sized_new (FALSE, TRUE, sizeof(LttTracefile), 10);
3865ea09 912 g_datalist_id_set_data_full(&trace->tracefiles, name,
3aee1200 913 group, ltt_tracefile_group_destroy);
914 }
cb03932a 915
3aee1200 916 /* Add the per cpu tracefile to the named group */
917 unsigned int old_len = group->len;
918 if(num+1 > old_len)
919 group = g_array_set_size(group, num+1);
cb03932a 920 g_array_index (group, LttTracefile, num) = tmp_tf;
3aee1200 921
62e4e7bf 922 }
923 }
924
925 closedir(dir);
3aee1200 926
62e4e7bf 927 return 0;
f7afe191 928}
929
3aee1200 930/* ltt_get_facility_description
931 *
29e7c5b3 932 * Opens the file corresponding to the requested facility (identified by fac_id
3aee1200 933 * and checksum).
934 *
935 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
936 *
937 * Returns 0 on success, or 1 on failure.
938 */
3c165eaf 939#if 0
3aee1200 940static int ltt_get_facility_description(LttFacility *f,
941 LttTrace *t,
942 LttTracefile *fac_tf)
6cd62ccf 943{
3aee1200 944 char desc_file_name[PATH_MAX];
945 const gchar *text;
946 guint textlen;
947 gint err;
62e4e7bf 948 gint arch_spec;
949 gint fac_name_len;
3aee1200 950
951 text = g_quark_to_string(t->pathname);
952 textlen = strlen(text);
953
954 if(textlen >= PATH_MAX) goto name_error;
955 strcpy(desc_file_name, text);
956
957 text = "/eventdefs/";
958 textlen+=strlen(text);
959 if(textlen >= PATH_MAX) goto name_error;
960 strcat(desc_file_name, text);
961
962 text = g_quark_to_string(f->name);
62e4e7bf 963 fac_name_len = strlen(text);
f5d7967f 964 textlen+=fac_name_len;
3aee1200 965 if(textlen >= PATH_MAX) goto name_error;
966 strcat(desc_file_name, text);
f5d7967f 967
62e4e7bf 968 /* arch specific facilities are named like this : name_arch */
969 if(fac_name_len+1 < sizeof("_arch"))
970 arch_spec = 0;
971 else {
972 if(!strcmp(&text[fac_name_len+1-sizeof("_arch")], "_arch"))
973 arch_spec = 1;
974 else
975 arch_spec = 0;
976 }
f5d7967f 977
29e7c5b3 978#if 0
3aee1200 979 text = "_";
980 textlen+=strlen(text);
981 if(textlen >= PATH_MAX) goto name_error;
982 strcat(desc_file_name, text);
963b5f2d 983
3aee1200 984 err = snprintf(desc_file_name+textlen, PATH_MAX-textlen-1,
985 "%u", f->checksum);
d2083cab 986 if(err < 0) goto name_error;
3aee1200 987
988 textlen=strlen(desc_file_name);
989
29e7c5b3 990#endif //0
62e4e7bf 991
992 if(arch_spec) {
993 switch(t->arch_type) {
994 case LTT_ARCH_TYPE_I386:
995 text = "_i386";
996 break;
997 case LTT_ARCH_TYPE_PPC:
998 text = "_ppc";
999 break;
1000 case LTT_ARCH_TYPE_SH:
1001 text = "_sh";
1002 break;
1003 case LTT_ARCH_TYPE_S390:
1004 text = "_s390";
1005 break;
1006 case LTT_ARCH_TYPE_MIPS:
1007 text = "_mips";
1008 break;
1009 case LTT_ARCH_TYPE_ARM:
1010 text = "_arm";
1011 break;
1012 case LTT_ARCH_TYPE_PPC64:
1013 text = "_ppc64";
1014 break;
1015 case LTT_ARCH_TYPE_X86_64:
1016 text = "_x86_64";
1017 break;
1018 case LTT_ARCH_TYPE_C2:
1019 text = "_c2";
1020 break;
1021 case LTT_ARCH_TYPE_POWERPC:
1022 text = "_powerpc";
1023 break;
1024 default:
1025 g_error("Trace from unsupported architecture.");
1026 }
1027 textlen+=strlen(text);
1028 if(textlen >= PATH_MAX) goto name_error;
1029 strcat(desc_file_name, text);
1030 }
1031
3aee1200 1032 text = ".xml";
1033 textlen+=strlen(text);
1034 if(textlen >= PATH_MAX) goto name_error;
1035 strcat(desc_file_name, text);
29e7c5b3 1036
3aee1200 1037 err = ltt_facility_open(f, t, desc_file_name);
1038 if(err) goto facility_error;
3aee1200 1039
1040 return 0;
1041
1042facility_error:
1043name_error:
1044 return 1;
1045}
1046
1047static void ltt_fac_ids_destroy(gpointer data)
1048{
1049 GArray *fac_ids = (GArray *)data;
963b5f2d 1050
3aee1200 1051 g_array_free(fac_ids, TRUE);
1052}
3c165eaf 1053#endif //0
3aee1200 1054
1055/* Presumes the tracefile is already seeked at the beginning. It makes sense,
1056 * because it must be done just after the opening */
3c165eaf 1057int ltt_process_facility_tracefile(LttTracefile *tf)
3aee1200 1058{
1059 int err;
29af7cfd 1060 //LttFacility *fac;
1061 //GArray *fac_ids;
cb03932a 1062 guint i;
29af7cfd 1063 //LttEventType *et;
3aee1200 1064
1065 while(1) {
1066 err = ltt_tracefile_read_seek(tf);
1067 if(err == EPERM) goto seek_error;
1068 else if(err == ERANGE) break; /* End of tracefile */
1069
1070 err = ltt_tracefile_read_update_event(tf);
1071 if(err) goto update_error;
1072
1073 /* We are on a facility load/or facility unload/ or heartbeat event */
1074 /* The rules are :
1075 * * facility 0 is hardcoded : this is the core facility. It will be shown
1076 * in the facility array though, and is shown as "loaded builtin" in the
1077 * trace.
1078 * It contains event :
1079 * 0 : facility load
1080 * 1 : facility unload
1081 * 2 : state dump facility load
d2083cab 1082 * 3 : heartbeat
3aee1200 1083 */
3c165eaf 1084 if(tf->event.event_id >= MARKER_CORE_IDS) {
d2083cab 1085 /* Should only contain core facility */
3aee1200 1086 g_warning("Error in processing facility file %s, "
3c165eaf 1087 "should not contain event id %u.", g_quark_to_string(tf->name),
1088 tf->event.event_id);
3aee1200 1089 err = EPERM;
3c165eaf 1090 goto event_id_error;
d2083cab 1091 } else {
3aee1200 1092
743e50fd 1093 void *pos;
3c165eaf 1094 const char *marker_name, *format;
1095 uint16_t id;
1096 guint8 int_size, long_size, pointer_size, size_t_size, alignment;
3aee1200 1097
1098 // FIXME align
3c165eaf 1099 switch((enum marker_id)tf->event.event_id) {
1100 case MARKER_ID_SET_MARKER_ID:
1101 marker_name = (char*)(tf->event.data);
1102 g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s", marker_name);
1103 pos = (tf->event.data + strlen(marker_name) + 1);
7cbcdb89 1104 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
3c165eaf 1105 pos += ltt_align((size_t)pos, sizeof(uint16_t), tf->has_alignment);
1106 id = ltt_get_uint16(LTT_GET_BO(tf), pos);
1107 pos += sizeof(guint16);
1108 int_size = *(guint8*)pos;
1109 pos += sizeof(guint8);
1110 long_size = *(guint8*)pos;
1111 pos += sizeof(guint8);
1112 pointer_size = *(guint8*)pos;
1113 pos += sizeof(guint8);
1114 size_t_size = *(guint8*)pos;
1115 pos += sizeof(guint8);
1116 alignment = *(guint8*)pos;
1117 pos += sizeof(guint8);
1118 marker_id_event(tf->trace, g_quark_from_string(marker_name),
1119 id, int_size, long_size,
1120 pointer_size, size_t_size, alignment);
3aee1200 1121 break;
3c165eaf 1122 case MARKER_ID_SET_MARKER_FORMAT:
1123 marker_name = (char*)(tf->event.data);
1124 g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s",
1125 marker_name);
1126 pos = (tf->event.data + strlen(marker_name) + 1);
7cbcdb89 1127 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
3c165eaf 1128 format = (const char*)pos;
1129 pos += strlen(format) + 1;
1130 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
1131 marker_format_event(tf->trace, g_quark_from_string(marker_name),
1132 format);
1133 /* get information from dictionnary TODO */
3aee1200 1134 break;
3c165eaf 1135 case MARKER_ID_HEARTBEAT_32:
1136 case MARKER_ID_HEARTBEAT_64:
d1bb700c 1137 break;
3aee1200 1138 default:
1139 g_warning("Error in processing facility file %s, "
3c165eaf 1140 "unknown event id %hhu.",
3aee1200 1141 g_quark_to_string(tf->name),
1142 tf->event.event_id);
1143 err = EPERM;
1144 goto event_id_error;
1145 }
1146 }
963b5f2d 1147 }
3aee1200 1148 return 0;
963b5f2d 1149
3aee1200 1150 /* Error handling */
3aee1200 1151event_id_error:
3aee1200 1152update_error:
1153seek_error:
d2083cab 1154 g_warning("An error occured in facility tracefile parsing");
3aee1200 1155 return err;
6cd62ccf 1156}
1157
963b5f2d 1158
3aee1200 1159LttTrace *ltt_trace_open(const gchar *pathname)
1160{
1161 gchar abs_path[PATH_MAX];
1162 LttTrace * t;
1163 LttTracefile *tf;
1164 GArray *group;
b56dcdf2 1165 int i, ret;
16fcbb80 1166 struct ltt_block_start_header *header;
62e4e7bf 1167 DIR *dir;
1168 struct dirent *entry;
b56dcdf2 1169 guint control_found = 0;
1170 guint eventdefs_found = 0;
62e4e7bf 1171 struct stat stat_buf;
b56dcdf2 1172 gchar path[PATH_MAX];
3aee1200 1173
1174 t = g_new(LttTrace, 1);
1175 if(!t) goto alloc_error;
1176
1177 get_absolute_pathname(pathname, abs_path);
1178 t->pathname = g_quark_from_string(abs_path);
1179
3aee1200 1180 g_datalist_init(&t->tracefiles);
b56dcdf2 1181
1182 /* Test to see if it looks like a trace */
62e4e7bf 1183 dir = opendir(abs_path);
1184 if(dir == NULL) {
1185 perror(abs_path);
1186 goto open_error;
1187 }
1188 while((entry = readdir(dir)) != NULL) {
b56dcdf2 1189 strcpy(path, abs_path);
1190 strcat(path, "/");
1191 strcat(path, entry->d_name);
62e4e7bf 1192 ret = stat(path, &stat_buf);
1193 if(ret == -1) {
1194 perror(path);
1195 continue;
1196 }
1197 if(S_ISDIR(stat_buf.st_mode)) {
b56dcdf2 1198 if(strcmp(entry->d_name, "control") == 0) {
1199 control_found = 1;
1200 }
1201 if(strcmp(entry->d_name, "eventdefs") == 0) {
1202 eventdefs_found = 1;
1203 }
1204 }
1205 }
1206 closedir(dir);
1207
1208 if(!control_found || !eventdefs_found) goto find_error;
1209
1210 /* Open all the tracefiles */
e45551ac 1211 if(open_tracefiles(t, abs_path, "")) {
1212 g_warning("Error opening tracefile %s", abs_path);
b56dcdf2 1213 goto find_error;
e45551ac 1214 }
3aee1200 1215
3aee1200 1216 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1217 group = g_datalist_id_get_data(&t->tracefiles, LTT_TRACEFILE_NAME_FACILITIES);
1218 if(group == NULL) {
1219 g_error("Trace %s has no facility tracefile", abs_path);
3865ea09 1220 g_assert(0);
3aee1200 1221 goto facilities_error;
1222 }
1223
16fcbb80 1224 /* Get the trace information for the control/facility 0 tracefile */
1225 g_assert(group->len > 0);
1226 tf = &g_array_index (group, LttTracefile, 0);
1227 header = (struct ltt_block_start_header*)tf->buffer.head;
51551c6f 1228 g_assert(parse_trace_header(header->trace,
1229 tf, t) == 0);
b56dcdf2 1230
1231 t->num_cpu = group->len;
16fcbb80 1232
d79909d1 1233 ret = allocate_marker_data(t);
1234 if (!ret)
1235 g_error("Error in allocating marker data");
1236
3aee1200 1237 for(i=0; i<group->len; i++) {
1238 tf = &g_array_index (group, LttTracefile, i);
1239 if(ltt_process_facility_tracefile(tf))
1240 goto facilities_error;
1241 }
dd3a6d39 1242
3aee1200 1243 return t;
1244
1245 /* Error handling */
1246facilities_error:
d79909d1 1247 destroy_marker_data(t);
b56dcdf2 1248find_error:
3aee1200 1249 g_datalist_clear(&t->tracefiles);
b56dcdf2 1250open_error:
3aee1200 1251 g_free(t);
1252alloc_error:
1253 return NULL;
1254
1255}
6cd62ccf 1256
826f1ab2 1257GQuark ltt_trace_name(const LttTrace *t)
6cd62ccf 1258{
3aee1200 1259 return t->pathname;
6cd62ccf 1260}
1261
6cd62ccf 1262
3aee1200 1263/******************************************************************************
1264 * When we copy a trace, we want all the opening actions to happen again :
1265 * the trace will be reopened and totally independant from the original.
1266 * That's why we call ltt_trace_open.
1267 *****************************************************************************/
1268LttTrace *ltt_trace_copy(LttTrace *self)
963b5f2d 1269{
3aee1200 1270 return ltt_trace_open(g_quark_to_string(self->pathname));
963b5f2d 1271}
1272
3aee1200 1273void ltt_trace_close(LttTrace *t)
6cd62ccf 1274{
3aee1200 1275 g_datalist_clear(&t->tracefiles);
1276 g_free(t);
6cd62ccf 1277}
1278
3aee1200 1279
6cd62ccf 1280/*****************************************************************************
3aee1200 1281 *Get the system description of the trace
6cd62ccf 1282 ****************************************************************************/
3c165eaf 1283#if 0
3aee1200 1284LttFacility *ltt_trace_facility_by_id(LttTrace *t, guint8 id)
6cd62ccf 1285{
3aee1200 1286 g_assert(id < t->facilities_by_num->len);
1287 return &g_array_index(t->facilities_by_num, LttFacility, id);
1288}
1289
1290/* ltt_trace_facility_get_by_name
1291 *
1292 * Returns the GArray of facility indexes. All the fac_ids that matches the
1293 * requested facility name.
1294 *
1295 * If name is not found, returns NULL.
1296 */
1297GArray *ltt_trace_facility_get_by_name(LttTrace *t, GQuark name)
1298{
1299 return g_datalist_id_get_data(&t->facilities_by_name, name);
6cd62ccf 1300}
3c165eaf 1301#endif //0
6cd62ccf 1302
1303/*****************************************************************************
963b5f2d 1304 * Functions to discover all the event types in the trace
6cd62ccf 1305 ****************************************************************************/
1306
3aee1200 1307#if 0
963b5f2d 1308unsigned ltt_trace_eventtype_number(LttTrace *t)
6cd62ccf 1309{
8d1e6362 1310 unsigned int i;
963b5f2d 1311 unsigned count = 0;
dc1cad90 1312 unsigned int num = t->facility_number;
963b5f2d 1313 LttFacility * f;
dc1cad90 1314
1315 for(i=0;i<num;i++){
963b5f2d 1316 f = (LttFacility*)g_ptr_array_index(t->facilities, i);
1317 count += f->event_number;
1318 }
1319 return count;
6cd62ccf 1320}
3aee1200 1321#endif //0
6cd62ccf 1322
3aee1200 1323#if 0
1324//use an iteration on all the trace facilities, and inside iteration on all the
1325//event types in each facilities instead.
963b5f2d 1326LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId)
6cd62ccf 1327{
6e8c19d4 1328 LttEventType *event_type;
1329
963b5f2d 1330 LttFacility * f;
1331 f = ltt_trace_facility_by_id(t,evId);
6e8c19d4 1332
1333 if(unlikely(!f)) event_type = NULL;
1334 else event_type = f->events[evId - f->base_id];
1335
1336 return event_type;
6cd62ccf 1337}
3aee1200 1338#endif //0
6cd62ccf 1339
3aee1200 1340#if 0
6cd62ccf 1341/*****************************************************************************
3aee1200 1342 * ltt_trace_find_tracefile
1343 *
1344 * Find a tracefile by name and index in the group.
1345 *
1346 * Returns a pointer to the tracefiles, else NULL.
6cd62ccf 1347 ****************************************************************************/
6cd62ccf 1348
3aee1200 1349LttTracefile *ltt_trace_find_tracefile(LttTrace *t, const gchar *name)
6cd62ccf 1350{
6cd62ccf 1351}
3aee1200 1352#endif //0
6cd62ccf 1353
1354/*****************************************************************************
3aee1200 1355 * Get the start time and end time of the trace
6cd62ccf 1356 ****************************************************************************/
1357
3c165eaf 1358void ltt_tracefile_time_span_get(LttTracefile *tf,
3aee1200 1359 LttTime *start, LttTime *end)
6cd62ccf 1360{
3aee1200 1361 int err;
6cd62ccf 1362
3aee1200 1363 err = map_block(tf, 0);
1364 if(unlikely(err)) {
1365 g_error("Can not map block");
1366 *start = ltt_time_infinite;
1367 } else
1368 *start = tf->buffer.begin.timestamp;
1369
1370 err = map_block(tf, tf->num_blocks - 1); /* Last block */
1371 if(unlikely(err)) {
1372 g_error("Can not map block");
1373 *end = ltt_time_zero;
1374 } else
1375 *end = tf->buffer.end.timestamp;
6cd62ccf 1376}
1377
3aee1200 1378struct tracefile_time_span_get_args {
1379 LttTrace *t;
1380 LttTime *start;
1381 LttTime *end;
1382};
963b5f2d 1383
3c165eaf 1384void group_time_span_get(GQuark name, gpointer data, gpointer user_data)
963b5f2d 1385{
3aee1200 1386 struct tracefile_time_span_get_args *args =
1387 (struct tracefile_time_span_get_args*)user_data;
1388
1389 GArray *group = (GArray *)data;
1390 int i;
1391 LttTracefile *tf;
1392 LttTime tmp_start;
1393 LttTime tmp_end;
1394
1395 for(i=0; i<group->len; i++) {
1396 tf = &g_array_index (group, LttTracefile, i);
1397 if(tf->cpu_online) {
1398 ltt_tracefile_time_span_get(tf, &tmp_start, &tmp_end);
1399 if(ltt_time_compare(*args->start, tmp_start)>0) *args->start = tmp_start;
1400 if(ltt_time_compare(*args->end, tmp_end)<0) *args->end = tmp_end;
1401 }
1402 }
6cd62ccf 1403}
1404
487ad181 1405void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end)
1406{
3aee1200 1407 LttTime min_start = ltt_time_infinite;
1408 LttTime max_end = ltt_time_zero;
1409 struct tracefile_time_span_get_args args = { t, &min_start, &max_end };
487ad181 1410
3aee1200 1411 g_datalist_foreach(&t->tracefiles, &group_time_span_get, &args);
1412
1413 if(start != NULL) *start = min_start;
1414 if(end != NULL) *end = max_end;
1415
487ad181 1416}
1417
1418
6cd62ccf 1419/*****************************************************************************
963b5f2d 1420 *Get the name of a tracefile
6cd62ccf 1421 ****************************************************************************/
1422
348c6ba8 1423GQuark ltt_tracefile_name(const LttTracefile *tf)
6cd62ccf 1424{
963b5f2d 1425 return tf->name;
6cd62ccf 1426}
1427
348c6ba8 1428GQuark ltt_tracefile_long_name(const LttTracefile *tf)
1429{
1430 return tf->long_name;
1431}
1432
1433
d3d34f49 1434
ae3d0f50 1435guint ltt_tracefile_cpu(LttTracefile *tf)
d3d34f49 1436{
1437 return tf->cpu_num;
1438}
1439
ae3d0f50 1440guint ltt_tracefile_tid(LttTracefile *tf)
1441{
1442 return tf->tid;
1443}
1444
1445guint ltt_tracefile_pgid(LttTracefile *tf)
1446{
1447 return tf->pgid;
1448}
1449
1450guint64 ltt_tracefile_creation(LttTracefile *tf)
1451{
1452 return tf->creation;
1453}
80da81ad 1454/*****************************************************************************
1455 * Get the number of blocks in the tracefile
1456 ****************************************************************************/
1457
3aee1200 1458guint ltt_tracefile_block_number(LttTracefile *tf)
80da81ad 1459{
3aee1200 1460 return tf->num_blocks;
80da81ad 1461}
1462
caf7a67a 1463
3aee1200 1464/* Seek to the first event in a tracefile that has a time equal or greater than
1465 * the time passed in parameter.
1466 *
1467 * If the time parameter is outside the tracefile time span, seek to the first
27304273 1468 * event or if after, return ERANGE.
3aee1200 1469 *
1470 * If the time parameter is before the first event, we have to seek specially to
1471 * there.
1472 *
27304273 1473 * If the time is after the end of the trace, return ERANGE.
3aee1200 1474 *
1475 * Do a binary search to find the right block, then a sequential search in the
1476 * block to find the event.
1477 *
1478 * In the special case where the time requested fits inside a block that has no
1479 * event corresponding to the requested time, the first event of the next block
1480 * will be seeked.
1481 *
1482 * IMPORTANT NOTE : // FIXME everywhere...
1483 *
1484 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1485 * you will jump over an event if you do.
1486 *
1487 * Return value : 0 : no error, the tf->event can be used
27304273 1488 * ERANGE : time if after the last event of the trace
3aee1200 1489 * otherwise : this is an error.
1490 *
1491 * */
1492
1493int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time)
1494{
1495 int ret = 0;
1496 int err;
1497 unsigned int block_num, high, low;
1498
1499 /* seek at the beginning of trace */
1500 err = map_block(tf, 0); /* First block */
1501 if(unlikely(err)) {
1502 g_error("Can not map block");
1503 goto fail;
caf7a67a 1504 }
1505
3aee1200 1506 /* If the time is lower or equal the beginning of the trace,
1507 * go to the first event. */
1508 if(ltt_time_compare(time, tf->buffer.begin.timestamp) <= 0) {
1509 ret = ltt_tracefile_read(tf);
27304273 1510 if(ret == ERANGE) goto range;
1511 else if (ret) goto fail;
3aee1200 1512 goto found; /* There is either no event in the trace or the event points
1513 to the first event in the trace */
1514 }
caf7a67a 1515
3aee1200 1516 err = map_block(tf, tf->num_blocks - 1); /* Last block */
1517 if(unlikely(err)) {
1518 g_error("Can not map block");
1519 goto fail;
caf7a67a 1520 }
6cd62ccf 1521
27304273 1522 /* If the time is after the end of the trace, return ERANGE. */
1523 if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) {
1524 goto range;
3aee1200 1525 }
62e55dd6 1526
3aee1200 1527 /* Binary search the block */
1528 high = tf->num_blocks - 1;
1529 low = 0;
1530
1531 while(1) {
1532 block_num = ((high-low) / 2) + low;
1533
1534 err = map_block(tf, block_num);
1535 if(unlikely(err)) {
1536 g_error("Can not map block");
1537 goto fail;
db55eaae 1538 }
3aee1200 1539 if(high == low) {
1540 /* We cannot divide anymore : this is what would happen if the time
1541 * requested was exactly between two consecutive buffers'end and start
1542 * timestamps. This is also what would happend if we didn't deal with out
1543 * of span cases prior in this function. */
1544 /* The event is right in the buffer!
1545 * (or in the next buffer first event) */
1546 while(1) {
1547 ret = ltt_tracefile_read(tf);
27304273 1548 if(ret == ERANGE) goto range; /* ERANGE or EPERM */
3aee1200 1549 else if(ret) goto fail;
1550
d9e13a0f 1551 if(ltt_time_compare(time, tf->event.event_time) <= 0)
e45551ac 1552 goto found;
3aee1200 1553 }
1554
27304273 1555 } else if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) {
3aee1200 1556 /* go to lower part */
b1369bef 1557 high = block_num - 1;
3aee1200 1558 } else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) {
1559 /* go to higher part */
b1369bef 1560 low = block_num + 1;
3aee1200 1561 } else {/* The event is right in the buffer!
1562 (or in the next buffer first event) */
1563 while(1) {
27304273 1564 ret = ltt_tracefile_read(tf);
1565 if(ret == ERANGE) goto range; /* ERANGE or EPERM */
3aee1200 1566 else if(ret) goto fail;
1567
d9e13a0f 1568 if(ltt_time_compare(time, tf->event.event_time) <= 0)
3aee1200 1569 break;
6cd62ccf 1570 }
3aee1200 1571 goto found;
6cd62ccf 1572 }
6cd62ccf 1573 }
3aee1200 1574
1575found:
1576 return 0;
27304273 1577range:
1578 return ERANGE;
3aee1200 1579
1580 /* Error handling */
1581fail:
1582 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1583 g_quark_to_string(tf->name));
1584 return EPERM;
6cd62ccf 1585}
1586
80da81ad 1587
3aee1200 1588int ltt_tracefile_seek_position(LttTracefile *tf, const LttEventPosition *ep) {
80da81ad 1589
3aee1200 1590 int err;
1591
1592 if(ep->tracefile != tf) {
1593 goto fail;
80da81ad 1594 }
1595
3aee1200 1596 err = map_block(tf, ep->block);
1597 if(unlikely(err)) {
1598 g_error("Can not map block");
1599 goto fail;
1600 }
1601
1602 tf->event.offset = ep->offset;
18206708 1603
62e4e7bf 1604 /* Put back the event real tsc */
1605 tf->event.tsc = ep->tsc;
1606 tf->buffer.tsc = ep->tsc;
78f79181 1607
3aee1200 1608 err = ltt_tracefile_read_update_event(tf);
1609 if(err) goto fail;
1610 err = ltt_tracefile_read_op(tf);
1611 if(err) goto fail;
80da81ad 1612
a0c1f622 1613 return 0;
3aee1200 1614
1615fail:
1616 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1617 g_quark_to_string(tf->name));
a0c1f622 1618 return 1;
3aee1200 1619}
1620
ae3d0f50 1621LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc)
3aee1200 1622{
1623 LttTime time;
62e4e7bf 1624
1625 if(tsc > tf->trace->start_tsc) {
1626 time = ltt_time_from_uint64(
1627 (double)(tsc - tf->trace->start_tsc)
1628 * (1000000000.0 / tf->trace->freq_scale)
1629 / (double)tf->trace->start_freq);
1630 time = ltt_time_add(tf->trace->start_time_from_tsc, time);
1631 } else {
1632 time = ltt_time_from_uint64(
1633 (double)(tf->trace->start_tsc - tsc)
1634 * (1000000000.0 / tf->trace->freq_scale)
1635 / (double)tf->trace->start_freq);
1636 time = ltt_time_sub(tf->trace->start_time_from_tsc, time);
1637 }
3aee1200 1638 return time;
80da81ad 1639}
1640
ae3d0f50 1641/* Calculate the real event time based on the buffer boundaries */
1642LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event)
1643{
62e4e7bf 1644 return ltt_interpolate_time_from_tsc(tf, tf->buffer.tsc);
ae3d0f50 1645}
1646
eed2ef37 1647
1648/* Get the current event of the tracefile : valid until the next read */
1649LttEvent *ltt_tracefile_get_event(LttTracefile *tf)
1650{
1651 return &tf->event;
1652}
1653
1654
1655
6cd62ccf 1656/*****************************************************************************
1657 *Function name
3aee1200 1658 * ltt_tracefile_read : Read the next event in the tracefile
6cd62ccf 1659 *Input params
1660 * t : tracefile
1661 *Return value
3aee1200 1662 *
1663 * Returns 0 if an event can be used in tf->event.
d822520b 1664 * Returns ERANGE on end of trace. The event in tf->event still can be used
1665 * (if the last block was not empty).
3aee1200 1666 * Returns EPERM on error.
1667 *
1668 * This function does make the tracefile event structure point to the event
1669 * currently pointed to by the tf->event.
1670 *
1671 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1672 * reinitialize it after an error if you want results to be coherent.
1673 * It would be the case if a end of trace last buffer has no event : the end
1674 * of trace wouldn't be returned, but an error.
1675 * We make the assumption there is at least one event per buffer.
6cd62ccf 1676 ****************************************************************************/
1677
3aee1200 1678int ltt_tracefile_read(LttTracefile *tf)
6cd62ccf 1679{
963b5f2d 1680 int err;
6cd62ccf 1681
3aee1200 1682 err = ltt_tracefile_read_seek(tf);
1683 if(err) return err;
1684 err = ltt_tracefile_read_update_event(tf);
1685 if(err) return err;
1686 err = ltt_tracefile_read_op(tf);
1687 if(err) return err;
1688
1689 return 0;
1690}
1691
1692int ltt_tracefile_read_seek(LttTracefile *tf)
1693{
1694 int err;
1695
1696 /* Get next buffer until we finally have an event, or end of trace */
1697 while(1) {
1698 err = ltt_seek_next_event(tf);
1699 if(unlikely(err == ENOPROTOOPT)) {
1700 return EPERM;
bdc36259 1701 }
bdc36259 1702
3aee1200 1703 /* Are we at the end of the buffer ? */
1704 if(err == ERANGE) {
1705 if(unlikely(tf->buffer.index == tf->num_blocks-1)){ /* end of trace ? */
1706 return ERANGE;
1707 } else {
1708 /* get next block */
1709 err = map_block(tf, tf->buffer.index + 1);
1710 if(unlikely(err)) {
1711 g_error("Can not map block");
1712 return EPERM;
1713 }
1714 }
1715 } else break; /* We found an event ! */
1716 }
2dee981d 1717
3aee1200 1718 return 0;
1719}
18206708 1720
1721
3aee1200 1722/* do specific operation on events */
1723int ltt_tracefile_read_op(LttTracefile *tf)
1724{
3aee1200 1725 LttEvent *event;
1726
1727 event = &tf->event;
18206708 1728
3aee1200 1729 /* do event specific operation */
40331ba8 1730
3aee1200 1731 /* do something if its an heartbeat event : increment the heartbeat count */
1732 //if(event->facility_id == LTT_FACILITY_CORE)
1733 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1734 // tf->cur_heart_beat_number++;
1735
1736 return 0;
6cd62ccf 1737}
1738
6cd62ccf 1739
3aee1200 1740/* same as ltt_tracefile_read, but does not seek to the next event nor call
1741 * event specific operation. */
1742int ltt_tracefile_read_update_event(LttTracefile *tf)
6cd62ccf 1743{
3aee1200 1744 void * pos;
1745 LttEvent *event;
1746
1747 event = &tf->event;
eed2ef37 1748 pos = tf->buffer.head + event->offset;
3aee1200 1749
1750 /* Read event header */
1751
62e4e7bf 1752 /* Align the head */
1753 if(!tf->compact)
1754 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
1755 else {
1756 g_assert(tf->has_heartbeat);
1757 pos += ltt_align((size_t)pos, sizeof(uint32_t), tf->has_alignment);
1758 }
3aee1200 1759
62e4e7bf 1760 if(tf->has_heartbeat) {
1761 event->timestamp = ltt_get_uint32(LTT_GET_BO(tf),
1762 pos);
d1bb700c 1763 if(!tf->compact) {
1764 /* 32 bits -> 64 bits tsc */
1765 /* note : still works for seek and non seek cases. */
1766 if(event->timestamp < (0xFFFFFFFFULL&tf->buffer.tsc)) {
1767 tf->buffer.tsc = ((tf->buffer.tsc&0xFFFFFFFF00000000ULL)
1768 + 0x100000000ULL)
1769 | (guint64)event->timestamp;
1770 event->tsc = tf->buffer.tsc;
1771 } else {
1772 /* no overflow */
1773 tf->buffer.tsc = (tf->buffer.tsc&0xFFFFFFFF00000000ULL)
1774 | (guint64)event->timestamp;
1775 event->tsc = tf->buffer.tsc;
62e4e7bf 1776 event->compact_data = 0;
d1bb700c 1777 }
1778 } else {
1779 /* Compact header */
1780 /* We keep the LSB of the previous timestamp, to make sure
1781 * we never go back */
1782 event->event_id = event->timestamp >> tf->tscbits;
dd3a6d39 1783 event->event_id = event->event_id & ((1 << tf->trace->compact_event_bits) - 1);
1784 event->compact_data = event->timestamp >>
62e4e7bf 1785 (tf->trace->compact_event_bits + tf->tscbits);
dd3a6d39 1786 //printf("tsc bits %u, ev bits %u init data %u\n",
62e4e7bf 1787 // tf->tscbits, tf->trace->compact_event_bits, event->compact_data);
dd3a6d39 1788 /* Put the compact data back in original endianness */
1789 event->compact_data = ltt_get_uint32(LTT_GET_BO(tf), &event->compact_data);
d1bb700c 1790 event->event_size = 0xFFFF;
dd3a6d39 1791 //printf("Found compact event %d\n", event->event_id);
1792 //printf("Compact data %d\n", event->compact_data);
d1bb700c 1793 event->timestamp = event->timestamp << tf->tsc_lsb_truncate;
1794 event->timestamp = event->timestamp & tf->tsc_mask;
dd3a6d39 1795 //printf("timestamp 0x%lX\n", event->timestamp);
1796 //printf("mask 0x%llX\n", tf->tsc_mask);
1797 //printf("mask_next 0x%llX\n", tf->tsc_mask_next_bit);
1798 //printf("previous tsc 0x%llX\n", tf->buffer.tsc);
1799 //printf("previous tsc&mask 0x%llX\n", tf->tsc_mask&tf->buffer.tsc);
1800 //printf("previous tsc&(~mask) 0x%llX\n", tf->buffer.tsc&(~tf->tsc_mask));
d1bb700c 1801 if(event->timestamp < (tf->tsc_mask&tf->buffer.tsc)) {
dd3a6d39 1802 //printf("wrap\n");
d1bb700c 1803 tf->buffer.tsc = ((tf->buffer.tsc&(~tf->tsc_mask))
1804 + tf->tsc_mask_next_bit)
1805 | (guint64)event->timestamp;
1806 event->tsc = tf->buffer.tsc;
1807 } else {
dd3a6d39 1808 //printf("no wrap\n");
d1bb700c 1809 /* no overflow */
1810 tf->buffer.tsc = (tf->buffer.tsc&(~tf->tsc_mask))
1811 | (guint64)event->timestamp;
1812 event->tsc = tf->buffer.tsc;
1813 }
dd3a6d39 1814 //printf("current tsc 0x%llX\n", tf->buffer.tsc);
d1bb700c 1815 }
62e4e7bf 1816 pos += sizeof(guint32);
1817 } else {
1818 event->tsc = ltt_get_uint64(LTT_GET_BO(tf), pos);
1819 tf->buffer.tsc = event->tsc;
1820 event->compact_data = 0;
1821 pos += sizeof(guint64);
1822 }
1823 event->event_time = ltt_interpolate_time(tf, event);
3aee1200 1824
d1bb700c 1825 if(!tf->compact) {
3c165eaf 1826 event->event_id = *(guint16*)pos;
1827 pos += sizeof(guint16);
d1bb700c 1828
1829 event->event_size = ltt_get_uint16(LTT_GET_BO(tf), pos);
1830 pos += sizeof(guint16);
1831 } else {
1832 /* Compact event */
1833 }
62e4e7bf 1834 /* Align the head */
1835 if(!tf->compact)
1836 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
f104d082 1837
3aee1200 1838 event->data = pos;
1839
77175651 1840 /* get the data size and update the event fields with the current
d1bb700c 1841 * information. Also update the time if a heartbeat_full event is found. */
eed2ef37 1842 ltt_update_event_size(tf);
77175651 1843
3aee1200 1844 return 0;
6cd62ccf 1845}
1846
507915ee 1847
6cd62ccf 1848/****************************************************************************
1849 *Function name
3aee1200 1850 * map_block : map a block from the file
6cd62ccf 1851 *Input Params
1852 * lttdes : ltt trace file
1853 * whichBlock : the block which will be read
1854 *return value
1855 * 0 : success
1856 * EINVAL : lseek fail
1857 * EIO : can not read from the file
1858 ****************************************************************************/
1859
3c165eaf 1860gint map_block(LttTracefile * tf, guint block_num)
6cd62ccf 1861{
b77d1b57 1862 int page_size = getpagesize();
3aee1200 1863 struct ltt_block_start_header *header;
1864
1865 g_assert(block_num < tf->num_blocks);
6cd62ccf 1866
f628823c 1867 if(tf->buffer.head != NULL) {
1868 if(munmap(tf->buffer.head, PAGE_ALIGN(tf->buf_size))) {
1869 g_warning("unmap size : %u\n",
1870 PAGE_ALIGN(tf->buf_size));
1871 perror("munmap error");
1872 g_assert(0);
1873 }
1874 }
1875
ac849774 1876
3aee1200 1877 /* Multiple of pages aligned head */
b77d1b57 1878 tf->buffer.head = mmap(0,
f628823c 1879 PAGE_ALIGN(tf->buf_size),
b77d1b57 1880 PROT_READ, MAP_PRIVATE, tf->fd,
f628823c 1881 PAGE_ALIGN((off_t)tf->buf_size * (off_t)block_num));
3aee1200 1882
3865ea09 1883 if(tf->buffer.head == MAP_FAILED) {
3aee1200 1884 perror("Error in allocating memory for buffer of tracefile");
3865ea09 1885 g_assert(0);
3aee1200 1886 goto map_error;
6cd62ccf 1887 }
3865ea09 1888 g_assert( ( (guint)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
3aee1200 1889
6cd62ccf 1890
3aee1200 1891 tf->buffer.index = block_num;
1892
1893 header = (struct ltt_block_start_header*)tf->buffer.head;
1894
791dffa6 1895#if 0
986e2a7c 1896 tf->buffer.begin.timestamp = ltt_time_add(
1897 ltt_time_from_uint64(
1898 ltt_get_uint64(LTT_GET_BO(tf),
1899 &header->begin.timestamp)
1900 - tf->trace->start_monotonic),
1901 tf->trace->start_time);
791dffa6 1902#endif //0
348c6ba8 1903 //g_debug("block %u begin : %lu.%lu", block_num,
1904 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
3aee1200 1905 tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
1906 &header->begin.cycle_count);
986e2a7c 1907 tf->buffer.begin.freq = ltt_get_uint64(LTT_GET_BO(tf),
1908 &header->begin.freq);
62e4e7bf 1909 if(tf->buffer.begin.freq == 0)
1910 tf->buffer.begin.freq = tf->trace->start_freq;
ae3d0f50 1911
1912 tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf,
62e4e7bf 1913 tf->buffer.begin.cycle_count);
ae3d0f50 1914#if 0
62e4e7bf 1915 ltt_time_add(
791dffa6 1916 ltt_time_from_uint64(
88612d17 1917 (double)(tf->buffer.begin.cycle_count
1918 - tf->trace->start_tsc) * 1000000.0
791dffa6 1919 / (double)tf->trace->start_freq),
62e4e7bf 1920 tf->trace->start_time_from_tsc);
ae3d0f50 1921#endif //0
791dffa6 1922#if 0
1923
986e2a7c 1924 tf->buffer.end.timestamp = ltt_time_add(
1925 ltt_time_from_uint64(
1926 ltt_get_uint64(LTT_GET_BO(tf),
1927 &header->end.timestamp)
1928 - tf->trace->start_monotonic),
1929 tf->trace->start_time);
791dffa6 1930#endif //0
348c6ba8 1931 //g_debug("block %u end : %lu.%lu", block_num,
1932 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
3aee1200 1933 tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
1934 &header->end.cycle_count);
986e2a7c 1935 tf->buffer.end.freq = ltt_get_uint64(LTT_GET_BO(tf),
1936 &header->end.freq);
62e4e7bf 1937 if(tf->buffer.end.freq == 0)
1938 tf->buffer.end.freq = tf->trace->start_freq;
1939
3aee1200 1940 tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf),
986e2a7c 1941 &header->lost_size);
ae3d0f50 1942 tf->buffer.end.timestamp = ltt_interpolate_time_from_tsc(tf,
62e4e7bf 1943 tf->buffer.end.cycle_count);
ae3d0f50 1944#if 0
62e4e7bf 1945 ltt_time_add(
791dffa6 1946 ltt_time_from_uint64(
88612d17 1947 (double)(tf->buffer.end.cycle_count
1948 - tf->trace->start_tsc) * 1000000.0
791dffa6 1949 / (double)tf->trace->start_freq),
88612d17 1950 tf->trace->start_time_from_tsc);
ae3d0f50 1951#endif //0
3aee1200 1952 tf->buffer.tsc = tf->buffer.begin.cycle_count;
1953 tf->event.tsc = tf->buffer.tsc;
986e2a7c 1954 tf->buffer.freq = tf->buffer.begin.freq;
3aee1200 1955
1956 /* FIXME
1957 * eventually support variable buffer size : will need a partial pre-read of
1958 * the headers to create an index when we open the trace... eventually. */
f628823c 1959 g_assert(tf->buf_size == ltt_get_uint32(LTT_GET_BO(tf),
3aee1200 1960 &header->buf_size));
507915ee 1961
3aee1200 1962 /* Now that the buffer is mapped, calculate the time interpolation for the
1963 * block. */
1964
791dffa6 1965// tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1966 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
3aee1200 1967
1968 /* Make the current event point to the beginning of the buffer :
1969 * it means that the event read must get the first event. */
1970 tf->event.tracefile = tf;
1971 tf->event.block = block_num;
eed2ef37 1972 tf->event.offset = 0;
3aee1200 1973
1974 return 0;
6cd62ccf 1975
3aee1200 1976map_error:
1977 return -errno;
40331ba8 1978
6cd62ccf 1979}
1980
77175651 1981/* It will update the fields offsets too */
1982void ltt_update_event_size(LttTracefile *tf)
6cd62ccf 1983{
2312de30 1984 off_t size = 0;
d1bb700c 1985 char *tscdata;
d2007fbd 1986 struct marker_info *info;
44f317b7 1987
d2007fbd 1988 switch((enum marker_id)tf->event.event_id) {
1989 case MARKER_ID_SET_MARKER_ID:
44f317b7 1990 size = strlen((char*)tf->event.data) + 1;
d2007fbd 1991 //g_debug("marker %s id set", (char*)tf->event.data);
1992 size += ltt_align(size, sizeof(guint16), tf->has_alignment);
1993 size += sizeof(guint16);
3c165eaf 1994 size += sizeof(guint8);
1995 size += sizeof(guint8);
1996 size += sizeof(guint8);
1997 size += sizeof(guint8);
1998 size += sizeof(guint8);
44f317b7 1999 break;
d2007fbd 2000 case MARKER_ID_SET_MARKER_FORMAT:
2001 //g_debug("marker %s format set", (char*)tf->event.data);
44f317b7 2002 size = strlen((char*)tf->event.data) + 1;
d2007fbd 2003 size += strlen((char*)tf->event.data) + 1;
44f317b7 2004 break;
d2007fbd 2005 case MARKER_ID_HEARTBEAT_32:
2006 //g_debug("Update Event heartbeat 32 bits");
2007 size = ltt_align(size, sizeof(guint32), tf->has_alignment);
2008 size += sizeof(guint32);
44f317b7 2009 break;
d2007fbd 2010 case MARKER_ID_HEARTBEAT_64:
2011 //g_debug("Update Event heartbeat 64 bits");
d1bb700c 2012 tscdata = (char*)(tf->event.data);
2013 tf->event.tsc = ltt_get_uint64(LTT_GET_BO(tf), tscdata);
2014 tf->buffer.tsc = tf->event.tsc;
2015 tf->event.event_time = ltt_interpolate_time(tf, &tf->event);
d2007fbd 2016 size = ltt_align(size, sizeof(guint64), tf->has_alignment);
2017 size += sizeof(guint64);
d1bb700c 2018 break;
44f317b7 2019 default:
d2007fbd 2020 info = marker_get_info_from_id(tf->trace, tf->event.event_id);
2021 g_assert(info != NULL);
3c165eaf 2022 if (info->size != -1) {
d2007fbd 2023 size = info->size;
2024 } else {
3c165eaf 2025 size = marker_update_fields_offsets(marker_get_info_from_id(tf->trace,
2026 tf->event.event_id), tf->event.data);
44f317b7 2027 }
44f317b7 2028 }
c4afd5d8 2029
d2007fbd 2030 tf->event.data_size = size;
2031
2032 /* Check consistency between kernel and LTTV structure sizes */
2033 if(tf->event.event_size == 0xFFFF) {
2034 /* Event size too big to fit in the event size field */
2035 tf->event.event_size = tf->event.data_size;
2036 }
2037 if (tf->event.data_size != tf->event.event_size) {
3c165eaf 2038 struct marker_info *info = marker_get_info_from_id(tf->trace,
2039 tf->event.event_id);
2040 g_error("Kernel/LTTV event size differs for event %s: kernel %u, LTTV %u",
2041 g_quark_to_string(info->name),
2042 tf->event.event_size, tf->event.data_size);
d2007fbd 2043 exit(-1);
2044 }
2045
2046#if 0
44f317b7 2047 LttEventType *event_type =
2048 ltt_facility_eventtype_get(f, tf->event.event_id);
c4afd5d8 2049
44f317b7 2050 if(!event_type) {
2051 g_warning("Unknown event id %hhu in facility %s in tracefile %s",
2052 tf->event.event_id,
2053 g_quark_to_string(f->name),
2054 g_quark_to_string(tf->name));
2055 goto event_type_error;
3aee1200 2056 }
3aee1200 2057
44f317b7 2058 /* Compute the dynamic offsets */
2059 compute_offsets(tf, f, event_type, &size, tf->event.data);
2060
2061 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
2062 // tf->event.facility_id,
2063 // tf->event.event_id, size);
7cbcdb89 2064
2065no_offset:
77175651 2066 tf->event.data_size = size;
eed2ef37 2067
b77d1b57 2068 /* Check consistency between kernel and LTTV structure sizes */
62e4e7bf 2069 if(tf->event.event_size == 0xFFFF) {
2070 /* Event size too big to fit in the event size field */
2071 tf->event.event_size = tf->event.data_size;
2072 }
f63ebe51 2073 if (tf->event.data_size != tf->event.event_size) {
2074 g_error("Kernel/LTTV event size differs for event %s.%s: kernel %u, LTTV %u",
62e4e7bf 2075 g_quark_to_string(f->name), g_quark_to_string(event_type->name),
2076 tf->event.event_size, tf->event.data_size);
f63ebe51 2077 exit(-1);
2078 }
2079 //g_assert(tf->event.data_size == tf->event.event_size);
9eb6aa7a 2080
eed2ef37 2081 return;
2082
c4afd5d8 2083event_type_error:
3aee1200 2084event_id_error:
62e4e7bf 2085 if(tf->event.event_size == 0xFFFF) {
2086 g_error("Cannot jump over an unknown event bigger than 0xFFFE bytes");
2087 }
2088 /* The facility is unknown : use the kernel information about this event
2089 * to jump over it. */
9d7e0c25 2090 tf->event.data_size = tf->event.event_size;
d2007fbd 2091#endif //0
6cd62ccf 2092}
2093
6cd62ccf 2094
3aee1200 2095/* Take the tf current event offset and use the event facility id and event id
2096 * to figure out where is the next event offset.
2097 *
2098 * This is an internal function not aiming at being used elsewhere : it will
2099 * not jump over the current block limits. Please consider using
2100 * ltt_tracefile_read to do this.
2101 *
2102 * Returns 0 on success
2103 * ERANGE if we are at the end of the buffer.
2104 * ENOPROTOOPT if an error occured when getting the current event size.
2105 */
3c165eaf 2106int ltt_seek_next_event(LttTracefile *tf)
6cd62ccf 2107{
3aee1200 2108 int ret = 0;
2109 void *pos;
3aee1200 2110
2111 /* seek over the buffer header if we are at the buffer start */
eed2ef37 2112 if(tf->event.offset == 0) {
51551c6f 2113 tf->event.offset += tf->buffer_header_size;
b77d1b57 2114
f628823c 2115 if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) {
b77d1b57 2116 ret = ERANGE;
2117 }
3aee1200 2118 goto found;
2119 }
6cd62ccf 2120
6cd62ccf 2121
3aee1200 2122 pos = tf->event.data;
2123
77175651 2124 if(tf->event.data_size < 0) goto error;
3aee1200 2125
77175651 2126 pos += (size_t)tf->event.data_size;
3aee1200 2127
eed2ef37 2128 tf->event.offset = pos - tf->buffer.head;
cb03932a 2129
f628823c 2130 if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) {
cb03932a 2131 ret = ERANGE;
2132 goto found;
2133 }
36d36c9f 2134 g_assert(tf->event.offset < tf->buf_size - tf->buffer.lost_size);
3aee1200 2135
2136found:
2137 return ret;
2138
2139error:
2140 g_error("Error in ltt_seek_next_event for tracefile %s",
2141 g_quark_to_string(tf->name));
2142 return ENOPROTOOPT;
6cd62ccf 2143}
2144
791dffa6 2145#if 0
6cd62ccf 2146/*****************************************************************************
2147 *Function name
3aee1200 2148 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
986e2a7c 2149 *
2150 * 1.0 / (freq(khz) *1000) * 1000000000
6cd62ccf 2151 *Input Params
2152 * t : tracefile
2153 ****************************************************************************/
986e2a7c 2154/* from timer_tsc.c */
2155#define CYC2NS_SCALE_FACTOR 10
791dffa6 2156static guint32 calc_nsecs_per_cycle(LttTracefile * tf)
6cd62ccf 2157{
986e2a7c 2158 //return 1e6 / (double)tf->buffer.freq;
791dffa6 2159 guint32 cpu_mhz = tf->buffer.freq / 1000;
2160 guint32 cyc2ns_scale = (1000 << CYC2NS_SCALE_FACTOR)/cpu_mhz;
6cd62ccf 2161
791dffa6 2162 return cyc2ns_scale;
986e2a7c 2163 // return 1e6 / (double)tf->buffer.freq;
3aee1200 2164}
791dffa6 2165
2166static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles)
2167{
2168 return (cycles * tf->buffer.cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
2169}
2170#endif //0
2171
3aee1200 2172#if 0
2173void setFieldsOffset(LttTracefile *tf, LttEventType *evT,void *evD)
2174{
2175 LttField * rootFld = evT->root_field;
2176 // rootFld->base_address = evD;
2dee981d 2177
3aee1200 2178 if(likely(rootFld))
2179 rootFld->field_size = getFieldtypeSize(tf, evT->facility,
2180 evT, 0,0,rootFld, evD);
6cd62ccf 2181}
3aee1200 2182#endif //0
f104d082 2183#if 0
3aee1200 2184/*****************************************************************************
6cd62ccf 2185 *Function name
3aee1200 2186 * set_fields_offsets : set the precomputable offset of the fields
6cd62ccf 2187 *Input params
3aee1200 2188 * tracefile : opened trace file
2189 * event_type : the event type
6cd62ccf 2190 ****************************************************************************/
2191
3aee1200 2192void set_fields_offsets(LttTracefile *tf, LttEventType *event_type)
6cd62ccf 2193{
3aee1200 2194 LttField *field = event_type->root_field;
2195 enum field_status fixed_root = FIELD_FIXED, fixed_parent = FIELD_FIXED;
2196
2197 if(likely(field))
2198 preset_field_type_size(tf, event_type, 0, 0,
2199 &fixed_root, &fixed_parent,
2200 field);
2201
2202}
f104d082 2203#endif //0
2204
2205
2206/*****************************************************************************
2207 *Function name
2208 * get_alignment : Get the alignment needed for a field.
2209 *Input params
f104d082 2210 * field : field
2211 *
2212 * returns : The size on which it must be aligned.
2213 *
2214 ****************************************************************************/
3c165eaf 2215#if 0
743e50fd 2216off_t get_alignment(LttField *field)
f104d082 2217{
2312de30 2218 LttType *type = &field->field_type;
f104d082 2219
2220 switch(type->type_class) {
2221 case LTT_INT_FIXED:
2222 case LTT_UINT_FIXED:
2223 case LTT_POINTER:
2224 case LTT_CHAR:
2225 case LTT_UCHAR:
2226 case LTT_SHORT:
2227 case LTT_USHORT:
2228 case LTT_INT:
2229 case LTT_UINT:
2230 case LTT_LONG:
2231 case LTT_ULONG:
2232 case LTT_SIZE_T:
2233 case LTT_SSIZE_T:
2234 case LTT_OFF_T:
2235 case LTT_FLOAT:
2236 case LTT_ENUM:
2237 /* Align offset on type size */
83e160f2 2238 g_assert(field->field_size != 0);
f104d082 2239 return field->field_size;
2240 break;
2241 case LTT_STRING:
83e160f2 2242 return 1;
f104d082 2243 break;
2244 case LTT_ARRAY:
2245 g_assert(type->fields->len == 1);
2246 {
2247 LttField *child = &g_array_index(type->fields, LttField, 0);
743e50fd 2248 return get_alignment(child);
f104d082 2249 }
2250 break;
2251 case LTT_SEQUENCE:
2252 g_assert(type->fields->len == 2);
2253 {
83e160f2 2254 off_t localign = 1;
f104d082 2255 LttField *child = &g_array_index(type->fields, LttField, 0);
2256
743e50fd 2257 localign = max(localign, get_alignment(child));
f104d082 2258
2259 child = &g_array_index(type->fields, LttField, 1);
743e50fd 2260 localign = max(localign, get_alignment(child));
f104d082 2261
2262 return localign;
2263 }
2264 break;
2265 case LTT_STRUCT:
2266 case LTT_UNION:
2267 {
2268 guint i;
83e160f2 2269 off_t localign = 1;
f104d082 2270
2271 for(i=0; i<type->fields->len; i++) {
2272 LttField *child = &g_array_index(type->fields, LttField, i);
743e50fd 2273 localign = max(localign, get_alignment(child));
f104d082 2274 }
2275 return localign;
2276 }
2277 break;
2278 case LTT_NONE:
2279 default:
2280 g_error("get_alignment : unknown type");
83e160f2 2281 return -1;
f104d082 2282 }
f104d082 2283}
2284
3c165eaf 2285#endif //0
2286
f104d082 2287/*****************************************************************************
2288 *Function name
2289 * field_compute_static_size : Determine the size of fields known by their
2290 * sole definition. Unions, arrays and struct sizes might be known, but
2291 * the parser does not give that information.
2292 *Input params
2293 * tf : tracefile
2294 * field : field
2295 *
2296 ****************************************************************************/
3c165eaf 2297#if 0
743e50fd 2298void field_compute_static_size(LttFacility *fac, LttField *field)
f104d082 2299{
2312de30 2300 LttType *type = &field->field_type;
f104d082 2301
2302 switch(type->type_class) {
2303 case LTT_INT_FIXED:
2304 case LTT_UINT_FIXED:
2305 case LTT_POINTER:
2306 case LTT_CHAR:
2307 case LTT_UCHAR:
2308 case LTT_SHORT:
2309 case LTT_USHORT:
2310 case LTT_INT:
2311 case LTT_UINT:
2312 case LTT_LONG:
2313 case LTT_ULONG:
2314 case LTT_SIZE_T:
2315 case LTT_SSIZE_T:
2316 case LTT_OFF_T:
2317 case LTT_FLOAT:
2318 case LTT_ENUM:
2319 case LTT_STRING:
2320 /* nothing to do */
2321 break;
2322 case LTT_ARRAY:
2323 /* note this : array type size is the number of elements in the array,
2324 * while array field size of the length of the array in bytes */
2325 g_assert(type->fields->len == 1);
2326 {
2327 LttField *child = &g_array_index(type->fields, LttField, 0);
743e50fd 2328 field_compute_static_size(fac, child);
f104d082 2329
2330 if(child->field_size != 0) {
2331 field->field_size = type->size * child->field_size;
2332 field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
2333 sizeof(off_t), type->size);
2334 } else {
2335 field->field_size = 0;
2336 }
2337 }
2338 break;
2339 case LTT_SEQUENCE:
2340 g_assert(type->fields->len == 2);
2341 {
2312de30 2342 off_t local_offset = 0;
f104d082 2343 LttField *child = &g_array_index(type->fields, LttField, 1);
743e50fd 2344 field_compute_static_size(fac, child);
f104d082 2345 field->field_size = 0;
2346 type->size = 0;
2347 if(child->field_size != 0) {
2348 field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
2349 sizeof(off_t), SEQUENCE_AVG_ELEMENTS);
2350 }
2351 }
2352 break;
2353 case LTT_STRUCT:
2354 case LTT_UNION:
2355 {
2356 guint i;
2357 for(i=0;i<type->fields->len;i++) {
2358 LttField *child = &g_array_index(type->fields, LttField, i);
743e50fd 2359 field_compute_static_size(fac, child);
f104d082 2360 if(child->field_size != 0) {
743e50fd 2361 type->size += ltt_align(type->size, get_alignment(child),
2362 fac->alignment);
f104d082 2363 type->size += child->field_size;
2364 } else {
2365 /* As soon as we find a child with variable size, we have
2366 * a variable size */
2367 type->size = 0;
2368 break;
2369 }
2370 }
2371 field->field_size = type->size;
2372 }
2373 break;
2374 default:
2375 g_error("field_static_size : unknown type");
2312de30 2376 }
f104d082 2377
2378}
3c165eaf 2379#endif //0
f104d082 2380
2381
2382/*****************************************************************************
2383 *Function name
2384 * precompute_fields_offsets : set the precomputable offset of the fields
2385 *Input params
743e50fd 2386 * fac : facility
f104d082 2387 * field : the field
2388 * offset : pointer to the current offset, must be incremented
2389 *
2390 * return : 1 : found a variable length field, stop the processing.
2391 * 0 otherwise.
2392 ****************************************************************************/
2393
3c165eaf 2394#if 0
dd3a6d39 2395gint precompute_fields_offsets(LttFacility *fac, LttField *field, off_t *offset, gint is_compact)
f104d082 2396{
2312de30 2397 LttType *type = &field->field_type;
dd3a6d39 2398
2399 if(unlikely(is_compact)) {
2400 g_assert(field->field_size != 0);
2401 /* FIXME THIS IS A HUUUUUGE hack :
2402 * offset is between the compact_data field in struct LttEvent
2403 * and the address of the field root in the memory map.
2404 * ark. Both will stay at the same addresses while the event
2405 * is readable, so it's ok.
2406 */
2407 field->offset_root = 0;
2408 field->fixed_root = FIELD_FIXED;
2409 return 0;
2410 }
f104d082 2411
2412 switch(type->type_class) {
2413 case LTT_INT_FIXED:
2414 case LTT_UINT_FIXED:
2415 case LTT_POINTER:
2416 case LTT_CHAR:
2417 case LTT_UCHAR:
2418 case LTT_SHORT:
2419 case LTT_USHORT:
2420 case LTT_INT:
2421 case LTT_UINT:
2422 case LTT_LONG:
2423 case LTT_ULONG:
2424 case LTT_SIZE_T:
2425 case LTT_SSIZE_T:
2426 case LTT_OFF_T:
2427 case LTT_FLOAT:
2428 case LTT_ENUM:
743e50fd 2429 g_assert(field->field_size != 0);
f104d082 2430 /* Align offset on type size */
743e50fd 2431 *offset += ltt_align(*offset, get_alignment(field),
2432 fac->alignment);
f104d082 2433 /* remember offset */
2434 field->offset_root = *offset;
2435 field->fixed_root = FIELD_FIXED;
2436 /* Increment offset */
2437 *offset += field->field_size;
2438 return 0;
2439 break;
2440 case LTT_STRING:
2441 field->offset_root = *offset;
2442 field->fixed_root = FIELD_FIXED;
2443 return 1;
2444 break;
2445 case LTT_ARRAY:
2446 g_assert(type->fields->len == 1);
2447 {
2448 LttField *child = &g_array_index(type->fields, LttField, 0);
2449
743e50fd 2450 *offset += ltt_align(*offset, get_alignment(field),
2451 fac->alignment);
f104d082 2452
2453 /* remember offset */
2454 field->offset_root = *offset;
2455 field->array_offset = *offset;
2456 field->fixed_root = FIELD_FIXED;
2457
2458 /* Let the child be variable */
2459 //precompute_fields_offsets(tf, child, offset);
2460
2461 if(field->field_size != 0) {
2462 /* Increment offset */
2463 /* field_size is the array size in bytes */
2464 *offset += field->field_size;
2465 return 0;
2466 } else {
2467 return 1;
2468 }
2469 }
2470 break;
2471 case LTT_SEQUENCE:
2472 g_assert(type->fields->len == 2);
2473 {
2474 LttField *child;
2475 guint ret;
2476
743e50fd 2477 *offset += ltt_align(*offset, get_alignment(field),
2478 fac->alignment);
f104d082 2479
2480 /* remember offset */
2481 field->offset_root = *offset;
2482 field->fixed_root = FIELD_FIXED;
2483
2484 child = &g_array_index(type->fields, LttField, 0);
dd3a6d39 2485 ret = precompute_fields_offsets(fac, child, offset, is_compact);
f104d082 2486 g_assert(ret == 0); /* Seq len cannot have variable len */
2487
2488 child = &g_array_index(type->fields, LttField, 1);
743e50fd 2489 *offset += ltt_align(*offset, get_alignment(child),
2490 fac->alignment);
f104d082 2491 field->array_offset = *offset;
743e50fd 2492 /* Let the child be variable. */
2493 //ret = precompute_fields_offsets(fac, child, offset);
f104d082 2494
2495 /* Cannot precompute fields offsets of sequence members, and has
2496 * variable length. */
2497 return 1;
2498 }
2499 break;
2500 case LTT_STRUCT:
2501 {
2502 LttField *child;
2503 guint i;
2504 gint ret=0;
2505
743e50fd 2506 *offset += ltt_align(*offset, get_alignment(field),
2507 fac->alignment);
f104d082 2508 /* remember offset */
2509 field->offset_root = *offset;
2510 field->fixed_root = FIELD_FIXED;
2511
2512 for(i=0; i< type->fields->len; i++) {
2513 child = &g_array_index(type->fields, LttField, i);
dd3a6d39 2514 ret = precompute_fields_offsets(fac, child, offset, is_compact);
f104d082 2515
2516 if(ret) break;
2517 }
2518 return ret;
2519 }
2520 break;
2521 case LTT_UNION:
2522 {
2523 LttField *child;
2524 guint i;
2525 gint ret=0;
2526
743e50fd 2527 *offset += ltt_align(*offset, get_alignment(field),
2528 fac->alignment);
f104d082 2529 /* remember offset */
2530 field->offset_root = *offset;
2531 field->fixed_root = FIELD_FIXED;
2532
2533 for(i=0; i< type->fields->len; i++) {
2534 *offset = field->offset_root;
2535 child = &g_array_index(type->fields, LttField, i);
dd3a6d39 2536 ret = precompute_fields_offsets(fac, child, offset, is_compact);
f104d082 2537
2538 if(ret) break;
2539 }
2540 *offset = field->offset_root + field->field_size;
2541 return ret;
2542 }
2543
2544 break;
2545 case LTT_NONE:
2546 default:
2547 g_error("precompute_fields_offsets : unknown type");
2548 return 1;
2549 }
2550
2551}
2552
3c165eaf 2553#endif //0
f104d082 2554
3c165eaf 2555#if 0
f104d082 2556/*****************************************************************************
2557 *Function name
2558 * precompute_offsets : set the precomputable offset of an event type
2559 *Input params
2560 * tf : tracefile
2561 * event : event type
2562 *
2563 ****************************************************************************/
743e50fd 2564void precompute_offsets(LttFacility *fac, LttEventType *event)
f104d082 2565{
2566 guint i;
2567 off_t offset = 0;
2568 gint ret;
2569
2570 /* First, compute the size of fixed size fields. Will determine size for
2571 * arrays, struct and unions, which is not done by the parser */
2572 for(i=0; i<event->fields->len; i++) {
2573 LttField *field = &g_array_index(event->fields, LttField, i);
743e50fd 2574 field_compute_static_size(fac, field);
f104d082 2575 }
2576
2577 /* Precompute all known offsets */
2578 for(i=0; i<event->fields->len; i++) {
2579 LttField *field = &g_array_index(event->fields, LttField, i);
dd3a6d39 2580 if(event->has_compact_data && i == 0)
2581 ret = precompute_fields_offsets(fac, field, &offset, 1);
2582 else
2583 ret = precompute_fields_offsets(fac, field, &offset, 0);
f104d082 2584 if(ret) break;
2585 }
2586}
3c165eaf 2587#endif //0
f104d082 2588
e4eced0f 2589
bbf28e50 2590
3aee1200 2591/*****************************************************************************
2592 *Function name
2593 * preset_field_type_size : set the fixed sizes of the field type
2594 *Input params
2595 * tf : tracefile
2596 * event_type : event type
2597 * offset_root : offset from the root
2598 * offset_parent : offset from the parent
2599 * fixed_root : Do we know a fixed offset to the root ?
2600 * fixed_parent : Do we know a fixed offset to the parent ?
2601 * field : field
2602 ****************************************************************************/
f104d082 2603
2604
2605
2606// preset the fixed size offsets. Calculate them just like genevent-new : an
2607// increment of a *to value that represents the offset from the start of the
2608// event data.
2609// The preset information is : offsets up to (and including) the first element
2610// of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2611#if 0
3aee1200 2612void preset_field_type_size(LttTracefile *tf, LttEventType *event_type,
2613 off_t offset_root, off_t offset_parent,
2614 enum field_status *fixed_root, enum field_status *fixed_parent,
2615 LttField *field)
2616{
2617 enum field_status local_fixed_root, local_fixed_parent;
2618 guint i;
2619 LttType *type;
dfb73233 2620
3aee1200 2621 g_assert(field->fixed_root == FIELD_UNKNOWN);
2622 g_assert(field->fixed_parent == FIELD_UNKNOWN);
2623 g_assert(field->fixed_size == FIELD_UNKNOWN);
dfb73233 2624
3aee1200 2625 type = field->field_type;
2626
2627 field->fixed_root = *fixed_root;
2628 if(field->fixed_root == FIELD_FIXED)
2629 field->offset_root = offset_root;
2630 else
2631 field->offset_root = 0;
2632
2633 field->fixed_parent = *fixed_parent;
2634 if(field->fixed_parent == FIELD_FIXED)
2635 field->offset_parent = offset_parent;
2636 else
2637 field->offset_parent = 0;
2638
2639 size_t current_root_offset;
2640 size_t current_offset;
2641 enum field_status current_child_status, final_child_status;
2642 size_t max_size;
2643
2644 switch(type->type_class) {
83e160f2 2645 case LTT_INT_FIXED:
2646 case LTT_UINT_FIXED:
2647 case LTT_CHAR:
2648 case LTT_UCHAR:
2649 case LTT_SHORT:
2650 case LTT_USHORT:
3aee1200 2651 case LTT_INT:
2652 case LTT_UINT:
2653 case LTT_FLOAT:
2654 case LTT_ENUM:
2655 field->field_size = ltt_type_size(tf->trace, type);
2656 field->fixed_size = FIELD_FIXED;
2657 break;
2658 case LTT_POINTER:
2659 field->field_size = (off_t)event_type->facility->pointer_size;
2660 field->fixed_size = FIELD_FIXED;
2661 break;
2662 case LTT_LONG:
2663 case LTT_ULONG:
cb03932a 2664 field->field_size = (off_t)event_type->facility->long_size;
3aee1200 2665 field->fixed_size = FIELD_FIXED;
2666 break;
2667 case LTT_SIZE_T:
2668 case LTT_SSIZE_T:
2669 case LTT_OFF_T:
2670 field->field_size = (off_t)event_type->facility->size_t_size;
2671 field->fixed_size = FIELD_FIXED;
2672 break;
2673 case LTT_SEQUENCE:
2674 local_fixed_root = FIELD_VARIABLE;
2675 local_fixed_parent = FIELD_VARIABLE;
2676 preset_field_type_size(tf, event_type,
2677 0, 0,
2678 &local_fixed_root, &local_fixed_parent,
2679 field->child[0]);
2680 field->fixed_size = FIELD_VARIABLE;
2681 field->field_size = 0;
27304273 2682 *fixed_root = FIELD_VARIABLE;
2683 *fixed_parent = FIELD_VARIABLE;
3aee1200 2684 break;
2685 case LTT_STRING:
2686 field->fixed_size = FIELD_VARIABLE;
2687 field->field_size = 0;
27304273 2688 *fixed_root = FIELD_VARIABLE;
2689 *fixed_parent = FIELD_VARIABLE;
3aee1200 2690 break;
2691 case LTT_ARRAY:
2692 local_fixed_root = FIELD_VARIABLE;
2693 local_fixed_parent = FIELD_VARIABLE;
2694 preset_field_type_size(tf, event_type,
2695 0, 0,
2696 &local_fixed_root, &local_fixed_parent,
2697 field->child[0]);
2698 field->fixed_size = field->child[0]->fixed_size;
27304273 2699 if(field->fixed_size == FIELD_FIXED) {
3aee1200 2700 field->field_size = type->element_number * field->child[0]->field_size;
27304273 2701 } else {
3aee1200 2702 field->field_size = 0;
27304273 2703 *fixed_root = FIELD_VARIABLE;
2704 *fixed_parent = FIELD_VARIABLE;
2705 }
3aee1200 2706 break;
2707 case LTT_STRUCT:
2708 current_root_offset = field->offset_root;
2709 current_offset = 0;
2710 current_child_status = FIELD_FIXED;
2711 for(i=0;i<type->element_number;i++) {
2712 preset_field_type_size(tf, event_type,
2713 current_root_offset, current_offset,
2714 fixed_root, &current_child_status,
2715 field->child[i]);
2716 if(current_child_status == FIELD_FIXED) {
2717 current_root_offset += field->child[i]->field_size;
2718 current_offset += field->child[i]->field_size;
2719 } else {
2720 current_root_offset = 0;
2721 current_offset = 0;
2722 }
2723 }
2724 if(current_child_status != FIELD_FIXED) {
2725 *fixed_parent = current_child_status;
2726 field->field_size = 0;
2727 field->fixed_size = current_child_status;
2728 } else {
2729 field->field_size = current_offset;
2730 field->fixed_size = FIELD_FIXED;
2731 }
2732 break;
2733 case LTT_UNION:
2734 current_root_offset = field->offset_root;
2735 current_offset = 0;
2736 max_size = 0;
2737 final_child_status = FIELD_FIXED;
2738 for(i=0;i<type->element_number;i++) {
2739 enum field_status current_root_child_status = FIELD_FIXED;
2740 enum field_status current_child_status = FIELD_FIXED;
2741 preset_field_type_size(tf, event_type,
2742 current_root_offset, current_offset,
2743 &current_root_child_status, &current_child_status,
2744 field->child[i]);
2745 if(current_child_status != FIELD_FIXED)
2746 final_child_status = current_child_status;
2747 else
2748 max_size = max(max_size, field->child[i]->field_size);
2749 }
2750 if(final_child_status != FIELD_FIXED) {
62e4e7bf 2751 g_error("LTTV does not support variable size fields in unions.");
2752 /* This will stop the application. */
3aee1200 2753 *fixed_root = final_child_status;
2754 *fixed_parent = final_child_status;
2755 field->field_size = 0;
2756 field->fixed_size = current_child_status;
2757 } else {
2758 field->field_size = max_size;
2759 field->fixed_size = FIELD_FIXED;
2760 }
2761 break;
83e160f2 2762 case LTT_NONE:
2763 g_error("unexpected type NONE");
2764 break;
dfb73233 2765 }
2766
6cd62ccf 2767}
f104d082 2768#endif //0
3aee1200 2769
77175651 2770/*****************************************************************************
2771 *Function name
2772 * check_fields_compatibility : Check for compatibility between two fields :
2773 * do they use the same inner structure ?
2774 *Input params
2775 * event_type1 : event type
2776 * event_type2 : event type
2777 * field1 : field
2778 * field2 : field
2779 *Returns : 0 if identical
2780 * 1 if not.
2781 ****************************************************************************/
f104d082 2782// this function checks for equality of field types. Therefore, it does not use
2783// per se offsets. For instance, an aligned version of a structure is
2784// compatible with an unaligned version of the same structure.
3c165eaf 2785#if 0
f104d082 2786gint check_fields_compatibility(LttEventType *event_type1,
2787 LttEventType *event_type2,
2788 LttField *field1, LttField *field2)
2789{
2790 guint different = 0;
2312de30 2791 LttType *type1;
2792 LttType *type2;
f104d082 2793
2794 if(field1 == NULL) {
2795 if(field2 == NULL) goto end;
2796 else {
2797 different = 1;
2798 goto end;
2799 }
2800 } else if(field2 == NULL) {
2801 different = 1;
2802 goto end;
2803 }
2804
2312de30 2805 type1 = &field1->field_type;
2806 type2 = &field2->field_type;
f104d082 2807
2808 if(type1->type_class != type2->type_class) {
2809 different = 1;
2810 goto end;
2811 }
62e4e7bf 2812 if(type1->network != type2->network) {
2813 different = 1;
2814 goto end;
2815 }
f104d082 2816
2817 switch(type1->type_class) {
2818 case LTT_INT_FIXED:
2819 case LTT_UINT_FIXED:
2820 case LTT_POINTER:
2821 case LTT_CHAR:
2822 case LTT_UCHAR:
2823 case LTT_SHORT:
2824 case LTT_USHORT:
2825 case LTT_INT:
2826 case LTT_UINT:
2827 case LTT_LONG:
2828 case LTT_ULONG:
2829 case LTT_SIZE_T:
2830 case LTT_SSIZE_T:
2831 case LTT_OFF_T:
2832 case LTT_FLOAT:
2833 case LTT_ENUM:
2834 if(field1->field_size != field2->field_size)
2835 different = 1;
2836 break;
2837 case LTT_STRING:
2838 break;
2839 case LTT_ARRAY:
2840 {
2841 LttField *child1 = &g_array_index(type1->fields, LttField, 0);
2842 LttField *child2 = &g_array_index(type2->fields, LttField, 0);
2843
2844 if(type1->size != type2->size)
2845 different = 1;
2846 if(check_fields_compatibility(event_type1, event_type2, child1, child2))
2847 different = 1;
2848 }
2849 break;
2850 case LTT_SEQUENCE:
2851 {
2852 LttField *child1 = &g_array_index(type1->fields, LttField, 1);
2853 LttField *child2 = &g_array_index(type2->fields, LttField, 1);
2854
2855 if(check_fields_compatibility(event_type1, event_type2, child1, child2))
2856 different = 1;
2857 }
2858 break;
2859 case LTT_STRUCT:
2860 case LTT_UNION:
2861 {
2862 LttField *child;
2863 guint i;
2864
2865 if(type1->fields->len != type2->fields->len) {
2866 different = 1;
2867 goto end;
2868 }
2869
2870 for(i=0; i< type1->fields->len; i++) {
2312de30 2871 LttField *child1;
2872 LttField *child2;
f104d082 2873 child1 = &g_array_index(type1->fields, LttField, i);
2874 child2 = &g_array_index(type2->fields, LttField, i);
2875 different = check_fields_compatibility(event_type1,
2876 event_type2, child1, child2);
2877
2878 if(different) break;
2879 }
2880 }
2881 break;
2882 case LTT_NONE:
2883 default:
dd3a6d39 2884 g_error("check_fields_compatibility : unknown type");
f104d082 2885 }
2886
2887end:
2888 return different;
2889}
3c165eaf 2890#endif //0
f104d082 2891
2892#if 0
77175651 2893gint check_fields_compatibility(LttEventType *event_type1,
2894 LttEventType *event_type2,
2895 LttField *field1, LttField *field2)
2896{
2897 guint different = 0;
77175651 2898 guint i;
2899 LttType *type1;
2900 LttType *type2;
2901
2902 if(field1 == NULL) {
2903 if(field2 == NULL) goto end;
2904 else {
2905 different = 1;
2906 goto end;
2907 }
2908 } else if(field2 == NULL) {
2909 different = 1;
2910 goto end;
2911 }
2912
2913 g_assert(field1->fixed_root != FIELD_UNKNOWN);
2914 g_assert(field2->fixed_root != FIELD_UNKNOWN);
2915 g_assert(field1->fixed_parent != FIELD_UNKNOWN);
2916 g_assert(field2->fixed_parent != FIELD_UNKNOWN);
2917 g_assert(field1->fixed_size != FIELD_UNKNOWN);
2918 g_assert(field2->fixed_size != FIELD_UNKNOWN);
2919
2920 type1 = field1->field_type;
2921 type2 = field2->field_type;
2922
77175651 2923 if(type1->type_class != type2->type_class) {
2924 different = 1;
2925 goto end;
2926 }
2927 if(type1->element_name != type2->element_name) {
2928 different = 1;
2929 goto end;
2930 }
2931
2932 switch(type1->type_class) {
83e160f2 2933 case LTT_INT_FIXED:
2934 case LTT_UINT_FIXED:
2935 case LTT_POINTER:
2936 case LTT_CHAR:
2937 case LTT_UCHAR:
2938 case LTT_SHORT:
2939 case LTT_USHORT:
77175651 2940 case LTT_INT:
2941 case LTT_UINT:
2942 case LTT_FLOAT:
2943 case LTT_POINTER:
2944 case LTT_LONG:
2945 case LTT_ULONG:
2946 case LTT_SIZE_T:
2947 case LTT_SSIZE_T:
2948 case LTT_OFF_T:
2949 if(field1->field_size != field2->field_size) {
2950 different = 1;
2951 goto end;
2952 }
2953 break;
2954 case LTT_ENUM:
2955 if(type1->element_number != type2->element_number) {
2956 different = 1;
2957 goto end;
2958 }
2959 for(i=0;i<type1->element_number;i++) {
2960 if(type1->enum_strings[i] != type2->enum_strings[i]) {
2961 different = 1;
2962 goto end;
2963 }
2964 }
2965 break;
2966 case LTT_SEQUENCE:
2967 /* Two elements : size and child */
2968 g_assert(type1->element_number != type2->element_number);
2969 for(i=0;i<type1->element_number;i++) {
2970 if(check_fields_compatibility(event_type1, event_type2,
2971 field1->child[0], field2->child[0])) {
2972 different = 1;
2973 goto end;
2974 }
2975 }
2976 break;
2977 case LTT_STRING:
2978 break;
2979 case LTT_ARRAY:
2980 if(field1->field_size != field2->field_size) {
2981 different = 1;
2982 goto end;
2983 }
2984 /* Two elements : size and child */
2985 g_assert(type1->element_number != type2->element_number);
2986 for(i=0;i<type1->element_number;i++) {
2987 if(check_fields_compatibility(event_type1, event_type2,
2988 field1->child[0], field2->child[0])) {
2989 different = 1;
2990 goto end;
2991 }
2992 }
2993 break;
2994 case LTT_STRUCT:
2995 case LTT_UNION:
2996 if(type1->element_number != type2->element_number) {
2997 different = 1;
2998 break;
2999 }
3000 for(i=0;i<type1->element_number;i++) {
3001 if(check_fields_compatibility(event_type1, event_type2,
3002 field1->child[0], field2->child[0])) {
3003 different = 1;
3004 goto end;
3005 }
3006 }
3007 break;
3008 }
3009end:
3010 return different;
3011}
3aee1200 3012#endif //0
6cd62ccf 3013
f104d082 3014
6cd62ccf 3015/*****************************************************************************
3016 *Function name
eed2ef37 3017 * ltt_get_int : get an integer number
6cd62ccf 3018 *Input params
3aee1200 3019 * reverse_byte_order: must we reverse the byte order ?
6cd62ccf 3020 * size : the size of the integer
3aee1200 3021 * ptr : the data pointer
6cd62ccf 3022 *Return value
cf74a6f1 3023 * gint64 : a 64 bits integer
6cd62ccf 3024 ****************************************************************************/
3025
eed2ef37 3026gint64 ltt_get_int(gboolean reverse_byte_order, gint size, void *data)
6cd62ccf 3027{
3aee1200 3028 gint64 val;
cf74a6f1 3029
3030 switch(size) {
3aee1200 3031 case 1: val = *((gint8*)data); break;
3032 case 2: val = ltt_get_int16(reverse_byte_order, data); break;
3033 case 4: val = ltt_get_int32(reverse_byte_order, data); break;
3034 case 8: val = ltt_get_int64(reverse_byte_order, data); break;
3035 default: val = ltt_get_int64(reverse_byte_order, data);
3036 g_critical("get_int : integer size %d unknown", size);
cf74a6f1 3037 break;
3038 }
3039
3aee1200 3040 return val;
6cd62ccf 3041}
3aee1200 3042
6cd62ccf 3043/*****************************************************************************
3044 *Function name
eed2ef37 3045 * ltt_get_uint : get an unsigned integer number
6cd62ccf 3046 *Input params
3aee1200 3047 * reverse_byte_order: must we reverse the byte order ?
3048 * size : the size of the integer
3049 * ptr : the data pointer
3050 *Return value
3051 * guint64 : a 64 bits unsigned integer
6cd62ccf 3052 ****************************************************************************/
3053
eed2ef37 3054guint64 ltt_get_uint(gboolean reverse_byte_order, gint size, void *data)
6cd62ccf 3055{
3aee1200 3056 guint64 val;
3057
3058 switch(size) {
3059 case 1: val = *((gint8*)data); break;
3060 case 2: val = ltt_get_uint16(reverse_byte_order, data); break;
3061 case 4: val = ltt_get_uint32(reverse_byte_order, data); break;
3062 case 8: val = ltt_get_uint64(reverse_byte_order, data); break;
3063 default: val = ltt_get_uint64(reverse_byte_order, data);
3064 g_critical("get_uint : unsigned integer size %d unknown",
3065 size);
3066 break;
3067 }
3068
3069 return val;
6cd62ccf 3070}
3aee1200 3071
3072
a5dcde2f 3073/* get the node name of the system */
3074
3075char * ltt_trace_system_description_node_name (LttSystemDescription * s)
3076{
3077 return s->node_name;
3078}
3079
3080
3081/* get the domain name of the system */
3082
3083char * ltt_trace_system_description_domain_name (LttSystemDescription * s)
3084{
3085 return s->domain_name;
3086}
3087
3088
3089/* get the description of the system */
3090
3091char * ltt_trace_system_description_description (LttSystemDescription * s)
3092{
3093 return s->description;
3094}
3095
3096
bf33dd50 3097/* get the NTP corrected start time of the trace */
7bd563ec 3098LttTime ltt_trace_start_time(LttTrace *t)
a5dcde2f 3099{
7bd563ec 3100 return t->start_time;
a5dcde2f 3101}
3102
bf33dd50 3103/* get the monotonic start time of the trace */
3104LttTime ltt_trace_start_time_monotonic(LttTrace *t)
3105{
3106 return t->start_time_from_tsc;
3107}
3108
18206708 3109LttTracefile *ltt_tracefile_new()
3110{
3111 return g_new(LttTracefile, 1);
3112}
3113
3114void ltt_tracefile_destroy(LttTracefile *tf)
3115{
3116 g_free(tf);
3117}
3118
3119void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src)
3120{
3121 *dest = *src;
3122}
3123
3aee1200 3124/* Before library loading... */
3125
3c165eaf 3126void init(void)
3aee1200 3127{
3128 LTT_FACILITY_NAME_HEARTBEAT = g_quark_from_string("heartbeat");
3129 LTT_EVENT_NAME_HEARTBEAT = g_quark_from_string("heartbeat");
d1bb700c 3130 LTT_EVENT_NAME_HEARTBEAT_FULL = g_quark_from_string("heartbeat_full");
3aee1200 3131
3865ea09 3132 LTT_TRACEFILE_NAME_FACILITIES = g_quark_from_string("/control/facilities");
3aee1200 3133}
This page took 0.220658 seconds and 4 git commands to generate.