Graphical mode synchronization
[lttv.git] / lttv / lttv / sync.h
CommitLineData
800dfee0
BP
1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2008 Benjamin Poirier <benjamin.poirier@polymtl.ca>
3 *
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;
7 *
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.
12 *
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,
16 * MA 02111-1307, USA.
17 */
18
19#ifndef SYNC_H
20#define SYNC_H
21
22#include <glib.h>
23#include <stdbool.h>
24#include <stdio.h>
25#include <sys/time.h>
26
27#include <lttv/tracecontext.h>
28#include <lttv/traceset.h>
29
30
31#ifndef g_debug
32#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
33#endif
34
35#ifndef g_info
36#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
37#endif
38
39
40struct _Packet;
41
42typedef struct
43{
44 struct _Packet* packet;
45 LttTrace* trace;
46 LttCycleCount tsc;
47 void* skb;
48} NetEvent;
49
50typedef struct
51{
52 uint32_t saddr, daddr;
53 uint16_t source, dest;
54} ConnectionKey;
55
56typedef struct _Packet
57{
58 ConnectionKey connKey;
59 unsigned int tot_len, ihl, seq, ack_seq, doff, ack, rst, syn, fin;
60 NetEvent* inE, * outE;
61 GQueue* acks;
62} Packet;
63
64typedef struct
65{
66 unsigned int n;
67 // notation: s__: sum of __; __2: __ squared; example sd2: sum of d squared
68 double st, st2, sd, sd2, std, x, d0, e;
69} Fit;
70
71typedef struct
72{
73 double errorSum;
74 unsigned int* previousVertex;
75 unsigned int reference;
76} Graph;
77
78typedef struct
79{
80 int totRecv, totRecvIp, totInE, totOutE, totPacket, totExchangeEffective,
81 totExchangeReal;
82 int totPacketNeedAck, totPacketCummAcked;
83} Stats;
84
85typedef struct
86{
87 LttvTracesetContext* tsc;
88
89 unsigned int traceNb;
90 // unsigned int traceNumTable[trace*]
91 GHashTable* traceNumTable;
92
93 // hookListList conceptually is a two dimensionnal array of LttvTraceHook
94 // elements. It uses GArrays to interface with other lttv functions that
95 // do.
96 GArray* hookListList;
97
98 // inE* pendingRecv[trace]
99 GHashTable* pendingRecv;
100 // inE* unMatchedInE[packet]
101 GHashTable* unMatchedInE;
102 // outE* unMatchedOutE[packet]
103 GHashTable* unMatchedOutE;
104 // packet* unAcked[connKey]
105 GHashTable* unAcked;
106 Fit** fitArray;
107
108 GQueue* graphList;
109
110 FILE* dataFd;
111 Stats* stats;
112} SyncState;
113
114typedef struct
115{
116 LttvTraceHook* traceHook;
117 SyncState* syncState;
118} HookData;
119
120
121static void init();
122static void destroy();
123
124void sync_traceset(LttvTracesetContext* const tsc);
125
126void registerHooks(SyncState* const syncState);
127void unregisterHooks(SyncState* const syncState);
128void finalizeLSA(SyncState* const syncState);
129void doGraphProcessing(SyncState* const syncState);
130void calculateFactors(SyncState* const syncState);
131
132static gboolean process_event_by_id(void* hook_data, void* call_data);
133
134static void matchEvents(NetEvent* const netEvent, GHashTable* const unMatchedList,
135 GHashTable* const unMatchedOppositeList, LttEvent* const event,
136 LttvTraceHook* const trace_hook, const size_t fieldOffset);
137
138static bool isAck(const Packet* const packet);
139static bool isAcking(const Packet* const ackPacket, const Packet* const
140 ackedPacket);
141static bool needsAck(const Packet* const packet);
142
143static bool connectionKeyEqual(const ConnectionKey* const a, const
144 ConnectionKey* const b);
145
146static void netEventListDestroy(gpointer data);
147static void netEventRemove(gpointer data, gpointer user_data);
148
149static guint netEventPacketHash(gconstpointer key);
150static gboolean netEventPacketEqual(gconstpointer a, gconstpointer b);
151static void ghtDestroyNetEvent(gpointer data);
152
153static void packetListDestroy(gpointer data);
154static void packetRemove(gpointer data, gpointer user_data);
155
156static void destroyPacket(Packet* const packet);
157static void destroyNetEvent(NetEvent* const event);
158
159static void graphRemove(gpointer data, gpointer user_data);
160
161static gint netEventSkbCompare(gconstpointer a, gconstpointer b);
162static gint netEventPacketCompare(gconstpointer a, gconstpointer b);
163static gint packetAckCompare(gconstpointer a, gconstpointer b);
164static gint graphTraceCompare(gconstpointer a, gconstpointer b);
165
166static guint connectionHash(gconstpointer key);
167static gboolean connectionEqual(gconstpointer a, gconstpointer b);
168static void connectionDestroy(gpointer data);
169
170static void convertIP(char* const str, const uint32_t addr);
171static void printPacket(const Packet* const packet);
172
173static void shortestPath(Fit* const* const fitArray, const unsigned int
174 traceNum, const unsigned int traceNb, double* const distances, unsigned
175 int* const previousVertex);
176static double sumDistances(const double* const distances, const unsigned int traceNb);
177static void factors(Fit* const* const fitArray, const unsigned int* const
178 previousVertex, const unsigned int traceNum, double* const drift, double*
179 const offset, double* const stDev);
180
181static void timeDiff(struct timeval* const end, const struct timeval* const start);
182
183#endif // SYNC_H
This page took 0.028279 seconds and 4 git commands to generate.