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 LTT_MAGIC_NUMBER 0x00D6B7ED
34 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
36 #define NSEC_PER_USEC 1000
38 #define LTT_PACKED_STRUCT __attribute__ ((packed))
40 /* Hardcoded facilities */
41 #define LTT_FACILITY_CORE 0
44 #define LTT_GET_BO(t) ((t)->reverse_bo)
46 #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
47 #define LTT_GET_FLOAT_BO(t) \
48 (((t)->float_word_order==__BYTE_ORDER)?0:1)
50 #define SEQUENCE_AVG_ELEMENTS 1000
52 /* Hardcoded core events */
53 enum ltt_core_events
{
54 LTT_EVENT_FACILITY_LOAD
,
55 LTT_EVENT_FACILITY_UNLOAD
,
57 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
62 /* enumeration definition */
64 typedef enum _BuildinEvent
{
65 TRACE_FACILITY_LOAD
= 0,
66 TRACE_BLOCK_START
= 17,
68 TRACE_TIME_HEARTBEAT
= 19
72 /* structure definition */
74 typedef struct _FacilityLoad
{
78 } LTT_PACKED_STRUCT FacilityLoad
;
80 typedef struct _BlockStart
{
81 LttTime time
; //Time stamp of this block
82 LttCycleCount cycle_count
; //cycle count of the event
83 guint32 block_id
; //block id
84 } LTT_PACKED_STRUCT BlockStart
;
86 typedef struct _BlockEnd
{
87 LttTime time
; //Time stamp of this block
88 LttCycleCount cycle_count
; //cycle count of the event
89 guint32 block_id
; //block id
90 } LTT_PACKED_STRUCT BlockEnd
;
94 typedef guint8
uint8_t;
95 typedef guint16
uint16_t;
96 typedef guint32
uint32_t;
97 typedef guint64
uint64_t;
99 /* Hardcoded facility load event : this plus an preceding "name" string */
100 struct LttFacilityLoad
{
105 guint32 pointer_size
;
107 guint32 has_alignment
;
110 struct LttFacilityUnload
{
114 struct LttStateDumpFacilityLoad
{
119 guint32 pointer_size
;
121 guint32 has_alignment
;
124 typedef struct _TimeHeartbeat
{
125 LttTime time
; //Time stamp of this block
126 uint64_t cycle_count
; //cycle count of the event
127 } LTT_PACKED_STRUCT TimeHeartbeat
;
129 struct ltt_event_header_hb
{
131 unsigned char facility_id
;
132 unsigned char event_id
;
136 struct ltt_event_header_nohb
{
138 unsigned char facility_id
;
139 unsigned char event_id
;
144 /* Block and trace headers */
146 struct ltt_trace_header_any
{
147 uint32_t magic_number
;
149 uint32_t arch_variant
;
150 uint32_t float_word_order
;
152 uint8_t major_version
;
153 uint8_t minor_version
;
154 uint8_t flight_recorder
;
155 uint8_t has_heartbeat
;
156 uint8_t has_alignment
; /* Event header alignment */
161 /* For version 0.3 */
163 struct ltt_trace_header_0_3
{
164 uint32_t magic_number
;
166 uint32_t arch_variant
;
167 uint32_t float_word_order
;
169 uint8_t major_version
;
170 uint8_t minor_version
;
171 uint8_t flight_recorder
;
172 uint8_t has_heartbeat
;
173 uint8_t has_alignment
; /* Event header alignment */
177 /* For version 0.4 */
179 struct ltt_trace_header_0_4
{
180 uint32_t magic_number
;
182 uint32_t arch_variant
;
183 uint32_t float_word_order
;
185 uint8_t major_version
;
186 uint8_t minor_version
;
187 uint8_t flight_recorder
;
188 uint8_t has_heartbeat
;
189 uint8_t has_alignment
; /* Event header alignment */
193 uint64_t start_monotonic
;
194 struct timeval start_time
;
198 struct ltt_block_start_header
{
200 struct timeval timestamp
;
201 uint64_t cycle_count
;
205 struct timeval timestamp
;
206 uint64_t cycle_count
;
209 uint32_t lost_size
; /* Size unused at the end of the buffer */
210 uint32_t buf_size
; /* The size of this sub-buffer */
211 struct ltt_trace_header_any trace
[0];
216 // LTTV does not care about type names. Everything is a field.
217 // GQuark type_name; //type name if it is a named type
220 LttTypeEnum type_class
; //which type
221 GData
*enum_map
; //maps enum labels to numbers.
222 GArray
*fields
; // Array of LttFields, for array, sequence, union, struct.
223 GData
*fields_by_name
;
226 struct _LttEventType
{
229 guint index
; //id of the event type within the facility
230 LttFacility
* facility
; //the facility that contains the event type
231 GArray
* fields
; //event's fields (LttField)
232 GData
*fields_by_name
;
235 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
236 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
239 /* Begin of LttEventPosition fields */
240 LttTracefile
*tracefile
;
245 uint64_t tsc
; /* Current timestamp counter */
247 /* End of LttEventPosition fields */
249 union { /* choice by trace has_tsc */
250 guint32 timestamp
; /* truncated timestamp */
254 unsigned char facility_id
; /* facility ID are never reused. */
255 unsigned char event_id
;
259 void * data
; //event data
261 guint event_size
; //event_size field of the header :
262 //used to verify data_size from facility.
264 int count
; //the number of overflow of cycle count
265 gint64 overflow_nsec
; //precalculated nsec for overflows
268 struct _LttEventPosition
{
269 LttTracefile
*tracefile
;
274 uint64_t tsc
; /* Current timestamp counter */
278 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
283 LttType field_type
; //field type
285 off_t offset_root
; //offset from the root
286 enum field_status fixed_root
; //offset fixed according to the root
288 guint field_size
; // size of the field
289 // Only if field type size is set to 0
290 // (it's variable), then the field_size should be
291 // dynamically calculated while reading the trace
292 // and put here. Otherwise, the field_size always
293 // equels the type size.
294 off_t array_offset
; // offset of the beginning of the array (for array
296 GArray
* dynamic_offsets
; // array of offsets calculated dynamically at
297 // each event for sequences and arrays that
298 // contain variable length fields.
304 guint32 checksum
; //checksum of the facility
305 guint32 id
; //id of the facility
309 guint32 pointer_size
;
314 GData
*events_by_name
;
315 // not necessary in LTTV GData *named_types;
317 unsigned char exists
; /* 0 does not exist, 1 exists */
320 typedef struct _LttBuffer
{
326 uint64_t cycle_count
;
327 uint64_t freq
; /* Frequency in khz */
331 uint64_t cycle_count
;
332 uint64_t freq
; /* Frequency in khz */
334 uint32_t lost_size
; /* Size unused at the end of the buffer */
337 uint64_t tsc
; /* Current timestamp counter */
338 uint64_t freq
; /* Frequency in khz */
339 //double nsecs_per_cycle; /* Precalculated from freq */
340 guint32 cyc2ns_scale
;
343 struct _LttTracefile
{
344 gboolean cpu_online
; //is the cpu online ?
345 GQuark long_name
; //tracefile complete filename
346 GQuark name
; //tracefile name
347 guint cpu_num
; //cpu number of the tracefile
348 LttTrace
* trace
; //trace containing the tracefile
349 int fd
; //file descriptor
350 off_t file_size
; //file size
351 //unsigned block_size; //block_size
352 guint num_blocks
; //number of blocks in the file
353 gboolean reverse_bo
; //must we reverse byte order ?
354 gboolean float_word_order
; //what is the byte order of floats ?
355 size_t has_alignment
; //alignment of events in the tracefile.
356 // 0 or the architecture size in bytes.
358 size_t buffer_header_size
;
361 LttEvent event
; //Event currently accessible in the trace
364 LttBuffer buffer
; //current buffer
365 guint32 buf_size
; /* The size of blocks */
368 //unsigned int count; //the number of overflow of cycle count
369 //double nsec_per_cycle; //Nsec per cycle
370 //TimeHeartbeat * last_heartbeat; //last heartbeat
372 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
373 //void * last_event_pos;
375 //LttTime prev_block_end_time; //the end time of previous block
376 //LttTime prev_event_time; //the time of the previous event
377 //LttCycleCount pre_cycle_count; //previous cycle count of the event
381 GQuark pathname
; //the pathname of the trace
382 //LttSystemDescription * system_description;//system description
384 GArray
*facilities_by_num
; /* fac_id as index in array */
385 GData
*facilities_by_name
; /* fac name (GQuark) as index */
386 /* Points to array of fac_id of all the
387 * facilities that has this name. */
391 guint32 arch_variant
;
393 guint8 ltt_major_version
;
394 guint8 ltt_minor_version
;
395 guint8 flight_recorder
;
396 guint8 has_heartbeat
;
400 uint64_t start_monotonic
;
402 LttTime start_time_from_tsc
;
404 GData
*tracefiles
; //tracefiles groups
407 /* The characteristics of the system on which the trace was obtained
408 is described in a LttSystemDescription structure. */
410 struct _LttSystemDescription
{
416 LttArchEndian endian
;
418 gchar
*kernel_release
;
419 gchar
*kernel_version
;
422 gchar
*hardware_platform
;
423 gchar
*operating_system
;
428 /*****************************************************************************
429 macro for size of some data types
430 *****************************************************************************/
431 // alignment -> dynamic!
433 //#define TIMESTAMP_SIZE sizeof(guint32)
434 //#define EVENT_ID_SIZE sizeof(guint16)
435 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
438 /* Calculate the offset needed to align the type.
439 * If has_alignment is 0, alignment is disactivated.
440 * else, the function returns the offset needed to
441 * align align_drift on the has_alignment value (should be
442 * the size of the architecture). */
443 static inline unsigned int ltt_align(size_t align_drift
,
445 size_t has_alignment
)
447 size_t alignment
= min(has_alignment
, size_of_type
);
449 return ((alignment
- align_drift
) & (alignment
-1));
452 off_t
field_align(LttTracefile
*tf
, LttField
*field
, off_t offset
);
455 #endif /* LTT_PRIVATE_H */