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