Perform trace factor reduction as a separate step
[lttv.git] / lttv / lttv / sync / data_structures.h
CommitLineData
10341d26 1/* This file is part of the Linux Trace Toolkit viewer
277e5b53 2 * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca>
10341d26 3 *
277e5b53
BP
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or (at
7 * your option) any later version.
10341d26 8 *
277e5b53
BP
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
10341d26 13 *
277e5b53
BP
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
10341d26
BP
16 */
17
18#ifndef DATA_STRUCTURES_H
19#define DATA_STRUCTURES_H
20
21#include <glib.h>
22#include <stdbool.h>
23#include <stdint.h>
24
f10c27a8
BP
25
26enum Direction
27{
28 OUT,
29 IN,
30};
31
32enum EventType
33{
34 TCP,
35 UDP,
2bd4b3e4 36 TYPE_COUNT // This must be the last field
f10c27a8
BP
37};
38
10341d26
BP
39// Stage 1 to 2: These structures are passed from processing to matching modules
40// TCP events
41typedef struct
42{
43 uint32_t saddr, daddr;
44 uint16_t source, dest;
45} ConnectionKey;
46
47typedef struct
48{
49 ConnectionKey connectionKey;
50 uint8_t ihl;
51 uint16_t tot_len;
52 uint32_t seq, ack_seq;
53 uint8_t doff;
54 uint8_t ack, rst, syn, fin;
55} SegmentKey;
56
10341d26
BP
57typedef struct
58{
59 enum Direction direction;
60 SegmentKey* segmentKey;
61} TCPEvent;
62
63// UDP events
64typedef struct
65{
66 uint32_t saddr, daddr;
f6691532
BP
67 uint16_t source, dest;
68 uint16_t ulen;
10341d26
BP
69 uint8_t dataKey[8];
70} DatagramKey;
71
72typedef struct
73{
74 enum Direction direction;
75 DatagramKey* datagramKey;
76 bool unicast;
77} UDPEvent;
78
76be6fc2
BP
79typedef struct
80{
81 uint32_t seconds;
82 uint32_t nanosec;
83} WallTime;
84
10341d26
BP
85typedef struct _Event
86{
87 unsigned long traceNum;
467066ee
BP
88 // wallTime is corrected according to factors in trace struct, cpuTime
89 // is not
76be6fc2
BP
90 uint64_t cpuTime;
91 WallTime wallTime;
10341d26
BP
92
93 // specific event structures and functions could be in separate files and
94 // type could be an int
f6691532 95 enum EventType type;
10341d26
BP
96 // event could be a void*, this union is to avoid having to cast
97 union {
98 TCPEvent* tcpEvent;
99 UDPEvent* udpEvent;
100 } event;
101
d4721e1a 102 void (*copy)(const struct _Event* const event, struct _Event** const newEvent);
10341d26
BP
103 void (*destroy)(struct _Event* const event);
104} Event;
105
106// Stage 2 to 3: These structures are passed from matching to analysis modules
107typedef struct _Message
108{
109 Event* inE, * outE;
110
111 void (*print)(const struct _Message* const message);
112} Message;
113
114typedef struct
115{
116 Message* message;
ffa21cfd 117 // Event* acks[]
10341d26
BP
118 GQueue* acks;
119} Exchange;
120
121typedef struct
122{
ffa21cfd 123 // Event* events[]
10341d26
BP
124 GQueue* events;
125} Broadcast;
126
0a87ec9a
BP
127// Stage 4: These structures contain correction factors
128/* Correction factors for each trace, this is the final result of
129 * synchronization */
10341d26
BP
130typedef struct
131{
132 double drift, offset;
133} Factors;
134
0a87ec9a
BP
135// Correction factors between trace pairs, to be used for reduction
136typedef enum
137{
138 EXACT,
139 /* Used for identity factors (a0= 0, a1= 1) that map a trace to itself. In
140 * this case, min, max and accuracy are NULL.
141 */
142
143 ACCURATE,
144 /* The approximation is the middle of the min and max limits. All fields
145 * are initialized.
146 */
147
148 APPROXIMATE,
149 /* min and max are not available. The approximation is a "best effort".
150 * min and max are NULL.
151 */
152
153 INCOMPLETE,
154 /* min or max is available but not both. approx and accuracy are not
155 * NULL.
156 */
157
158 ABSENT,
159 /* The pair of trace did not have communications in both directions (maybe
160 * even no communication at all). approx and accuracy are NULL.
161 */
162
163 SCREWED,
164 /* The algorithms are screwed. All fields may be NULL.
165 */
166
167 APPROX_NB, // This must be the last member
168} ApproxType;
169
170extern const char* const approxNames[APPROX_NB];
171
172typedef struct
173{
174 Factors* min, * max, * approx;
175 ApproxType type;
176 double accuracy;
177} PairFactors;
178
179typedef struct
180{
181 unsigned int refCount;
182 unsigned int traceNb;
183 PairFactors** pairFactors;
184} AllFactors;
185
10341d26
BP
186
187// ConnectionKey-related functions
188guint ghfConnectionKeyHash(gconstpointer key);
189
190gboolean gefConnectionKeyEqual(gconstpointer a, gconstpointer b);
191bool connectionKeyEqual(const ConnectionKey* const a, const ConnectionKey*
192 const b);
193
194void gdnConnectionKeyDestroy(gpointer data);
195
196// SegmentKey-related functions
197guint ghfSegmentKeyHash(gconstpointer key);
198gboolean gefSegmentKeyEqual(gconstpointer a, gconstpointer b);
199
f10c27a8
BP
200// DatagramKey-related functions
201guint ghfDatagramKeyHash(gconstpointer key);
202gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b);
203void gdnDestroyDatagramKey(gpointer data);
204
10341d26
BP
205// Event-related functions
206void gdnDestroyEvent(gpointer data);
d4721e1a
BP
207void copyEvent(const Event* const event, Event** const newEvent);
208void copyTCPEvent(const Event* const event, Event** const newEvent);
209void copyUDPEvent(const Event* const event, Event** const newEvent);
10341d26
BP
210void destroyEvent(Event* const event);
211void destroyTCPEvent(Event* const event);
212void destroyUDPEvent(Event* const event);
f6691532 213void gfDestroyEvent(gpointer data, gpointer user_data);
76be6fc2 214double wallTimeSub(const WallTime const* tA, const WallTime const* tB);
66eaf2eb 215void gfAddEventToArray(gpointer data, gpointer user_data);
10341d26
BP
216
217// Message-related functions
218void printTCPSegment(const Message* const segment);
219void convertIP(char* const str, const uint32_t addr);
220
221gint gcfTCPSegmentAckCompare(gconstpointer a, gconstpointer b);
222bool isAcking(const Message* const ackSegment, const Message* const ackedSegment);
223
224void gdnTCPSegmentListDestroy(gpointer data);
225void gfTCPSegmentDestroy(gpointer data, gpointer user_data);
226void destroyTCPSegment(Message* const segment);
227
228// Exchange-related functions
229void destroyTCPExchange(Exchange* const exchange);
f6691532
BP
230
231// Broadcast-related functions
232void gdnDestroyBroadcast(gpointer data);
233void destroyBroadcast(Broadcast* const broadcast);
234
0a87ec9a
BP
235// Factor-related functions
236void destroyPairFactors(PairFactors* factorsCHull);
237
238AllFactors* createAllFactors(const unsigned int traceNb);
239void freeAllFactors(AllFactors* const allFactors);
240
10341d26 241#endif
This page took 0.034494 seconds and 4 git commands to generate.