update ltt
[lttv.git] / trunk / lttv / ltt / ltt-private.h
... / ...
CommitLineData
1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3 * 2006 Mathieu Desnoyers
4 *
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.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
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.
18 */
19
20#ifndef LTT_PRIVATE_H
21#define LTT_PRIVATE_H
22
23#include <glib.h>
24#include <sys/types.h>
25#include <ltt/ltt.h>
26#include <endian.h>
27#include <ltt/event.h>
28
29#ifndef max
30#define max(a,b) ((a)>(b)?(a):(b))
31#endif
32
33#ifndef min
34#define min(a,b) ((a)<(b)?(a):(b))
35#endif
36
37
38
39#define LTT_MAGIC_NUMBER 0x00D6B7ED
40#define LTT_REV_MAGIC_NUMBER 0xEDB7D600
41
42#define NSEC_PER_USEC 1000
43
44#define LTT_PACKED_STRUCT __attribute__ ((packed))
45
46/* Byte ordering */
47#define LTT_GET_BO(t) ((t)->reverse_bo)
48
49#define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0)
50#define LTT_GET_FLOAT_BO(t) \
51 (((t)->float_word_order==__BYTE_ORDER)?0:1)
52
53#define SEQUENCE_AVG_ELEMENTS 1000
54
55typedef guint8 uint8_t;
56typedef guint16 uint16_t;
57typedef guint32 uint32_t;
58typedef guint64 uint64_t;
59
60/* Block and trace headers */
61
62struct ltt_trace_header_any {
63 uint32_t magic_number;
64 uint32_t arch_type;
65 uint32_t arch_variant;
66 uint32_t float_word_order;
67 uint8_t arch_size;
68 uint8_t major_version;
69 uint8_t minor_version;
70 uint8_t flight_recorder;
71 uint8_t alignment; /* Architecture alignment */
72} LTT_PACKED_STRUCT;
73
74struct ltt_trace_header_2_0 {
75 uint32_t magic_number;
76 uint32_t arch_type;
77 uint32_t arch_variant;
78 uint32_t float_word_order;
79 uint8_t arch_size;
80 uint8_t major_version;
81 uint8_t minor_version;
82 uint8_t flight_recorder;
83 uint8_t alignment; /* Architecture alignment */
84 uint8_t tscbits;
85 uint8_t eventbits;
86 uint8_t unused1;
87 uint32_t freq_scale;
88 uint64_t start_freq;
89 uint64_t start_tsc;
90 uint64_t start_monotonic;
91 uint64_t start_time_sec;
92 uint64_t start_time_usec;
93} LTT_PACKED_STRUCT;
94
95struct ltt_block_start_header {
96 struct {
97 uint64_t cycle_count;
98 uint64_t freq;
99 } begin;
100 struct {
101 uint64_t cycle_count;
102 uint64_t freq;
103 } end;
104 uint32_t lost_size; /* Size unused at the end of the buffer */
105 uint32_t buf_size; /* The size of this sub-buffer */
106 struct ltt_trace_header_any trace[0];
107} LTT_PACKED_STRUCT;
108
109
110enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED };
111
112typedef struct _LttBuffer {
113 void * head;
114 unsigned int index;
115
116 struct {
117 LttTime timestamp;
118 uint64_t cycle_count;
119 uint64_t freq; /* Frequency in khz */
120 } begin;
121 struct {
122 LttTime timestamp;
123 uint64_t cycle_count;
124 uint64_t freq; /* Frequency in khz */
125 } end;
126 uint32_t lost_size; /* Size unused at the end of the buffer */
127
128 /* Timekeeping */
129 uint64_t tsc; /* Current timestamp counter */
130 uint64_t freq; /* Frequency in khz */
131 //double nsecs_per_cycle; /* Precalculated from freq */
132 guint32 cyc2ns_scale;
133} LttBuffer;
134
135struct LttTracefile {
136 gboolean cpu_online; //is the cpu online ?
137 GQuark long_name; //tracefile complete filename
138 GQuark name; //tracefile name
139 guint cpu_num; //cpu number of the tracefile
140 guint tid; //Usertrace tid, else 0
141 guint pgid; //Usertrace pgid, else 0
142 guint64 creation; //Usertrace creation, else 0
143 LttTrace * trace; //trace containing the tracefile
144 int fd; //file descriptor
145 off_t file_size; //file size
146 //unsigned block_size; //block_size
147 guint num_blocks; //number of blocks in the file
148 gboolean reverse_bo; //must we reverse byte order ?
149 gboolean float_word_order; //what is the byte order of floats ?
150 size_t alignment; //alignment of events in the tracefile.
151 // 0 or the architecture size in bytes.
152
153 size_t buffer_header_size;
154 uint8_t tscbits;
155 uint8_t eventbits;
156 uint64_t tsc_mask;
157 uint64_t tsc_mask_next_bit; //next MSB after the mask
158
159 /* Current event */
160 LttEvent event; //Event currently accessible in the trace
161
162 /* Current block */
163 LttBuffer buffer; //current buffer
164 guint32 buf_size; /* The size of blocks */
165};
166
167/* The characteristics of the system on which the trace was obtained
168 is described in a LttSystemDescription structure. */
169
170struct LttSystemDescription {
171 gchar *description;
172 gchar *node_name;
173 gchar *domain_name;
174 unsigned nb_cpu;
175 LttArchSize size;
176 LttArchEndian endian;
177 gchar *kernel_name;
178 gchar *kernel_release;
179 gchar *kernel_version;
180 gchar *machine;
181 gchar *processor;
182 gchar *hardware_platform;
183 gchar *operating_system;
184 LttTime trace_start;
185 LttTime trace_end;
186};
187
188/* Calculate the offset needed to align the type.
189 * If alignment is 0, alignment is disactivated.
190 * else, the function returns the offset needed to
191 * align align_drift on the alignment value (should be
192 * the size of the architecture). */
193static inline unsigned int ltt_align(size_t align_drift,
194 size_t size_of_type,
195 size_t alignment)
196{
197 size_t align_offset = min(alignment, size_of_type);
198
199 if(!alignment)
200 return 0;
201
202 g_assert(size_of_type != 0);
203 return ((align_offset - align_drift) & (align_offset-1));
204}
205
206
207#endif /* LTT_PRIVATE_H */
This page took 0.023432 seconds and 4 git commands to generate.