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 /* Hardcoded core events */
51 enum ltt_core_events
{
52 LTT_EVENT_FACILITY_LOAD
,
53 LTT_EVENT_FACILITY_UNLOAD
,
55 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
60 /* enumeration definition */
62 typedef enum _BuildinEvent
{
63 TRACE_FACILITY_LOAD
= 0,
64 TRACE_BLOCK_START
= 17,
66 TRACE_TIME_HEARTBEAT
= 19
70 /* structure definition */
72 typedef struct _FacilityLoad
{
76 } LTT_PACKED_STRUCT FacilityLoad
;
78 typedef struct _BlockStart
{
79 LttTime time
; //Time stamp of this block
80 LttCycleCount cycle_count
; //cycle count of the event
81 guint32 block_id
; //block id
82 } LTT_PACKED_STRUCT BlockStart
;
84 typedef struct _BlockEnd
{
85 LttTime time
; //Time stamp of this block
86 LttCycleCount cycle_count
; //cycle count of the event
87 guint32 block_id
; //block id
88 } LTT_PACKED_STRUCT BlockEnd
;
92 typedef guint8
uint8_t;
93 typedef guint16
uint16_t;
94 typedef guint32
uint32_t;
95 typedef guint64
uint64_t;
97 /* Hardcoded facility load event : this plus an preceding "name" string */
98 struct LttFacilityLoad
{
102 guint32 pointer_size
;
107 struct LttFacilityUnload
{
111 struct LttStateDumpFacilityLoad
{
115 guint32 pointer_size
;
120 typedef struct _TimeHeartbeat
{
121 LttTime time
; //Time stamp of this block
122 uint64_t cycle_count
; //cycle count of the event
123 } LTT_PACKED_STRUCT TimeHeartbeat
;
125 struct ltt_event_header_hb
{
127 unsigned char facility_id
;
128 unsigned char event_id
;
132 struct ltt_event_header_nohb
{
134 unsigned char facility_id
;
135 unsigned char event_id
;
140 /* Block and trace headers */
142 struct ltt_trace_header_any
{
143 uint32_t magic_number
;
145 uint32_t arch_variant
;
146 uint32_t float_word_order
;
148 uint8_t major_version
;
149 uint8_t minor_version
;
150 uint8_t flight_recorder
;
151 uint8_t has_heartbeat
;
152 uint8_t has_alignment
; /* Event header alignment */
157 /* For version 0.3 */
159 struct ltt_trace_header_0_3
{
160 uint32_t magic_number
;
162 uint32_t arch_variant
;
163 uint32_t float_word_order
;
165 uint8_t major_version
;
166 uint8_t minor_version
;
167 uint8_t flight_recorder
;
168 uint8_t has_heartbeat
;
169 uint8_t has_alignment
; /* Event header alignment */
175 struct ltt_block_start_header
{
177 struct timeval timestamp
;
178 uint64_t cycle_count
;
181 struct timeval timestamp
;
182 uint64_t cycle_count
;
184 uint32_t lost_size
; /* Size unused at the end of the buffer */
185 uint32_t buf_size
; /* The size of this sub-buffer */
186 struct ltt_trace_header_any trace
[0];
191 GQuark type_name
; //type name if it is a named type
192 GQuark element_name
; //elements name of the struct
195 LttTypeEnum type_class
; //which type
196 GQuark
* enum_strings
; //for enum labels
197 struct _LttType
** element_type
; //for array, sequence and struct
198 unsigned element_number
; //the number of elements
199 //for enum, array, sequence and structure
202 struct _LttEventType
{
205 guint index
; //id of the event type within the facility
206 LttFacility
* facility
; //the facility that contains the event type
207 LttField
* root_field
; //root field
210 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
211 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
214 /* Begin of LttEventPosition fields */
215 LttTracefile
*tracefile
;
220 uint64_t tsc
; /* Current timestamp counter */
222 /* End of LttEventPosition fields */
224 union { /* choice by trace has_tsc */
225 guint32 timestamp
; /* truncated timestamp */
229 unsigned char facility_id
; /* facility ID are never reused. */
230 unsigned char event_id
;
234 void * data
; //event data
236 guint event_size
; //event_size field of the header :
237 //used to verify data_size from facility.
239 int count
; //the number of overflow of cycle count
240 gint64 overflow_nsec
; //precalculated nsec for overflows
243 struct _LttEventPosition
{
244 LttTracefile
*tracefile
;
249 uint64_t tsc
; /* Current timestamp counter */
253 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
256 //guint field_pos; //field position within its parent
257 LttType
* field_type
; //field type, if it is root field
258 //then it must be struct type
260 off_t offset_root
; //offset from the root, -1:uninitialized
261 enum field_status fixed_root
; //offset fixed according to the root
262 //-1:uninitialized, 0:unfixed, 1:fixed
263 off_t offset_parent
; //offset from the parent,-1:uninitialized
264 enum field_status fixed_parent
; //offset fixed according to its parent
265 //-1:uninitialized, 0:unfixed, 1:fixed
266 // void * base_address; //base address of the field ????
268 guint field_size
; // //>0: size of the field,
270 // //-1: uninitialize
271 enum field_status fixed_size
;
274 gint sequ_number_size
; //the size of unsigned used to save the
275 //number of elements in the sequence
277 gint element_size
; //the element size of the sequence
278 //int field_fixed; //0: field has string or sequence
279 //1: field has no string or sequenc
282 struct _LttField
* parent
;
283 struct _LttField
** child
; //for array, sequence, struct and union:
284 //list of fields, it may have only one
285 //field if the element is not a struct or
287 unsigned current_element
; //which element is currently processed
288 // Used for sequences and arrays.
294 //gchar * name; //facility name
296 guint32 checksum
; //checksum of the facility
297 guint32 id
; //id of the facility
299 guint32 pointer_size
;
305 //LttEventType ** events; //array of event types
306 //unsigned int event_number; //number of events in the facility
307 //LttType ** named_types;
308 //unsigned int named_types_number;
311 GData
*events_by_name
;
312 // GArray *named_types;
313 //GData *named_types_by_name;
316 unsigned char exists
; /* 0 does not exist, 1 exists */
319 typedef struct _LttBuffer
{
325 uint64_t cycle_count
;
329 uint64_t cycle_count
;
331 uint32_t lost_size
; /* Size unused at the end of the buffer */
334 uint64_t tsc
; /* Current timestamp counter */
335 double nsecs_per_cycle
;
338 struct _LttTracefile
{
339 gboolean cpu_online
; //is the cpu online ?
340 GQuark long_name
; //tracefile complete filename
341 GQuark name
; //tracefile name
342 guint cpu_num
; //cpu number of the tracefile
343 LttTrace
* trace
; //trace containing the tracefile
344 int fd
; //file descriptor
345 off_t file_size
; //file size
346 //unsigned block_size; //block_size
347 unsigned int num_blocks
; //number of blocks in the file
348 gboolean reverse_bo
; //must we reverse byte order ?
349 gboolean float_word_order
; //what is the byte order of floats ?
351 size_t buffer_header_size
;
354 LttEvent event
; //Event currently accessible in the trace
357 LttBuffer buffer
; //current buffer
358 guint32 buf_size
; /* The size of blocks */
361 //unsigned int count; //the number of overflow of cycle count
362 //double nsec_per_cycle; //Nsec per cycle
363 //TimeHeartbeat * last_heartbeat; //last heartbeat
365 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
366 //void * last_event_pos;
368 //LttTime prev_block_end_time; //the end time of previous block
369 //LttTime prev_event_time; //the time of the previous event
370 //LttCycleCount pre_cycle_count; //previous cycle count of the event
374 GQuark pathname
; //the pathname of the trace
375 //LttSystemDescription * system_description;//system description
377 GArray
*facilities_by_num
; /* fac_id as index in array */
378 GData
*facilities_by_name
; /* fac name (GQuark) as index */
379 /* Points to array of fac_id of all the
380 * facilities that has this name. */
384 guint32 arch_variant
;
386 guint8 ltt_major_version
;
387 guint8 ltt_minor_version
;
388 guint8 flight_recorder
;
389 guint8 has_heartbeat
;
390 guint8 has_alignment
;
393 GData
*tracefiles
; //tracefiles groups
396 /* The characteristics of the system on which the trace was obtained
397 is described in a LttSystemDescription structure. */
399 struct _LttSystemDescription
{
405 LttArchEndian endian
;
407 gchar
*kernel_release
;
408 gchar
*kernel_version
;
411 gchar
*hardware_platform
;
412 gchar
*operating_system
;
417 /*****************************************************************************
418 macro for size of some data types
419 *****************************************************************************/
420 // alignment -> dynamic!
422 //#define TIMESTAMP_SIZE sizeof(guint32)
423 //#define EVENT_ID_SIZE sizeof(guint16)
424 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
427 #endif /* LTT_PRIVATE_H */