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 events */
39 enum ltt_core_events
{
40 LTT_EVENT_FACILITY_LOAD
,
41 LTT_EVENT_FACILITY_UNLOAD
,
42 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
45 /* Hardcoded events */
46 enum ltt_heartbeat_events
{
54 /* enumeration definition */
56 typedef enum _BuildinEvent
{
57 TRACE_FACILITY_LOAD
= 0,
58 TRACE_BLOCK_START
= 17,
60 TRACE_TIME_HEARTBEAT
= 19
64 /* structure definition */
66 typedef struct _FacilityLoad
{
70 } LTT_PACKED_STRUCT FacilityLoad
;
72 typedef struct _BlockStart
{
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 BlockStart
;
78 typedef struct _BlockEnd
{
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 BlockEnd
;
86 typedef guint8
uint8_t;
87 typedef guint16
uint16_t;
88 typedef guint32
uint32_t;
89 typedef guint64
uint64_t;
91 /* Hardcoded facility load event : this plus an following "name" string */
92 struct LttFacilityLoad
{
101 struct LttFacilityUnload
{
107 typedef struct _TimeHeartbeat
{
108 LttTime time
; //Time stamp of this block
109 uint64_t cycle_count
; //cycle count of the event
110 } LTT_PACKED_STRUCT TimeHeartbeat
;
112 struct ltt_event_header_hb
{
114 unsigned char facility_id
;
115 unsigned char event_id
;
117 } __attribute((aligned(8)));
119 struct ltt_event_header_nohb
{
121 unsigned char facility_id
;
122 unsigned char event_id
;
124 } __attribute((aligned(8)));
126 struct ltt_trace_header
{
127 uint32_t magic_number
;
129 uint32_t arch_variant
;
131 //uint32_t system_type;
132 uint8_t major_version
;
133 uint8_t minor_version
;
134 uint8_t flight_recorder
;
135 uint8_t has_heartbeat
;
136 uint8_t has_alignment
; /* Event header alignment */
138 } __attribute((aligned(8)));
141 struct ltt_block_start_header
{
143 struct timeval timestamp
;
144 uint64_t cycle_count
;
147 struct timeval timestamp
;
148 uint64_t cycle_count
;
150 uint32_t lost_size
; /* Size unused at the end of the buffer */
151 uint32_t buf_size
; /* The size of this sub-buffer */
152 struct ltt_trace_header trace
;
153 } __attribute((aligned(8)));
157 GQuark type_name
; //type name if it is a named type
158 GQuark element_name
; //elements name of the struct
161 LttTypeEnum type_class
; //which type
162 gchar
** enum_strings
; //for enum labels
163 struct _LttType
** element_type
; //for array, sequence and struct
164 unsigned element_number
; //the number of elements
165 //for enum, array, sequence and structure
168 struct _LttEventType
{
171 guint index
; //id of the event type within the facility
172 LttFacility
* facility
; //the facility that contains the event type
173 LttField
* root_field
; //root field
178 /* Where is this event ? */
179 LttTracefile
*tracefile
;
183 union { /* choice by trace has_tsc */
184 guint32 timestamp
; /* truncated timestamp */
188 unsigned char facility_id
; /* facility ID are never reused. */
189 unsigned char event_id
;
193 void * data
; //event data
195 int count
; //the number of overflow of cycle count
196 gint64 overflow_nsec
; //precalculated nsec for overflows
197 TimeHeartbeat
* last_heartbeat
; //last heartbeat
202 unsigned field_pos
; //field position within its parent
203 LttType
* field_type
; //field type, if it is root field
204 //then it must be struct type
206 off_t offset_root
; //offset from the root, -1:uninitialized
207 short fixed_root
; //offset fixed according to the root
208 //-1:uninitialized, 0:unfixed, 1:fixed
209 off_t offset_parent
; //offset from the parent,-1:uninitialized
210 short fixed_parent
; //offset fixed according to its parent
211 //-1:uninitialized, 0:unfixed, 1:fixed
212 // void * base_address; //base address of the field ????
214 int field_size
; //>0: size of the field,
217 int sequ_number_size
; //the size of unsigned used to save the
218 //number of elements in the sequence
220 int element_size
; //the element size of the sequence
221 int field_fixed
; //0: field has string or sequence
222 //1: field has no string or sequenc
225 struct _LttField
* parent
;
226 struct _LttField
** child
; //for array, sequence and struct:
227 //list of fields, it may have only one
228 //field if the element is not a struct
229 unsigned current_element
; //which element is currently processed
234 //gchar * name; //facility name
236 guint32 checksum
; //checksum of the facility
237 guint32 id
; //id of the facility
239 guint32 pointer_size
;
244 LttEventType
** events
; //array of event types
245 unsigned int event_number
; //number of events in the facility
246 LttType
** named_types
;
247 unsigned int named_types_number
;
250 GData
*events_by_name
;
251 // GArray *named_types;
252 //GData *named_types_by_name;
255 unsigned char exists
; /* 0 does not exist, 1 exists */
258 typedef struct _LttBuffer
{
263 struct timeval timestamp
;
264 uint64_t cycle_count
;
267 struct timeval timestamp
;
268 uint64_t cycle_count
;
270 uint32_t lost_size
; /* Size unused at the end of the buffer */
273 uint64_t tsc
; /* Current timestamp counter */
274 double nsecs_per_cycle
;
277 struct _LttTracefile
{
278 gboolean cpu_online
; //is the cpu online ?
279 GQuark name
; //tracefile name
280 LttTrace
* trace
; //trace containing the tracefile
281 int fd
; //file descriptor
282 off_t file_size
; //file size
283 unsigned block_size
; //block_size
284 unsigned int num_blocks
; //number of blocks in the file
285 gboolean reverse_bo
; //must we reverse byte order ?
288 LttEvent event
; //Event currently accessible in the trace
291 LttBuffer buffer
; //current buffer
292 guint32 buf_size
; /* The size of blocks */
295 //unsigned int count; //the number of overflow of cycle count
296 //double nsec_per_cycle; //Nsec per cycle
297 //TimeHeartbeat * last_heartbeat; //last heartbeat
299 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
300 //void * last_event_pos;
302 //LttTime prev_block_end_time; //the end time of previous block
303 //LttTime prev_event_time; //the time of the previous event
304 //LttCycleCount pre_cycle_count; //previous cycle count of the event
308 GQuark pathname
; //the pathname of the trace
309 //LttSystemDescription * system_description;//system description
311 GArray
*facilities_by_num
; /* fac_id as index in array */
312 GData
*facilities_by_name
; /* fac name (GQuark) as index */
313 /* Points to array of fac_id of all the
314 * facilities that has this name. */
316 guint8 ltt_major_version
;
317 guint8 ltt_minor_version
;
318 guint8 flight_recorder
;
319 guint8 has_heartbeat
;
323 GData
*tracefiles
; //tracefiles groups
326 struct _LttEventPosition
{
327 LttTracefile
*tracefile
;
332 uint64_t tsc
; /* Current timestamp counter */
335 /* The characteristics of the system on which the trace was obtained
336 is described in a LttSystemDescription structure. */
338 struct _LttSystemDescription
{
344 LttArchEndian endian
;
346 gchar
*kernel_release
;
347 gchar
*kernel_version
;
350 gchar
*hardware_platform
;
351 gchar
*operating_system
;
352 //unsigned ltt_block_size;
357 /*****************************************************************************
358 macro for size of some data types
359 *****************************************************************************/
360 // alignment -> dynamic!
362 //#define TIMESTAMP_SIZE sizeof(guint32)
363 //#define EVENT_ID_SIZE sizeof(guint16)
364 //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
366 #define LTT_GET_BO(t) ((t)->reverse_bo)
369 #endif /* LTT_PRIVATE_H */