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>
26 #define LTT_MAGIC_NUMBER 0x00D6B7ED
27 #define LTT_REV_MAGIC_NUMBER 0xEDB7D600
29 #define NSEC_PER_USEC 1000
31 #define LTT_PACKED_STRUCT __attribute__ ((packed))
33 #define NUM_FACILITIES 256
35 /* Hardcoded facilities */
36 #define LTT_FACILITY_CORE 0
38 /* Hardcoded core events */
39 enum ltt_core_events
{
40 LTT_EVENT_FACILITY_LOAD
,
41 LTT_EVENT_FACILITY_UNLOAD
,
42 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
,
48 /* enumeration definition */
50 typedef enum _BuildinEvent
{
51 TRACE_FACILITY_LOAD
= 0,
52 TRACE_BLOCK_START
= 17,
54 TRACE_TIME_HEARTBEAT
= 19
58 /* structure definition */
60 typedef struct _FacilityLoad
{
64 } LTT_PACKED_STRUCT FacilityLoad
;
66 typedef struct _BlockStart
{
67 LttTime time
; //Time stamp of this block
68 LttCycleCount cycle_count
; //cycle count of the event
69 guint32 block_id
; //block id
70 } LTT_PACKED_STRUCT BlockStart
;
72 typedef struct _BlockEnd
{
73 LttTime time
; //Time stamp of this block
74 LttCycleCount cycle_count
; //cycle count of the event
75 guint32 block_id
; //block id
76 } LTT_PACKED_STRUCT BlockEnd
;
80 typedef guint8
uint8_t;
81 typedef guint16
uint16_t;
82 typedef guint32
uint32_t;
83 typedef guint64
uint64_t;
85 /* Hardcoded facility load event : this plus an following "name" string */
86 struct LttFacilityLoad
{
95 struct LttFacilityUnload
{
99 struct LttStateDumpFacilityLoad
{
103 guint32 pointer_size
;
110 typedef struct _TimeHeartbeat
{
111 LttTime time
; //Time stamp of this block
112 uint64_t cycle_count
; //cycle count of the event
113 } LTT_PACKED_STRUCT TimeHeartbeat
;
115 struct ltt_event_header_hb
{
117 unsigned char facility_id
;
118 unsigned char event_id
;
120 } __attribute((aligned(8)));
122 struct ltt_event_header_nohb
{
124 unsigned char facility_id
;
125 unsigned char event_id
;
127 } __attribute((aligned(8)));
129 struct ltt_trace_header
{
130 uint32_t magic_number
;
132 uint32_t arch_variant
;
134 //uint32_t system_type;
135 uint8_t major_version
;
136 uint8_t minor_version
;
137 uint8_t flight_recorder
;
138 uint8_t has_heartbeat
;
139 uint8_t has_alignment
; /* Event header alignment */
141 } __attribute((aligned(8)));
144 struct ltt_block_start_header
{
146 struct timeval timestamp
;
147 uint64_t cycle_count
;
150 struct timeval timestamp
;
151 uint64_t cycle_count
;
153 uint32_t lost_size
; /* Size unused at the end of the buffer */
154 uint32_t buf_size
; /* The size of this sub-buffer */
155 struct ltt_trace_header trace
;
156 } __attribute((aligned(8)));
160 GQuark type_name
; //type name if it is a named type
161 GQuark element_name
; //elements name of the struct
164 LttTypeEnum type_class
; //which type
165 GQuark
* enum_strings
; //for enum labels
166 struct _LttType
** element_type
; //for array, sequence and struct
167 unsigned element_number
; //the number of elements
168 //for enum, array, sequence and structure
171 struct _LttEventType
{
174 guint index
; //id of the event type within the facility
175 LttFacility
* facility
; //the facility that contains the event type
176 LttField
* root_field
; //root field
179 /* Structure LttEvent and LttEventPosition must begin with the _exact_ same
180 * fields in the exact same order. LttEventPosition is a parent of LttEvent. */
183 /* Begin of LttEventPosition fields */
184 LttTracefile
*tracefile
;
189 uint64_t tsc
; /* Current timestamp counter */
191 /* End of LttEventPosition fields */
193 union { /* choice by trace has_tsc */
194 guint32 timestamp
; /* truncated timestamp */
198 unsigned char facility_id
; /* facility ID are never reused. */
199 unsigned char event_id
;
203 void * data
; //event data
205 int count
; //the number of overflow of cycle count
206 gint64 overflow_nsec
; //precalculated nsec for overflows
209 struct _LttEventPosition
{
210 LttTracefile
*tracefile
;
215 uint64_t tsc
; /* Current timestamp counter */
219 enum field_status
{ FIELD_UNKNOWN
, FIELD_VARIABLE
, FIELD_FIXED
};
222 //guint field_pos; //field position within its parent
223 LttType
* field_type
; //field type, if it is root field
224 //then it must be struct type
226 off_t offset_root
; //offset from the root, -1:uninitialized
227 enum field_status fixed_root
; //offset fixed according to the root
228 //-1:uninitialized, 0:unfixed, 1:fixed
229 off_t offset_parent
; //offset from the parent,-1:uninitialized
230 enum field_status fixed_parent
; //offset fixed according to its parent
231 //-1:uninitialized, 0:unfixed, 1:fixed
232 // void * base_address; //base address of the field ????
234 guint field_size
; // //>0: size of the field,
236 // //-1: uninitialize
237 enum field_status fixed_size
;
240 gint sequ_number_size
; //the size of unsigned used to save the
241 //number of elements in the sequence
243 gint element_size
; //the element size of the sequence
244 //int field_fixed; //0: field has string or sequence
245 //1: field has no string or sequenc
248 struct _LttField
* parent
;
249 struct _LttField
** child
; //for array, sequence, struct and union:
250 //list of fields, it may have only one
251 //field if the element is not a struct or
253 unsigned current_element
; //which element is currently processed
254 // Used for sequences and arrays.
260 //gchar * name; //facility name
262 guint32 checksum
; //checksum of the facility
263 guint32 id
; //id of the facility
265 guint32 pointer_size
;
270 //LttEventType ** events; //array of event types
271 //unsigned int event_number; //number of events in the facility
272 //LttType ** named_types;
273 //unsigned int named_types_number;
276 GData
*events_by_name
;
277 // GArray *named_types;
278 //GData *named_types_by_name;
281 unsigned char exists
; /* 0 does not exist, 1 exists */
284 typedef struct _LttBuffer
{
290 uint64_t cycle_count
;
294 uint64_t cycle_count
;
296 uint32_t lost_size
; /* Size unused at the end of the buffer */
299 uint64_t tsc
; /* Current timestamp counter */
300 double nsecs_per_cycle
;
303 struct _LttTracefile
{
304 gboolean cpu_online
; //is the cpu online ?
305 GQuark name
; //tracefile name
306 guint cpu_num
; //cpu number of the tracefile
307 LttTrace
* trace
; //trace containing the tracefile
308 int fd
; //file descriptor
309 off_t file_size
; //file size
310 unsigned block_size
; //block_size
311 unsigned int num_blocks
; //number of blocks in the file
312 gboolean reverse_bo
; //must we reverse byte order ?
315 LttEvent event
; //Event currently accessible in the trace
318 LttBuffer buffer
; //current buffer
319 guint32 buf_size
; /* The size of blocks */
322 //unsigned int count; //the number of overflow of cycle count
323 //double nsec_per_cycle; //Nsec per cycle
324 //TimeHeartbeat * last_heartbeat; //last heartbeat
326 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
327 //void * last_event_pos;
329 //LttTime prev_block_end_time; //the end time of previous block
330 //LttTime prev_event_time; //the time of the previous event
331 //LttCycleCount pre_cycle_count; //previous cycle count of the event
335 GQuark pathname
; //the pathname of the trace
336 //LttSystemDescription * system_description;//system description
338 GArray
*facilities_by_num
; /* fac_id as index in array */
339 GData
*facilities_by_name
; /* fac name (GQuark) as index */
340 /* Points to array of fac_id of all the
341 * facilities that has this name. */
343 guint8 ltt_major_version
;
344 guint8 ltt_minor_version
;
345 guint8 flight_recorder
;
346 guint8 has_heartbeat
;
350 GData
*tracefiles
; //tracefiles groups
353 /* The characteristics of the system on which the trace was obtained
354 is described in a LttSystemDescription structure. */
356 struct _LttSystemDescription
{
362 LttArchEndian endian
;
364 gchar
*kernel_release
;
365 gchar
*kernel_version
;
368 gchar
*hardware_platform
;
369 gchar
*operating_system
;
374 /*****************************************************************************
375 macro for size of some data types
376 *****************************************************************************/
377 // alignment -> dynamic!
379 //#define TIMESTAMP_SIZE sizeof(guint32)
380 //#define EVENT_ID_SIZE sizeof(guint16)
381 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
383 #define LTT_GET_BO(t) ((t)->reverse_bo)
386 #endif /* LTT_PRIVATE_H */