create directories branches, tags, trunk
[lttv.git] / ltt / branches / poly / ltt / ltt-private.h
CommitLineData
449cb9d7 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
1b44b0b5 3 * 2006 Mathieu Desnoyers
449cb9d7 4 *
1b44b0b5 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License Version 2.1 as published by the Free Software Foundation.
449cb9d7 8 *
1b44b0b5 9 * This library is distributed in the hope that it will be useful,
449cb9d7 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1b44b0b5 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
449cb9d7 13 *
1b44b0b5 14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
449cb9d7 18 */
19
fcdf0ec2 20#ifndef LTT_PRIVATE_H
21#define LTT_PRIVATE_H
22
858bd80a 23#include <glib.h>
cbd41522 24#include <sys/types.h>
fcdf0ec2 25#include <ltt/ltt.h>
3b10b765 26#include <endian.h>
29af7cfd 27#include <ltt/event.h>
e3247aa5 28
eed2ef37 29#ifndef max
30#define max(a,b) ((a)>(b)?(a):(b))
31#endif
32
2312de30 33#ifndef min
34#define min(a,b) ((a)<(b)?(a):(b))
35#endif
36
37
eed2ef37 38
3aee1200 39#define LTT_MAGIC_NUMBER 0x00D6B7ED
40#define LTT_REV_MAGIC_NUMBER 0xEDB7D600
41
42#define NSEC_PER_USEC 1000
43
cbd41522 44#define LTT_PACKED_STRUCT __attribute__ ((packed))
45
3aee1200 46/* Hardcoded facilities */
47#define LTT_FACILITY_CORE 0
3b10b765 48
49/* Byte ordering */
50#define LTT_GET_BO(t) ((t)->reverse_bo)
51
52#define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
53#define LTT_GET_FLOAT_BO(t) \
54 (((t)->float_word_order==__BYTE_ORDER)?0:1)
55
f104d082 56#define SEQUENCE_AVG_ELEMENTS 1000
57
3aee1200 58/* Hardcoded core events */
59enum ltt_core_events {
60 LTT_EVENT_FACILITY_LOAD,
61 LTT_EVENT_FACILITY_UNLOAD,
b77d1b57 62 LTT_EVENT_HEARTBEAT,
d1bb700c 63 LTT_EVENT_HEARTBEAT_FULL,
b77d1b57 64 LTT_EVENT_STATE_DUMP_FACILITY_LOAD
3aee1200 65};
66
67
3aee1200 68typedef guint8 uint8_t;
69typedef guint16 uint16_t;
70typedef guint32 uint32_t;
71typedef guint64 uint64_t;
72
3aee1200 73struct ltt_event_header_hb {
74 uint32_t timestamp;
3c165eaf 75 uint16_t event_id;
3aee1200 76 uint16_t event_size;
16fcbb80 77} LTT_PACKED_STRUCT;
3aee1200 78
79struct ltt_event_header_nohb {
80 uint64_t timestamp;
3c165eaf 81 uint16_t event_id;
3aee1200 82 uint16_t event_size;
16fcbb80 83} LTT_PACKED_STRUCT;
3aee1200 84
b7576a11 85
86/* Block and trace headers */
87
88struct ltt_trace_header_any {
89 uint32_t magic_number;
90 uint32_t arch_type;
91 uint32_t arch_variant;
92 uint32_t float_word_order;
93 uint8_t arch_size;
94 uint8_t major_version;
95 uint8_t minor_version;
96 uint8_t flight_recorder;
97 uint8_t has_heartbeat;
256a5b3a 98 uint8_t alignment; /* Event header alignment */
c88ddec5 99 uint32_t freq_scale;
b7576a11 100} LTT_PACKED_STRUCT;
101
3c165eaf 102struct ltt_trace_header_1_0 {
d1bb700c 103 uint32_t magic_number;
104 uint32_t arch_type;
105 uint32_t arch_variant;
106 uint32_t float_word_order;
107 uint8_t arch_size;
108 uint8_t major_version;
109 uint8_t minor_version;
110 uint8_t flight_recorder;
111 uint8_t has_heartbeat;
256a5b3a 112 uint8_t alignment; /* Event header alignment */
d1bb700c 113 uint8_t tsc_lsb_truncate;
114 uint8_t tscbits;
08a986f1 115 uint8_t compact_data_shift;
d1bb700c 116 uint32_t freq_scale;
117 uint64_t start_freq;
118 uint64_t start_tsc;
119 uint64_t start_monotonic;
120 uint64_t start_time_sec;
121 uint64_t start_time_usec;
122} LTT_PACKED_STRUCT;
123
e939e5b2 124
3aee1200 125struct ltt_block_start_header {
126 struct {
3aee1200 127 uint64_t cycle_count;
986e2a7c 128 uint64_t freq;
3aee1200 129 } begin;
130 struct {
3aee1200 131 uint64_t cycle_count;
986e2a7c 132 uint64_t freq;
3aee1200 133 } end;
134 uint32_t lost_size; /* Size unused at the end of the buffer */
135 uint32_t buf_size; /* The size of this sub-buffer */
51551c6f 136 struct ltt_trace_header_any trace[0];
16fcbb80 137} LTT_PACKED_STRUCT;
3aee1200 138
e3247aa5 139
3aee1200 140enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
141
3aee1200 142typedef struct _LttBuffer {
143 void * head;
144 unsigned int index;
145
146 struct {
147 LttTime timestamp;
148 uint64_t cycle_count;
986e2a7c 149 uint64_t freq; /* Frequency in khz */
3aee1200 150 } begin;
151 struct {
152 LttTime timestamp;
153 uint64_t cycle_count;
986e2a7c 154 uint64_t freq; /* Frequency in khz */
3aee1200 155 } end;
156 uint32_t lost_size; /* Size unused at the end of the buffer */
157
158 /* Timekeeping */
159 uint64_t tsc; /* Current timestamp counter */
986e2a7c 160 uint64_t freq; /* Frequency in khz */
791dffa6 161 //double nsecs_per_cycle; /* Precalculated from freq */
162 guint32 cyc2ns_scale;
3aee1200 163} LttBuffer;
164
29af7cfd 165struct LttTracefile {
3aee1200 166 gboolean cpu_online; //is the cpu online ?
d3d34f49 167 GQuark long_name; //tracefile complete filename
3aee1200 168 GQuark name; //tracefile name
169 guint cpu_num; //cpu number of the tracefile
c88ddec5 170 guint tid; //Usertrace tid, else 0
171 guint pgid; //Usertrace pgid, else 0
172 guint64 creation; //Usertrace creation, else 0
e3247aa5 173 LttTrace * trace; //trace containing the tracefile
174 int fd; //file descriptor
175 off_t file_size; //file size
f628823c 176 //unsigned block_size; //block_size
f104d082 177 guint num_blocks; //number of blocks in the file
3aee1200 178 gboolean reverse_bo; //must we reverse byte order ?
3b10b765 179 gboolean float_word_order; //what is the byte order of floats ?
256a5b3a 180 size_t alignment; //alignment of events in the tracefile.
c88ddec5 181 // 0 or the architecture size in bytes.
3aee1200 182
90440c06 183 guint8 has_heartbeat;
823820eb 184 size_t buffer_header_size;
d1bb700c 185 int compact; //compact tracefile ?
186 uint8_t tsc_lsb_truncate;
187 uint8_t tscbits;
188 uint8_t tsc_msb_cutoff;
08a986f1 189 uint8_t compact_event_bits;
d1bb700c 190 uint64_t tsc_mask;
191 uint64_t tsc_mask_next_bit; //next MSB after the mask
823820eb 192
c88ddec5 193 /* Current event */
3aee1200 194 LttEvent event; //Event currently accessible in the trace
195
c88ddec5 196 /* Current block */
3aee1200 197 LttBuffer buffer; //current buffer
198 guint32 buf_size; /* The size of blocks */
199
c88ddec5 200 /* Time flow */
3aee1200 201 //unsigned int count; //the number of overflow of cycle count
202 //double nsec_per_cycle; //Nsec per cycle
203 //TimeHeartbeat * last_heartbeat; //last heartbeat
204
887208b7 205 //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed
3aee1200 206 //void * last_event_pos;
7c6b3cd7 207
3aee1200 208 //LttTime prev_block_end_time; //the end time of previous block
209 //LttTime prev_event_time; //the time of the previous event
210 //LttCycleCount pre_cycle_count; //previous cycle count of the event
e3247aa5 211};
7c6b3cd7 212
a5dcde2f 213/* The characteristics of the system on which the trace was obtained
214 is described in a LttSystemDescription structure. */
215
29af7cfd 216struct LttSystemDescription {
45e14832 217 gchar *description;
218 gchar *node_name;
219 gchar *domain_name;
a5dcde2f 220 unsigned nb_cpu;
221 LttArchSize size;
222 LttArchEndian endian;
45e14832 223 gchar *kernel_name;
224 gchar *kernel_release;
225 gchar *kernel_version;
226 gchar *machine;
227 gchar *processor;
228 gchar *hardware_platform;
229 gchar *operating_system;
a5dcde2f 230 LttTime trace_start;
231 LttTime trace_end;
232};
233
7c6b3cd7 234/*****************************************************************************
235 macro for size of some data types
236 *****************************************************************************/
3aee1200 237// alignment -> dynamic!
238
239//#define TIMESTAMP_SIZE sizeof(guint32)
240//#define EVENT_ID_SIZE sizeof(guint16)
241//#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE)
242
7c6b3cd7 243
29af7cfd 244//off_t get_alignment(LttField *field);
83e160f2 245
f104d082 246/* Calculate the offset needed to align the type.
256a5b3a 247 * If alignment is 0, alignment is disactivated.
f104d082 248 * else, the function returns the offset needed to
256a5b3a 249 * align align_drift on the alignment value (should be
f104d082 250 * the size of the architecture). */
251static inline unsigned int ltt_align(size_t align_drift,
83e160f2 252 size_t size_of_type,
256a5b3a 253 size_t alignment)
f104d082 254{
256a5b3a 255 size_t align_offset = min(alignment, size_of_type);
c88ddec5 256
256a5b3a 257 if(!alignment)
258 return 0;
c88ddec5 259
260 g_assert(size_of_type != 0);
256a5b3a 261 return ((align_offset - align_drift) & (align_offset-1));
f104d082 262}
263
f104d082 264
fcdf0ec2 265#endif /* LTT_PRIVATE_H */
This page took 0.06528 seconds and 4 git commands to generate.