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
);
271 struct ltt_trace_header_0_5
*vheader
=
272 (struct ltt_trace_header_0_5
*)header
;
273 tf
->buffer_header_size
=
274 sizeof(struct ltt_block_start_header
)
275 + sizeof(struct ltt_trace_header_0_5
);
277 t
->start_freq
= ltt_get_uint64(LTT_GET_BO(tf
),
278 &vheader
->start_freq
);
279 t
->start_tsc
= ltt_get_uint64(LTT_GET_BO(tf
),
280 &vheader
->start_tsc
);
281 t
->start_monotonic
= ltt_get_uint64(LTT_GET_BO(tf
),
282 &vheader
->start_monotonic
);
283 t
->start_time
.tv_sec
= ltt_get_uint64(LTT_GET_BO(tf
),
284 &vheader
->start_time_sec
);
285 t
->start_time
.tv_nsec
= ltt_get_uint64(LTT_GET_BO(tf
),
286 &vheader
->start_time_usec
);
287 t
->start_time
.tv_nsec
*= 1000; /* microsec to nanosec */
289 t
->start_time_from_tsc
= ltt_time_from_uint64(
290 (double)t
->start_tsc
* 1000000.0 / (double)t
->start_freq
);
295 g_warning("Unsupported trace version : %hhu.%hhu",
296 any
->major_version
, any
->minor_version
);
302 g_warning("Unsupported trace version : %hhu.%hhu",
303 any
->major_version
, any
->minor_version
);
313 /*****************************************************************************
315 * ltt_tracefile_open : open a trace file, construct a LttTracefile
317 * t : the trace containing the tracefile
318 * fileName : path name of the trace file
319 * tf : the tracefile structure
321 * : 0 for success, -1 otherwise.
322 ****************************************************************************/
324 gint
ltt_tracefile_open(LttTrace
*t
, gchar
* fileName
, LttTracefile
*tf
)
326 struct stat lTDFStat
; /* Trace data file status */
327 struct ltt_block_start_header
*header
;
328 int page_size
= getpagesize();
331 tf
->long_name
= g_quark_from_string(fileName
);
333 tf
->fd
= open(fileName
, O_RDONLY
);
335 g_warning("Unable to open input data file %s\n", fileName
);
339 // Get the file's status
340 if(fstat(tf
->fd
, &lTDFStat
) < 0){
341 g_warning("Unable to get the status of the input data file %s\n", fileName
);
345 // Is the file large enough to contain a trace
346 if(lTDFStat
.st_size
<
347 (off_t
)(sizeof(struct ltt_block_start_header
)
348 + sizeof(struct ltt_trace_header_any
))){
349 g_print("The input data file %s does not contain a trace\n", fileName
);
353 /* Temporarily map the buffer start header to get trace information */
354 /* Multiple of pages aligned head */
355 tf
->buffer
.head
= mmap(0,
356 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
357 + sizeof(struct ltt_trace_header_any
)), PROT_READ
,
358 MAP_PRIVATE
, tf
->fd
, 0);
359 if(tf
->buffer
.head
== MAP_FAILED
) {
360 perror("Error in allocating memory for buffer of tracefile");
363 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
365 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
367 if(parse_trace_header(header
->trace
, tf
, NULL
)) {
368 g_warning("parse_trace_header error");
372 //store the size of the file
373 tf
->file_size
= lTDFStat
.st_size
;
374 tf
->buf_size
= ltt_get_uint32(LTT_GET_BO(tf
), &header
->buf_size
);
375 tf
->num_blocks
= tf
->file_size
/ tf
->buf_size
;
377 if(munmap(tf
->buffer
.head
,
378 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
379 + sizeof(struct ltt_trace_header_any
)))) {
380 g_warning("unmap size : %u\n",
381 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
382 + sizeof(struct ltt_trace_header_any
)));
383 perror("munmap error");
386 tf
->buffer
.head
= NULL
;
388 //read the first block
389 if(map_block(tf
,0)) {
390 perror("Cannot map block for tracefile");
398 if(munmap(tf
->buffer
.head
,
399 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
400 + sizeof(struct ltt_trace_header_any
)))) {
401 g_warning("unmap size : %u\n",
402 PAGE_ALIGN(sizeof(struct ltt_block_start_header
)
403 + sizeof(struct ltt_trace_header_any
)));
404 perror("munmap error");
413 LttTrace
*ltt_tracefile_get_trace(LttTracefile
*tf
)
419 /*****************************************************************************
420 *Open control and per cpu tracefiles
421 ****************************************************************************/
423 void ltt_tracefile_open_cpu(LttTrace
*t
, gchar
* tracefile_name
)
426 tf
= ltt_tracefile_open(t
,tracefile_name
);
428 t
->per_cpu_tracefile_number
++;
429 g_ptr_array_add(t
->per_cpu_tracefiles
, tf
);
432 gint
ltt_tracefile_open_control(LttTrace
*t
, gchar
* control_name
)
441 tf
= ltt_tracefile_open(t
,control_name
);
443 g_warning("ltt_tracefile_open_control : bad file descriptor");
446 t
->control_tracefile_number
++;
447 g_ptr_array_add(t
->control_tracefiles
,tf
);
449 //parse facilities tracefile to get base_id
450 if(strcmp(&control_name
[strlen(control_name
)-10],"facilities") ==0){
452 if(!ltt_tracefile_read(tf
,&ev
)) return 0; // end of file
454 if(ev
.event_id
== TRACE_FACILITY_LOAD
){
456 fLoad
.name
= (gchar
*)pos
;
457 fLoad
.checksum
= *(LttChecksum
*)(pos
+ strlen(fLoad
.name
));
458 fLoad
.base_code
= *(guint32
*)(pos
+ strlen(fLoad
.name
) + sizeof(LttChecksum
));
460 for(i
=0;i
<t
->facility_number
;i
++){
461 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
,i
);
462 if(strcmp(f
->name
,fLoad
.name
)==0 && fLoad
.checksum
==f
->checksum
){
463 f
->base_id
= fLoad
.base_code
;
467 if(i
==t
->facility_number
) {
468 g_warning("Facility: %s, checksum: %u is not found",
469 fLoad
.name
,(unsigned int)fLoad
.checksum
);
472 }else if(ev
.event_id
== TRACE_BLOCK_START
){
474 }else if(ev
.event_id
== TRACE_BLOCK_END
){
477 g_warning("Not valid facilities trace file");
486 /*****************************************************************************
488 * ltt_tracefile_close: close a trace file,
490 * t : tracefile which will be closed
491 ****************************************************************************/
493 void ltt_tracefile_close(LttTracefile
*t
)
495 int page_size
= getpagesize();
497 if(t
->buffer
.head
!= NULL
)
498 if(munmap(t
->buffer
.head
, PAGE_ALIGN(t
->buf_size
))) {
499 g_warning("unmap size : %u\n",
500 PAGE_ALIGN(t
->buf_size
));
501 perror("munmap error");
509 /*****************************************************************************
510 *Get system information
511 ****************************************************************************/
513 gint
getSystemInfo(LttSystemDescription
* des
, gchar
* pathname
)
520 GMarkupParseContext
* context
;
521 GError
* error
= NULL
;
522 GMarkupParser markup_parser
=
524 parser_start_element
,
527 NULL
, /* passthrough */
531 fd
= g_open(pathname
, O_RDONLY
, 0);
533 g_warning("Can not open file : %s\n", pathname
);
537 iochan
= g_io_channel_unix_new(fd
);
539 context
= g_markup_parse_context_new(&markup_parser
, 0, des
,NULL
);
541 //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
542 while(g_io_channel_read_line(iochan
, &buf
, &length
, NULL
, &error
)
543 != G_IO_STATUS_EOF
) {
546 g_warning("Can not read xml file: \n%s\n", error
->message
);
549 if(!g_markup_parse_context_parse(context
, buf
, length
, &error
)){
551 g_warning("Can not parse xml file: \n%s\n", error
->message
);
554 g_markup_parse_context_free(context
);
556 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
558 g_warning("Can not close file: \n%s\n", error
->message
);
566 g_markup_parse_context_free(context
);
568 g_io_channel_shutdown(iochan
, FALSE
, &error
); /* No flush */
570 g_warning("Can not close file: \n%s\n", error
->message
);
581 /*****************************************************************************
582 *The following functions get facility/tracefile information
583 ****************************************************************************/
585 gint
getFacilityInfo(LttTrace
*t
, gchar
* eventdefs
)
592 gchar fullname
[DIR_NAME_SIZE
];
593 GError
* error
= NULL
;
595 dir
= g_dir_open(eventdefs
, 0, &error
);
598 g_warning("Can not open directory: %s, %s\n", eventdefs
, error
->message
);
603 while((name
= g_dir_read_name(dir
)) != NULL
){
604 if(!g_pattern_match_simple("*.xml", name
)) continue;
605 strcpy(fullname
,eventdefs
);
606 strcat(fullname
,name
);
607 ltt_facility_open(t
,fullname
);
611 for(j
=0;j
<t
->facility_number
;j
++){
612 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, j
);
613 for(i
=0; i
<f
->event_number
; i
++){
615 setFieldsOffset(NULL
, et
, NULL
, t
);
622 /*****************************************************************************
623 *A trace is specified as a pathname to the directory containing all the
624 *associated data (control tracefiles, per cpu tracefiles, event
627 *When a trace is closed, all the associated facilities, types and fields
628 *are released as well.
632 /****************************************************************************
633 * get_absolute_pathname
635 * return the unique pathname in the system
637 * MD : Fixed this function so it uses realpath, dealing well with
638 * forgotten cases (.. were not used correctly before).
640 ****************************************************************************/
641 void get_absolute_pathname(const gchar
*pathname
, gchar
* abs_pathname
)
643 abs_pathname
[0] = '\0';
645 if ( realpath (pathname
, abs_pathname
) != NULL
)
649 /* error, return the original path unmodified */
650 strcpy(abs_pathname
, pathname
);
656 /* Search for something like : .*_.*
658 * The left side is the name, the right side is the number.
661 int get_tracefile_name_number(const gchar
*raw_name
,
665 guint raw_name_len
= strlen(raw_name
);
666 gchar char_name
[PATH_MAX
];
672 for(i
=raw_name_len
-1;i
>=0;i
--) {
673 if(raw_name
[i
] == '_') break;
675 if(i
==0) /* Either not found or name length is 0 */
679 cpu_num
= strtol(raw_name
+underscore_pos
+1, &endptr
, 10);
681 if(endptr
== raw_name
+underscore_pos
+1)
682 return -1; /* No digit */
683 if(cpu_num
== LONG_MIN
|| cpu_num
== LONG_MAX
)
684 return -1; /* underflow / overflow */
686 strncpy(char_name
, raw_name
, underscore_pos
);
688 char_name
[underscore_pos
] = '\0';
690 *name
= g_quark_from_string(char_name
);
697 GData
**ltt_trace_get_tracefiles_groups(LttTrace
*trace
)
699 return &trace
->tracefiles
;
703 void compute_tracefile_group(GQuark key_id
,
705 struct compute_tracefile_group_args
*args
)
710 for(i
=0; i
<group
->len
; i
++) {
711 tf
= &g_array_index (group
, LttTracefile
, i
);
713 args
->func(tf
, args
->func_args
);
718 void ltt_tracefile_group_destroy(gpointer data
)
720 GArray
*group
= (GArray
*)data
;
724 for(i
=0; i
<group
->len
; i
++) {
725 tf
= &g_array_index (group
, LttTracefile
, i
);
727 ltt_tracefile_close(tf
);
729 g_array_free(group
, TRUE
);
732 gboolean
ltt_tracefile_group_has_cpu_online(gpointer data
)
734 GArray
*group
= (GArray
*)data
;
738 for(i
=0; i
<group
->len
; i
++) {
739 tf
= &g_array_index (group
, LttTracefile
, i
);
740 if(tf
->cpu_online
) return 1;
746 /* Open each tracefile under a specific directory. Put them in a
747 * GData : permits to access them using their tracefile group pathname.
748 * i.e. access control/modules tracefile group by index :
751 * relative path is the path relative to the trace root
752 * root path is the full path
754 * A tracefile group is simply an array where all the per cpu tracefiles sits.
757 static int open_tracefiles(LttTrace
*trace
, gchar
*root_path
,
758 gchar
*relative_path
)
760 DIR *dir
= opendir(root_path
);
761 struct dirent
*entry
;
762 struct stat stat_buf
;
765 gchar path
[PATH_MAX
];
770 gchar rel_path
[PATH_MAX
];
779 strncpy(path
, root_path
, PATH_MAX
-1);
780 path_len
= strlen(path
);
781 path
[path_len
] = '/';
783 path_ptr
= path
+ path_len
;
785 strncpy(rel_path
, relative_path
, PATH_MAX
-1);
786 rel_path_len
= strlen(rel_path
);
787 rel_path
[rel_path_len
] = '/';
789 rel_path_ptr
= rel_path
+ rel_path_len
;
791 while((entry
= readdir(dir
)) != NULL
) {
793 if(entry
->d_name
[0] == '.') continue;
795 strncpy(path_ptr
, entry
->d_name
, PATH_MAX
- path_len
);
796 strncpy(rel_path_ptr
, entry
->d_name
, PATH_MAX
- rel_path_len
);
798 ret
= stat(path
, &stat_buf
);
804 g_debug("Tracefile file or directory : %s\n", path
);
806 if(strcmp(rel_path
, "/eventdefs") == 0) continue;
808 if(S_ISDIR(stat_buf
.st_mode
)) {
810 g_debug("Entering subdirectory...\n");
811 ret
= open_tracefiles(trace
, path
, rel_path
);
812 if(ret
< 0) continue;
813 } else if(S_ISREG(stat_buf
.st_mode
)) {
818 if(get_tracefile_name_number(rel_path
, &name
, &num
))
819 continue; /* invalid name */
821 g_debug("Opening file.\n");
822 if(ltt_tracefile_open(trace
, path
, &tmp_tf
)) {
823 g_info("Error opening tracefile %s", path
);
825 continue; /* error opening the tracefile : bad magic number ? */
828 g_debug("Tracefile name is %s and number is %u",
829 g_quark_to_string(name
), num
);
831 tmp_tf
.cpu_online
= 1;
832 tmp_tf
.cpu_num
= num
;
835 group
= g_datalist_id_get_data(&trace
->tracefiles
, name
);
837 /* Elements are automatically cleared when the array is allocated.
838 * It makes the cpu_online variable set to 0 : cpu offline, by default.
840 group
= g_array_sized_new (FALSE
, TRUE
, sizeof(LttTracefile
), 10);
841 g_datalist_id_set_data_full(&trace
->tracefiles
, name
,
842 group
, ltt_tracefile_group_destroy
);
845 /* Add the per cpu tracefile to the named group */
846 unsigned int old_len
= group
->len
;
848 group
= g_array_set_size(group
, num
+1);
849 g_array_index (group
, LttTracefile
, num
) = tmp_tf
;
859 /* ltt_get_facility_description
861 * Opens the file corresponding to the requested facility (identified by fac_id
864 * The name searched is : %trace root%/eventdefs/facname_checksum.xml
866 * Returns 0 on success, or 1 on failure.
869 static int ltt_get_facility_description(LttFacility
*f
,
871 LttTracefile
*fac_tf
)
873 char desc_file_name
[PATH_MAX
];
878 text
= g_quark_to_string(t
->pathname
);
879 textlen
= strlen(text
);
881 if(textlen
>= PATH_MAX
) goto name_error
;
882 strcpy(desc_file_name
, text
);
884 text
= "/eventdefs/";
885 textlen
+=strlen(text
);
886 if(textlen
>= PATH_MAX
) goto name_error
;
887 strcat(desc_file_name
, text
);
889 text
= g_quark_to_string(f
->name
);
890 textlen
+=strlen(text
);
891 if(textlen
>= PATH_MAX
) goto name_error
;
892 strcat(desc_file_name
, text
);
895 textlen
+=strlen(text
);
896 if(textlen
>= PATH_MAX
) goto name_error
;
897 strcat(desc_file_name
, text
);
899 err
= snprintf(desc_file_name
+textlen
, PATH_MAX
-textlen
-1,
901 if(err
< 0) goto name_error
;
903 textlen
=strlen(desc_file_name
);
907 textlen
+=strlen(text
);
908 if(textlen
>= PATH_MAX
) goto name_error
;
909 strcat(desc_file_name
, text
);
911 err
= ltt_facility_open(f
, t
, desc_file_name
);
912 if(err
) goto facility_error
;
921 static void ltt_fac_ids_destroy(gpointer data
)
923 GArray
*fac_ids
= (GArray
*)data
;
925 g_array_free(fac_ids
, TRUE
);
929 /* Presumes the tracefile is already seeked at the beginning. It makes sense,
930 * because it must be done just after the opening */
931 static int ltt_process_facility_tracefile(LttTracefile
*tf
)
940 err
= ltt_tracefile_read_seek(tf
);
941 if(err
== EPERM
) goto seek_error
;
942 else if(err
== ERANGE
) break; /* End of tracefile */
944 err
= ltt_tracefile_read_update_event(tf
);
945 if(err
) goto update_error
;
947 /* We are on a facility load/or facility unload/ or heartbeat event */
949 * * facility 0 is hardcoded : this is the core facility. It will be shown
950 * in the facility array though, and is shown as "loaded builtin" in the
952 * It contains event :
954 * 1 : facility unload
955 * 2 : state dump facility load
958 if(tf
->event
.facility_id
!= LTT_FACILITY_CORE
) {
959 /* Should only contain core facility */
960 g_warning("Error in processing facility file %s, "
961 "should not contain facility id %u.", g_quark_to_string(tf
->name
),
962 tf
->event
.facility_id
);
967 struct LttFacilityLoad
*fac_load_data
;
968 struct LttStateDumpFacilityLoad
*fac_state_dump_load_data
;
972 switch((enum ltt_core_events
)tf
->event
.event_id
) {
973 case LTT_EVENT_FACILITY_LOAD
:
974 fac_name
= (char*)(tf
->event
.data
);
975 g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
978 (struct LttFacilityLoad
*)
979 (tf
->event
.data
+ strlen(fac_name
) + 1);
980 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
981 ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
));
982 /* facility may already exist if trace is paused/unpaused */
983 if(fac
->exists
) continue;
984 fac
->name
= g_quark_from_string(fac_name
);
985 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
986 &fac_load_data
->checksum
);
987 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
), &fac_load_data
->id
);
988 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
989 &fac_load_data
->pointer_size
);
990 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
991 &fac_load_data
->long_size
);
992 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
993 &fac_load_data
->size_t_size
);
994 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
995 &fac_load_data
->alignment
);
997 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
998 continue; /* error opening description */
1000 fac
->trace
= tf
->trace
;
1002 /* Preset the field offsets */
1003 for(i
=0; i
<fac
->events
->len
; i
++){
1004 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1005 set_fields_offsets(tf
, et
);
1010 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1012 if(fac_ids
== NULL
) {
1013 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1014 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1016 fac_ids
, ltt_fac_ids_destroy
);
1018 g_array_append_val(fac_ids
, fac
->id
);
1021 case LTT_EVENT_FACILITY_UNLOAD
:
1022 g_debug("Doing LTT_EVENT_FACILITY_UNLOAD");
1023 /* We don't care about unload : facilities ID are valid for the whole
1024 * trace. They simply won't be used after the unload. */
1026 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1027 fac_name
= (char*)(tf
->event
.data
);
1028 g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s",
1030 fac_state_dump_load_data
=
1031 (struct LttStateDumpFacilityLoad
*)
1032 (tf
->event
.data
+ strlen(fac_name
) + 1);
1033 fac
= &g_array_index (tf
->trace
->facilities_by_num
, LttFacility
,
1034 ltt_get_uint32(LTT_GET_BO(tf
), &fac_state_dump_load_data
->id
));
1035 /* facility may already exist if trace is paused/unpaused */
1036 if(fac
->exists
) continue;
1037 fac
->name
= g_quark_from_string(fac_name
);
1038 fac
->checksum
= ltt_get_uint32(LTT_GET_BO(tf
),
1039 &fac_state_dump_load_data
->checksum
);
1040 fac
->id
= ltt_get_uint32(LTT_GET_BO(tf
),
1041 &fac_state_dump_load_data
->id
);
1042 fac
->pointer_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1043 &fac_state_dump_load_data
->pointer_size
);
1044 fac
->long_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1045 &fac_state_dump_load_data
->long_size
);
1046 fac
->size_t_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1047 &fac_state_dump_load_data
->size_t_size
);
1048 fac
->alignment
= ltt_get_uint32(LTT_GET_BO(tf
),
1049 &fac_state_dump_load_data
->alignment
);
1050 if(ltt_get_facility_description(fac
, tf
->trace
, tf
))
1051 continue; /* error opening description */
1053 fac
->trace
= tf
->trace
;
1055 /* Preset the field offsets */
1056 for(i
=0; i
<fac
->events
->len
; i
++){
1057 et
= &g_array_index(fac
->events
, LttEventType
, i
);
1058 set_fields_offsets(tf
, et
);
1063 fac_ids
= g_datalist_id_get_data(&tf
->trace
->facilities_by_name
,
1065 if(fac_ids
== NULL
) {
1066 fac_ids
= g_array_sized_new (FALSE
, TRUE
, sizeof(guint
), 1);
1067 g_datalist_id_set_data_full(&tf
->trace
->facilities_by_name
,
1069 fac_ids
, ltt_fac_ids_destroy
);
1071 g_array_append_val(fac_ids
, fac
->id
);
1074 case LTT_EVENT_HEARTBEAT
:
1077 g_warning("Error in processing facility file %s, "
1078 "unknown event id %hhu in core facility.",
1079 g_quark_to_string(tf
->name
),
1080 tf
->event
.event_id
);
1082 goto event_id_error
;
1088 /* Error handling */
1093 g_warning("An error occured in facility tracefile parsing");
1098 LttTrace
*ltt_trace_open(const gchar
*pathname
)
1100 gchar abs_path
[PATH_MAX
];
1105 struct ltt_block_start_header
*header
;
1107 struct dirent
*entry
;
1108 guint control_found
= 0;
1109 guint eventdefs_found
= 0;
1110 struct stat stat_buf
;
1111 gchar path
[PATH_MAX
];
1113 t
= g_new(LttTrace
, 1);
1114 if(!t
) goto alloc_error
;
1116 get_absolute_pathname(pathname
, abs_path
);
1117 t
->pathname
= g_quark_from_string(abs_path
);
1119 g_datalist_init(&t
->tracefiles
);
1121 /* Test to see if it looks like a trace */
1122 dir
= opendir(abs_path
);
1127 while((entry
= readdir(dir
)) != NULL
) {
1128 strcpy(path
, abs_path
);
1130 strcat(path
, entry
->d_name
);
1131 ret
= stat(path
, &stat_buf
);
1136 if(S_ISDIR(stat_buf
.st_mode
)) {
1137 if(strcmp(entry
->d_name
, "control") == 0) {
1140 if(strcmp(entry
->d_name
, "eventdefs") == 0) {
1141 eventdefs_found
= 1;
1147 if(!control_found
|| !eventdefs_found
) goto find_error
;
1149 /* Open all the tracefiles */
1150 if(open_tracefiles(t
, abs_path
, "")) {
1151 g_warning("Error opening tracefile %s", abs_path
);
1155 /* Prepare the facilities containers : array and mapping */
1156 /* Array is zeroed : the "exists" field is set to false by default */
1157 t
->facilities_by_num
= g_array_sized_new (FALSE
,
1158 TRUE
, sizeof(LttFacility
),
1160 t
->facilities_by_num
= g_array_set_size(t
->facilities_by_num
, NUM_FACILITIES
);
1162 g_datalist_init(&t
->facilities_by_name
);
1164 /* Parse each trace control/facilitiesN files : get runtime fac. info */
1165 group
= g_datalist_id_get_data(&t
->tracefiles
, LTT_TRACEFILE_NAME_FACILITIES
);
1167 g_error("Trace %s has no facility tracefile", abs_path
);
1169 goto facilities_error
;
1172 /* Get the trace information for the control/facility 0 tracefile */
1173 g_assert(group
->len
> 0);
1174 tf
= &g_array_index (group
, LttTracefile
, 0);
1175 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1176 g_assert(parse_trace_header(header
->trace
,
1179 t
->num_cpu
= group
->len
;
1181 for(i
=0; i
<group
->len
; i
++) {
1182 tf
= &g_array_index (group
, LttTracefile
, i
);
1183 if(ltt_process_facility_tracefile(tf
))
1184 goto facilities_error
;
1189 /* Error handling */
1191 g_datalist_clear(&t
->facilities_by_name
);
1192 g_array_free(t
->facilities_by_num
, TRUE
);
1194 g_datalist_clear(&t
->tracefiles
);
1202 GQuark
ltt_trace_name(const LttTrace
*t
)
1208 /******************************************************************************
1209 * When we copy a trace, we want all the opening actions to happen again :
1210 * the trace will be reopened and totally independant from the original.
1211 * That's why we call ltt_trace_open.
1212 *****************************************************************************/
1213 LttTrace
*ltt_trace_copy(LttTrace
*self
)
1215 return ltt_trace_open(g_quark_to_string(self
->pathname
));
1218 void ltt_trace_close(LttTrace
*t
)
1223 for(i
=0; i
<t
->facilities_by_num
->len
; i
++) {
1224 fac
= &g_array_index (t
->facilities_by_num
, LttFacility
, i
);
1226 ltt_facility_close(fac
);
1229 g_datalist_clear(&t
->facilities_by_name
);
1230 g_array_free(t
->facilities_by_num
, TRUE
);
1231 g_datalist_clear(&t
->tracefiles
);
1236 /*****************************************************************************
1237 *Get the system description of the trace
1238 ****************************************************************************/
1240 LttFacility
*ltt_trace_facility_by_id(LttTrace
*t
, guint8 id
)
1242 g_assert(id
< t
->facilities_by_num
->len
);
1243 return &g_array_index(t
->facilities_by_num
, LttFacility
, id
);
1246 /* ltt_trace_facility_get_by_name
1248 * Returns the GArray of facility indexes. All the fac_ids that matches the
1249 * requested facility name.
1251 * If name is not found, returns NULL.
1253 GArray
*ltt_trace_facility_get_by_name(LttTrace
*t
, GQuark name
)
1255 return g_datalist_id_get_data(&t
->facilities_by_name
, name
);
1258 /*****************************************************************************
1259 * Functions to discover all the event types in the trace
1260 ****************************************************************************/
1263 unsigned ltt_trace_eventtype_number(LttTrace
*t
)
1267 unsigned int num
= t
->facility_number
;
1271 f
= (LttFacility
*)g_ptr_array_index(t
->facilities
, i
);
1272 count
+= f
->event_number
;
1279 //use an iteration on all the trace facilities, and inside iteration on all the
1280 //event types in each facilities instead.
1281 LttEventType
*ltt_trace_eventtype_get(LttTrace
*t
, unsigned evId
)
1283 LttEventType
*event_type
;
1286 f
= ltt_trace_facility_by_id(t
,evId
);
1288 if(unlikely(!f
)) event_type
= NULL
;
1289 else event_type
= f
->events
[evId
- f
->base_id
];
1296 /*****************************************************************************
1297 * ltt_trace_find_tracefile
1299 * Find a tracefile by name and index in the group.
1301 * Returns a pointer to the tracefiles, else NULL.
1302 ****************************************************************************/
1304 LttTracefile
*ltt_trace_find_tracefile(LttTrace
*t
, const gchar
*name
)
1309 /*****************************************************************************
1310 * Get the start time and end time of the trace
1311 ****************************************************************************/
1313 static void ltt_tracefile_time_span_get(LttTracefile
*tf
,
1314 LttTime
*start
, LttTime
*end
)
1318 err
= map_block(tf
, 0);
1320 g_error("Can not map block");
1321 *start
= ltt_time_infinite
;
1323 *start
= tf
->buffer
.begin
.timestamp
;
1325 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1327 g_error("Can not map block");
1328 *end
= ltt_time_zero
;
1330 *end
= tf
->buffer
.end
.timestamp
;
1333 struct tracefile_time_span_get_args
{
1339 static void group_time_span_get(GQuark name
, gpointer data
, gpointer user_data
)
1341 struct tracefile_time_span_get_args
*args
=
1342 (struct tracefile_time_span_get_args
*)user_data
;
1344 GArray
*group
= (GArray
*)data
;
1350 for(i
=0; i
<group
->len
; i
++) {
1351 tf
= &g_array_index (group
, LttTracefile
, i
);
1352 if(tf
->cpu_online
) {
1353 ltt_tracefile_time_span_get(tf
, &tmp_start
, &tmp_end
);
1354 if(ltt_time_compare(*args
->start
, tmp_start
)>0) *args
->start
= tmp_start
;
1355 if(ltt_time_compare(*args
->end
, tmp_end
)<0) *args
->end
= tmp_end
;
1360 void ltt_trace_time_span_get(LttTrace
*t
, LttTime
*start
, LttTime
*end
)
1362 LttTime min_start
= ltt_time_infinite
;
1363 LttTime max_end
= ltt_time_zero
;
1364 struct tracefile_time_span_get_args args
= { t
, &min_start
, &max_end
};
1366 g_datalist_foreach(&t
->tracefiles
, &group_time_span_get
, &args
);
1368 if(start
!= NULL
) *start
= min_start
;
1369 if(end
!= NULL
) *end
= max_end
;
1374 /*****************************************************************************
1375 *Get the name of a tracefile
1376 ****************************************************************************/
1378 GQuark
ltt_tracefile_name(const LttTracefile
*tf
)
1383 GQuark
ltt_tracefile_long_name(const LttTracefile
*tf
)
1385 return tf
->long_name
;
1390 guint
ltt_tracefile_num(LttTracefile
*tf
)
1395 /*****************************************************************************
1396 * Get the number of blocks in the tracefile
1397 ****************************************************************************/
1399 guint
ltt_tracefile_block_number(LttTracefile
*tf
)
1401 return tf
->num_blocks
;
1405 /* Seek to the first event in a tracefile that has a time equal or greater than
1406 * the time passed in parameter.
1408 * If the time parameter is outside the tracefile time span, seek to the first
1409 * event or if after, return ERANGE.
1411 * If the time parameter is before the first event, we have to seek specially to
1414 * If the time is after the end of the trace, return ERANGE.
1416 * Do a binary search to find the right block, then a sequential search in the
1417 * block to find the event.
1419 * In the special case where the time requested fits inside a block that has no
1420 * event corresponding to the requested time, the first event of the next block
1423 * IMPORTANT NOTE : // FIXME everywhere...
1425 * You MUST NOT do a ltt_tracefile_read right after a ltt_tracefile_seek_time :
1426 * you will jump over an event if you do.
1428 * Return value : 0 : no error, the tf->event can be used
1429 * ERANGE : time if after the last event of the trace
1430 * otherwise : this is an error.
1434 int ltt_tracefile_seek_time(LttTracefile
*tf
, LttTime time
)
1438 unsigned int block_num
, high
, low
;
1440 /* seek at the beginning of trace */
1441 err
= map_block(tf
, 0); /* First block */
1443 g_error("Can not map block");
1447 /* If the time is lower or equal the beginning of the trace,
1448 * go to the first event. */
1449 if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) <= 0) {
1450 ret
= ltt_tracefile_read(tf
);
1451 if(ret
== ERANGE
) goto range
;
1452 else if (ret
) goto fail
;
1453 goto found
; /* There is either no event in the trace or the event points
1454 to the first event in the trace */
1457 err
= map_block(tf
, tf
->num_blocks
- 1); /* Last block */
1459 g_error("Can not map block");
1463 /* If the time is after the end of the trace, return ERANGE. */
1464 if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1468 /* Binary search the block */
1469 high
= tf
->num_blocks
- 1;
1473 block_num
= ((high
-low
) / 2) + low
;
1475 err
= map_block(tf
, block_num
);
1477 g_error("Can not map block");
1481 /* We cannot divide anymore : this is what would happen if the time
1482 * requested was exactly between two consecutive buffers'end and start
1483 * timestamps. This is also what would happend if we didn't deal with out
1484 * of span cases prior in this function. */
1485 /* The event is right in the buffer!
1486 * (or in the next buffer first event) */
1488 ret
= ltt_tracefile_read(tf
);
1489 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1490 else if(ret
) goto fail
;
1492 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1496 } else if(ltt_time_compare(time
, tf
->buffer
.begin
.timestamp
) < 0) {
1497 /* go to lower part */
1498 high
= block_num
- 1;
1499 } else if(ltt_time_compare(time
, tf
->buffer
.end
.timestamp
) > 0) {
1500 /* go to higher part */
1501 low
= block_num
+ 1;
1502 } else {/* The event is right in the buffer!
1503 (or in the next buffer first event) */
1505 ret
= ltt_tracefile_read(tf
);
1506 if(ret
== ERANGE
) goto range
; /* ERANGE or EPERM */
1507 else if(ret
) goto fail
;
1509 if(ltt_time_compare(time
, tf
->event
.event_time
) <= 0)
1521 /* Error handling */
1523 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1524 g_quark_to_string(tf
->name
));
1529 int ltt_tracefile_seek_position(LttTracefile
*tf
, const LttEventPosition
*ep
) {
1533 if(ep
->tracefile
!= tf
) {
1537 err
= map_block(tf
, ep
->block
);
1539 g_error("Can not map block");
1543 tf
->event
.offset
= ep
->offset
;
1545 err
= ltt_tracefile_read_update_event(tf
);
1547 err
= ltt_tracefile_read_op(tf
);
1553 g_error("ltt_tracefile_seek_time failed on tracefile %s",
1554 g_quark_to_string(tf
->name
));
1558 /* Calculate the real event time based on the buffer boundaries */
1559 LttTime
ltt_interpolate_time(LttTracefile
*tf
, LttEvent
*event
)
1563 g_assert(tf
->trace
->has_tsc
);
1565 // time = ltt_time_from_uint64(
1566 // cycles_2_ns(tf, (guint64)(tf->buffer.tsc - tf->buffer.begin.cycle_count)));
1567 time
= ltt_time_from_uint64(
1568 (double)(tf
->buffer
.tsc
- tf
->trace
->start_tsc
) * 1000000.0
1569 / (double)tf
->trace
->start_freq
);
1570 //time = ltt_time_add(tf->buffer.begin.timestamp, time);
1571 time
= ltt_time_add(tf
->trace
->start_time_from_tsc
, time
);
1577 /* Get the current event of the tracefile : valid until the next read */
1578 LttEvent
*ltt_tracefile_get_event(LttTracefile
*tf
)
1585 /*****************************************************************************
1587 * ltt_tracefile_read : Read the next event in the tracefile
1592 * Returns 0 if an event can be used in tf->event.
1593 * Returns ERANGE on end of trace. The event in tf->event still can be used
1594 * (if the last block was not empty).
1595 * Returns EPERM on error.
1597 * This function does make the tracefile event structure point to the event
1598 * currently pointed to by the tf->event.
1600 * Note : you must call a ltt_tracefile_seek to the beginning of the trace to
1601 * reinitialize it after an error if you want results to be coherent.
1602 * It would be the case if a end of trace last buffer has no event : the end
1603 * of trace wouldn't be returned, but an error.
1604 * We make the assumption there is at least one event per buffer.
1605 ****************************************************************************/
1607 int ltt_tracefile_read(LttTracefile
*tf
)
1611 err
= ltt_tracefile_read_seek(tf
);
1613 err
= ltt_tracefile_read_update_event(tf
);
1615 err
= ltt_tracefile_read_op(tf
);
1621 int ltt_tracefile_read_seek(LttTracefile
*tf
)
1625 /* Get next buffer until we finally have an event, or end of trace */
1627 err
= ltt_seek_next_event(tf
);
1628 if(unlikely(err
== ENOPROTOOPT
)) {
1632 /* Are we at the end of the buffer ? */
1634 if(unlikely(tf
->buffer
.index
== tf
->num_blocks
-1)){ /* end of trace ? */
1637 /* get next block */
1638 err
= map_block(tf
, tf
->buffer
.index
+ 1);
1640 g_error("Can not map block");
1644 } else break; /* We found an event ! */
1651 /* do specific operation on events */
1652 int ltt_tracefile_read_op(LttTracefile
*tf
)
1658 /* do event specific operation */
1660 /* do something if its an heartbeat event : increment the heartbeat count */
1661 //if(event->facility_id == LTT_FACILITY_CORE)
1662 // if(event->event_id == LTT_EVENT_HEARTBEAT)
1663 // tf->cur_heart_beat_number++;
1669 /* same as ltt_tracefile_read, but does not seek to the next event nor call
1670 * event specific operation. */
1671 int ltt_tracefile_read_update_event(LttTracefile
*tf
)
1677 pos
= tf
->buffer
.head
+ event
->offset
;
1679 /* Read event header */
1683 if(tf
->trace
->has_tsc
) {
1684 if(tf
->trace
->has_heartbeat
) {
1685 event
->time
.timestamp
= ltt_get_uint32(LTT_GET_BO(tf
),
1687 /* 32 bits -> 64 bits tsc */
1688 /* note : still works for seek and non seek cases. */
1689 if(event
->time
.timestamp
< (0xFFFFFFFFULL
&tf
->buffer
.tsc
)) {
1690 tf
->buffer
.tsc
= ((tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1692 | (guint64
)event
->time
.timestamp
;
1693 event
->tsc
= tf
->buffer
.tsc
;
1696 tf
->buffer
.tsc
= (tf
->buffer
.tsc
&0xFFFFFFFF00000000ULL
)
1697 | (guint64
)event
->time
.timestamp
;
1698 event
->tsc
= tf
->buffer
.tsc
;
1700 pos
+= sizeof(guint32
);
1702 event
->tsc
= ltt_get_uint64(LTT_GET_BO(tf
), pos
);
1703 tf
->buffer
.tsc
= event
->tsc
;
1704 pos
+= sizeof(guint64
);
1707 event
->event_time
= ltt_interpolate_time(tf
, event
);
1709 event
->time
.delta
.tv_sec
= 0;
1710 event
->time
.delta
.tv_nsec
= ltt_get_uint32(LTT_GET_BO(tf
),
1711 pos
) * NSEC_PER_USEC
;
1713 event
->tsc
= tf
->buffer
.tsc
;
1715 event
->event_time
= ltt_time_add(tf
->buffer
.begin
.timestamp
,
1717 pos
+= sizeof(guint32
);
1720 event
->facility_id
= *(guint8
*)pos
;
1721 pos
+= sizeof(guint8
);
1723 event
->event_id
= *(guint8
*)pos
;
1724 pos
+= sizeof(guint8
);
1726 event
->event_size
= ltt_get_uint16(LTT_GET_BO(tf
), pos
);
1727 pos
+= sizeof(guint16
);
1731 /* get the data size and update the event fields with the current
1733 ltt_update_event_size(tf
);
1739 /****************************************************************************
1741 * map_block : map a block from the file
1743 * lttdes : ltt trace file
1744 * whichBlock : the block which will be read
1747 * EINVAL : lseek fail
1748 * EIO : can not read from the file
1749 ****************************************************************************/
1751 static gint
map_block(LttTracefile
* tf
, guint block_num
)
1753 int page_size
= getpagesize();
1754 struct ltt_block_start_header
*header
;
1756 g_assert(block_num
< tf
->num_blocks
);
1758 if(tf
->buffer
.head
!= NULL
) {
1759 if(munmap(tf
->buffer
.head
, PAGE_ALIGN(tf
->buf_size
))) {
1760 g_warning("unmap size : %u\n",
1761 PAGE_ALIGN(tf
->buf_size
));
1762 perror("munmap error");
1768 /* Multiple of pages aligned head */
1769 tf
->buffer
.head
= mmap(0,
1770 PAGE_ALIGN(tf
->buf_size
),
1771 PROT_READ
, MAP_PRIVATE
, tf
->fd
,
1772 PAGE_ALIGN((off_t
)tf
->buf_size
* (off_t
)block_num
));
1774 if(tf
->buffer
.head
== MAP_FAILED
) {
1775 perror("Error in allocating memory for buffer of tracefile");
1779 g_assert( ( (guint
)tf
->buffer
.head
&(8-1) ) == 0); // make sure it's aligned.
1782 tf
->buffer
.index
= block_num
;
1784 header
= (struct ltt_block_start_header
*)tf
->buffer
.head
;
1787 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1788 ltt_time_from_uint64(
1789 ltt_get_uint64(LTT_GET_BO(tf
),
1790 &header
->begin
.timestamp
)
1791 - tf
->trace
->start_monotonic
),
1792 tf
->trace
->start_time
);
1794 //g_debug("block %u begin : %lu.%lu", block_num,
1795 // tf->buffer.begin.timestamp.tv_sec, tf->buffer.begin.timestamp.tv_nsec);
1796 tf
->buffer
.begin
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1797 &header
->begin
.cycle_count
);
1798 tf
->buffer
.begin
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1799 &header
->begin
.freq
);
1800 tf
->buffer
.begin
.timestamp
= ltt_time_add(
1801 ltt_time_from_uint64(
1802 (double)(tf
->buffer
.begin
.cycle_count
1803 - tf
->trace
->start_tsc
) * 1000000.0
1804 / (double)tf
->trace
->start_freq
),
1805 tf
->trace
->start_time_from_tsc
);
1808 tf
->buffer
.end
.timestamp
= ltt_time_add(
1809 ltt_time_from_uint64(
1810 ltt_get_uint64(LTT_GET_BO(tf
),
1811 &header
->end
.timestamp
)
1812 - tf
->trace
->start_monotonic
),
1813 tf
->trace
->start_time
);
1815 //g_debug("block %u end : %lu.%lu", block_num,
1816 // tf->buffer.end.timestamp.tv_sec, tf->buffer.end.timestamp.tv_nsec);
1817 tf
->buffer
.end
.cycle_count
= ltt_get_uint64(LTT_GET_BO(tf
),
1818 &header
->end
.cycle_count
);
1819 tf
->buffer
.end
.freq
= ltt_get_uint64(LTT_GET_BO(tf
),
1821 tf
->buffer
.lost_size
= ltt_get_uint32(LTT_GET_BO(tf
),
1822 &header
->lost_size
);
1823 tf
->buffer
.end
.timestamp
= ltt_time_add(
1824 ltt_time_from_uint64(
1825 (double)(tf
->buffer
.end
.cycle_count
1826 - tf
->trace
->start_tsc
) * 1000000.0
1827 / (double)tf
->trace
->start_freq
),
1828 tf
->trace
->start_time_from_tsc
);
1830 tf
->buffer
.tsc
= tf
->buffer
.begin
.cycle_count
;
1831 tf
->event
.tsc
= tf
->buffer
.tsc
;
1832 tf
->buffer
.freq
= tf
->buffer
.begin
.freq
;
1835 * eventually support variable buffer size : will need a partial pre-read of
1836 * the headers to create an index when we open the trace... eventually. */
1837 g_assert(tf
->buf_size
== ltt_get_uint32(LTT_GET_BO(tf
),
1838 &header
->buf_size
));
1840 /* Now that the buffer is mapped, calculate the time interpolation for the
1843 // tf->buffer.nsecs_per_cycle = calc_nsecs_per_cycle(tf);
1844 //tf->buffer.cyc2ns_scale = calc_nsecs_per_cycle(tf);
1846 /* Make the current event point to the beginning of the buffer :
1847 * it means that the event read must get the first event. */
1848 tf
->event
.tracefile
= tf
;
1849 tf
->event
.block
= block_num
;
1850 tf
->event
.offset
= 0;
1859 /* It will update the fields offsets too */
1860 void ltt_update_event_size(LttTracefile
*tf
)
1864 /* Specific handling of core events : necessary to read the facility control
1866 LttFacility
*f
= ltt_trace_get_facility_by_num(tf
->trace
,
1867 tf
->event
.facility_id
);
1869 if(likely(tf
->event
.facility_id
== LTT_FACILITY_CORE
)) {
1870 switch((enum ltt_core_events
)tf
->event
.event_id
) {
1871 case LTT_EVENT_FACILITY_LOAD
:
1872 size
= strlen((char*)tf
->event
.data
) + 1;
1873 //g_debug("Update Event facility load of facility %s", (char*)tf->event.data);
1874 size
+= sizeof(struct LttFacilityLoad
);
1876 case LTT_EVENT_FACILITY_UNLOAD
:
1877 //g_debug("Update Event facility unload");
1878 size
= sizeof(struct LttFacilityUnload
);
1880 case LTT_EVENT_STATE_DUMP_FACILITY_LOAD
:
1881 size
= strlen((char*)tf
->event
.data
) + 1;
1882 //g_debug("Update Event facility load state dump of facility %s",
1883 // (char*)tf->event.data);
1884 size
+= sizeof(struct LttStateDumpFacilityLoad
);
1886 case LTT_EVENT_HEARTBEAT
:
1887 //g_debug("Update Event heartbeat");
1888 size
= sizeof(TimeHeartbeat
);
1891 g_warning("Error in getting event size : tracefile %s, "
1892 "unknown event id %hhu in core facility.",
1893 g_quark_to_string(tf
->name
),
1894 tf
->event
.event_id
);
1895 goto event_id_error
;
1900 g_error("Unknown facility %hhu (0x%hhx) in tracefile %s",
1901 tf
->event
.facility_id
,
1902 tf
->event
.facility_id
,
1903 g_quark_to_string(tf
->name
));
1904 goto facility_error
;
1907 LttEventType
*event_type
=
1908 ltt_facility_eventtype_get(f
, tf
->event
.event_id
);
1911 g_error("Unknown event id %hhu in facility %s in tracefile %s",
1913 g_quark_to_string(f
->name
),
1914 g_quark_to_string(tf
->name
));
1915 goto event_type_error
;
1918 if(event_type
->root_field
)
1919 size
= get_field_type_size(tf
, event_type
,
1920 0, 0, event_type
->root_field
, tf
->event
.data
);
1924 //g_debug("Event root field : f.e %hhu.%hhu size %zd",
1925 // tf->event.facility_id,
1926 // tf->event.event_id, size);
1929 tf
->event
.data_size
= size
;
1931 /* Check consistency between kernel and LTTV structure sizes */
1932 g_assert(tf
->event
.data_size
== tf
->event
.event_size
);
1939 tf
->event
.data_size
= 0;
1943 /* Take the tf current event offset and use the event facility id and event id
1944 * to figure out where is the next event offset.
1946 * This is an internal function not aiming at being used elsewhere : it will
1947 * not jump over the current block limits. Please consider using
1948 * ltt_tracefile_read to do this.
1950 * Returns 0 on success
1951 * ERANGE if we are at the end of the buffer.
1952 * ENOPROTOOPT if an error occured when getting the current event size.
1954 static int ltt_seek_next_event(LttTracefile
*tf
)
1959 /* seek over the buffer header if we are at the buffer start */
1960 if(tf
->event
.offset
== 0) {
1961 tf
->event
.offset
+= tf
->buffer_header_size
;
1963 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1970 pos
= tf
->event
.data
;
1972 if(tf
->event
.data_size
< 0) goto error
;
1974 pos
+= (size_t)tf
->event
.data_size
;
1976 tf
->event
.offset
= pos
- tf
->buffer
.head
;
1978 if(tf
->event
.offset
== tf
->buf_size
- tf
->buffer
.lost_size
) {
1982 g_assert(tf
->event
.offset
< tf
->buf_size
- tf
->buffer
.lost_size
);
1988 g_error("Error in ltt_seek_next_event for tracefile %s",
1989 g_quark_to_string(tf
->name
));
1994 /*****************************************************************************
1996 * calc_nsecs_per_cycle : calculate nsecs per cycle for current block
1998 * 1.0 / (freq(khz) *1000) * 1000000000
2001 ****************************************************************************/
2002 /* from timer_tsc.c */
2003 #define CYC2NS_SCALE_FACTOR 10
2004 static guint32
calc_nsecs_per_cycle(LttTracefile
* tf
)
2006 //return 1e6 / (double)tf->buffer.freq;
2007 guint32 cpu_mhz
= tf
->buffer
.freq
/ 1000;
2008 guint32 cyc2ns_scale
= (1000 << CYC2NS_SCALE_FACTOR
)/cpu_mhz
;
2010 return cyc2ns_scale
;
2011 // return 1e6 / (double)tf->buffer.freq;
2014 static guint64
cycles_2_ns(LttTracefile
*tf
, guint64 cycles
)
2016 return (cycles
* tf
->buffer
.cyc2ns_scale
) >> CYC2NS_SCALE_FACTOR
;
2021 void setFieldsOffset(LttTracefile
*tf
, LttEventType
*evT
,void *evD
)
2023 LttField
* rootFld
= evT
->root_field
;
2024 // rootFld->base_address = evD;
2027 rootFld
->field_size
= getFieldtypeSize(tf
, evT
->facility
,
2028 evT
, 0,0,rootFld
, evD
);
2032 /*****************************************************************************
2034 * set_fields_offsets : set the precomputable offset of the fields
2036 * tracefile : opened trace file
2037 * event_type : the event type
2038 ****************************************************************************/
2040 void set_fields_offsets(LttTracefile
*tf
, LttEventType
*event_type
)
2042 LttField
*field
= event_type
->root_field
;
2043 enum field_status fixed_root
= FIELD_FIXED
, fixed_parent
= FIELD_FIXED
;
2046 preset_field_type_size(tf
, event_type
, 0, 0,
2047 &fixed_root
, &fixed_parent
,
2053 /*****************************************************************************
2055 * preset_field_type_size : set the fixed sizes of the field type
2058 * event_type : event type
2059 * offset_root : offset from the root
2060 * offset_parent : offset from the parent
2061 * fixed_root : Do we know a fixed offset to the root ?
2062 * fixed_parent : Do we know a fixed offset to the parent ?
2064 ****************************************************************************/
2065 void preset_field_type_size(LttTracefile
*tf
, LttEventType
*event_type
,
2066 off_t offset_root
, off_t offset_parent
,
2067 enum field_status
*fixed_root
, enum field_status
*fixed_parent
,
2070 enum field_status local_fixed_root
, local_fixed_parent
;
2074 g_assert(field
->fixed_root
== FIELD_UNKNOWN
);
2075 g_assert(field
->fixed_parent
== FIELD_UNKNOWN
);
2076 g_assert(field
->fixed_size
== FIELD_UNKNOWN
);
2078 type
= field
->field_type
;
2080 field
->fixed_root
= *fixed_root
;
2081 if(field
->fixed_root
== FIELD_FIXED
)
2082 field
->offset_root
= offset_root
;
2084 field
->offset_root
= 0;
2086 field
->fixed_parent
= *fixed_parent
;
2087 if(field
->fixed_parent
== FIELD_FIXED
)
2088 field
->offset_parent
= offset_parent
;
2090 field
->offset_parent
= 0;
2092 size_t current_root_offset
;
2093 size_t current_offset
;
2094 enum field_status current_child_status
, final_child_status
;
2097 switch(type
->type_class
) {
2102 field
->field_size
= ltt_type_size(tf
->trace
, type
);
2103 field
->fixed_size
= FIELD_FIXED
;
2106 field
->field_size
= (off_t
)event_type
->facility
->pointer_size
;
2107 field
->fixed_size
= FIELD_FIXED
;
2111 field
->field_size
= (off_t
)event_type
->facility
->long_size
;
2112 field
->fixed_size
= FIELD_FIXED
;
2117 field
->field_size
= (off_t
)event_type
->facility
->size_t_size
;
2118 field
->fixed_size
= FIELD_FIXED
;
2121 local_fixed_root
= FIELD_VARIABLE
;
2122 local_fixed_parent
= FIELD_VARIABLE
;
2123 preset_field_type_size(tf
, event_type
,
2125 &local_fixed_root
, &local_fixed_parent
,
2127 field
->fixed_size
= FIELD_VARIABLE
;
2128 field
->field_size
= 0;
2129 *fixed_root
= FIELD_VARIABLE
;
2130 *fixed_parent
= FIELD_VARIABLE
;
2133 field
->fixed_size
= FIELD_VARIABLE
;
2134 field
->field_size
= 0;
2135 *fixed_root
= FIELD_VARIABLE
;
2136 *fixed_parent
= FIELD_VARIABLE
;
2139 local_fixed_root
= FIELD_VARIABLE
;
2140 local_fixed_parent
= FIELD_VARIABLE
;
2141 preset_field_type_size(tf
, event_type
,
2143 &local_fixed_root
, &local_fixed_parent
,
2145 field
->fixed_size
= field
->child
[0]->fixed_size
;
2146 if(field
->fixed_size
== FIELD_FIXED
) {
2147 field
->field_size
= type
->element_number
* field
->child
[0]->field_size
;
2149 field
->field_size
= 0;
2150 *fixed_root
= FIELD_VARIABLE
;
2151 *fixed_parent
= FIELD_VARIABLE
;
2155 current_root_offset
= field
->offset_root
;
2157 current_child_status
= FIELD_FIXED
;
2158 for(i
=0;i
<type
->element_number
;i
++) {
2159 preset_field_type_size(tf
, event_type
,
2160 current_root_offset
, current_offset
,
2161 fixed_root
, ¤t_child_status
,
2163 if(current_child_status
== FIELD_FIXED
) {
2164 current_root_offset
+= field
->child
[i
]->field_size
;
2165 current_offset
+= field
->child
[i
]->field_size
;
2167 current_root_offset
= 0;
2171 if(current_child_status
!= FIELD_FIXED
) {
2172 *fixed_parent
= current_child_status
;
2173 field
->field_size
= 0;
2174 field
->fixed_size
= current_child_status
;
2176 field
->field_size
= current_offset
;
2177 field
->fixed_size
= FIELD_FIXED
;
2181 current_root_offset
= field
->offset_root
;
2184 final_child_status
= FIELD_FIXED
;
2185 for(i
=0;i
<type
->element_number
;i
++) {
2186 enum field_status current_root_child_status
= FIELD_FIXED
;
2187 enum field_status current_child_status
= FIELD_FIXED
;
2188 preset_field_type_size(tf
, event_type
,
2189 current_root_offset
, current_offset
,
2190 ¤t_root_child_status
, ¤t_child_status
,
2192 if(current_child_status
!= FIELD_FIXED
)
2193 final_child_status
= current_child_status
;
2195 max_size
= max(max_size
, field
->child
[i
]->field_size
);
2197 if(final_child_status
!= FIELD_FIXED
) {
2198 *fixed_root
= final_child_status
;
2199 *fixed_parent
= final_child_status
;
2200 field
->field_size
= 0;
2201 field
->fixed_size
= current_child_status
;
2203 field
->field_size
= max_size
;
2204 field
->fixed_size
= FIELD_FIXED
;
2212 /*****************************************************************************
2214 * check_fields_compatibility : Check for compatibility between two fields :
2215 * do they use the same inner structure ?
2217 * event_type1 : event type
2218 * event_type2 : event type
2221 *Returns : 0 if identical
2223 ****************************************************************************/
2224 gint
check_fields_compatibility(LttEventType
*event_type1
,
2225 LttEventType
*event_type2
,
2226 LttField
*field1
, LttField
*field2
)
2228 guint different
= 0;
2233 if(field1
== NULL
) {
2234 if(field2
== NULL
) goto end
;
2239 } else if(field2
== NULL
) {
2244 g_assert(field1
->fixed_root
!= FIELD_UNKNOWN
);
2245 g_assert(field2
->fixed_root
!= FIELD_UNKNOWN
);
2246 g_assert(field1
->fixed_parent
!= FIELD_UNKNOWN
);
2247 g_assert(field2
->fixed_parent
!= FIELD_UNKNOWN
);
2248 g_assert(field1
->fixed_size
!= FIELD_UNKNOWN
);
2249 g_assert(field2
->fixed_size
!= FIELD_UNKNOWN
);
2251 type1
= field1
->field_type
;
2252 type2
= field2
->field_type
;
2254 if(type1
->type_class
!= type2
->type_class
) {
2258 if(type1
->element_name
!= type2
->element_name
) {
2263 switch(type1
->type_class
) {
2273 if(field1
->field_size
!= field2
->field_size
) {
2279 if(type1
->element_number
!= type2
->element_number
) {
2283 for(i
=0;i
<type1
->element_number
;i
++) {
2284 if(type1
->enum_strings
[i
] != type2
->enum_strings
[i
]) {
2291 /* Two elements : size and child */
2292 g_assert(type1
->element_number
!= type2
->element_number
);
2293 for(i
=0;i
<type1
->element_number
;i
++) {
2294 if(check_fields_compatibility(event_type1
, event_type2
,
2295 field1
->child
[0], field2
->child
[0])) {
2304 if(field1
->field_size
!= field2
->field_size
) {
2308 /* Two elements : size and child */
2309 g_assert(type1
->element_number
!= type2
->element_number
);
2310 for(i
=0;i
<type1
->element_number
;i
++) {
2311 if(check_fields_compatibility(event_type1
, event_type2
,
2312 field1
->child
[0], field2
->child
[0])) {
2320 if(type1
->element_number
!= type2
->element_number
) {
2324 for(i
=0;i
<type1
->element_number
;i
++) {
2325 if(check_fields_compatibility(event_type1
, event_type2
,
2326 field1
->child
[0], field2
->child
[0])) {
2341 /*****************************************************************************
2343 * getFieldtypeSize: get the size of the field type (primitive type)
2346 * offsetRoot : offset from the root
2347 * offsetParent : offset from the parrent
2349 * evD : event data, it may be NULL
2351 * int : size of the field
2352 ****************************************************************************/
2354 static inline gint
getFieldtypeSize(LttTracefile
*tf
,
2355 LttEventType
* evT
, gint offsetRoot
,
2356 gint offsetParent
, LttField
* fld
, void *evD
)
2358 gint size
, size1
, element_number
, i
, offset1
, offset2
;
2359 LttType
* type
= fld
->field_type
;
2361 /* This likely has been tested with gcov : half of them.. */
2362 if(unlikely(fld
->field_fixed
== 1)){
2364 if(unlikely(fld
== evT
->root_field
)) {
2365 size
= fld
->field_size
;
2366 goto end_getFieldtypeSize
;
2370 /* From gcov profiling : half string, half struct, can we gain something
2371 * from that ? (Mathieu) */
2372 switch(type
->type_class
) {
2374 element_number
= (int) type
->element_number
;
2375 if(fld
->field_fixed
== -1){
2376 size
= getFieldtypeSize(tf
, evT
, offsetRoot
,
2377 0,fld
->child
[0], NULL
);
2378 if(size
== 0){ //has string or sequence
2379 fld
->field_fixed
= 0;
2381 fld
->field_fixed
= 1;
2382 size
*= element_number
;
2384 }else if(fld
->field_fixed
== 0){// has string or sequence
2386 for(i
=0;i
<element_number
;i
++){
2387 size
+= getFieldtypeSize(tf
, evT
, offsetRoot
+size
,size
,
2388 fld
->child
[0], evD
+size
);
2390 }else size
= fld
->field_size
;
2392 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2393 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2399 size1
= (int) ltt_type_size(fac
, type
);
2400 if(fld
->field_fixed
== -1){
2401 fld
->sequ_number_size
= size1
;
2402 fld
->field_fixed
= 0;
2403 size
= getFieldtypeSize(evT
, offsetRoot
,
2404 0,fld
->child
[0], NULL
);
2405 fld
->element_size
= size
;
2407 element_number
= getIntNumber(tf
,size1
,evD
);
2408 type
->element_number
= element_number
;
2409 if(fld
->element_size
> 0){
2410 size
= element_number
* fld
->element_size
;
2411 }else{//sequence has string or sequence
2413 for(i
=0;i
<element_number
;i
++){
2414 size
+= getFieldtypeSize(tf
, evT
,
2415 offsetRoot
+size
+size1
,size
+size1
,
2416 fld
->child
[0], evD
+size
+size1
);
2422 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2423 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2430 if(fld
->field_fixed
== -1){
2431 fld
->field_fixed
= 0;
2433 /* Hope my implementation is faster than strlen (Mathieu) */
2434 char *ptr
=(char*)evD
;
2436 /* from gcov : many many strings are empty, make it the common case.*/
2437 while(unlikely(*ptr
!= '\0')) { size
++; ptr
++; }
2438 //size = ptr - (char*)evD + 1; //include end : '\0'
2440 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2441 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2446 element_number
= (int) type
->element_number
;
2448 /* tested with gcov */
2449 if(unlikely(fld
->field_fixed
== -1)){
2450 offset1
= offsetRoot
;
2452 for(i
=0;i
<element_number
;i
++){
2453 size1
=getFieldtypeSize(tf
, evT
,offset1
,offset2
,
2454 fld
->child
[i
], NULL
);
2455 if(likely(size1
> 0 && size
>= 0)){
2457 if(likely(offset1
>= 0)) offset1
+= size1
;
2465 if(unlikely(size
== -1)){
2466 fld
->field_fixed
= 0;
2468 }else fld
->field_fixed
= 1;
2469 }else if(likely(fld
->field_fixed
== 0)){
2470 offset1
= offsetRoot
;
2472 for(i
=0;unlikely(i
<element_number
);i
++){
2473 size
=getFieldtypeSize(tf
, evT
, offset1
, offset2
,
2474 fld
->child
[i
], evD
+offset2
);
2479 }else size
= fld
->field_size
;
2480 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2481 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2485 if(unlikely(fld
->field_fixed
== -1)){
2486 size
= (int) ltt_type_size(LTT_GET_BO(tf
), type
);
2487 fld
->field_fixed
= 1;
2488 }else size
= fld
->field_size
;
2490 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
2491 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
2496 fld
->offset_root
= offsetRoot
;
2497 fld
->offset_parent
= offsetParent
;
2498 fld
->field_size
= size
;
2500 end_getFieldtypeSize
:
2506 /*****************************************************************************
2508 * ltt_get_int : get an integer number
2510 * reverse_byte_order: must we reverse the byte order ?
2511 * size : the size of the integer
2512 * ptr : the data pointer
2514 * gint64 : a 64 bits integer
2515 ****************************************************************************/
2517 gint64
ltt_get_int(gboolean reverse_byte_order
, gint size
, void *data
)
2522 case 1: val
= *((gint8
*)data
); break;
2523 case 2: val
= ltt_get_int16(reverse_byte_order
, data
); break;
2524 case 4: val
= ltt_get_int32(reverse_byte_order
, data
); break;
2525 case 8: val
= ltt_get_int64(reverse_byte_order
, data
); break;
2526 default: val
= ltt_get_int64(reverse_byte_order
, data
);
2527 g_critical("get_int : integer size %d unknown", size
);
2534 /*****************************************************************************
2536 * ltt_get_uint : get an unsigned integer number
2538 * reverse_byte_order: must we reverse the byte order ?
2539 * size : the size of the integer
2540 * ptr : the data pointer
2542 * guint64 : a 64 bits unsigned integer
2543 ****************************************************************************/
2545 guint64
ltt_get_uint(gboolean reverse_byte_order
, gint size
, void *data
)
2550 case 1: val
= *((gint8
*)data
); break;
2551 case 2: val
= ltt_get_uint16(reverse_byte_order
, data
); break;
2552 case 4: val
= ltt_get_uint32(reverse_byte_order
, data
); break;
2553 case 8: val
= ltt_get_uint64(reverse_byte_order
, data
); break;
2554 default: val
= ltt_get_uint64(reverse_byte_order
, data
);
2555 g_critical("get_uint : unsigned integer size %d unknown",
2564 /* get the node name of the system */
2566 char * ltt_trace_system_description_node_name (LttSystemDescription
* s
)
2568 return s
->node_name
;
2572 /* get the domain name of the system */
2574 char * ltt_trace_system_description_domain_name (LttSystemDescription
* s
)
2576 return s
->domain_name
;
2580 /* get the description of the system */
2582 char * ltt_trace_system_description_description (LttSystemDescription
* s
)
2584 return s
->description
;
2588 /* get the NTP corrected start time of the trace */
2589 LttTime
ltt_trace_start_time(LttTrace
*t
)
2591 return t
->start_time
;
2594 /* get the monotonic start time of the trace */
2595 LttTime
ltt_trace_start_time_monotonic(LttTrace
*t
)
2597 return t
->start_time_from_tsc
;
2600 LttTracefile
*ltt_tracefile_new()
2602 return g_new(LttTracefile
, 1);
2605 void ltt_tracefile_destroy(LttTracefile
*tf
)
2610 void ltt_tracefile_copy(LttTracefile
*dest
, const LttTracefile
*src
)
2615 /* Before library loading... */
2617 static void __attribute__((constructor
)) init(void)
2619 LTT_FACILITY_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2620 LTT_EVENT_NAME_HEARTBEAT
= g_quark_from_string("heartbeat");
2622 LTT_TRACEFILE_NAME_FACILITIES
= g_quark_from_string("/control/facilities");