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