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