print field names by default
[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
2e13d6af 1093 char *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:
2e13d6af 1101 marker_name = pos = tf->event.data;
3c165eaf 1102 g_debug("Doing MARKER_ID_SET_MARKER_ID of marker %s", marker_name);
2e13d6af 1103 pos += strlen(marker_name) + 1;
1104 //remove genevent compatibility
1105 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
3c165eaf 1106 pos += ltt_align((size_t)pos, sizeof(uint16_t), tf->has_alignment);
1107 id = ltt_get_uint16(LTT_GET_BO(tf), pos);
1108 pos += sizeof(guint16);
1109 int_size = *(guint8*)pos;
1110 pos += sizeof(guint8);
1111 long_size = *(guint8*)pos;
1112 pos += sizeof(guint8);
1113 pointer_size = *(guint8*)pos;
1114 pos += sizeof(guint8);
1115 size_t_size = *(guint8*)pos;
1116 pos += sizeof(guint8);
1117 alignment = *(guint8*)pos;
1118 pos += sizeof(guint8);
1119 marker_id_event(tf->trace, g_quark_from_string(marker_name),
1120 id, int_size, long_size,
1121 pointer_size, size_t_size, alignment);
3aee1200 1122 break;
3c165eaf 1123 case MARKER_ID_SET_MARKER_FORMAT:
2e13d6af 1124 marker_name = pos = tf->event.data;
3c165eaf 1125 g_debug("Doing MARKER_ID_SET_MARKER_FORMAT of marker %s",
1126 marker_name);
2e13d6af 1127 pos += strlen(marker_name) + 1;
1128 //break genevent.
1129 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
1130 format = pos;
3c165eaf 1131 pos += strlen(format) + 1;
2e13d6af 1132 //break genevent
1133 //pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
3c165eaf 1134 marker_format_event(tf->trace, g_quark_from_string(marker_name),
1135 format);
1136 /* get information from dictionnary TODO */
3aee1200 1137 break;
3c165eaf 1138 case MARKER_ID_HEARTBEAT_32:
1139 case MARKER_ID_HEARTBEAT_64:
d1bb700c 1140 break;
3aee1200 1141 default:
1142 g_warning("Error in processing facility file %s, "
3c165eaf 1143 "unknown event id %hhu.",
3aee1200 1144 g_quark_to_string(tf->name),
1145 tf->event.event_id);
1146 err = EPERM;
1147 goto event_id_error;
1148 }
1149 }
963b5f2d 1150 }
3aee1200 1151 return 0;
963b5f2d 1152
3aee1200 1153 /* Error handling */
3aee1200 1154event_id_error:
3aee1200 1155update_error:
1156seek_error:
d2083cab 1157 g_warning("An error occured in facility tracefile parsing");
3aee1200 1158 return err;
6cd62ccf 1159}
1160
963b5f2d 1161
3aee1200 1162LttTrace *ltt_trace_open(const gchar *pathname)
1163{
1164 gchar abs_path[PATH_MAX];
1165 LttTrace * t;
1166 LttTracefile *tf;
1167 GArray *group;
b56dcdf2 1168 int i, ret;
16fcbb80 1169 struct ltt_block_start_header *header;
62e4e7bf 1170 DIR *dir;
1171 struct dirent *entry;
b56dcdf2 1172 guint control_found = 0;
1173 guint eventdefs_found = 0;
62e4e7bf 1174 struct stat stat_buf;
b56dcdf2 1175 gchar path[PATH_MAX];
3aee1200 1176
1177 t = g_new(LttTrace, 1);
1178 if(!t) goto alloc_error;
1179
1180 get_absolute_pathname(pathname, abs_path);
1181 t->pathname = g_quark_from_string(abs_path);
1182
3aee1200 1183 g_datalist_init(&t->tracefiles);
b56dcdf2 1184
1185 /* Test to see if it looks like a trace */
62e4e7bf 1186 dir = opendir(abs_path);
1187 if(dir == NULL) {
1188 perror(abs_path);
1189 goto open_error;
1190 }
1191 while((entry = readdir(dir)) != NULL) {
b56dcdf2 1192 strcpy(path, abs_path);
1193 strcat(path, "/");
1194 strcat(path, entry->d_name);
62e4e7bf 1195 ret = stat(path, &stat_buf);
1196 if(ret == -1) {
1197 perror(path);
1198 continue;
1199 }
1200 if(S_ISDIR(stat_buf.st_mode)) {
b56dcdf2 1201 if(strcmp(entry->d_name, "control") == 0) {
1202 control_found = 1;
1203 }
1204 if(strcmp(entry->d_name, "eventdefs") == 0) {
1205 eventdefs_found = 1;
1206 }
1207 }
1208 }
1209 closedir(dir);
1210
1211 if(!control_found || !eventdefs_found) goto find_error;
1212
1213 /* Open all the tracefiles */
e45551ac 1214 if(open_tracefiles(t, abs_path, "")) {
1215 g_warning("Error opening tracefile %s", abs_path);
b56dcdf2 1216 goto find_error;
e45551ac 1217 }
3aee1200 1218
3aee1200 1219 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1220 group = g_datalist_id_get_data(&t->tracefiles, LTT_TRACEFILE_NAME_FACILITIES);
1221 if(group == NULL) {
1222 g_error("Trace %s has no facility tracefile", abs_path);
3865ea09 1223 g_assert(0);
3aee1200 1224 goto facilities_error;
1225 }
1226
16fcbb80 1227 /* Get the trace information for the control/facility 0 tracefile */
1228 g_assert(group->len > 0);
1229 tf = &g_array_index (group, LttTracefile, 0);
1230 header = (struct ltt_block_start_header*)tf->buffer.head;
51551c6f 1231 g_assert(parse_trace_header(header->trace,
1232 tf, t) == 0);
b56dcdf2 1233
1234 t->num_cpu = group->len;
16fcbb80 1235
d79909d1 1236 ret = allocate_marker_data(t);
b44ba972 1237 if (ret)
d79909d1 1238 g_error("Error in allocating marker data");
1239
3aee1200 1240 for(i=0; i<group->len; i++) {
1241 tf = &g_array_index (group, LttTracefile, i);
1242 if(ltt_process_facility_tracefile(tf))
1243 goto facilities_error;
1244 }
dd3a6d39 1245
3aee1200 1246 return t;
1247
1248 /* Error handling */
1249facilities_error:
d79909d1 1250 destroy_marker_data(t);
b56dcdf2 1251find_error:
3aee1200 1252 g_datalist_clear(&t->tracefiles);
b56dcdf2 1253open_error:
3aee1200 1254 g_free(t);
1255alloc_error:
1256 return NULL;
1257
1258}
6cd62ccf 1259
826f1ab2 1260GQuark ltt_trace_name(const LttTrace *t)
6cd62ccf 1261{
3aee1200 1262 return t->pathname;
6cd62ccf 1263}
1264
6cd62ccf 1265
3aee1200 1266/******************************************************************************
1267 * When we copy a trace, we want all the opening actions to happen again :
1268 * the trace will be reopened and totally independant from the original.
1269 * That's why we call ltt_trace_open.
1270 *****************************************************************************/
1271LttTrace *ltt_trace_copy(LttTrace *self)
963b5f2d 1272{
3aee1200 1273 return ltt_trace_open(g_quark_to_string(self->pathname));
963b5f2d 1274}
1275
3aee1200 1276void ltt_trace_close(LttTrace *t)
6cd62ccf 1277{
3aee1200 1278 g_datalist_clear(&t->tracefiles);
1279 g_free(t);
6cd62ccf 1280}
1281
3aee1200 1282
6cd62ccf 1283/*****************************************************************************
3aee1200 1284 *Get the system description of the trace
6cd62ccf 1285 ****************************************************************************/
3c165eaf 1286#if 0
3aee1200 1287LttFacility *ltt_trace_facility_by_id(LttTrace *t, guint8 id)
6cd62ccf 1288{
3aee1200 1289 g_assert(id < t->facilities_by_num->len);
1290 return &g_array_index(t->facilities_by_num, LttFacility, id);
1291}
1292
1293/* ltt_trace_facility_get_by_name
1294 *
1295 * Returns the GArray of facility indexes. All the fac_ids that matches the
1296 * requested facility name.
1297 *
1298 * If name is not found, returns NULL.
1299 */
1300GArray *ltt_trace_facility_get_by_name(LttTrace *t, GQuark name)
1301{
1302 return g_datalist_id_get_data(&t->facilities_by_name, name);
6cd62ccf 1303}
3c165eaf 1304#endif //0
6cd62ccf 1305
1306/*****************************************************************************
963b5f2d 1307 * Functions to discover all the event types in the trace
6cd62ccf 1308 ****************************************************************************/
1309
3aee1200 1310#if 0
963b5f2d 1311unsigned ltt_trace_eventtype_number(LttTrace *t)
6cd62ccf 1312{
8d1e6362 1313 unsigned int i;
963b5f2d 1314 unsigned count = 0;
dc1cad90 1315 unsigned int num = t->facility_number;
963b5f2d 1316 LttFacility * f;
dc1cad90 1317
1318 for(i=0;i<num;i++){
963b5f2d 1319 f = (LttFacility*)g_ptr_array_index(t->facilities, i);
1320 count += f->event_number;
1321 }
1322 return count;
6cd62ccf 1323}
3aee1200 1324#endif //0
6cd62ccf 1325
3aee1200 1326#if 0
1327//use an iteration on all the trace facilities, and inside iteration on all the
1328//event types in each facilities instead.
963b5f2d 1329LttEventType *ltt_trace_eventtype_get(LttTrace *t, unsigned evId)
6cd62ccf 1330{
6e8c19d4 1331 LttEventType *event_type;
1332
963b5f2d 1333 LttFacility * f;
1334 f = ltt_trace_facility_by_id(t,evId);
6e8c19d4 1335
1336 if(unlikely(!f)) event_type = NULL;
1337 else event_type = f->events[evId - f->base_id];
1338
1339 return event_type;
6cd62ccf 1340}
3aee1200 1341#endif //0
6cd62ccf 1342
3aee1200 1343#if 0
6cd62ccf 1344/*****************************************************************************
3aee1200 1345 * ltt_trace_find_tracefile
1346 *
1347 * Find a tracefile by name and index in the group.
1348 *
1349 * Returns a pointer to the tracefiles, else NULL.
6cd62ccf 1350 ****************************************************************************/
6cd62ccf 1351
3aee1200 1352LttTracefile *ltt_trace_find_tracefile(LttTrace *t, const gchar *name)
6cd62ccf 1353{
6cd62ccf 1354}
3aee1200 1355#endif //0
6cd62ccf 1356
1357/*****************************************************************************
3aee1200 1358 * Get the start time and end time of the trace
6cd62ccf 1359 ****************************************************************************/
1360
3c165eaf 1361void ltt_tracefile_time_span_get(LttTracefile *tf,
3aee1200 1362 LttTime *start, LttTime *end)
6cd62ccf 1363{
3aee1200 1364 int err;
6cd62ccf 1365
3aee1200 1366 err = map_block(tf, 0);
1367 if(unlikely(err)) {
1368 g_error("Can not map block");
1369 *start = ltt_time_infinite;
1370 } else
1371 *start = tf->buffer.begin.timestamp;
1372
1373 err = map_block(tf, tf->num_blocks - 1); /* Last block */
1374 if(unlikely(err)) {
1375 g_error("Can not map block");
1376 *end = ltt_time_zero;
1377 } else
1378 *end = tf->buffer.end.timestamp;
6cd62ccf 1379}
1380
3aee1200 1381struct tracefile_time_span_get_args {
1382 LttTrace *t;
1383 LttTime *start;
1384 LttTime *end;
1385};
963b5f2d 1386
3c165eaf 1387void group_time_span_get(GQuark name, gpointer data, gpointer user_data)
963b5f2d 1388{
3aee1200 1389 struct tracefile_time_span_get_args *args =
1390 (struct tracefile_time_span_get_args*)user_data;
1391
1392 GArray *group = (GArray *)data;
1393 int i;
1394 LttTracefile *tf;
1395 LttTime tmp_start;
1396 LttTime tmp_end;
1397
1398 for(i=0; i<group->len; i++) {
1399 tf = &g_array_index (group, LttTracefile, i);
1400 if(tf->cpu_online) {
1401 ltt_tracefile_time_span_get(tf, &tmp_start, &tmp_end);
1402 if(ltt_time_compare(*args->start, tmp_start)>0) *args->start = tmp_start;
1403 if(ltt_time_compare(*args->end, tmp_end)<0) *args->end = tmp_end;
1404 }
1405 }
6cd62ccf 1406}
1407
487ad181 1408void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end)
1409{
3aee1200 1410 LttTime min_start = ltt_time_infinite;
1411 LttTime max_end = ltt_time_zero;
1412 struct tracefile_time_span_get_args args = { t, &min_start, &max_end };
487ad181 1413
3aee1200 1414 g_datalist_foreach(&t->tracefiles, &group_time_span_get, &args);
1415
1416 if(start != NULL) *start = min_start;
1417 if(end != NULL) *end = max_end;
1418
487ad181 1419}
1420
1421
6cd62ccf 1422/*****************************************************************************
963b5f2d 1423 *Get the name of a tracefile
6cd62ccf 1424 ****************************************************************************/
1425
348c6ba8 1426GQuark ltt_tracefile_name(const LttTracefile *tf)
6cd62ccf 1427{
963b5f2d 1428 return tf->name;
6cd62ccf 1429}
1430
348c6ba8 1431GQuark ltt_tracefile_long_name(const LttTracefile *tf)
1432{
1433 return tf->long_name;
1434}
1435
1436
d3d34f49 1437
ae3d0f50 1438guint ltt_tracefile_cpu(LttTracefile *tf)
d3d34f49 1439{
1440 return tf->cpu_num;
1441}
1442
ae3d0f50 1443guint ltt_tracefile_tid(LttTracefile *tf)
1444{
1445 return tf->tid;
1446}
1447
1448guint ltt_tracefile_pgid(LttTracefile *tf)
1449{
1450 return tf->pgid;
1451}
1452
1453guint64 ltt_tracefile_creation(LttTracefile *tf)
1454{
1455 return tf->creation;
1456}
80da81ad 1457/*****************************************************************************
1458 * Get the number of blocks in the tracefile
1459 ****************************************************************************/
1460
3aee1200 1461guint ltt_tracefile_block_number(LttTracefile *tf)
80da81ad 1462{
3aee1200 1463 return tf->num_blocks;
80da81ad 1464}
1465
caf7a67a 1466
3aee1200 1467/* Seek to the first event in a tracefile that has a time equal or greater than
1468 * the time passed in parameter.
1469 *
1470 * If the time parameter is outside the tracefile time span, seek to the first
27304273 1471 * event or if after, return ERANGE.
3aee1200 1472 *
1473 * If the time parameter is before the first event, we have to seek specially to
1474 * there.
1475 *
27304273 1476 * If the time is after the end of the trace, return ERANGE.
3aee1200 1477 *
1478 * Do a binary search to find the right block, then a sequential search in the
1479 * block to find the event.
1480 *
1481 * In the special case where the time requested fits inside a block that has no
1482 * event corresponding to the requested time, the first event of the next block
1483 * will be seeked.
1484 *
1485 * IMPORTANT NOTE : // FIXME everywhere...
1486 *
1487 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1488 * you will jump over an event if you do.
1489 *
1490 * Return value : 0 : no error, the tf->event can be used
27304273 1491 * ERANGE : time if after the last event of the trace
3aee1200 1492 * otherwise : this is an error.
1493 *
1494 * */
1495
1496int ltt_tracefile_seek_time(LttTracefile *tf, LttTime time)
1497{
1498 int ret = 0;
1499 int err;
1500 unsigned int block_num, high, low;
1501
1502 /* seek at the beginning of trace */
1503 err = map_block(tf, 0); /* First block */
1504 if(unlikely(err)) {
1505 g_error("Can not map block");
1506 goto fail;
caf7a67a 1507 }
1508
3aee1200 1509 /* If the time is lower or equal the beginning of the trace,
1510 * go to the first event. */
1511 if(ltt_time_compare(time, tf->buffer.begin.timestamp) <= 0) {
1512 ret = ltt_tracefile_read(tf);
27304273 1513 if(ret == ERANGE) goto range;
1514 else if (ret) goto fail;
3aee1200 1515 goto found; /* There is either no event in the trace or the event points
1516 to the first event in the trace */
1517 }
caf7a67a 1518
3aee1200 1519 err = map_block(tf, tf->num_blocks - 1); /* Last block */
1520 if(unlikely(err)) {
1521 g_error("Can not map block");
1522 goto fail;
caf7a67a 1523 }
6cd62ccf 1524
27304273 1525 /* If the time is after the end of the trace, return ERANGE. */
1526 if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) {
1527 goto range;
3aee1200 1528 }
62e55dd6 1529
3aee1200 1530 /* Binary search the block */
1531 high = tf->num_blocks - 1;
1532 low = 0;
1533
1534 while(1) {
1535 block_num = ((high-low) / 2) + low;
1536
1537 err = map_block(tf, block_num);
1538 if(unlikely(err)) {
1539 g_error("Can not map block");
1540 goto fail;
db55eaae 1541 }
3aee1200 1542 if(high == low) {
1543 /* We cannot divide anymore : this is what would happen if the time
1544 * requested was exactly between two consecutive buffers'end and start
1545 * timestamps. This is also what would happend if we didn't deal with out
1546 * of span cases prior in this function. */
1547 /* The event is right in the buffer!
1548 * (or in the next buffer first event) */
1549 while(1) {
1550 ret = ltt_tracefile_read(tf);
27304273 1551 if(ret == ERANGE) goto range; /* ERANGE or EPERM */
3aee1200 1552 else if(ret) goto fail;
1553
d9e13a0f 1554 if(ltt_time_compare(time, tf->event.event_time) <= 0)
e45551ac 1555 goto found;
3aee1200 1556 }
1557
27304273 1558 } else if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) {
3aee1200 1559 /* go to lower part */
b1369bef 1560 high = block_num - 1;
3aee1200 1561 } else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) {
1562 /* go to higher part */
b1369bef 1563 low = block_num + 1;
3aee1200 1564 } else {/* The event is right in the buffer!
1565 (or in the next buffer first event) */
1566 while(1) {
27304273 1567 ret = ltt_tracefile_read(tf);
1568 if(ret == ERANGE) goto range; /* ERANGE or EPERM */
3aee1200 1569 else if(ret) goto fail;
1570
d9e13a0f 1571 if(ltt_time_compare(time, tf->event.event_time) <= 0)
3aee1200 1572 break;
6cd62ccf 1573 }
3aee1200 1574 goto found;
6cd62ccf 1575 }
6cd62ccf 1576 }
3aee1200 1577
1578found:
1579 return 0;
27304273 1580range:
1581 return ERANGE;
3aee1200 1582
1583 /* Error handling */
1584fail:
1585 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1586 g_quark_to_string(tf->name));
1587 return EPERM;
6cd62ccf 1588}
1589
80da81ad 1590
3aee1200 1591int ltt_tracefile_seek_position(LttTracefile *tf, const LttEventPosition *ep) {
80da81ad 1592
3aee1200 1593 int err;
1594
1595 if(ep->tracefile != tf) {
1596 goto fail;
80da81ad 1597 }
1598
3aee1200 1599 err = map_block(tf, ep->block);
1600 if(unlikely(err)) {
1601 g_error("Can not map block");
1602 goto fail;
1603 }
1604
1605 tf->event.offset = ep->offset;
18206708 1606
62e4e7bf 1607 /* Put back the event real tsc */
1608 tf->event.tsc = ep->tsc;
1609 tf->buffer.tsc = ep->tsc;
78f79181 1610
3aee1200 1611 err = ltt_tracefile_read_update_event(tf);
1612 if(err) goto fail;
1613 err = ltt_tracefile_read_op(tf);
1614 if(err) goto fail;
80da81ad 1615
a0c1f622 1616 return 0;
3aee1200 1617
1618fail:
1619 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1620 g_quark_to_string(tf->name));
a0c1f622 1621 return 1;
3aee1200 1622}
1623
ae3d0f50 1624LttTime ltt_interpolate_time_from_tsc(LttTracefile *tf, guint64 tsc)
3aee1200 1625{
1626 LttTime time;
62e4e7bf 1627
1628 if(tsc > tf->trace->start_tsc) {
1629 time = ltt_time_from_uint64(
1630 (double)(tsc - tf->trace->start_tsc)
1631 * (1000000000.0 / tf->trace->freq_scale)
1632 / (double)tf->trace->start_freq);
1633 time = ltt_time_add(tf->trace->start_time_from_tsc, time);
1634 } else {
1635 time = ltt_time_from_uint64(
1636 (double)(tf->trace->start_tsc - tsc)
1637 * (1000000000.0 / tf->trace->freq_scale)
1638 / (double)tf->trace->start_freq);
1639 time = ltt_time_sub(tf->trace->start_time_from_tsc, time);
1640 }
3aee1200 1641 return time;
80da81ad 1642}
1643
ae3d0f50 1644/* Calculate the real event time based on the buffer boundaries */
1645LttTime ltt_interpolate_time(LttTracefile *tf, LttEvent *event)
1646{
62e4e7bf 1647 return ltt_interpolate_time_from_tsc(tf, tf->buffer.tsc);
ae3d0f50 1648}
1649
eed2ef37 1650
1651/* Get the current event of the tracefile : valid until the next read */
1652LttEvent *ltt_tracefile_get_event(LttTracefile *tf)
1653{
1654 return &tf->event;
1655}
1656
1657
1658
6cd62ccf 1659/*****************************************************************************
1660 *Function name
3aee1200 1661 * ltt_tracefile_read : Read the next event in the tracefile
6cd62ccf 1662 *Input params
1663 * t : tracefile
1664 *Return value
3aee1200 1665 *
1666 * Returns 0 if an event can be used in tf->event.
d822520b 1667 * Returns ERANGE on end of trace. The event in tf->event still can be used
1668 * (if the last block was not empty).
3aee1200 1669 * Returns EPERM on error.
1670 *
1671 * This function does make the tracefile event structure point to the event
1672 * currently pointed to by the tf->event.
1673 *
1674 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1675 * reinitialize it after an error if you want results to be coherent.
1676 * It would be the case if a end of trace last buffer has no event : the end
1677 * of trace wouldn't be returned, but an error.
1678 * We make the assumption there is at least one event per buffer.
6cd62ccf 1679 ****************************************************************************/
1680
3aee1200 1681int ltt_tracefile_read(LttTracefile *tf)
6cd62ccf 1682{
963b5f2d 1683 int err;
6cd62ccf 1684
3aee1200 1685 err = ltt_tracefile_read_seek(tf);
1686 if(err) return err;
1687 err = ltt_tracefile_read_update_event(tf);
1688 if(err) return err;
1689 err = ltt_tracefile_read_op(tf);
1690 if(err) return err;
1691
1692 return 0;
1693}
1694
1695int ltt_tracefile_read_seek(LttTracefile *tf)
1696{
1697 int err;
1698
1699 /* Get next buffer until we finally have an event, or end of trace */
1700 while(1) {
1701 err = ltt_seek_next_event(tf);
1702 if(unlikely(err == ENOPROTOOPT)) {
1703 return EPERM;
bdc36259 1704 }
bdc36259 1705
3aee1200 1706 /* Are we at the end of the buffer ? */
1707 if(err == ERANGE) {
1708 if(unlikely(tf->buffer.index == tf->num_blocks-1)){ /* end of trace ? */
1709 return ERANGE;
1710 } else {
1711 /* get next block */
1712 err = map_block(tf, tf->buffer.index + 1);
1713 if(unlikely(err)) {
1714 g_error("Can not map block");
1715 return EPERM;
1716 }
1717 }
1718 } else break; /* We found an event ! */
1719 }
2dee981d 1720
3aee1200 1721 return 0;
1722}
18206708 1723
1724
3aee1200 1725/* do specific operation on events */
1726int ltt_tracefile_read_op(LttTracefile *tf)
1727{
3aee1200 1728 LttEvent *event;
1729
1730 event = &tf->event;
18206708 1731
3aee1200 1732 /* do event specific operation */
40331ba8 1733
3aee1200 1734 /* do something if its an heartbeat event : increment the heartbeat count */
1735 //if(event->facility_id == LTT_FACILITY_CORE)
1736 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1737 // tf->cur_heart_beat_number++;
1738
1739 return 0;
6cd62ccf 1740}
1741
6cd62ccf 1742
3aee1200 1743/* same as ltt_tracefile_read, but does not seek to the next event nor call
1744 * event specific operation. */
1745int ltt_tracefile_read_update_event(LttTracefile *tf)
6cd62ccf 1746{
3aee1200 1747 void * pos;
1748 LttEvent *event;
1749
1750 event = &tf->event;
eed2ef37 1751 pos = tf->buffer.head + event->offset;
3aee1200 1752
1753 /* Read event header */
1754
62e4e7bf 1755 /* Align the head */
1756 if(!tf->compact)
1757 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
1758 else {
1759 g_assert(tf->has_heartbeat);
1760 pos += ltt_align((size_t)pos, sizeof(uint32_t), tf->has_alignment);
1761 }
3aee1200 1762
62e4e7bf 1763 if(tf->has_heartbeat) {
1764 event->timestamp = ltt_get_uint32(LTT_GET_BO(tf),
1765 pos);
d1bb700c 1766 if(!tf->compact) {
1767 /* 32 bits -> 64 bits tsc */
1768 /* note : still works for seek and non seek cases. */
1769 if(event->timestamp < (0xFFFFFFFFULL&tf->buffer.tsc)) {
1770 tf->buffer.tsc = ((tf->buffer.tsc&0xFFFFFFFF00000000ULL)
1771 + 0x100000000ULL)
1772 | (guint64)event->timestamp;
1773 event->tsc = tf->buffer.tsc;
1774 } else {
1775 /* no overflow */
1776 tf->buffer.tsc = (tf->buffer.tsc&0xFFFFFFFF00000000ULL)
1777 | (guint64)event->timestamp;
1778 event->tsc = tf->buffer.tsc;
62e4e7bf 1779 event->compact_data = 0;
d1bb700c 1780 }
1781 } else {
1782 /* Compact header */
1783 /* We keep the LSB of the previous timestamp, to make sure
1784 * we never go back */
1785 event->event_id = event->timestamp >> tf->tscbits;
dd3a6d39 1786 event->event_id = event->event_id & ((1 << tf->trace->compact_event_bits) - 1);
1787 event->compact_data = event->timestamp >>
62e4e7bf 1788 (tf->trace->compact_event_bits + tf->tscbits);
dd3a6d39 1789 //printf("tsc bits %u, ev bits %u init data %u\n",
62e4e7bf 1790 // tf->tscbits, tf->trace->compact_event_bits, event->compact_data);
dd3a6d39 1791 /* Put the compact data back in original endianness */
1792 event->compact_data = ltt_get_uint32(LTT_GET_BO(tf), &event->compact_data);
d1bb700c 1793 event->event_size = 0xFFFF;
dd3a6d39 1794 //printf("Found compact event %d\n", event->event_id);
1795 //printf("Compact data %d\n", event->compact_data);
d1bb700c 1796 event->timestamp = event->timestamp << tf->tsc_lsb_truncate;
1797 event->timestamp = event->timestamp & tf->tsc_mask;
dd3a6d39 1798 //printf("timestamp 0x%lX\n", event->timestamp);
1799 //printf("mask 0x%llX\n", tf->tsc_mask);
1800 //printf("mask_next 0x%llX\n", tf->tsc_mask_next_bit);
1801 //printf("previous tsc 0x%llX\n", tf->buffer.tsc);
1802 //printf("previous tsc&mask 0x%llX\n", tf->tsc_mask&tf->buffer.tsc);
1803 //printf("previous tsc&(~mask) 0x%llX\n", tf->buffer.tsc&(~tf->tsc_mask));
d1bb700c 1804 if(event->timestamp < (tf->tsc_mask&tf->buffer.tsc)) {
dd3a6d39 1805 //printf("wrap\n");
d1bb700c 1806 tf->buffer.tsc = ((tf->buffer.tsc&(~tf->tsc_mask))
1807 + tf->tsc_mask_next_bit)
1808 | (guint64)event->timestamp;
1809 event->tsc = tf->buffer.tsc;
1810 } else {
dd3a6d39 1811 //printf("no wrap\n");
d1bb700c 1812 /* no overflow */
1813 tf->buffer.tsc = (tf->buffer.tsc&(~tf->tsc_mask))
1814 | (guint64)event->timestamp;
1815 event->tsc = tf->buffer.tsc;
1816 }
dd3a6d39 1817 //printf("current tsc 0x%llX\n", tf->buffer.tsc);
d1bb700c 1818 }
62e4e7bf 1819 pos += sizeof(guint32);
1820 } else {
1821 event->tsc = ltt_get_uint64(LTT_GET_BO(tf), pos);
1822 tf->buffer.tsc = event->tsc;
1823 event->compact_data = 0;
1824 pos += sizeof(guint64);
1825 }
1826 event->event_time = ltt_interpolate_time(tf, event);
3aee1200 1827
d1bb700c 1828 if(!tf->compact) {
3c165eaf 1829 event->event_id = *(guint16*)pos;
1830 pos += sizeof(guint16);
d1bb700c 1831
1832 event->event_size = ltt_get_uint16(LTT_GET_BO(tf), pos);
1833 pos += sizeof(guint16);
1834 } else {
1835 /* Compact event */
1836 }
62e4e7bf 1837 /* Align the head */
1838 if(!tf->compact)
1839 pos += ltt_align((size_t)pos, tf->trace->arch_size, tf->has_alignment);
f104d082 1840
3aee1200 1841 event->data = pos;
1842
77175651 1843 /* get the data size and update the event fields with the current
d1bb700c 1844 * information. Also update the time if a heartbeat_full event is found. */
eed2ef37 1845 ltt_update_event_size(tf);
77175651 1846
3aee1200 1847 return 0;
6cd62ccf 1848}
1849
507915ee 1850
6cd62ccf 1851/****************************************************************************
1852 *Function name
3aee1200 1853 * map_block : map a block from the file
6cd62ccf 1854 *Input Params
1855 * lttdes : ltt trace file
1856 * whichBlock : the block which will be read
1857 *return value
1858 * 0 : success
1859 * EINVAL : lseek fail
1860 * EIO : can not read from the file
1861 ****************************************************************************/
1862
3c165eaf 1863gint map_block(LttTracefile * tf, guint block_num)
6cd62ccf 1864{
b77d1b57 1865 int page_size = getpagesize();
3aee1200 1866 struct ltt_block_start_header *header;
1867
1868 g_assert(block_num < tf->num_blocks);
6cd62ccf 1869
f628823c 1870 if(tf->buffer.head != NULL) {
1871 if(munmap(tf->buffer.head, PAGE_ALIGN(tf->buf_size))) {
1872 g_warning("unmap size : %u\n",
1873 PAGE_ALIGN(tf->buf_size));
1874 perror("munmap error");
1875 g_assert(0);
1876 }
1877 }
1878
ac849774 1879
3aee1200 1880 /* Multiple of pages aligned head */
b77d1b57 1881 tf->buffer.head = mmap(0,
f628823c 1882 PAGE_ALIGN(tf->buf_size),
b77d1b57 1883 PROT_READ, MAP_PRIVATE, tf->fd,
f628823c 1884 PAGE_ALIGN((off_t)tf->buf_size * (off_t)block_num));
3aee1200 1885
3865ea09 1886 if(tf->buffer.head == MAP_FAILED) {
3aee1200 1887 perror("Error in allocating memory for buffer of tracefile");
3865ea09 1888 g_assert(0);
3aee1200 1889 goto map_error;
6cd62ccf 1890 }
3865ea09 1891 g_assert( ( (guint)tf->buffer.head&(8-1) ) == 0); // make sure it's aligned.
3aee1200 1892
6cd62ccf 1893
3aee1200 1894 tf->buffer.index = block_num;
1895
1896 header = (struct ltt_block_start_header*)tf->buffer.head;
1897
791dffa6 1898#if 0
986e2a7c 1899 tf->buffer.begin.timestamp = ltt_time_add(
1900 ltt_time_from_uint64(
1901 ltt_get_uint64(LTT_GET_BO(tf),
1902 &header->begin.timestamp)
1903 - tf->trace->start_monotonic),
1904 tf->trace->start_time);
791dffa6 1905#endif //0
348c6ba8 1906 //g_debug("block %u begin : %lu.%lu", block_num,
1907 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
3aee1200 1908 tf->buffer.begin.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
1909 &header->begin.cycle_count);
986e2a7c 1910 tf->buffer.begin.freq = ltt_get_uint64(LTT_GET_BO(tf),
1911 &header->begin.freq);
62e4e7bf 1912 if(tf->buffer.begin.freq == 0)
1913 tf->buffer.begin.freq = tf->trace->start_freq;
ae3d0f50 1914
1915 tf->buffer.begin.timestamp = ltt_interpolate_time_from_tsc(tf,
62e4e7bf 1916 tf->buffer.begin.cycle_count);
ae3d0f50 1917#if 0
62e4e7bf 1918 ltt_time_add(
791dffa6 1919 ltt_time_from_uint64(
88612d17 1920 (double)(tf->buffer.begin.cycle_count
1921 - tf->trace->start_tsc) * 1000000.0
791dffa6 1922 / (double)tf->trace->start_freq),
62e4e7bf 1923 tf->trace->start_time_from_tsc);
ae3d0f50 1924#endif //0
791dffa6 1925#if 0
1926
986e2a7c 1927 tf->buffer.end.timestamp = ltt_time_add(
1928 ltt_time_from_uint64(
1929 ltt_get_uint64(LTT_GET_BO(tf),
1930 &header->end.timestamp)
1931 - tf->trace->start_monotonic),
1932 tf->trace->start_time);
791dffa6 1933#endif //0
348c6ba8 1934 //g_debug("block %u end : %lu.%lu", block_num,
1935 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
3aee1200 1936 tf->buffer.end.cycle_count = ltt_get_uint64(LTT_GET_BO(tf),
1937 &header->end.cycle_count);
986e2a7c 1938 tf->buffer.end.freq = ltt_get_uint64(LTT_GET_BO(tf),
1939 &header->end.freq);
62e4e7bf 1940 if(tf->buffer.end.freq == 0)
1941 tf->buffer.end.freq = tf->trace->start_freq;
1942
3aee1200 1943 tf->buffer.lost_size = ltt_get_uint32(LTT_GET_BO(tf),
986e2a7c 1944 &header->lost_size);
ae3d0f50 1945 tf->buffer.end.timestamp = ltt_interpolate_time_from_tsc(tf,
62e4e7bf 1946 tf->buffer.end.cycle_count);
ae3d0f50 1947#if 0
62e4e7bf 1948 ltt_time_add(
791dffa6 1949 ltt_time_from_uint64(
88612d17 1950 (double)(tf->buffer.end.cycle_count
1951 - tf->trace->start_tsc) * 1000000.0
791dffa6 1952 / (double)tf->trace->start_freq),
88612d17 1953 tf->trace->start_time_from_tsc);
ae3d0f50 1954#endif //0
3aee1200 1955 tf->buffer.tsc = tf->buffer.begin.cycle_count;
1956 tf->event.tsc = tf->buffer.tsc;
986e2a7c 1957 tf->buffer.freq = tf->buffer.begin.freq;
3aee1200 1958
1959 /* FIXME
1960 * eventually support variable buffer size : will need a partial pre-read of
1961 * the headers to create an index when we open the trace... eventually. */
f628823c 1962 g_assert(tf->buf_size == ltt_get_uint32(LTT_GET_BO(tf),
3aee1200 1963 &header->buf_size));
507915ee 1964
3aee1200 1965 /* Now that the buffer is mapped, calculate the time interpolation for the
1966 * block. */
1967
791dffa6 1968// tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1969 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
3aee1200 1970
1971 /* Make the current event point to the beginning of the buffer :
1972 * it means that the event read must get the first event. */
1973 tf->event.tracefile = tf;
1974 tf->event.block = block_num;
eed2ef37 1975 tf->event.offset = 0;
3aee1200 1976
1977 return 0;
6cd62ccf 1978
3aee1200 1979map_error:
1980 return -errno;
40331ba8 1981
6cd62ccf 1982}
1983
77175651 1984/* It will update the fields offsets too */
1985void ltt_update_event_size(LttTracefile *tf)
6cd62ccf 1986{
2312de30 1987 off_t size = 0;
d1bb700c 1988 char *tscdata;
d2007fbd 1989 struct marker_info *info;
44f317b7 1990
d2007fbd 1991 switch((enum marker_id)tf->event.event_id) {
1992 case MARKER_ID_SET_MARKER_ID:
44f317b7 1993 size = strlen((char*)tf->event.data) + 1;
d2007fbd 1994 //g_debug("marker %s id set", (char*)tf->event.data);
1995 size += ltt_align(size, sizeof(guint16), tf->has_alignment);
1996 size += sizeof(guint16);
3c165eaf 1997 size += sizeof(guint8);
1998 size += sizeof(guint8);
1999 size += sizeof(guint8);
2000 size += sizeof(guint8);
2001 size += sizeof(guint8);
44f317b7 2002 break;
d2007fbd 2003 case MARKER_ID_SET_MARKER_FORMAT:
2004 //g_debug("marker %s format set", (char*)tf->event.data);
44f317b7 2005 size = strlen((char*)tf->event.data) + 1;
2e13d6af 2006 size += strlen((char*)tf->event.data + size) + 1;
44f317b7 2007 break;
d2007fbd 2008 case MARKER_ID_HEARTBEAT_32:
2009 //g_debug("Update Event heartbeat 32 bits");
44f317b7 2010 break;
d2007fbd 2011 case MARKER_ID_HEARTBEAT_64:
2012 //g_debug("Update Event heartbeat 64 bits");
d1bb700c 2013 tscdata = (char*)(tf->event.data);
2014 tf->event.tsc = ltt_get_uint64(LTT_GET_BO(tf), tscdata);
2015 tf->buffer.tsc = tf->event.tsc;
2016 tf->event.event_time = ltt_interpolate_time(tf, &tf->event);
d2007fbd 2017 size = ltt_align(size, sizeof(guint64), tf->has_alignment);
2018 size += sizeof(guint64);
d1bb700c 2019 break;
44f317b7 2020 default:
d2007fbd 2021 info = marker_get_info_from_id(tf->trace, tf->event.event_id);
2022 g_assert(info != NULL);
3c165eaf 2023 if (info->size != -1) {
d2007fbd 2024 size = info->size;
2025 } else {
3c165eaf 2026 size = marker_update_fields_offsets(marker_get_info_from_id(tf->trace,
2027 tf->event.event_id), tf->event.data);
44f317b7 2028 }
44f317b7 2029 }
c4afd5d8 2030
d2007fbd 2031 tf->event.data_size = size;
2032
2033 /* Check consistency between kernel and LTTV structure sizes */
2034 if(tf->event.event_size == 0xFFFF) {
2035 /* Event size too big to fit in the event size field */
2036 tf->event.event_size = tf->event.data_size;
2037 }
2038 if (tf->event.data_size != tf->event.event_size) {
3c165eaf 2039 struct marker_info *info = marker_get_info_from_id(tf->trace,
2040 tf->event.event_id);
2041 g_error("Kernel/LTTV event size differs for event %s: kernel %u, LTTV %u",
2042 g_quark_to_string(info->name),
2043 tf->event.event_size, tf->event.data_size);
d2007fbd 2044 exit(-1);
2045 }
2046
2047#if 0
44f317b7 2048 LttEventType *event_type =
2049 ltt_facility_eventtype_get(f, tf->event.event_id);
c4afd5d8 2050
44f317b7 2051 if(!event_type) {
2052 g_warning("Unknown event id %hhu in facility %s in tracefile %s",
2053 tf->event.event_id,
2054 g_quark_to_string(f->name),
2055 g_quark_to_string(tf->name));
2056 goto event_type_error;
3aee1200 2057 }
3aee1200 2058
44f317b7 2059 /* Compute the dynamic offsets */
2060 compute_offsets(tf, f, event_type, &size, tf->event.data);
2061
2062 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
2063 // tf->event.facility_id,
2064 // tf->event.event_id, size);
7cbcdb89 2065
2066no_offset:
77175651 2067 tf->event.data_size = size;
eed2ef37 2068
b77d1b57 2069 /* Check consistency between kernel and LTTV structure sizes */
62e4e7bf 2070 if(tf->event.event_size == 0xFFFF) {
2071 /* Event size too big to fit in the event size field */
2072 tf->event.event_size = tf->event.data_size;
2073 }
f63ebe51 2074 if (tf->event.data_size != tf->event.event_size) {
2075 g_error("Kernel/LTTV event size differs for event %s.%s: kernel %u, LTTV %u",
62e4e7bf 2076 g_quark_to_string(f->name), g_quark_to_string(event_type->name),
2077 tf->event.event_size, tf->event.data_size);
f63ebe51 2078 exit(-1);
2079 }
2080 //g_assert(tf->event.data_size == tf->event.event_size);
9eb6aa7a 2081
eed2ef37 2082 return;
2083
c4afd5d8 2084event_type_error:
3aee1200 2085event_id_error:
62e4e7bf 2086 if(tf->event.event_size == 0xFFFF) {
2087 g_error("Cannot jump over an unknown event bigger than 0xFFFE bytes");
2088 }
2089 /* The facility is unknown : use the kernel information about this event
2090 * to jump over it. */
9d7e0c25 2091 tf->event.data_size = tf->event.event_size;
d2007fbd 2092#endif //0
6cd62ccf 2093}
2094
6cd62ccf 2095
3aee1200 2096/* Take the tf current event offset and use the event facility id and event id
2097 * to figure out where is the next event offset.
2098 *
2099 * This is an internal function not aiming at being used elsewhere : it will
2100 * not jump over the current block limits. Please consider using
2101 * ltt_tracefile_read to do this.
2102 *
2103 * Returns 0 on success
2104 * ERANGE if we are at the end of the buffer.
2105 * ENOPROTOOPT if an error occured when getting the current event size.
2106 */
3c165eaf 2107int ltt_seek_next_event(LttTracefile *tf)
6cd62ccf 2108{
3aee1200 2109 int ret = 0;
2110 void *pos;
3aee1200 2111
2112 /* seek over the buffer header if we are at the buffer start */
eed2ef37 2113 if(tf->event.offset == 0) {
51551c6f 2114 tf->event.offset += tf->buffer_header_size;
b77d1b57 2115
f628823c 2116 if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) {
b77d1b57 2117 ret = ERANGE;
2118 }
3aee1200 2119 goto found;
2120 }
6cd62ccf 2121
6cd62ccf 2122
3aee1200 2123 pos = tf->event.data;
2124
77175651 2125 if(tf->event.data_size < 0) goto error;
3aee1200 2126
77175651 2127 pos += (size_t)tf->event.data_size;
3aee1200 2128
eed2ef37 2129 tf->event.offset = pos - tf->buffer.head;
cb03932a 2130
f628823c 2131 if(tf->event.offset == tf->buf_size - tf->buffer.lost_size) {
cb03932a 2132 ret = ERANGE;
2133 goto found;
2134 }
36d36c9f 2135 g_assert(tf->event.offset < tf->buf_size - tf->buffer.lost_size);
3aee1200 2136
2137found:
2138 return ret;
2139
2140error:
2141 g_error("Error in ltt_seek_next_event for tracefile %s",
2142 g_quark_to_string(tf->name));
2143 return ENOPROTOOPT;
6cd62ccf 2144}
2145
791dffa6 2146#if 0
6cd62ccf 2147/*****************************************************************************
2148 *Function name
3aee1200 2149 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
986e2a7c 2150 *
2151 * 1.0 / (freq(khz) *1000) * 1000000000
6cd62ccf 2152 *Input Params
2153 * t : tracefile
2154 ****************************************************************************/
986e2a7c 2155/* from timer_tsc.c */
2156#define CYC2NS_SCALE_FACTOR 10
791dffa6 2157static guint32 calc_nsecs_per_cycle(LttTracefile * tf)
6cd62ccf 2158{
986e2a7c 2159 //return 1e6 / (double)tf->buffer.freq;
791dffa6 2160 guint32 cpu_mhz = tf->buffer.freq / 1000;
2161 guint32 cyc2ns_scale = (1000 << CYC2NS_SCALE_FACTOR)/cpu_mhz;
6cd62ccf 2162
791dffa6 2163 return cyc2ns_scale;
986e2a7c 2164 // return 1e6 / (double)tf->buffer.freq;
3aee1200 2165}
791dffa6 2166
2167static guint64 cycles_2_ns(LttTracefile *tf, guint64 cycles)
2168{
2169 return (cycles * tf->buffer.cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
2170}
2171#endif //0
2172
3aee1200 2173#if 0
2174void setFieldsOffset(LttTracefile *tf, LttEventType *evT,void *evD)
2175{
2176 LttField * rootFld = evT->root_field;
2177 // rootFld->base_address = evD;
2dee981d 2178
3aee1200 2179 if(likely(rootFld))
2180 rootFld->field_size = getFieldtypeSize(tf, evT->facility,
2181 evT, 0,0,rootFld, evD);
6cd62ccf 2182}
3aee1200 2183#endif //0
f104d082 2184#if 0
3aee1200 2185/*****************************************************************************
6cd62ccf 2186 *Function name
3aee1200 2187 * set_fields_offsets : set the precomputable offset of the fields
6cd62ccf 2188 *Input params
3aee1200 2189 * tracefile : opened trace file
2190 * event_type : the event type
6cd62ccf 2191 ****************************************************************************/
2192
3aee1200 2193void set_fields_offsets(LttTracefile *tf, LttEventType *event_type)
6cd62ccf 2194{
3aee1200 2195 LttField *field = event_type->root_field;
2196 enum field_status fixed_root = FIELD_FIXED, fixed_parent = FIELD_FIXED;
2197
2198 if(likely(field))
2199 preset_field_type_size(tf, event_type, 0, 0,
2200 &fixed_root, &fixed_parent,
2201 field);
2202
2203}
f104d082 2204#endif //0
2205
2206
2207/*****************************************************************************
2208 *Function name
2209 * get_alignment : Get the alignment needed for a field.
2210 *Input params
f104d082 2211 * field : field
2212 *
2213 * returns : The size on which it must be aligned.
2214 *
2215 ****************************************************************************/
3c165eaf 2216#if 0
743e50fd 2217off_t get_alignment(LttField *field)
f104d082 2218{
2312de30 2219 LttType *type = &field->field_type;
f104d082 2220
2221 switch(type->type_class) {
2222 case LTT_INT_FIXED:
2223 case LTT_UINT_FIXED:
2224 case LTT_POINTER:
2225 case LTT_CHAR:
2226 case LTT_UCHAR:
2227 case LTT_SHORT:
2228 case LTT_USHORT:
2229 case LTT_INT:
2230 case LTT_UINT:
2231 case LTT_LONG:
2232 case LTT_ULONG:
2233 case LTT_SIZE_T:
2234 case LTT_SSIZE_T:
2235 case LTT_OFF_T:
2236 case LTT_FLOAT:
2237 case LTT_ENUM:
2238 /* Align offset on type size */
83e160f2 2239 g_assert(field->field_size != 0);
f104d082 2240 return field->field_size;
2241 break;
2242 case LTT_STRING:
83e160f2 2243 return 1;
f104d082 2244 break;
2245 case LTT_ARRAY:
2246 g_assert(type->fields->len == 1);
2247 {
2248 LttField *child = &g_array_index(type->fields, LttField, 0);
743e50fd 2249 return get_alignment(child);
f104d082 2250 }
2251 break;
2252 case LTT_SEQUENCE:
2253 g_assert(type->fields->len == 2);
2254 {
83e160f2 2255 off_t localign = 1;
f104d082 2256 LttField *child = &g_array_index(type->fields, LttField, 0);
2257
743e50fd 2258 localign = max(localign, get_alignment(child));
f104d082 2259
2260 child = &g_array_index(type->fields, LttField, 1);
743e50fd 2261 localign = max(localign, get_alignment(child));
f104d082 2262
2263 return localign;
2264 }
2265 break;
2266 case LTT_STRUCT:
2267 case LTT_UNION:
2268 {
2269 guint i;
83e160f2 2270 off_t localign = 1;
f104d082 2271
2272 for(i=0; i<type->fields->len; i++) {
2273 LttField *child = &g_array_index(type->fields, LttField, i);
743e50fd 2274 localign = max(localign, get_alignment(child));
f104d082 2275 }
2276 return localign;
2277 }
2278 break;
2279 case LTT_NONE:
2280 default:
2281 g_error("get_alignment : unknown type");
83e160f2 2282 return -1;
f104d082 2283 }
f104d082 2284}
2285
3c165eaf 2286#endif //0
2287
f104d082 2288/*****************************************************************************
2289 *Function name
2290 * field_compute_static_size : Determine the size of fields known by their
2291 * sole definition. Unions, arrays and struct sizes might be known, but
2292 * the parser does not give that information.
2293 *Input params
2294 * tf : tracefile
2295 * field : field
2296 *
2297 ****************************************************************************/
3c165eaf 2298#if 0
743e50fd 2299void field_compute_static_size(LttFacility *fac, LttField *field)
f104d082 2300{
2312de30 2301 LttType *type = &field->field_type;
f104d082 2302
2303 switch(type->type_class) {
2304 case LTT_INT_FIXED:
2305 case LTT_UINT_FIXED:
2306 case LTT_POINTER:
2307 case LTT_CHAR:
2308 case LTT_UCHAR:
2309 case LTT_SHORT:
2310 case LTT_USHORT:
2311 case LTT_INT:
2312 case LTT_UINT:
2313 case LTT_LONG:
2314 case LTT_ULONG:
2315 case LTT_SIZE_T:
2316 case LTT_SSIZE_T:
2317 case LTT_OFF_T:
2318 case LTT_FLOAT:
2319 case LTT_ENUM:
2320 case LTT_STRING:
2321 /* nothing to do */
2322 break;
2323 case LTT_ARRAY:
2324 /* note this : array type size is the number of elements in the array,
2325 * while array field size of the length of the array in bytes */
2326 g_assert(type->fields->len == 1);
2327 {
2328 LttField *child = &g_array_index(type->fields, LttField, 0);
743e50fd 2329 field_compute_static_size(fac, child);
f104d082 2330
2331 if(child->field_size != 0) {
2332 field->field_size = type->size * child->field_size;
2333 field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
2334 sizeof(off_t), type->size);
2335 } else {
2336 field->field_size = 0;
2337 }
2338 }
2339 break;
2340 case LTT_SEQUENCE:
2341 g_assert(type->fields->len == 2);
2342 {
2312de30 2343 off_t local_offset = 0;
f104d082 2344 LttField *child = &g_array_index(type->fields, LttField, 1);
743e50fd 2345 field_compute_static_size(fac, child);
f104d082 2346 field->field_size = 0;
2347 type->size = 0;
2348 if(child->field_size != 0) {
2349 field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
2350 sizeof(off_t), SEQUENCE_AVG_ELEMENTS);
2351 }
2352 }
2353 break;
2354 case LTT_STRUCT:
2355 case LTT_UNION:
2356 {
2357 guint i;
2358 for(i=0;i<type->fields->len;i++) {
2359 LttField *child = &g_array_index(type->fields, LttField, i);
743e50fd 2360 field_compute_static_size(fac, child);
f104d082 2361 if(child->field_size != 0) {
743e50fd 2362 type->size += ltt_align(type->size, get_alignment(child),
2363 fac->alignment);
f104d082 2364 type->size += child->field_size;
2365 } else {
2366 /* As soon as we find a child with variable size, we have
2367 * a variable size */
2368 type->size = 0;
2369 break;
2370 }
2371 }
2372 field->field_size = type->size;
2373 }
2374 break;
2375 default:
2376 g_error("field_static_size : unknown type");
2312de30 2377 }
f104d082 2378
2379}
3c165eaf 2380#endif //0
f104d082 2381
2382
2383/*****************************************************************************
2384 *Function name
2385 * precompute_fields_offsets : set the precomputable offset of the fields
2386 *Input params
743e50fd 2387 * fac : facility
f104d082 2388 * field : the field
2389 * offset : pointer to the current offset, must be incremented
2390 *
2391 * return : 1 : found a variable length field, stop the processing.
2392 * 0 otherwise.
2393 ****************************************************************************/
2394
3c165eaf 2395#if 0
dd3a6d39 2396gint precompute_fields_offsets(LttFacility *fac, LttField *field, off_t *offset, gint is_compact)
f104d082 2397{
2312de30 2398 LttType *type = &field->field_type;
dd3a6d39 2399
2400 if(unlikely(is_compact)) {
2401 g_assert(field->field_size != 0);
2402 /* FIXME THIS IS A HUUUUUGE hack :
2403 * offset is between the compact_data field in struct LttEvent
2404 * and the address of the field root in the memory map.
2405 * ark. Both will stay at the same addresses while the event
2406 * is readable, so it's ok.
2407 */
2408 field->offset_root = 0;
2409 field->fixed_root = FIELD_FIXED;
2410 return 0;
2411 }
f104d082 2412
2413 switch(type->type_class) {
2414 case LTT_INT_FIXED:
2415 case LTT_UINT_FIXED:
2416 case LTT_POINTER:
2417 case LTT_CHAR:
2418 case LTT_UCHAR:
2419 case LTT_SHORT:
2420 case LTT_USHORT:
2421 case LTT_INT:
2422 case LTT_UINT:
2423 case LTT_LONG:
2424 case LTT_ULONG:
2425 case LTT_SIZE_T:
2426 case LTT_SSIZE_T:
2427 case LTT_OFF_T:
2428 case LTT_FLOAT:
2429 case LTT_ENUM:
743e50fd 2430 g_assert(field->field_size != 0);
f104d082 2431 /* Align offset on type size */
743e50fd 2432 *offset += ltt_align(*offset, get_alignment(field),
2433 fac->alignment);
f104d082 2434 /* remember offset */
2435 field->offset_root = *offset;
2436 field->fixed_root = FIELD_FIXED;
2437 /* Increment offset */
2438 *offset += field->field_size;
2439 return 0;
2440 break;
2441 case LTT_STRING:
2442 field->offset_root = *offset;
2443 field->fixed_root = FIELD_FIXED;
2444 return 1;
2445 break;
2446 case LTT_ARRAY:
2447 g_assert(type->fields->len == 1);
2448 {
2449 LttField *child = &g_array_index(type->fields, LttField, 0);
2450
743e50fd 2451 *offset += ltt_align(*offset, get_alignment(field),
2452 fac->alignment);
f104d082 2453
2454 /* remember offset */
2455 field->offset_root = *offset;
2456 field->array_offset = *offset;
2457 field->fixed_root = FIELD_FIXED;
2458
2459 /* Let the child be variable */
2460 //precompute_fields_offsets(tf, child, offset);
2461
2462 if(field->field_size != 0) {
2463 /* Increment offset */
2464 /* field_size is the array size in bytes */
2465 *offset += field->field_size;
2466 return 0;
2467 } else {
2468 return 1;
2469 }
2470 }
2471 break;
2472 case LTT_SEQUENCE:
2473 g_assert(type->fields->len == 2);
2474 {
2475 LttField *child;
2476 guint ret;
2477
743e50fd 2478 *offset += ltt_align(*offset, get_alignment(field),
2479 fac->alignment);
f104d082 2480
2481 /* remember offset */
2482 field->offset_root = *offset;
2483 field->fixed_root = FIELD_FIXED;
2484
2485 child = &g_array_index(type->fields, LttField, 0);
dd3a6d39 2486 ret = precompute_fields_offsets(fac, child, offset, is_compact);
f104d082 2487 g_assert(ret == 0); /* Seq len cannot have variable len */
2488
2489 child = &g_array_index(type->fields, LttField, 1);
743e50fd 2490 *offset += ltt_align(*offset, get_alignment(child),
2491 fac->alignment);
f104d082 2492 field->array_offset = *offset;
743e50fd 2493 /* Let the child be variable. */
2494 //ret = precompute_fields_offsets(fac, child, offset);
f104d082 2495
2496 /* Cannot precompute fields offsets of sequence members, and has
2497 * variable length. */
2498 return 1;
2499 }
2500 break;
2501 case LTT_STRUCT:
2502 {
2503 LttField *child;
2504 guint i;
2505 gint ret=0;
2506
743e50fd 2507 *offset += ltt_align(*offset, get_alignment(field),
2508 fac->alignment);
f104d082 2509 /* remember offset */
2510 field->offset_root = *offset;
2511 field->fixed_root = FIELD_FIXED;
2512
2513 for(i=0; i< type->fields->len; i++) {
2514 child = &g_array_index(type->fields, LttField, i);
dd3a6d39 2515 ret = precompute_fields_offsets(fac, child, offset, is_compact);
f104d082 2516
2517 if(ret) break;
2518 }
2519 return ret;
2520 }
2521 break;
2522 case LTT_UNION:
2523 {
2524 LttField *child;
2525 guint i;
2526 gint ret=0;
2527
743e50fd 2528 *offset += ltt_align(*offset, get_alignment(field),
2529 fac->alignment);
f104d082 2530 /* remember offset */
2531 field->offset_root = *offset;
2532 field->fixed_root = FIELD_FIXED;
2533
2534 for(i=0; i< type->fields->len; i++) {
2535 *offset = field->offset_root;
2536 child = &g_array_index(type->fields, LttField, i);
dd3a6d39 2537 ret = precompute_fields_offsets(fac, child, offset, is_compact);
f104d082 2538
2539 if(ret) break;
2540 }
2541 *offset = field->offset_root + field->field_size;
2542 return ret;
2543 }
2544
2545 break;
2546 case LTT_NONE:
2547 default:
2548 g_error("precompute_fields_offsets : unknown type");
2549 return 1;
2550 }
2551
2552}
2553
3c165eaf 2554#endif //0
f104d082 2555
3c165eaf 2556#if 0
f104d082 2557/*****************************************************************************
2558 *Function name
2559 * precompute_offsets : set the precomputable offset of an event type
2560 *Input params
2561 * tf : tracefile
2562 * event : event type
2563 *
2564 ****************************************************************************/
743e50fd 2565void precompute_offsets(LttFacility *fac, LttEventType *event)
f104d082 2566{
2567 guint i;
2568 off_t offset = 0;
2569 gint ret;
2570
2571 /* First, compute the size of fixed size fields. Will determine size for
2572 * arrays, struct and unions, which is not done by the parser */
2573 for(i=0; i<event->fields->len; i++) {
2574 LttField *field = &g_array_index(event->fields, LttField, i);
743e50fd 2575 field_compute_static_size(fac, field);
f104d082 2576 }
2577
2578 /* Precompute all known offsets */
2579 for(i=0; i<event->fields->len; i++) {
2580 LttField *field = &g_array_index(event->fields, LttField, i);
dd3a6d39 2581 if(event->has_compact_data && i == 0)
2582 ret = precompute_fields_offsets(fac, field, &offset, 1);
2583 else
2584 ret = precompute_fields_offsets(fac, field, &offset, 0);
f104d082 2585 if(ret) break;
2586 }
2587}
3c165eaf 2588#endif //0
f104d082 2589
e4eced0f 2590
bbf28e50 2591
3aee1200 2592/*****************************************************************************
2593 *Function name
2594 * preset_field_type_size : set the fixed sizes of the field type
2595 *Input params
2596 * tf : tracefile
2597 * event_type : event type
2598 * offset_root : offset from the root
2599 * offset_parent : offset from the parent
2600 * fixed_root : Do we know a fixed offset to the root ?
2601 * fixed_parent : Do we know a fixed offset to the parent ?
2602 * field : field
2603 ****************************************************************************/
f104d082 2604
2605
2606
2607// preset the fixed size offsets. Calculate them just like genevent-new : an
2608// increment of a *to value that represents the offset from the start of the
2609// event data.
2610// The preset information is : offsets up to (and including) the first element
2611// of variable size. All subsequent fields must be flagged "VARIABLE OFFSET".
2612#if 0
3aee1200 2613void preset_field_type_size(LttTracefile *tf, LttEventType *event_type,
2614 off_t offset_root, off_t offset_parent,
2615 enum field_status *fixed_root, enum field_status *fixed_parent,
2616 LttField *field)
2617{
2618 enum field_status local_fixed_root, local_fixed_parent;
2619 guint i;
2620 LttType *type;
dfb73233 2621
3aee1200 2622 g_assert(field->fixed_root == FIELD_UNKNOWN);
2623 g_assert(field->fixed_parent == FIELD_UNKNOWN);
2624 g_assert(field->fixed_size == FIELD_UNKNOWN);
dfb73233 2625
3aee1200 2626 type = field->field_type;
2627
2628 field->fixed_root = *fixed_root;
2629 if(field->fixed_root == FIELD_FIXED)
2630 field->offset_root = offset_root;
2631 else
2632 field->offset_root = 0;
2633
2634 field->fixed_parent = *fixed_parent;
2635 if(field->fixed_parent == FIELD_FIXED)
2636 field->offset_parent = offset_parent;
2637 else
2638 field->offset_parent = 0;
2639
2640 size_t current_root_offset;
2641 size_t current_offset;
2642 enum field_status current_child_status, final_child_status;
2643 size_t max_size;
2644
2645 switch(type->type_class) {
83e160f2 2646 case LTT_INT_FIXED:
2647 case LTT_UINT_FIXED:
2648 case LTT_CHAR:
2649 case LTT_UCHAR:
2650 case LTT_SHORT:
2651 case LTT_USHORT:
3aee1200 2652 case LTT_INT:
2653 case LTT_UINT:
2654 case LTT_FLOAT:
2655 case LTT_ENUM:
2656 field->field_size = ltt_type_size(tf->trace, type);
2657 field->fixed_size = FIELD_FIXED;
2658 break;
2659 case LTT_POINTER:
2660 field->field_size = (off_t)event_type->facility->pointer_size;
2661 field->fixed_size = FIELD_FIXED;
2662 break;
2663 case LTT_LONG:
2664 case LTT_ULONG:
cb03932a 2665 field->field_size = (off_t)event_type->facility->long_size;
3aee1200 2666 field->fixed_size = FIELD_FIXED;
2667 break;
2668 case LTT_SIZE_T:
2669 case LTT_SSIZE_T:
2670 case LTT_OFF_T:
2671 field->field_size = (off_t)event_type->facility->size_t_size;
2672 field->fixed_size = FIELD_FIXED;
2673 break;
2674 case LTT_SEQUENCE:
2675 local_fixed_root = FIELD_VARIABLE;
2676 local_fixed_parent = FIELD_VARIABLE;
2677 preset_field_type_size(tf, event_type,
2678 0, 0,
2679 &local_fixed_root, &local_fixed_parent,
2680 field->child[0]);
2681 field->fixed_size = FIELD_VARIABLE;
2682 field->field_size = 0;
27304273 2683 *fixed_root = FIELD_VARIABLE;
2684 *fixed_parent = FIELD_VARIABLE;
3aee1200 2685 break;
2686 case LTT_STRING:
2687 field->fixed_size = FIELD_VARIABLE;
2688 field->field_size = 0;
27304273 2689 *fixed_root = FIELD_VARIABLE;
2690 *fixed_parent = FIELD_VARIABLE;
3aee1200 2691 break;
2692 case LTT_ARRAY:
2693 local_fixed_root = FIELD_VARIABLE;
2694 local_fixed_parent = FIELD_VARIABLE;
2695 preset_field_type_size(tf, event_type,
2696 0, 0,
2697 &local_fixed_root, &local_fixed_parent,
2698 field->child[0]);
2699 field->fixed_size = field->child[0]->fixed_size;
27304273 2700 if(field->fixed_size == FIELD_FIXED) {
3aee1200 2701 field->field_size = type->element_number * field->child[0]->field_size;
27304273 2702 } else {
3aee1200 2703 field->field_size = 0;
27304273 2704 *fixed_root = FIELD_VARIABLE;
2705 *fixed_parent = FIELD_VARIABLE;
2706 }
3aee1200 2707 break;
2708 case LTT_STRUCT:
2709 current_root_offset = field->offset_root;
2710 current_offset = 0;
2711 current_child_status = FIELD_FIXED;
2712 for(i=0;i<type->element_number;i++) {
2713 preset_field_type_size(tf, event_type,
2714 current_root_offset, current_offset,
2715 fixed_root, &current_child_status,
2716 field->child[i]);
2717 if(current_child_status == FIELD_FIXED) {
2718 current_root_offset += field->child[i]->field_size;
2719 current_offset += field->child[i]->field_size;
2720 } else {
2721 current_root_offset = 0;
2722 current_offset = 0;
2723 }
2724 }
2725 if(current_child_status != FIELD_FIXED) {
2726 *fixed_parent = current_child_status;
2727 field->field_size = 0;
2728 field->fixed_size = current_child_status;
2729 } else {
2730 field->field_size = current_offset;
2731 field->fixed_size = FIELD_FIXED;
2732 }
2733 break;
2734 case LTT_UNION:
2735 current_root_offset = field->offset_root;
2736 current_offset = 0;
2737 max_size = 0;
2738 final_child_status = FIELD_FIXED;
2739 for(i=0;i<type->element_number;i++) {
2740 enum field_status current_root_child_status = FIELD_FIXED;
2741 enum field_status current_child_status = FIELD_FIXED;
2742 preset_field_type_size(tf, event_type,
2743 current_root_offset, current_offset,
2744 &current_root_child_status, &current_child_status,
2745 field->child[i]);
2746 if(current_child_status != FIELD_FIXED)
2747 final_child_status = current_child_status;
2748 else
2749 max_size = max(max_size, field->child[i]->field_size);
2750 }
2751 if(final_child_status != FIELD_FIXED) {
62e4e7bf 2752 g_error("LTTV does not support variable size fields in unions.");
2753 /* This will stop the application. */
3aee1200 2754 *fixed_root = final_child_status;
2755 *fixed_parent = final_child_status;
2756 field->field_size = 0;
2757 field->fixed_size = current_child_status;
2758 } else {
2759 field->field_size = max_size;
2760 field->fixed_size = FIELD_FIXED;
2761 }
2762 break;
83e160f2 2763 case LTT_NONE:
2764 g_error("unexpected type NONE");
2765 break;
dfb73233 2766 }
2767
6cd62ccf 2768}
f104d082 2769#endif //0
3aee1200 2770
77175651 2771/*****************************************************************************
2772 *Function name
2773 * check_fields_compatibility : Check for compatibility between two fields :
2774 * do they use the same inner structure ?
2775 *Input params
2776 * event_type1 : event type
2777 * event_type2 : event type
2778 * field1 : field
2779 * field2 : field
2780 *Returns : 0 if identical
2781 * 1 if not.
2782 ****************************************************************************/
f104d082 2783// this function checks for equality of field types. Therefore, it does not use
2784// per se offsets. For instance, an aligned version of a structure is
2785// compatible with an unaligned version of the same structure.
3c165eaf 2786#if 0
f104d082 2787gint check_fields_compatibility(LttEventType *event_type1,
2788 LttEventType *event_type2,
2789 LttField *field1, LttField *field2)
2790{
2791 guint different = 0;
2312de30 2792 LttType *type1;
2793 LttType *type2;
f104d082 2794
2795 if(field1 == NULL) {
2796 if(field2 == NULL) goto end;
2797 else {
2798 different = 1;
2799 goto end;
2800 }
2801 } else if(field2 == NULL) {
2802 different = 1;
2803 goto end;
2804 }
2805
2312de30 2806 type1 = &field1->field_type;
2807 type2 = &field2->field_type;
f104d082 2808
2809 if(type1->type_class != type2->type_class) {
2810 different = 1;
2811 goto end;
2812 }
62e4e7bf 2813 if(type1->network != type2->network) {
2814 different = 1;
2815 goto end;
2816 }
f104d082 2817
2818 switch(type1->type_class) {
2819 case LTT_INT_FIXED:
2820 case LTT_UINT_FIXED:
2821 case LTT_POINTER:
2822 case LTT_CHAR:
2823 case LTT_UCHAR:
2824 case LTT_SHORT:
2825 case LTT_USHORT:
2826 case LTT_INT:
2827 case LTT_UINT:
2828 case LTT_LONG:
2829 case LTT_ULONG:
2830 case LTT_SIZE_T:
2831 case LTT_SSIZE_T:
2832 case LTT_OFF_T:
2833 case LTT_FLOAT:
2834 case LTT_ENUM:
2835 if(field1->field_size != field2->field_size)
2836 different = 1;
2837 break;
2838 case LTT_STRING:
2839 break;
2840 case LTT_ARRAY:
2841 {
2842 LttField *child1 = &g_array_index(type1->fields, LttField, 0);
2843 LttField *child2 = &g_array_index(type2->fields, LttField, 0);
2844
2845 if(type1->size != type2->size)
2846 different = 1;
2847 if(check_fields_compatibility(event_type1, event_type2, child1, child2))
2848 different = 1;
2849 }
2850 break;
2851 case LTT_SEQUENCE:
2852 {
2853 LttField *child1 = &g_array_index(type1->fields, LttField, 1);
2854 LttField *child2 = &g_array_index(type2->fields, LttField, 1);
2855
2856 if(check_fields_compatibility(event_type1, event_type2, child1, child2))
2857 different = 1;
2858 }
2859 break;
2860 case LTT_STRUCT:
2861 case LTT_UNION:
2862 {
2863 LttField *child;
2864 guint i;
2865
2866 if(type1->fields->len != type2->fields->len) {
2867 different = 1;
2868 goto end;
2869 }
2870
2871 for(i=0; i< type1->fields->len; i++) {
2312de30 2872 LttField *child1;
2873 LttField *child2;
f104d082 2874 child1 = &g_array_index(type1->fields, LttField, i);
2875 child2 = &g_array_index(type2->fields, LttField, i);
2876 different = check_fields_compatibility(event_type1,
2877 event_type2, child1, child2);
2878
2879 if(different) break;
2880 }
2881 }
2882 break;
2883 case LTT_NONE:
2884 default:
dd3a6d39 2885 g_error("check_fields_compatibility : unknown type");
f104d082 2886 }
2887
2888end:
2889 return different;
2890}
3c165eaf 2891#endif //0
f104d082 2892
2893#if 0
77175651 2894gint check_fields_compatibility(LttEventType *event_type1,
2895 LttEventType *event_type2,
2896 LttField *field1, LttField *field2)
2897{
2898 guint different = 0;
77175651 2899 guint i;
2900 LttType *type1;
2901 LttType *type2;
2902
2903 if(field1 == NULL) {
2904 if(field2 == NULL) goto end;
2905 else {
2906 different = 1;
2907 goto end;
2908 }
2909 } else if(field2 == NULL) {
2910 different = 1;
2911 goto end;
2912 }
2913
2914 g_assert(field1->fixed_root != FIELD_UNKNOWN);
2915 g_assert(field2->fixed_root != FIELD_UNKNOWN);
2916 g_assert(field1->fixed_parent != FIELD_UNKNOWN);
2917 g_assert(field2->fixed_parent != FIELD_UNKNOWN);
2918 g_assert(field1->fixed_size != FIELD_UNKNOWN);
2919 g_assert(field2->fixed_size != FIELD_UNKNOWN);
2920
2921 type1 = field1->field_type;
2922 type2 = field2->field_type;
2923
77175651 2924 if(type1->type_class != type2->type_class) {
2925 different = 1;
2926 goto end;
2927 }
2928 if(type1->element_name != type2->element_name) {
2929 different = 1;
2930 goto end;
2931 }
2932
2933 switch(type1->type_class) {
83e160f2 2934 case LTT_INT_FIXED:
2935 case LTT_UINT_FIXED:
2936 case LTT_POINTER:
2937 case LTT_CHAR:
2938 case LTT_UCHAR:
2939 case LTT_SHORT:
2940 case LTT_USHORT:
77175651 2941 case LTT_INT:
2942 case LTT_UINT:
2943 case LTT_FLOAT:
2944 case LTT_POINTER:
2945 case LTT_LONG:
2946 case LTT_ULONG:
2947 case LTT_SIZE_T:
2948 case LTT_SSIZE_T:
2949 case LTT_OFF_T:
2950 if(field1->field_size != field2->field_size) {
2951 different = 1;
2952 goto end;
2953 }
2954 break;
2955 case LTT_ENUM:
2956 if(type1->element_number != type2->element_number) {
2957 different = 1;
2958 goto end;
2959 }
2960 for(i=0;i<type1->element_number;i++) {
2961 if(type1->enum_strings[i] != type2->enum_strings[i]) {
2962 different = 1;
2963 goto end;
2964 }
2965 }
2966 break;
2967 case LTT_SEQUENCE:
2968 /* Two elements : size and child */
2969 g_assert(type1->element_number != type2->element_number);
2970 for(i=0;i<type1->element_number;i++) {
2971 if(check_fields_compatibility(event_type1, event_type2,
2972 field1->child[0], field2->child[0])) {
2973 different = 1;
2974 goto end;
2975 }
2976 }
2977 break;
2978 case LTT_STRING:
2979 break;
2980 case LTT_ARRAY:
2981 if(field1->field_size != field2->field_size) {
2982 different = 1;
2983 goto end;
2984 }
2985 /* Two elements : size and child */
2986 g_assert(type1->element_number != type2->element_number);
2987 for(i=0;i<type1->element_number;i++) {
2988 if(check_fields_compatibility(event_type1, event_type2,
2989 field1->child[0], field2->child[0])) {
2990 different = 1;
2991 goto end;
2992 }
2993 }
2994 break;
2995 case LTT_STRUCT:
2996 case LTT_UNION:
2997 if(type1->element_number != type2->element_number) {
2998 different = 1;
2999 break;
3000 }
3001 for(i=0;i<type1->element_number;i++) {
3002 if(check_fields_compatibility(event_type1, event_type2,
3003 field1->child[0], field2->child[0])) {
3004 different = 1;
3005 goto end;
3006 }
3007 }
3008 break;
3009 }
3010end:
3011 return different;
3012}
3aee1200 3013#endif //0
6cd62ccf 3014
f104d082 3015
6cd62ccf 3016/*****************************************************************************
3017 *Function name
eed2ef37 3018 * ltt_get_int : get an integer number
6cd62ccf 3019 *Input params
3aee1200 3020 * reverse_byte_order: must we reverse the byte order ?
6cd62ccf 3021 * size : the size of the integer
3aee1200 3022 * ptr : the data pointer
6cd62ccf 3023 *Return value
cf74a6f1 3024 * gint64 : a 64 bits integer
6cd62ccf 3025 ****************************************************************************/
3026
eed2ef37 3027gint64 ltt_get_int(gboolean reverse_byte_order, gint size, void *data)
6cd62ccf 3028{
3aee1200 3029 gint64 val;
cf74a6f1 3030
3031 switch(size) {
3aee1200 3032 case 1: val = *((gint8*)data); break;
3033 case 2: val = ltt_get_int16(reverse_byte_order, data); break;
3034 case 4: val = ltt_get_int32(reverse_byte_order, data); break;
3035 case 8: val = ltt_get_int64(reverse_byte_order, data); break;
3036 default: val = ltt_get_int64(reverse_byte_order, data);
3037 g_critical("get_int : integer size %d unknown", size);
cf74a6f1 3038 break;
3039 }
3040
3aee1200 3041 return val;
6cd62ccf 3042}
3aee1200 3043
6cd62ccf 3044/*****************************************************************************
3045 *Function name
eed2ef37 3046 * ltt_get_uint : get an unsigned integer number
6cd62ccf 3047 *Input params
3aee1200 3048 * reverse_byte_order: must we reverse the byte order ?
3049 * size : the size of the integer
3050 * ptr : the data pointer
3051 *Return value
3052 * guint64 : a 64 bits unsigned integer
6cd62ccf 3053 ****************************************************************************/
3054
eed2ef37 3055guint64 ltt_get_uint(gboolean reverse_byte_order, gint size, void *data)
6cd62ccf 3056{
3aee1200 3057 guint64 val;
3058
3059 switch(size) {
3060 case 1: val = *((gint8*)data); break;
3061 case 2: val = ltt_get_uint16(reverse_byte_order, data); break;
3062 case 4: val = ltt_get_uint32(reverse_byte_order, data); break;
3063 case 8: val = ltt_get_uint64(reverse_byte_order, data); break;
3064 default: val = ltt_get_uint64(reverse_byte_order, data);
3065 g_critical("get_uint : unsigned integer size %d unknown",
3066 size);
3067 break;
3068 }
3069
3070 return val;
6cd62ccf 3071}
3aee1200 3072
3073
a5dcde2f 3074/* get the node name of the system */
3075
3076char * ltt_trace_system_description_node_name (LttSystemDescription * s)
3077{
3078 return s->node_name;
3079}
3080
3081
3082/* get the domain name of the system */
3083
3084char * ltt_trace_system_description_domain_name (LttSystemDescription * s)
3085{
3086 return s->domain_name;
3087}
3088
3089
3090/* get the description of the system */
3091
3092char * ltt_trace_system_description_description (LttSystemDescription * s)
3093{
3094 return s->description;
3095}
3096
3097
bf33dd50 3098/* get the NTP corrected start time of the trace */
7bd563ec 3099LttTime ltt_trace_start_time(LttTrace *t)
a5dcde2f 3100{
7bd563ec 3101 return t->start_time;
a5dcde2f 3102}
3103
bf33dd50 3104/* get the monotonic start time of the trace */
3105LttTime ltt_trace_start_time_monotonic(LttTrace *t)
3106{
3107 return t->start_time_from_tsc;
3108}
3109
18206708 3110LttTracefile *ltt_tracefile_new()
3111{
3112 return g_new(LttTracefile, 1);
3113}
3114
3115void ltt_tracefile_destroy(LttTracefile *tf)
3116{
3117 g_free(tf);
3118}
3119
3120void ltt_tracefile_copy(LttTracefile *dest, const LttTracefile *src)
3121{
3122 *dest = *src;
3123}
3124
3aee1200 3125/* Before library loading... */
3126
3c165eaf 3127void init(void)
3aee1200 3128{
3129 LTT_FACILITY_NAME_HEARTBEAT = g_quark_from_string("heartbeat");
3130 LTT_EVENT_NAME_HEARTBEAT = g_quark_from_string("heartbeat");
d1bb700c 3131 LTT_EVENT_NAME_HEARTBEAT_FULL = g_quark_from_string("heartbeat_full");
3aee1200 3132
3865ea09 3133 LTT_TRACEFILE_NAME_FACILITIES = g_quark_from_string("/control/facilities");
3aee1200 3134}
This page took 0.222653 seconds and 4 git commands to generate.