1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Mathieu Desnoyers
4 * Complete rewrite from the original version made by XangXiu Yang.
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;
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.
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,
30 #include <sys/types.h>
45 #include "ltt-private.h"
46 #include <ltt/trace.h>
47 #include <ltt/facility.h>
48 #include <ltt/event.h>
50 #include <ltt/ltt-types.h>
53 /* Facility names used in this file */
55 GQuark LTT_FACILITY_NAME_HEARTBEAT
,
56 LTT_EVENT_NAME_HEARTBEAT
;
57 GQuark LTT_TRACEFILE_NAME_FACILITIES
;
64 #define __UNUSED__ __attribute__((__unused__))
66 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
69 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
74 /* Those macros must be called from within a function where page_size is a known
76 #define PAGE_MASK (~(page_size-1))
77 #define PAGE_ALIGN(addr) (((addr)+page_size-1)&PAGE_MASK)
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);
84 /* get the size of the field type according to
85 * The facility size information. */
86 static inline void preset_field_type_size(LttTracefile
*tf
,
87 LttEventType
*event_type
,
88 off_t offset_root
, off_t offset_parent
,
89 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
92 /* map a fixed size or a block information from the file (fd) */
93 static gint
map_block(LttTracefile
* tf
, guint block_num
);
95 /* calculate nsec per cycles for current block */
97 static guint32
calc_nsecs_per_cycle(LttTracefile
* t
);
98 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
);
101 /* go to the next event */
102 static int ltt_seek_next_event(LttTracefile
*tf
);
104 void ltt_update_event_size(LttTracefile
*tf
);
107 /* Functions to parse system.xml file (using glib xml parser) */
108 static void parser_start_element (GMarkupParseContext __UNUSED__
*context
,
109 const gchar
*element_name
,
110 const gchar
**attribute_names
,
111 const gchar
**attribute_values
,
116 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
117 if(strcmp("system", element_name
)){
118 *error
= g_error_new(G_MARKUP_ERROR
,
120 "This is not system.xml file");
124 while(attribute_names
[i
]){
125 if(strcmp("node_name", attribute_names
[i
])==0){
126 des
->node_name
= g_strdup(attribute_values
[i
]);
127 }else if(strcmp("domainname", attribute_names
[i
])==0){
128 des
->domain_name
= g_strdup(attribute_values
[i
]);
129 }else if(strcmp("cpu", attribute_names
[i
])==0){
130 des
->nb_cpu
= atoi(attribute_values
[i
]);
131 }else if(strcmp("arch_size", attribute_names
[i
])==0){
132 if(strcmp(attribute_values
[i
],"LP32") == 0) des
->size
= LTT_LP32
;
133 else if(strcmp(attribute_values
[i
],"ILP32") == 0) des
->size
= LTT_ILP32
;
134 else if(strcmp(attribute_values
[i
],"LP64") == 0) des
->size
= LTT_LP64
;
135 else if(strcmp(attribute_values
[i
],"ILP64") == 0) des
->size
= LTT_ILP64
;
136 else if(strcmp(attribute_values
[i
],"UNKNOWN") == 0) des
->size
= LTT_UNKNOWN
;
137 }else if(strcmp("endian", attribute_names
[i
])==0){
138 if(strcmp(attribute_values
[i
],"LITTLE_ENDIAN") == 0)
139 des
->endian
= LTT_LITTLE_ENDIAN
;
140 else if(strcmp(attribute_values
[i
],"BIG_ENDIAN") == 0)
141 des
->endian
= LTT_BIG_ENDIAN
;
142 }else if(strcmp("kernel_name", attribute_names
[i
])==0){
143 des
->kernel_name
= g_strdup(attribute_values
[i
]);
144 }else if(strcmp("kernel_release", attribute_names
[i
])==0){
145 des
->kernel_release
= g_strdup(attribute_values
[i
]);
146 }else if(strcmp("kernel_version", attribute_names
[i
])==0){
147 des
->kernel_version
= g_strdup(attribute_values
[i
]);
148 }else if(strcmp("machine", attribute_names
[i
])==0){
149 des
->machine
= g_strdup(attribute_values
[i
]);
150 }else if(strcmp("processor", attribute_names
[i
])==0){
151 des
->processor
= g_strdup(attribute_values
[i
]);
152 }else if(strcmp("hardware_platform", attribute_names
[i
])==0){
153 des
->hardware_platform
= g_strdup(attribute_values
[i
]);
154 }else if(strcmp("operating_system", attribute_names
[i
])==0){
155 des
->operating_system
= g_strdup(attribute_values
[i
]);
156 }else if(strcmp("ltt_major_version", attribute_names
[i
])==0){
157 des
->ltt_major_version
= atoi(attribute_values
[i
]);
158 }else if(strcmp("ltt_minor_version", attribute_names
[i
])==0){
159 des
->ltt_minor_version
= atoi(attribute_values
[i
]);
160 }else if(strcmp("ltt_block_size", attribute_names
[i
])==0){
161 des
->ltt_block_size
= atoi(attribute_values
[i
]);
163 *error
= g_error_new(G_MARKUP_ERROR
,
165 "Not a valid attribute");
172 static void parser_characters (GMarkupParseContext __UNUSED__
*context
,
174 gsize __UNUSED__ text_len
,
176 GError __UNUSED__
**error
)
178 LttSystemDescription
* des
= (LttSystemDescription
* )user_data
;
179 des
->description
= g_strdup(text
);
182 LttFacility
*ltt_trace_get_facility_by_num(LttTrace
*t
,
185 g_assert(num
< t
->facilities_by_num
->len
);
187 return &g_array_index(t
->facilities_by_num
, LttFacility
, num
);
191 guint
ltt_trace_get_num_cpu(LttTrace
*t
)
199 * Return value : 0 success, 1 bad tracefile
201 int parse_trace_header(void *header
, LttTracefile
*tf
, LttTrace
*t
)
203 guint32
*magic_number
= (guint32
*)header
;
204 struct ltt_trace_header_any
*any
= (struct ltt_trace_header_any
*)header
;
206 if(*magic_number
== LTT_MAGIC_NUMBER
)
208 else if(*magic_number
== LTT_REV_MAGIC_NUMBER
)
210 else /* invalid magic number, bad tracefile ! */
213 /* Get float byte order : might be different from int byte order
214 * (or is set to 0 if the trace has no float (kernel trace)) */
215 tf
->float_word_order
= any
->float_word_order
;
218 t
->arch_type
= ltt_get_uint32(LTT_GET_BO(tf
),
220 t
->arch_variant
= ltt_get_uint32(LTT_GET_BO(tf
),
222 t
->arch_size
= any
->arch_size
;
223 t
->ltt_major_version
= any
->major_version
;
224 t
->ltt_minor_version
= any
->minor_version
;
225 t
->flight_recorder
= any
->flight_recorder
;
226 t
->has_heartbeat
= any
->has_heartbeat
;
227 t
->has_alignment
= any
->has_alignment
;
228 t
->has_tsc
= any
->has_tsc
;
232 switch(any
->major_version
) {
235 switch(any
->minor_version
) {
238 tf
->buffer_header_size
=
239 sizeof(struct ltt_block_start_header
)
240 + sizeof(struct ltt_trace_header_0_3
);
241 g_warning("Unsupported trace version : %hhu.%hhu",
242 any
->major_version
, any
->minor_version
);
248 struct ltt_trace_header_0_4
*vheader
=
249 (struct ltt_trace_header_0_4
*)header
;
250 tf
->buffer_header_size
=
251 sizeof(struct ltt_block_start_header
)
252 + sizeof(struct ltt_trace_header_0_4
);
254 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
255 &vheader
->start_freq
);
256 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
257 &vheader
->start_tsc
);
258 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
259 &vheader
->start_monotonic
);
260 t
->start_time
= ltt_get_time(LTT_GET_BO(tf
),
261 &vheader
->start_time
);
262 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
264 t
->start_time_from_tsc
= ltt_time_from_uint64(
265 (double)t
->start_tsc
* 1000000.0 / (double)t
->start_freq
);
270 g_warning("Unsupported trace version : %hhu.%hhu",
271 any
->major_version
, any
->minor_version
);
277 g_warning("Unsupported trace version : %hhu.%hhu",
278 any
->major_version
, any
->minor_version
);
288 /*****************************************************************************
290 * ltt_tracefile_open : open a trace file, construct a LttTracefile
292 * t : the trace containing the tracefile
293 * fileName : path name of the trace file
294 * tf : the tracefile structure
296 * : 0 for success, -1 otherwise.
297 ****************************************************************************/
299 gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
301 struct stat lTDFStat
; /* Trace data file status */
302 struct ltt_block_start_header
*header
;
303 int page_size
= getpagesize();
306 tf
->long_name
= g_quark_from_string(fileName
);
308 tf
->fd
= open(fileName
, O_RDONLY
);
310 g_warning("Unable to open input data file %s\n", fileName
);
314 // Get the file's status
315 if(fstat(tf
->fd
, &lTDFStat
) < 0){
316 g_warning("Unable to get the status of the input data file %s\n", fileName
);
320 // Is the file large enough to contain a trace
321 if(lTDFStat
.st_size
<
322 (off_t
)(sizeof(struct ltt_block_start_header
)
323 + sizeof(struct ltt_trace_header_any
))){
324 g_print("The input data file %s does not contain a trace\n", fileName
);
328 /* Temporarily map the buffer start header to get trace information */
329 /* Multiple of pages aligned head */
330 tf
->buffer
.head
= mmap(0,
331 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
332 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
333 MAP_PRIVATE
, tf
->fd
, 0);
334 if(tf
->buffer
.head
== MAP_FAILED
) {
335 perror("Error in allocating memory for buffer of tracefile");
338 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
340 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
342 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
343 g_warning("parse_trace_header error");
347 //store the size of the file
348 tf
->file_size
= lTDFStat
.st_size
;
349 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
350 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
352 if(munmap(tf
->buffer
.head
,
353 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
354 + sizeof(struct ltt_trace_header_any
)))) {
355 g_warning("unmap size : %u\n",
356 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
357 + sizeof(struct ltt_trace_header_any
)));
358 perror("munmap error");
361 tf
->buffer
.head
= NULL
;
363 //read the first block
364 if(map_block(tf
,0)) {
365 perror("Cannot map block for tracefile");
373 if(munmap(tf
->buffer
.head
,
374 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
375 + sizeof(struct ltt_trace_header_any
)))) {
376 g_warning("unmap size : %u\n",
377 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
378 + sizeof(struct ltt_trace_header_any
)));
379 perror("munmap error");
388 LttTrace
*ltt_tracefile_get_trace(LttTracefile
*tf
)
394 /*****************************************************************************
395 *Open control and per cpu tracefiles
396 ****************************************************************************/
398 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
401 tf
= ltt_tracefile_open(t
,tracefile_name
);
403 t
->per_cpu_tracefile_number
++;
404 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
407 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
416 tf
= ltt_tracefile_open(t
,control_name
);
418 g_warning("ltt_tracefile_open_control : bad file descriptor");
421 t
->control_tracefile_number
++;
422 g_ptr_array_add(t
->control_tracefiles
,tf
);
424 //parse facilities tracefile to get base_id
425 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
427 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
429 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
431 fLoad
.name
= (gchar
*)pos
;
432 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
433 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
435 for(i
=0;i
<t
->facility_number
;i
++){
436 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
437 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
438 f
->base_id
= fLoad
.base_code
;
442 if(i
==t
->facility_number
) {
443 g_warning("Facility: %s, checksum: %u is not found",
444 fLoad
.name
,(unsigned int)fLoad
.checksum
);
447 }else if(ev
.event_id
== TRACE_BLOCK_START
){
449 }else if(ev
.event_id
== TRACE_BLOCK_END
){
452 g_warning("Not valid facilities trace file");
461 /*****************************************************************************
463 * ltt_tracefile_close: close a trace file,
465 * t : tracefile which will be closed
466 ****************************************************************************/
468 void ltt_tracefile_close(LttTracefile
*t
)
470 int page_size
= getpagesize();
472 if(t
->buffer
.head
!= NULL
)
473 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
474 g_warning("unmap size : %u\n",
475 PAGE_ALIGN(t
->buf_size
));
476 perror("munmap error");
484 /*****************************************************************************
485 *Get system information
486 ****************************************************************************/
488 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
495 GMarkupParseContext
* context
;
496 GError
* error
= NULL
;
497 GMarkupParser markup_parser
=
499 parser_start_element
,
502 NULL
, /* passthrough */
506 fd
= g_open(pathname
, O_RDONLY
, 0);
508 g_warning("Can not open file : %s\n", pathname
);
512 iochan
= g_io_channel_unix_new(fd
);
514 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
516 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
517 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
518 != G_IO_STATUS_EOF
) {
521 g_warning("Can not read xml file: \n%s\n", error
->message
);
524 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
526 g_warning("Can not parse xml file: \n%s\n", error
->message
);
529 g_markup_parse_context_free(context
);
531 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
533 g_warning("Can not close file: \n%s\n", error
->message
);
541 g_markup_parse_context_free(context
);
543 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
545 g_warning("Can not close file: \n%s\n", error
->message
);
556 /*****************************************************************************
557 *The following functions get facility/tracefile information
558 ****************************************************************************/
560 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
567 gchar fullname
[DIR_NAME_SIZE
];
568 GError
* error
= NULL
;
570 dir
= g_dir_open(eventdefs
, 0, &error
);
573 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
578 while((name
= g_dir_read_name(dir
)) != NULL
){
579 if(!g_pattern_match_simple("*.xml", name
)) continue;
580 strcpy(fullname
,eventdefs
);
581 strcat(fullname
,name
);
582 ltt_facility_open(t
,fullname
);
586 for(j
=0;j
<t
->facility_number
;j
++){
587 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
588 for(i
=0; i
<f
->event_number
; i
++){
590 setFieldsOffset(NULL
, et
, NULL
, t
);
597 /*****************************************************************************
598 *A trace is specified as a pathname to the directory containing all the
599 *associated data (control tracefiles, per cpu tracefiles, event
602 *When a trace is closed, all the associated facilities, types and fields
603 *are released as well.
607 /****************************************************************************
608 * get_absolute_pathname
610 * return the unique pathname in the system
612 * MD : Fixed this function so it uses realpath, dealing well with
613 * forgotten cases (.. were not used correctly before).
615 ****************************************************************************/
616 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
618 abs_pathname
[0] = '\0';
620 if ( realpath (pathname
, abs_pathname
) != NULL
)
624 /* error, return the original path unmodified */
625 strcpy(abs_pathname
, pathname
);
631 /* Search for something like : .*_.*
633 * The left side is the name, the right side is the number.
636 int get_tracefile_name_number(const gchar
*raw_name
,
640 guint raw_name_len
= strlen(raw_name
);
641 gchar char_name
[PATH_MAX
];
647 for(i
=raw_name_len
-1;i
>=0;i
--) {
648 if(raw_name
[i
] == '_') break;
650 if(i
==0) /* Either not found or name length is 0 */
654 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
656 if(endptr
== raw_name
+underscore_pos
+1)
657 return -1; /* No digit */
658 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
659 return -1; /* underflow / overflow */
661 strncpy(char_name
, raw_name
, underscore_pos
);
663 char_name
[underscore_pos
] = '\0';
665 *name
= g_quark_from_string(char_name
);
672 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
674 return &trace
->tracefiles
;
678 void compute_tracefile_group(GQuark key_id
,
680 struct compute_tracefile_group_args
*args
)
685 for(i
=0; i
<group
->len
; i
++) {
686 tf
= &g_array_index (group
, LttTracefile
, i
);
688 args
->func(tf
, args
->func_args
);
693 void ltt_tracefile_group_destroy(gpointer data
)
695 GArray
*group
= (GArray
*)data
;
699 for(i
=0; i
<group
->len
; i
++) {
700 tf
= &g_array_index (group
, LttTracefile
, i
);
702 ltt_tracefile_close(tf
);
704 g_array_free(group
, TRUE
);
707 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
709 GArray
*group
= (GArray
*)data
;
713 for(i
=0; i
<group
->len
; i
++) {
714 tf
= &g_array_index (group
, LttTracefile
, i
);
715 if(tf
->cpu_online
) return 1;
721 /* Open each tracefile under a specific directory. Put them in a
722 * GData : permits to access them using their tracefile group pathname.
723 * i.e. access control/modules tracefile group by index :
726 * relative path is the path relative to the trace root
727 * root path is the full path
729 * A tracefile group is simply an array where all the per cpu tracefiles sits.
732 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
733 gchar
*relative_path
)
735 DIR *dir
= opendir(root_path
);
736 struct dirent
*entry
;
737 struct stat stat_buf
;
740 gchar path
[PATH_MAX
];
745 gchar rel_path
[PATH_MAX
];
754 strncpy(path
, root_path
, PATH_MAX
-1);
755 path_len
= strlen(path
);
756 path
[path_len
] = '/';
758 path_ptr
= path
+ path_len
;
760 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
761 rel_path_len
= strlen(rel_path
);
762 rel_path
[rel_path_len
] = '/';
764 rel_path_ptr
= rel_path
+ rel_path_len
;
766 while((entry
= readdir(dir
)) != NULL
) {
768 if(entry
->d_name
[0] == '.') continue;
770 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
771 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
773 ret
= stat(path
, &stat_buf
);
779 g_debug("Tracefile file or directory : %s\n", path
);
781 if(strcmp(rel_path
, "/eventdefs") == 0) continue;
783 if(S_ISDIR(stat_buf
.st_mode
)) {
785 g_debug("Entering subdirectory...\n");
786 ret
= open_tracefiles(trace
, path
, rel_path
);
787 if(ret
< 0) continue;
788 } else if(S_ISREG(stat_buf
.st_mode
)) {
793 if(get_tracefile_name_number(rel_path
, &name
, &num
))
794 continue; /* invalid name */
796 g_debug("Opening file.\n");
797 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
798 g_info("Error opening tracefile %s", path
);
800 continue; /* error opening the tracefile : bad magic number ? */
803 g_debug("Tracefile name is %s and number is %u",
804 g_quark_to_string(name
), num
);
806 tmp_tf
.cpu_online
= 1;
807 tmp_tf
.cpu_num
= num
;
810 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
812 /* Elements are automatically cleared when the array is allocated.
813 * It makes the cpu_online variable set to 0 : cpu offline, by default.
815 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
816 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
817 group
, ltt_tracefile_group_destroy
);
820 /* Add the per cpu tracefile to the named group */
821 unsigned int old_len
= group
->len
;
823 group
= g_array_set_size(group
, num
+1);
824 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
834 /* ltt_get_facility_description
836 * Opens the file corresponding to the requested facility (identified by fac_id
839 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
841 * Returns 0 on success, or 1 on failure.
844 static int ltt_get_facility_description(LttFacility
*f
,
846 LttTracefile
*fac_tf
)
848 char desc_file_name
[PATH_MAX
];
853 text
= g_quark_to_string(t
->pathname
);
854 textlen
= strlen(text
);
856 if(textlen
>= PATH_MAX
) goto name_error
;
857 strcpy(desc_file_name
, text
);
859 text
= "/eventdefs/";
860 textlen
+=strlen(text
);
861 if(textlen
>= PATH_MAX
) goto name_error
;
862 strcat(desc_file_name
, text
);
864 text
= g_quark_to_string(f
->name
);
865 textlen
+=strlen(text
);
866 if(textlen
>= PATH_MAX
) goto name_error
;
867 strcat(desc_file_name
, text
);
870 textlen
+=strlen(text
);
871 if(textlen
>= PATH_MAX
) goto name_error
;
872 strcat(desc_file_name
, text
);
874 err
= snprintf(desc_file_name
+textlen
, PATH_MAX
-textlen
-1,
876 if(err
< 0) goto name_error
;
878 textlen
=strlen(desc_file_name
);
882 textlen
+=strlen(text
);
883 if(textlen
>= PATH_MAX
) goto name_error
;
884 strcat(desc_file_name
, text
);
886 err
= ltt_facility_open(f
, t
, desc_file_name
);
887 if(err
) goto facility_error
;
896 static void ltt_fac_ids_destroy(gpointer data
)
898 GArray
*fac_ids
= (GArray
*)data
;
900 g_array_free(fac_ids
, TRUE
);
904 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
905 * because it must be done just after the opening */
906 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
915 err
= ltt_tracefile_read_seek(tf
);
916 if(err
== EPERM
) goto seek_error
;
917 else if(err
== ERANGE
) break; /* End of tracefile */
919 err
= ltt_tracefile_read_update_event(tf
);
920 if(err
) goto update_error
;
922 /* We are on a facility load/or facility unload/ or heartbeat event */
924 * * facility 0 is hardcoded : this is the core facility. It will be shown
925 * in the facility array though, and is shown as "loaded builtin" in the
927 * It contains event :
929 * 1 : facility unload
930 * 2 : state dump facility load
933 if(tf
->event
.facility_id
!= LTT_FACILITY_CORE
) {
934 /* Should only contain core facility */
935 g_warning("Error in processing facility file %s, "
936 "should not contain facility id %u.", g_quark_to_string(tf
->name
),
937 tf
->event
.facility_id
);
942 struct LttFacilityLoad
*fac_load_data
;
943 struct LttStateDumpFacilityLoad
*fac_state_dump_load_data
;
947 switch((enum ltt_core_events
)tf
->event
.event_id
) {
948 case LTT_EVENT_FACILITY_LOAD
:
949 fac_name
= (char*)(tf
->event
.data
);
950 g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
953 (struct LttFacilityLoad
*)
954 (tf
->event
.data
+ strlen(fac_name
) + 1);
955 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
956 ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
));
957 /* facility may already exist if trace is paused/unpaused */
958 if(fac
->exists
) continue;
959 fac
->name
= g_quark_from_string(fac_name
);
960 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
961 &fac_load_data
->checksum
);
962 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
);
963 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
964 &fac_load_data
->pointer_size
);
965 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
966 &fac_load_data
->long_size
);
967 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
968 &fac_load_data
->size_t_size
);
969 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
970 &fac_load_data
->alignment
);
972 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
973 continue; /* error opening description */
975 fac
->trace
= tf
->trace
;
977 /* Preset the field offsets */
978 for(i
=0; i
<fac
->events
->len
; i
++){
979 et
= &g_array_index(fac
->events
, LttEventType
, i
);
980 set_fields_offsets(tf
, et
);
985 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
987 if(fac_ids
== NULL
) {
988 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
989 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
991 fac_ids
, ltt_fac_ids_destroy
);
993 g_array_append_val(fac_ids
, fac
->id
);
996 case LTT_EVENT_FACILITY_UNLOAD
:
997 g_debug("Doing LTT_EVENT_FACILITY_UNLOAD");
998 /* We don't care about unload : facilities ID are valid for the whole
999 * trace. They simply won't be used after the unload. */
1001 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1002 fac_name
= (char*)(tf
->event
.data
);
1003 g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s",
1005 fac_state_dump_load_data
=
1006 (struct LttStateDumpFacilityLoad
*)
1007 (tf
->event
.data
+ strlen(fac_name
) + 1);
1008 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
1009 ltt_get_uint32(LTT_GET_BO(tf
), &fac_state_dump_load_data
->id
));
1010 /* facility may already exist if trace is paused/unpaused */
1011 if(fac
->exists
) continue;
1012 fac
->name
= g_quark_from_string(fac_name
);
1013 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
1014 &fac_state_dump_load_data
->checksum
);
1015 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
),
1016 &fac_state_dump_load_data
->id
);
1017 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1018 &fac_state_dump_load_data
->pointer_size
);
1019 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1020 &fac_state_dump_load_data
->long_size
);
1021 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1022 &fac_state_dump_load_data
->size_t_size
);
1023 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1024 &fac_state_dump_load_data
->alignment
);
1025 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1026 continue; /* error opening description */
1028 fac
->trace
= tf
->trace
;
1030 /* Preset the field offsets */
1031 for(i
=0; i
<fac
->events
->len
; i
++){
1032 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1033 set_fields_offsets(tf
, et
);
1038 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1040 if(fac_ids
== NULL
) {
1041 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1042 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1044 fac_ids
, ltt_fac_ids_destroy
);
1046 g_array_append_val(fac_ids
, fac
->id
);
1049 case LTT_EVENT_HEARTBEAT
:
1052 g_warning("Error in processing facility file %s, "
1053 "unknown event id %hhu in core facility.",
1054 g_quark_to_string(tf
->name
),
1055 tf
->event
.event_id
);
1057 goto event_id_error
;
1063 /* Error handling */
1068 g_warning("An error occured in facility tracefile parsing");
1073 LttTrace
*ltt_trace_open(const gchar
*pathname
)
1075 gchar abs_path
[PATH_MAX
];
1080 struct ltt_block_start_header
*header
;
1082 struct dirent
*entry
;
1083 guint control_found
= 0;
1084 guint eventdefs_found
= 0;
1085 struct stat stat_buf
;
1086 gchar path
[PATH_MAX
];
1088 t
= g_new(LttTrace
, 1);
1089 if(!t
) goto alloc_error
;
1091 get_absolute_pathname(pathname
, abs_path
);
1092 t
->pathname
= g_quark_from_string(abs_path
);
1094 g_datalist_init(&t
->tracefiles
);
1096 /* Test to see if it looks like a trace */
1097 dir
= opendir(abs_path
);
1102 while((entry
= readdir(dir
)) != NULL
) {
1103 strcpy(path
, abs_path
);
1105 strcat(path
, entry
->d_name
);
1106 ret
= stat(path
, &stat_buf
);
1111 if(S_ISDIR(stat_buf
.st_mode
)) {
1112 if(strcmp(entry
->d_name
, "control") == 0) {
1115 if(strcmp(entry
->d_name
, "eventdefs") == 0) {
1116 eventdefs_found
= 1;
1122 if(!control_found
|| !eventdefs_found
) goto find_error
;
1124 /* Open all the tracefiles */
1125 if(open_tracefiles(t
, abs_path
, "")) {
1126 g_warning("Error opening tracefile %s", abs_path
);
1130 /* Prepare the facilities containers : array and mapping */
1131 /* Array is zeroed : the "exists" field is set to false by default */
1132 t
->facilities_by_num
= g_array_sized_new (FALSE
,
1133 TRUE
, sizeof(LttFacility
),
1135 t
->facilities_by_num
= g_array_set_size(t
->facilities_by_num
, NUM_FACILITIES
);
1137 g_datalist_init(&t
->facilities_by_name
);
1139 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1140 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1142 g_error("Trace %s has no facility tracefile", abs_path
);
1144 goto facilities_error
;
1147 /* Get the trace information for the control/facility 0 tracefile */
1148 g_assert(group
->len
> 0);
1149 tf
= &g_array_index (group
, LttTracefile
, 0);
1150 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1151 g_assert(parse_trace_header(header
->trace
,
1154 t
->num_cpu
= group
->len
;
1156 for(i
=0; i
<group
->len
; i
++) {
1157 tf
= &g_array_index (group
, LttTracefile
, i
);
1158 if(ltt_process_facility_tracefile(tf
))
1159 goto facilities_error
;
1164 /* Error handling */
1166 g_datalist_clear(&t
->facilities_by_name
);
1167 g_array_free(t
->facilities_by_num
, TRUE
);
1169 g_datalist_clear(&t
->tracefiles
);
1177 GQuark
ltt_trace_name(const LttTrace
*t
)
1183 /******************************************************************************
1184 * When we copy a trace, we want all the opening actions to happen again :
1185 * the trace will be reopened and totally independant from the original.
1186 * That's why we call ltt_trace_open.
1187 *****************************************************************************/
1188 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1190 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1193 void ltt_trace_close(LttTrace
*t
)
1198 for(i
=0; i
<t
->facilities_by_num
->len
; i
++) {
1199 fac
= &g_array_index (t
->facilities_by_num
, LttFacility
, i
);
1201 ltt_facility_close(fac
);
1204 g_datalist_clear(&t
->facilities_by_name
);
1205 g_array_free(t
->facilities_by_num
, TRUE
);
1206 g_datalist_clear(&t
->tracefiles
);
1211 /*****************************************************************************
1212 *Get the system description of the trace
1213 ****************************************************************************/
1215 LttFacility
*ltt_trace_facility_by_id(LttTrace
*t
, guint8 id
)
1217 g_assert(id
< t
->facilities_by_num
->len
);
1218 return &g_array_index(t
->facilities_by_num
, LttFacility
, id
);
1221 /* ltt_trace_facility_get_by_name
1223 * Returns the GArray of facility indexes. All the fac_ids that matches the
1224 * requested facility name.
1226 * If name is not found, returns NULL.
1228 GArray
*ltt_trace_facility_get_by_name(LttTrace
*t
, GQuark name
)
1230 return g_datalist_id_get_data(&t
->facilities_by_name
, name
);
1233 /*****************************************************************************
1234 * Functions to discover all the event types in the trace
1235 ****************************************************************************/
1238 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
1242 unsigned int num
= t
->facility_number
;
1246 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
1247 count
+= f
->event_number
;
1254 //use an iteration on all the trace facilities, and inside iteration on all the
1255 //event types in each facilities instead.
1256 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
1258 LttEventType
*event_type
;
1261 f
= ltt_trace_facility_by_id(t
,evId
);
1263 if(unlikely(!f
)) event_type
= NULL
;
1264 else event_type
= f
->events
[evId
- f
->base_id
];
1271 /*****************************************************************************
1272 * ltt_trace_find_tracefile
1274 * Find a tracefile by name and index in the group.
1276 * Returns a pointer to the tracefiles, else NULL.
1277 ****************************************************************************/
1279 LttTracefile
*ltt_trace_find_tracefile(LttTrace
*t
, const gchar
*name
)
1284 /*****************************************************************************
1285 * Get the start time and end time of the trace
1286 ****************************************************************************/
1288 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1289 LttTime
*start
, LttTime
*end
)
1293 err
= map_block(tf
, 0);
1295 g_error("Can not map block");
1296 *start
= ltt_time_infinite
;
1298 *start
= tf
->buffer
.begin
.timestamp
;
1300 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1302 g_error("Can not map block");
1303 *end
= ltt_time_zero
;
1305 *end
= tf
->buffer
.end
.timestamp
;
1308 struct tracefile_time_span_get_args
{
1314 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1316 struct tracefile_time_span_get_args
*args
=
1317 (struct tracefile_time_span_get_args
*)user_data
;
1319 GArray
*group
= (GArray
*)data
;
1325 for(i
=0; i
<group
->len
; i
++) {
1326 tf
= &g_array_index (group
, LttTracefile
, i
);
1327 if(tf
->cpu_online
) {
1328 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1329 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1330 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1335 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1337 LttTime min_start
= ltt_time_infinite
;
1338 LttTime max_end
= ltt_time_zero
;
1339 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1341 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1343 if(start
!= NULL
) *start
= min_start
;
1344 if(end
!= NULL
) *end
= max_end
;
1349 /*****************************************************************************
1350 *Get the name of a tracefile
1351 ****************************************************************************/
1353 GQuark
ltt_tracefile_name(const LttTracefile
*tf
)
1358 GQuark
ltt_tracefile_long_name(const LttTracefile
*tf
)
1360 return tf
->long_name
;
1365 guint
ltt_tracefile_num(LttTracefile
*tf
)
1370 /*****************************************************************************
1371 * Get the number of blocks in the tracefile
1372 ****************************************************************************/
1374 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1376 return tf
->num_blocks
;
1380 /* Seek to the first event in a tracefile that has a time equal or greater than
1381 * the time passed in parameter.
1383 * If the time parameter is outside the tracefile time span, seek to the first
1384 * event or if after, return ERANGE.
1386 * If the time parameter is before the first event, we have to seek specially to
1389 * If the time is after the end of the trace, return ERANGE.
1391 * Do a binary search to find the right block, then a sequential search in the
1392 * block to find the event.
1394 * In the special case where the time requested fits inside a block that has no
1395 * event corresponding to the requested time, the first event of the next block
1398 * IMPORTANT NOTE : // FIXME everywhere...
1400 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1401 * you will jump over an event if you do.
1403 * Return value : 0 : no error, the tf->event can be used
1404 * ERANGE : time if after the last event of the trace
1405 * otherwise : this is an error.
1409 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1413 unsigned int block_num
, high
, low
;
1415 /* seek at the beginning of trace */
1416 err
= map_block(tf
, 0); /* First block */
1418 g_error("Can not map block");
1422 /* If the time is lower or equal the beginning of the trace,
1423 * go to the first event. */
1424 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1425 ret
= ltt_tracefile_read(tf
);
1426 if(ret
== ERANGE
) goto range
;
1427 else if (ret
) goto fail
;
1428 goto found
; /* There is either no event in the trace or the event points
1429 to the first event in the trace */
1432 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1434 g_error("Can not map block");
1438 /* If the time is after the end of the trace, return ERANGE. */
1439 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1443 /* Binary search the block */
1444 high
= tf
->num_blocks
- 1;
1448 block_num
= ((high
-low
) / 2) + low
;
1450 err
= map_block(tf
, block_num
);
1452 g_error("Can not map block");
1456 /* We cannot divide anymore : this is what would happen if the time
1457 * requested was exactly between two consecutive buffers'end and start
1458 * timestamps. This is also what would happend if we didn't deal with out
1459 * of span cases prior in this function. */
1460 /* The event is right in the buffer!
1461 * (or in the next buffer first event) */
1463 ret
= ltt_tracefile_read(tf
);
1464 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1465 else if(ret
) goto fail
;
1467 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1471 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1472 /* go to lower part */
1473 high
= block_num
- 1;
1474 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1475 /* go to higher part */
1476 low
= block_num
+ 1;
1477 } else {/* The event is right in the buffer!
1478 (or in the next buffer first event) */
1480 ret
= ltt_tracefile_read(tf
);
1481 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1482 else if(ret
) goto fail
;
1484 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1496 /* Error handling */
1498 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1499 g_quark_to_string(tf
->name
));
1504 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1508 if(ep
->tracefile
!= tf
) {
1512 err
= map_block(tf
, ep
->block
);
1514 g_error("Can not map block");
1518 tf
->event
.offset
= ep
->offset
;
1520 err
= ltt_tracefile_read_update_event(tf
);
1522 err
= ltt_tracefile_read_op(tf
);
1528 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1529 g_quark_to_string(tf
->name
));
1533 /* Calculate the real event time based on the buffer boundaries */
1534 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1538 g_assert(tf
->trace
->has_tsc
);
1540 // time = ltt_time_from_uint64(
1541 // cycles_2_ns(tf, (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count)));
1542 time
= ltt_time_from_uint64(
1543 (double)(tf
->buffer
.tsc
- tf
->trace
->start_tsc
) * 1000000.0
1544 / (double)tf
->trace
->start_freq
);
1545 //time = ltt_time_add(tf->buffer.begin.timestamp, time);
1546 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1552 /* Get the current event of the tracefile : valid until the next read */
1553 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1560 /*****************************************************************************
1562 * ltt_tracefile_read : Read the next event in the tracefile
1567 * Returns 0 if an event can be used in tf->event.
1568 * Returns ERANGE on end of trace. The event in tf->event still can be used
1569 * (if the last block was not empty).
1570 * Returns EPERM on error.
1572 * This function does make the tracefile event structure point to the event
1573 * currently pointed to by the tf->event.
1575 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1576 * reinitialize it after an error if you want results to be coherent.
1577 * It would be the case if a end of trace last buffer has no event : the end
1578 * of trace wouldn't be returned, but an error.
1579 * We make the assumption there is at least one event per buffer.
1580 ****************************************************************************/
1582 int ltt_tracefile_read(LttTracefile
*tf
)
1586 err
= ltt_tracefile_read_seek(tf
);
1588 err
= ltt_tracefile_read_update_event(tf
);
1590 err
= ltt_tracefile_read_op(tf
);
1596 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1600 /* Get next buffer until we finally have an event, or end of trace */
1602 err
= ltt_seek_next_event(tf
);
1603 if(unlikely(err
== ENOPROTOOPT
)) {
1607 /* Are we at the end of the buffer ? */
1609 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1612 /* get next block */
1613 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1615 g_error("Can not map block");
1619 } else break; /* We found an event ! */
1626 /* do specific operation on events */
1627 int ltt_tracefile_read_op(LttTracefile
*tf
)
1633 /* do event specific operation */
1635 /* do something if its an heartbeat event : increment the heartbeat count */
1636 //if(event->facility_id == LTT_FACILITY_CORE)
1637 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1638 // tf->cur_heart_beat_number++;
1644 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1645 * event specific operation. */
1646 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1652 pos
= tf
->buffer
.head
+ event
->offset
;
1654 /* Read event header */
1658 if(tf
->trace
->has_tsc
) {
1659 if(tf
->trace
->has_heartbeat
) {
1660 event
->time
.timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1662 /* 32 bits -> 64 bits tsc */
1663 /* note : still works for seek and non seek cases. */
1664 if(event
->time
.timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1665 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1667 | (guint64
)event
->time
.timestamp
;
1668 event
->tsc
= tf
->buffer
.tsc
;
1671 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1672 | (guint64
)event
->time
.timestamp
;
1673 event
->tsc
= tf
->buffer
.tsc
;
1675 pos
+= sizeof(guint32
);
1677 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1678 tf
->buffer
.tsc
= event
->tsc
;
1679 pos
+= sizeof(guint64
);
1682 event
->event_time
= ltt_interpolate_time(tf
, event
);
1684 event
->time
.delta
.tv_sec
= 0;
1685 event
->time
.delta
.tv_nsec
= ltt_get_uint32(LTT_GET_BO(tf
),
1686 pos
) * NSEC_PER_USEC
;
1688 event
->tsc
= tf
->buffer
.tsc
;
1690 event
->event_time
= ltt_time_add(tf
->buffer
.begin
.timestamp
,
1692 pos
+= sizeof(guint32
);
1695 event
->facility_id
= *(guint8
*)pos
;
1696 pos
+= sizeof(guint8
);
1698 event
->event_id
= *(guint8
*)pos
;
1699 pos
+= sizeof(guint8
);
1701 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1702 pos
+= sizeof(guint16
);
1706 /* get the data size and update the event fields with the current
1708 ltt_update_event_size(tf
);
1714 /****************************************************************************
1716 * map_block : map a block from the file
1718 * lttdes : ltt trace file
1719 * whichBlock : the block which will be read
1722 * EINVAL : lseek fail
1723 * EIO : can not read from the file
1724 ****************************************************************************/
1726 static gint
map_block(LttTracefile
* tf
, guint block_num
)
1728 int page_size
= getpagesize();
1729 struct ltt_block_start_header
*header
;
1731 g_assert(block_num
< tf
->num_blocks
);
1733 if(tf
->buffer
.head
!= NULL
) {
1734 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1735 g_warning("unmap size : %u\n",
1736 PAGE_ALIGN(tf
->buf_size
));
1737 perror("munmap error");
1743 /* Multiple of pages aligned head */
1744 tf
->buffer
.head
= mmap(0,
1745 PAGE_ALIGN(tf
->buf_size
),
1746 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1747 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1749 if(tf
->buffer
.head
== MAP_FAILED
) {
1750 perror("Error in allocating memory for buffer of tracefile");
1754 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1757 tf
->buffer
.index
= block_num
;
1759 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1762 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1763 ltt_time_from_uint64(
1764 ltt_get_uint64(LTT_GET_BO(tf
),
1765 &header
->begin
.timestamp
)
1766 - tf
->trace
->start_monotonic
),
1767 tf
->trace
->start_time
);
1769 //g_debug("block %u begin : %lu.%lu", block_num,
1770 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1771 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1772 &header
->begin
.cycle_count
);
1773 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1774 &header
->begin
.freq
);
1775 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1776 ltt_time_from_uint64(
1777 (double)(tf
->buffer
.begin
.cycle_count
1778 - tf
->trace
->start_tsc
) * 1000000.0
1779 / (double)tf
->trace
->start_freq
),
1780 tf
->trace
->start_time_from_tsc
);
1783 tf
->buffer
.end
.timestamp
= ltt_time_add(
1784 ltt_time_from_uint64(
1785 ltt_get_uint64(LTT_GET_BO(tf
),
1786 &header
->end
.timestamp
)
1787 - tf
->trace
->start_monotonic
),
1788 tf
->trace
->start_time
);
1790 //g_debug("block %u end : %lu.%lu", block_num,
1791 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1792 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1793 &header
->end
.cycle_count
);
1794 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1796 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1797 &header
->lost_size
);
1798 tf
->buffer
.end
.timestamp
= ltt_time_add(
1799 ltt_time_from_uint64(
1800 (double)(tf
->buffer
.end
.cycle_count
1801 - tf
->trace
->start_tsc
) * 1000000.0
1802 / (double)tf
->trace
->start_freq
),
1803 tf
->trace
->start_time_from_tsc
);
1805 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1806 tf
->event
.tsc
= tf
->buffer
.tsc
;
1807 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1810 * eventually support variable buffer size : will need a partial pre-read of
1811 * the headers to create an index when we open the trace... eventually. */
1812 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1813 &header
->buf_size
));
1815 /* Now that the buffer is mapped, calculate the time interpolation for the
1818 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1819 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1821 /* Make the current event point to the beginning of the buffer :
1822 * it means that the event read must get the first event. */
1823 tf
->event
.tracefile
= tf
;
1824 tf
->event
.block
= block_num
;
1825 tf
->event
.offset
= 0;
1834 /* It will update the fields offsets too */
1835 void ltt_update_event_size(LttTracefile
*tf
)
1839 /* Specific handling of core events : necessary to read the facility control
1841 LttFacility
*f
= ltt_trace_get_facility_by_num(tf
->trace
,
1842 tf
->event
.facility_id
);
1844 if(likely(tf
->event
.facility_id
== LTT_FACILITY_CORE
)) {
1845 switch((enum ltt_core_events
)tf
->event
.event_id
) {
1846 case LTT_EVENT_FACILITY_LOAD
:
1847 size
= strlen((char*)tf
->event
.data
) + 1;
1848 //g_debug("Update Event facility load of facility %s", (char*)tf->event.data);
1849 size
+= sizeof(struct LttFacilityLoad
);
1851 case LTT_EVENT_FACILITY_UNLOAD
:
1852 //g_debug("Update Event facility unload");
1853 size
= sizeof(struct LttFacilityUnload
);
1855 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1856 size
= strlen((char*)tf
->event
.data
) + 1;
1857 //g_debug("Update Event facility load state dump of facility %s",
1858 // (char*)tf->event.data);
1859 size
+= sizeof(struct LttStateDumpFacilityLoad
);
1861 case LTT_EVENT_HEARTBEAT
:
1862 //g_debug("Update Event heartbeat");
1863 size
= sizeof(TimeHeartbeat
);
1866 g_warning("Error in getting event size : tracefile %s, "
1867 "unknown event id %hhu in core facility.",
1868 g_quark_to_string(tf
->name
),
1869 tf
->event
.event_id
);
1870 goto event_id_error
;
1875 g_error("Unknown facility %hhu (0x%hhx) in tracefile %s",
1876 tf
->event
.facility_id
,
1877 tf
->event
.facility_id
,
1878 g_quark_to_string(tf
->name
));
1879 goto facility_error
;
1882 LttEventType
*event_type
=
1883 ltt_facility_eventtype_get(f
, tf
->event
.event_id
);
1886 g_error("Unknown event id %hhu in facility %s in tracefile %s",
1888 g_quark_to_string(f
->name
),
1889 g_quark_to_string(tf
->name
));
1890 goto event_type_error
;
1893 if(event_type
->root_field
)
1894 size
= get_field_type_size(tf
, event_type
,
1895 0, 0, event_type
->root_field
, tf
->event
.data
);
1899 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
1900 // tf->event.facility_id,
1901 // tf->event.event_id, size);
1904 tf
->event
.data_size
= size
;
1906 /* Check consistency between kernel and LTTV structure sizes */
1907 g_assert(tf
->event
.data_size
== tf
->event
.event_size
);
1914 tf
->event
.data_size
= 0;
1918 /* Take the tf current event offset and use the event facility id and event id
1919 * to figure out where is the next event offset.
1921 * This is an internal function not aiming at being used elsewhere : it will
1922 * not jump over the current block limits. Please consider using
1923 * ltt_tracefile_read to do this.
1925 * Returns 0 on success
1926 * ERANGE if we are at the end of the buffer.
1927 * ENOPROTOOPT if an error occured when getting the current event size.
1929 static int ltt_seek_next_event(LttTracefile
*tf
)
1934 /* seek over the buffer header if we are at the buffer start */
1935 if(tf
->event
.offset
== 0) {
1936 tf
->event
.offset
+= tf
->buffer_header_size
;
1938 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1945 pos
= tf
->event
.data
;
1947 if(tf
->event
.data_size
< 0) goto error
;
1949 pos
+= (size_t)tf
->event
.data_size
;
1951 tf
->event
.offset
= pos
- tf
->buffer
.head
;
1953 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1957 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
1963 g_error("Error in ltt_seek_next_event for tracefile %s",
1964 g_quark_to_string(tf
->name
));
1969 /*****************************************************************************
1971 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
1973 * 1.0 / (freq(khz) *1000) * 1000000000
1976 ****************************************************************************/
1977 /* from timer_tsc.c */
1978 #define CYC2NS_SCALE_FACTOR 10
1979 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
1981 //return 1e6 / (double)tf->buffer.freq;
1982 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
1983 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
1985 return cyc2ns_scale
;
1986 // return 1e6 / (double)tf->buffer.freq;
1989 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
1991 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
1996 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
1998 LttField
* rootFld
= evT
->root_field
;
1999 // rootFld->base_address = evD;
2002 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
2003 evT
, 0,0,rootFld
, evD
);
2007 /*****************************************************************************
2009 * set_fields_offsets : set the precomputable offset of the fields
2011 * tracefile : opened trace file
2012 * event_type : the event type
2013 ****************************************************************************/
2015 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
2017 LttField
*field
= event_type
->root_field
;
2018 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
2021 preset_field_type_size(tf
, event_type
, 0, 0,
2022 &fixed_root
, &fixed_parent
,
2028 /*****************************************************************************
2030 * preset_field_type_size : set the fixed sizes of the field type
2033 * event_type : event type
2034 * offset_root : offset from the root
2035 * offset_parent : offset from the parent
2036 * fixed_root : Do we know a fixed offset to the root ?
2037 * fixed_parent : Do we know a fixed offset to the parent ?
2039 ****************************************************************************/
2040 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2041 off_t offset_root
, off_t offset_parent
,
2042 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2045 enum field_status local_fixed_root
, local_fixed_parent
;
2049 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2050 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2051 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2053 type
= field
->field_type
;
2055 field
->fixed_root
= *fixed_root
;
2056 if(field
->fixed_root
== FIELD_FIXED
)
2057 field
->offset_root
= offset_root
;
2059 field
->offset_root
= 0;
2061 field
->fixed_parent
= *fixed_parent
;
2062 if(field
->fixed_parent
== FIELD_FIXED
)
2063 field
->offset_parent
= offset_parent
;
2065 field
->offset_parent
= 0;
2067 size_t current_root_offset
;
2068 size_t current_offset
;
2069 enum field_status current_child_status
, final_child_status
;
2072 switch(type
->type_class
) {
2077 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2078 field
->fixed_size
= FIELD_FIXED
;
2081 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2082 field
->fixed_size
= FIELD_FIXED
;
2086 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2087 field
->fixed_size
= FIELD_FIXED
;
2092 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2093 field
->fixed_size
= FIELD_FIXED
;
2096 local_fixed_root
= FIELD_VARIABLE
;
2097 local_fixed_parent
= FIELD_VARIABLE
;
2098 preset_field_type_size(tf
, event_type
,
2100 &local_fixed_root
, &local_fixed_parent
,
2102 field
->fixed_size
= FIELD_VARIABLE
;
2103 field
->field_size
= 0;
2104 *fixed_root
= FIELD_VARIABLE
;
2105 *fixed_parent
= FIELD_VARIABLE
;
2108 field
->fixed_size
= FIELD_VARIABLE
;
2109 field
->field_size
= 0;
2110 *fixed_root
= FIELD_VARIABLE
;
2111 *fixed_parent
= FIELD_VARIABLE
;
2114 local_fixed_root
= FIELD_VARIABLE
;
2115 local_fixed_parent
= FIELD_VARIABLE
;
2116 preset_field_type_size(tf
, event_type
,
2118 &local_fixed_root
, &local_fixed_parent
,
2120 field
->fixed_size
= field
->child
[0]->fixed_size
;
2121 if(field
->fixed_size
== FIELD_FIXED
) {
2122 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2124 field
->field_size
= 0;
2125 *fixed_root
= FIELD_VARIABLE
;
2126 *fixed_parent
= FIELD_VARIABLE
;
2130 current_root_offset
= field
->offset_root
;
2132 current_child_status
= FIELD_FIXED
;
2133 for(i
=0;i
<type
->element_number
;i
++) {
2134 preset_field_type_size(tf
, event_type
,
2135 current_root_offset
, current_offset
,
2136 fixed_root
, ¤t_child_status
,
2138 if(current_child_status
== FIELD_FIXED
) {
2139 current_root_offset
+= field
->child
[i
]->field_size
;
2140 current_offset
+= field
->child
[i
]->field_size
;
2142 current_root_offset
= 0;
2146 if(current_child_status
!= FIELD_FIXED
) {
2147 *fixed_parent
= current_child_status
;
2148 field
->field_size
= 0;
2149 field
->fixed_size
= current_child_status
;
2151 field
->field_size
= current_offset
;
2152 field
->fixed_size
= FIELD_FIXED
;
2156 current_root_offset
= field
->offset_root
;
2159 final_child_status
= FIELD_FIXED
;
2160 for(i
=0;i
<type
->element_number
;i
++) {
2161 enum field_status current_root_child_status
= FIELD_FIXED
;
2162 enum field_status current_child_status
= FIELD_FIXED
;
2163 preset_field_type_size(tf
, event_type
,
2164 current_root_offset
, current_offset
,
2165 ¤t_root_child_status
, ¤t_child_status
,
2167 if(current_child_status
!= FIELD_FIXED
)
2168 final_child_status
= current_child_status
;
2170 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2172 if(final_child_status
!= FIELD_FIXED
) {
2173 g_error("LTTV does not support variable size fields in unions.");
2174 /* This will stop the application. */
2175 *fixed_root
= final_child_status
;
2176 *fixed_parent
= final_child_status
;
2177 field
->field_size
= 0;
2178 field
->fixed_size
= current_child_status
;
2180 field
->field_size
= max_size
;
2181 field
->fixed_size
= FIELD_FIXED
;
2189 /*****************************************************************************
2191 * check_fields_compatibility : Check for compatibility between two fields :
2192 * do they use the same inner structure ?
2194 * event_type1 : event type
2195 * event_type2 : event type
2198 *Returns : 0 if identical
2200 ****************************************************************************/
2201 gint
check_fields_compatibility(LttEventType
*event_type1
,
2202 LttEventType
*event_type2
,
2203 LttField
*field1
, LttField
*field2
)
2205 guint different
= 0;
2210 if(field1
== NULL
) {
2211 if(field2
== NULL
) goto end
;
2216 } else if(field2
== NULL
) {
2221 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2222 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2223 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2224 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2225 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2226 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2228 type1
= field1
->field_type
;
2229 type2
= field2
->field_type
;
2231 if(type1
->type_class
!= type2
->type_class
) {
2235 if(type1
->element_name
!= type2
->element_name
) {
2240 switch(type1
->type_class
) {
2250 if(field1
->field_size
!= field2
->field_size
) {
2256 if(type1
->element_number
!= type2
->element_number
) {
2260 for(i
=0;i
<type1
->element_number
;i
++) {
2261 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2268 /* Two elements : size and child */
2269 g_assert(type1
->element_number
!= type2
->element_number
);
2270 for(i
=0;i
<type1
->element_number
;i
++) {
2271 if(check_fields_compatibility(event_type1
, event_type2
,
2272 field1
->child
[0], field2
->child
[0])) {
2281 if(field1
->field_size
!= field2
->field_size
) {
2285 /* Two elements : size and child */
2286 g_assert(type1
->element_number
!= type2
->element_number
);
2287 for(i
=0;i
<type1
->element_number
;i
++) {
2288 if(check_fields_compatibility(event_type1
, event_type2
,
2289 field1
->child
[0], field2
->child
[0])) {
2297 if(type1
->element_number
!= type2
->element_number
) {
2301 for(i
=0;i
<type1
->element_number
;i
++) {
2302 if(check_fields_compatibility(event_type1
, event_type2
,
2303 field1
->child
[0], field2
->child
[0])) {
2318 /*****************************************************************************
2320 * getFieldtypeSize: get the size of the field type (primitive type)
2323 * offsetRoot : offset from the root
2324 * offsetParent : offset from the parrent
2326 * evD : event data, it may be NULL
2328 * int : size of the field
2329 ****************************************************************************/
2331 static inline gint
getFieldtypeSize(LttTracefile
*tf
,
2332 LttEventType
* evT
, gint offsetRoot
,
2333 gint offsetParent
, LttField
* fld
, void *evD
)
2335 gint size
, size1
, element_number
, i
, offset1
, offset2
;
2336 LttType
* type
= fld
->field_type
;
2338 /* This likely has been tested with gcov : half of them.. */
2339 if(unlikely(fld
->field_fixed
== 1)){
2341 if(unlikely(fld
== evT
->root_field
)) {
2342 size
= fld
->field_size
;
2343 goto end_getFieldtypeSize
;
2347 /* From gcov profiling : half string, half struct, can we gain something
2348 * from that ? (Mathieu) */
2349 switch(type
->type_class
) {
2351 element_number
= (int) type
->element_number
;
2352 if(fld
->field_fixed
== -1){
2353 size
= getFieldtypeSize(tf
, evT
, offsetRoot
,
2354 0,fld
->child
[0], NULL
);
2355 if(size
== 0){ //has string or sequence
2356 fld
->field_fixed
= 0;
2358 fld
->field_fixed
= 1;
2359 size
*= element_number
;
2361 }else if(fld
->field_fixed
== 0){// has string or sequence
2363 for(i
=0;i
<element_number
;i
++){
2364 size
+= getFieldtypeSize(tf
, evT
, offsetRoot
+size
,size
,
2365 fld
->child
[0], evD
+size
);
2367 }else size
= fld
->field_size
;
2369 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2370 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2376 size1
= (int) ltt_type_size(fac
, type
);
2377 if(fld
->field_fixed
== -1){
2378 fld
->sequ_number_size
= size1
;
2379 fld
->field_fixed
= 0;
2380 size
= getFieldtypeSize(evT
, offsetRoot
,
2381 0,fld
->child
[0], NULL
);
2382 fld
->element_size
= size
;
2384 element_number
= getIntNumber(tf
,size1
,evD
);
2385 type
->element_number
= element_number
;
2386 if(fld
->element_size
> 0){
2387 size
= element_number
* fld
->element_size
;
2388 }else{//sequence has string or sequence
2390 for(i
=0;i
<element_number
;i
++){
2391 size
+= getFieldtypeSize(tf
, evT
,
2392 offsetRoot
+size
+size1
,size
+size1
,
2393 fld
->child
[0], evD
+size
+size1
);
2399 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2400 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2407 if(fld
->field_fixed
== -1){
2408 fld
->field_fixed
= 0;
2410 /* Hope my implementation is faster than strlen (Mathieu) */
2411 char *ptr
=(char*)evD
;
2413 /* from gcov : many many strings are empty, make it the common case.*/
2414 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
2415 //size = ptr - (char*)evD + 1; //include end : '\0'
2417 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2418 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2423 element_number
= (int) type
->element_number
;
2425 /* tested with gcov */
2426 if(unlikely(fld
->field_fixed
== -1)){
2427 offset1
= offsetRoot
;
2429 for(i
=0;i
<element_number
;i
++){
2430 size1
=getFieldtypeSize(tf
, evT
,offset1
,offset2
,
2431 fld
->child
[i
], NULL
);
2432 if(likely(size1
> 0 && size
>= 0)){
2434 if(likely(offset1
>= 0)) offset1
+= size1
;
2442 if(unlikely(size
== -1)){
2443 fld
->field_fixed
= 0;
2445 }else fld
->field_fixed
= 1;
2446 }else if(likely(fld
->field_fixed
== 0)){
2447 offset1
= offsetRoot
;
2449 for(i
=0;unlikely(i
<element_number
);i
++){
2450 size
=getFieldtypeSize(tf
, evT
, offset1
, offset2
,
2451 fld
->child
[i
], evD
+offset2
);
2456 }else size
= fld
->field_size
;
2457 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2458 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2462 if(unlikely(fld
->field_fixed
== -1)){
2463 size
= (int) ltt_type_size(LTT_GET_BO(tf
), type
);
2464 fld
->field_fixed
= 1;
2465 }else size
= fld
->field_size
;
2467 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2468 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2473 fld
->offset_root
= offsetRoot
;
2474 fld
->offset_parent
= offsetParent
;
2475 fld
->field_size
= size
;
2477 end_getFieldtypeSize
:
2483 /*****************************************************************************
2485 * ltt_get_int : get an integer number
2487 * reverse_byte_order: must we reverse the byte order ?
2488 * size : the size of the integer
2489 * ptr : the data pointer
2491 * gint64 : a 64 bits integer
2492 ****************************************************************************/
2494 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2499 case 1: val
= *((gint8
*)data
); break;
2500 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2501 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2502 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2503 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2504 g_critical("get_int : integer size %d unknown", size
);
2511 /*****************************************************************************
2513 * ltt_get_uint : get an unsigned integer number
2515 * reverse_byte_order: must we reverse the byte order ?
2516 * size : the size of the integer
2517 * ptr : the data pointer
2519 * guint64 : a 64 bits unsigned integer
2520 ****************************************************************************/
2522 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2527 case 1: val
= *((gint8
*)data
); break;
2528 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2529 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2530 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2531 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2532 g_critical("get_uint : unsigned integer size %d unknown",
2541 /* get the node name of the system */
2543 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2545 return s
->node_name
;
2549 /* get the domain name of the system */
2551 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2553 return s
->domain_name
;
2557 /* get the description of the system */
2559 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2561 return s
->description
;
2565 /* get the NTP corrected start time of the trace */
2566 LttTime
ltt_trace_start_time(LttTrace
*t
)
2568 return t
->start_time
;
2571 /* get the monotonic start time of the trace */
2572 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2574 return t
->start_time_from_tsc
;
2577 LttTracefile
*ltt_tracefile_new()
2579 return g_new(LttTracefile
, 1);
2582 void ltt_tracefile_destroy(LttTracefile
*tf
)
2587 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2592 /* Before library loading... */
2594 static void __attribute__((constructor
)) init(void)
2596 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2597 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2599 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");