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