| 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 | |
| 40 | struct _Packet; |
| 41 | |
| 42 | typedef struct |
| 43 | { |
| 44 | struct _Packet* packet; |
| 45 | LttTrace* trace; |
| 46 | LttCycleCount tsc; |
| 47 | void* skb; |
| 48 | } NetEvent; |
| 49 | |
| 50 | typedef struct |
| 51 | { |
| 52 | uint32_t saddr, daddr; |
| 53 | uint16_t source, dest; |
| 54 | } ConnectionKey; |
| 55 | |
| 56 | typedef 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 | |
| 64 | typedef 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 | |
| 71 | typedef struct |
| 72 | { |
| 73 | double errorSum; |
| 74 | unsigned int* previousVertex; |
| 75 | unsigned int reference; |
| 76 | } Graph; |
| 77 | |
| 78 | typedef struct |
| 79 | { |
| 80 | int totRecv, totRecvIp, totInE, totOutE, totPacket, totExchangeEffective, |
| 81 | totExchangeReal; |
| 82 | int totPacketNeedAck, totPacketCummAcked; |
| 83 | } Stats; |
| 84 | |
| 85 | typedef 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 | |
| 114 | typedef struct |
| 115 | { |
| 116 | LttvTraceHook* traceHook; |
| 117 | SyncState* syncState; |
| 118 | } HookData; |
| 119 | |
| 120 | |
| 121 | static void init(); |
| 122 | static void destroy(); |
| 123 | |
| 124 | void sync_traceset(LttvTracesetContext* const tsc); |
| 125 | |
| 126 | void registerHooks(SyncState* const syncState); |
| 127 | void unregisterHooks(SyncState* const syncState); |
| 128 | void finalizeLSA(SyncState* const syncState); |
| 129 | void doGraphProcessing(SyncState* const syncState); |
| 130 | void calculateFactors(SyncState* const syncState); |
| 131 | |
| 132 | static gboolean process_event_by_id(void* hook_data, void* call_data); |
| 133 | |
| 134 | static 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 | |
| 138 | static bool isAck(const Packet* const packet); |
| 139 | static bool isAcking(const Packet* const ackPacket, const Packet* const |
| 140 | ackedPacket); |
| 141 | static bool needsAck(const Packet* const packet); |
| 142 | |
| 143 | static bool connectionKeyEqual(const ConnectionKey* const a, const |
| 144 | ConnectionKey* const b); |
| 145 | |
| 146 | static void netEventListDestroy(gpointer data); |
| 147 | static void netEventRemove(gpointer data, gpointer user_data); |
| 148 | |
| 149 | static guint netEventPacketHash(gconstpointer key); |
| 150 | static gboolean netEventPacketEqual(gconstpointer a, gconstpointer b); |
| 151 | static void ghtDestroyNetEvent(gpointer data); |
| 152 | |
| 153 | static void packetListDestroy(gpointer data); |
| 154 | static void packetRemove(gpointer data, gpointer user_data); |
| 155 | |
| 156 | static void destroyPacket(Packet* const packet); |
| 157 | static void destroyNetEvent(NetEvent* const event); |
| 158 | |
| 159 | static void graphRemove(gpointer data, gpointer user_data); |
| 160 | |
| 161 | static gint netEventSkbCompare(gconstpointer a, gconstpointer b); |
| 162 | static gint netEventPacketCompare(gconstpointer a, gconstpointer b); |
| 163 | static gint packetAckCompare(gconstpointer a, gconstpointer b); |
| 164 | static gint graphTraceCompare(gconstpointer a, gconstpointer b); |
| 165 | |
| 166 | static guint connectionHash(gconstpointer key); |
| 167 | static gboolean connectionEqual(gconstpointer a, gconstpointer b); |
| 168 | static void connectionDestroy(gpointer data); |
| 169 | |
| 170 | static void convertIP(char* const str, const uint32_t addr); |
| 171 | static void printPacket(const Packet* const packet); |
| 172 | |
| 173 | static void shortestPath(Fit* const* const fitArray, const unsigned int |
| 174 | traceNum, const unsigned int traceNb, double* const distances, unsigned |
| 175 | int* const previousVertex); |
| 176 | static double sumDistances(const double* const distances, const unsigned int traceNb); |
| 177 | static 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 | |
| 181 | static void timeDiff(struct timeval* const end, const struct timeval* const start); |
| 182 | |
| 183 | #endif // SYNC_H |