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