1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 #include <sys/types.h>
29 #define max(a,b) ((a)>(b)?(a):(b))
33 #define min(a,b) ((a)<(b)?(a):(b))
38 #define LTT_MAGIC_NUMBER 0x00D6B7ED
39 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
41 #define NSEC_PER_USEC 1000
43 #define LTT_PACKED_STRUCT __attribute__ ((packed))
45 /* Hardcoded facilities */
46 #define LTT_FACILITY_CORE 0
49 #define LTT_GET_BO(t) ((t)->reverse_bo)
51 #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
52 #define LTT_GET_FLOAT_BO(t) \
53 (((t)->float_word_order==__BYTE_ORDER)?0:1)
55 #define SEQUENCE_AVG_ELEMENTS 1000
57 /* Hardcoded core events */
58 enum ltt_core_events
{
59 LTT_EVENT_FACILITY_LOAD
,
60 LTT_EVENT_FACILITY_UNLOAD
,
62 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
67 /* enumeration definition */
69 typedef enum _BuildinEvent
{
70 TRACE_FACILITY_LOAD
= 0,
71 TRACE_BLOCK_START
= 17,
73 TRACE_TIME_HEARTBEAT
= 19
77 /* structure definition */
79 typedef struct _FacilityLoad
{
83 } LTT_PACKED_STRUCT FacilityLoad
;
85 typedef struct _BlockStart
{
86 LttTime time
; //Time stamp of this block
87 LttCycleCount cycle_count
; //cycle count of the event
88 guint32 block_id
; //block id
89 } LTT_PACKED_STRUCT BlockStart
;
91 typedef struct _BlockEnd
{
92 LttTime time
; //Time stamp of this block
93 LttCycleCount cycle_count
; //cycle count of the event
94 guint32 block_id
; //block id
95 } LTT_PACKED_STRUCT BlockEnd
;
99 typedef guint8
uint8_t;
100 typedef guint16
uint16_t;
101 typedef guint32
uint32_t;
102 typedef guint64
uint64_t;
104 /* Hardcoded facility load event : this plus an preceding "name" string */
105 struct LttFacilityLoad
{
110 guint32 pointer_size
;
112 guint32 has_alignment
;
115 struct LttFacilityUnload
{
119 struct LttStateDumpFacilityLoad
{
124 guint32 pointer_size
;
126 guint32 has_alignment
;
129 typedef struct _TimeHeartbeat
{
130 LttTime time
; //Time stamp of this block
131 uint64_t cycle_count
; //cycle count of the event
132 } LTT_PACKED_STRUCT TimeHeartbeat
;
134 struct ltt_event_header_hb
{
136 unsigned char facility_id
;
137 unsigned char event_id
;
141 struct ltt_event_header_nohb
{
143 unsigned char facility_id
;
144 unsigned char event_id
;
149 /* Block and trace headers */
151 struct ltt_trace_header_any
{
152 uint32_t magic_number
;
154 uint32_t arch_variant
;
155 uint32_t float_word_order
;
157 uint8_t major_version
;
158 uint8_t minor_version
;
159 uint8_t flight_recorder
;
160 uint8_t has_heartbeat
;
161 uint8_t has_alignment
; /* Event header alignment */
166 /* For version 0.3 */
168 struct ltt_trace_header_0_3
{
169 uint32_t magic_number
;
171 uint32_t arch_variant
;
172 uint32_t float_word_order
;
174 uint8_t major_version
;
175 uint8_t minor_version
;
176 uint8_t flight_recorder
;
177 uint8_t has_heartbeat
;
178 uint8_t has_alignment
; /* Event header alignment */
182 /* For version 0.6 */
184 struct ltt_trace_header_0_6
{
185 uint32_t magic_number
;
187 uint32_t arch_variant
;
188 uint32_t float_word_order
;
190 uint8_t major_version
;
191 uint8_t minor_version
;
192 uint8_t flight_recorder
;
193 uint8_t has_heartbeat
;
194 uint8_t has_alignment
; /* Event header alignment */
198 uint64_t start_monotonic
;
199 //struct timespec start_time; // not portable
200 uint64_t start_time_sec
;
201 uint64_t start_time_usec
;
205 struct ltt_block_start_header
{
207 //struct timeval timestamp;
208 uint64_t timestamp_sec
;
209 uint64_t timestamp_usec
;
210 uint64_t cycle_count
;
214 //struct timeval timestamp;
215 uint64_t timestamp_sec
;
216 uint64_t timestamp_usec
;
217 uint64_t cycle_count
;
220 uint32_t lost_size
; /* Size unused at the end of the buffer */
221 uint32_t buf_size
; /* The size of this sub-buffer */
222 struct ltt_trace_header_any trace
[0];
227 // LTTV does not care about type names. Everything is a field.
228 // GQuark type_name; //type name if it is a named type
231 LttTypeEnum type_class
; //which type
232 GHashTable
*enum_map
; //maps enum labels to numbers.
233 GArray
*fields
; // Array of LttFields, for array, sequence, union, struct.
234 GData
*fields_by_name
;
237 struct _LttEventType
{
240 guint index
; //id of the event type within the facility
241 LttFacility
* facility
; //the facility that contains the event type
242 GArray
* fields
; //event's fields (LttField)
243 GData
*fields_by_name
;
246 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
247 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
250 /* Begin of LttEventPosition fields */
251 LttTracefile
*tracefile
;
256 uint64_t tsc
; /* Current timestamp counter */
258 /* End of LttEventPosition fields */
260 union { /* choice by trace has_tsc */
261 guint32 timestamp
; /* truncated timestamp */
265 unsigned char facility_id
; /* facility ID are never reused. */
266 unsigned char event_id
;
270 void * data
; //event data
272 guint event_size
; //event_size field of the header :
273 //used to verify data_size from facility.
275 int count
; //the number of overflow of cycle count
276 gint64 overflow_nsec
; //precalculated nsec for overflows
279 struct _LttEventPosition
{
280 LttTracefile
*tracefile
;
285 uint64_t tsc
; /* Current timestamp counter */
289 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
294 LttType field_type
; //field type
296 off_t offset_root
; //offset from the root
297 enum field_status fixed_root
; //offset fixed according to the root
299 guint field_size
; // size of the field
300 // Only if field type size is set to 0
301 // (it's variable), then the field_size should be
302 // dynamically calculated while reading the trace
303 // and put here. Otherwise, the field_size always
304 // equels the type size.
305 off_t array_offset
; // offset of the beginning of the array (for array
307 GArray
* dynamic_offsets
; // array of offsets calculated dynamically at
308 // each event for sequences and arrays that
309 // contain variable length fields.
315 guint32 checksum
; //checksum of the facility
316 guint32 id
; //id of the facility
320 guint32 pointer_size
;
325 GData
*events_by_name
;
326 // not necessary in LTTV GData *named_types;
328 unsigned char exists
; /* 0 does not exist, 1 exists */
331 typedef struct _LttBuffer
{
337 uint64_t cycle_count
;
338 uint64_t freq
; /* Frequency in khz */
342 uint64_t cycle_count
;
343 uint64_t freq
; /* Frequency in khz */
345 uint32_t lost_size
; /* Size unused at the end of the buffer */
348 uint64_t tsc
; /* Current timestamp counter */
349 uint64_t freq
; /* Frequency in khz */
350 //double nsecs_per_cycle; /* Precalculated from freq */
351 guint32 cyc2ns_scale
;
354 struct _LttTracefile
{
355 gboolean cpu_online
; //is the cpu online ?
356 GQuark long_name
; //tracefile complete filename
357 GQuark name
; //tracefile name
358 guint cpu_num
; //cpu number of the tracefile
359 LttTrace
* trace
; //trace containing the tracefile
360 int fd
; //file descriptor
361 off_t file_size
; //file size
362 //unsigned block_size; //block_size
363 guint num_blocks
; //number of blocks in the file
364 gboolean reverse_bo
; //must we reverse byte order ?
365 gboolean float_word_order
; //what is the byte order of floats ?
366 size_t has_alignment
; //alignment of events in the tracefile.
367 // 0 or the architecture size in bytes.
369 size_t buffer_header_size
;
372 LttEvent event
; //Event currently accessible in the trace
375 LttBuffer buffer
; //current buffer
376 guint32 buf_size
; /* The size of blocks */
379 //unsigned int count; //the number of overflow of cycle count
380 //double nsec_per_cycle; //Nsec per cycle
381 //TimeHeartbeat * last_heartbeat; //last heartbeat
383 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
384 //void * last_event_pos;
386 //LttTime prev_block_end_time; //the end time of previous block
387 //LttTime prev_event_time; //the time of the previous event
388 //LttCycleCount pre_cycle_count; //previous cycle count of the event
392 GQuark pathname
; //the pathname of the trace
393 //LttSystemDescription * system_description;//system description
395 GArray
*facilities_by_num
; /* fac_id as index in array */
396 GData
*facilities_by_name
; /* fac name (GQuark) as index */
397 /* Points to array of fac_id of all the
398 * facilities that has this name. */
402 guint32 arch_variant
;
404 guint8 ltt_major_version
;
405 guint8 ltt_minor_version
;
406 guint8 flight_recorder
;
407 guint8 has_heartbeat
;
411 uint64_t start_monotonic
;
413 LttTime start_time_from_tsc
;
415 GData
*tracefiles
; //tracefiles groups
418 /* The characteristics of the system on which the trace was obtained
419 is described in a LttSystemDescription structure. */
421 struct _LttSystemDescription
{
427 LttArchEndian endian
;
429 gchar
*kernel_release
;
430 gchar
*kernel_version
;
433 gchar
*hardware_platform
;
434 gchar
*operating_system
;
439 /*****************************************************************************
440 macro for size of some data types
441 *****************************************************************************/
442 // alignment -> dynamic!
444 //#define TIMESTAMP_SIZE sizeof(guint32)
445 //#define EVENT_ID_SIZE sizeof(guint16)
446 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
449 /* Calculate the offset needed to align the type.
450 * If has_alignment is 0, alignment is disactivated.
451 * else, the function returns the offset needed to
452 * align align_drift on the has_alignment value (should be
453 * the size of the architecture). */
454 static inline unsigned int ltt_align(size_t align_drift
,
456 size_t has_alignment
)
458 size_t alignment
= min(has_alignment
, size_of_type
);
460 return ((alignment
- align_drift
) & (alignment
-1));
464 #endif /* LTT_PRIVATE_H */