| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2009, 2010 Benjamin Poirier <benjamin.poirier@polymtl.ca> |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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/>. |
| 16 | */ |
| 17 | |
| 18 | #ifdef HAVE_CONFIG_H |
| 19 | #include <config.h> |
| 20 | #endif |
| 21 | |
| 22 | #include <netinet/in.h> |
| 23 | #include <stdarg.h> |
| 24 | #include <stdint.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #include "sync_chain.h" |
| 29 | #include "event_processing_lttng_common.h" |
| 30 | |
| 31 | #include "event_processing_lttng_standard.h" |
| 32 | |
| 33 | /* IPv4 Ethertype, taken from <linux/if_ether.h>, unlikely to change as it's |
| 34 | * defined by IANA: http://www.iana.org/assignments/ethernet-numbers |
| 35 | */ |
| 36 | #define ETH_P_IP 0x0800 |
| 37 | |
| 38 | |
| 39 | // Functions common to all processing modules |
| 40 | static void initProcessingLTTVStandard(SyncState* const syncState, ...); |
| 41 | static void destroyProcessingLTTVStandard(SyncState* const syncState); |
| 42 | |
| 43 | static AllFactors* finalizeProcessingLTTVStandard(SyncState* const syncState); |
| 44 | static void printProcessingStatsLTTVStandard(SyncState* const syncState); |
| 45 | static void writeProcessingGraphVariablesLTTVStandard(SyncState* const |
| 46 | syncState, const unsigned int i); |
| 47 | static void writeProcessingTraceTraceOptionsLTTVStandard(SyncState* const |
| 48 | syncState, const unsigned int i, const unsigned int j); |
| 49 | static void writeProcessingTraceTimeOptionsLTTVStandard(SyncState* const |
| 50 | syncState, const unsigned int i, const unsigned int j); |
| 51 | |
| 52 | // Functions specific to this module |
| 53 | static gboolean processEventLTTVStandard(void* hookData, void* callData); |
| 54 | static void partialDestroyProcessingLTTVStandard(SyncState* const syncState); |
| 55 | |
| 56 | |
| 57 | static ProcessingModule processingModuleLTTVStandard = { |
| 58 | .name= "LTTV-standard", |
| 59 | .initProcessing= &initProcessingLTTVStandard, |
| 60 | .destroyProcessing= &destroyProcessingLTTVStandard, |
| 61 | .finalizeProcessing= &finalizeProcessingLTTVStandard, |
| 62 | .printProcessingStats= &printProcessingStatsLTTVStandard, |
| 63 | .graphFunctions= { |
| 64 | .writeVariables= &writeProcessingGraphVariablesLTTVStandard, |
| 65 | .writeTraceTraceOptions= &writeProcessingTraceTraceOptionsLTTVStandard, |
| 66 | .writeTraceTimeOptions= &writeProcessingTraceTimeOptionsLTTVStandard, |
| 67 | }, |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | /* |
| 72 | * Processing Module registering function |
| 73 | */ |
| 74 | void registerProcessingLTTVStandard() |
| 75 | { |
| 76 | g_queue_push_tail(&processingModules, &processingModuleLTTVStandard); |
| 77 | |
| 78 | createQuarks(); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /* |
| 83 | * Allocate and initialize data structures for synchronizing a traceset. |
| 84 | * Register event hooks. |
| 85 | * |
| 86 | * Args: |
| 87 | * syncState: container for synchronization data. |
| 88 | * This function allocates these processingData members: |
| 89 | * traceNumTable |
| 90 | * pendingRecv |
| 91 | * hookListList |
| 92 | * stats |
| 93 | * traceSetContext: LttvTracesetContext*, set of LTTV traces |
| 94 | */ |
| 95 | static void initProcessingLTTVStandard(SyncState* const syncState, ...) |
| 96 | { |
| 97 | unsigned int i; |
| 98 | ProcessingDataLTTVStandard* processingData; |
| 99 | va_list ap; |
| 100 | |
| 101 | processingData= malloc(sizeof(ProcessingDataLTTVStandard)); |
| 102 | syncState->processingData= processingData; |
| 103 | va_start(ap, syncState); |
| 104 | processingData->traceSetContext= va_arg(ap, LttvTracesetContext*); |
| 105 | va_end(ap); |
| 106 | syncState->traceNb= |
| 107 | lttv_traceset_number(processingData->traceSetContext->ts); |
| 108 | processingData->hookListList= g_array_sized_new(FALSE, FALSE, |
| 109 | sizeof(GArray*), syncState->traceNb); |
| 110 | |
| 111 | processingData->traceNumTable= g_hash_table_new(&g_direct_hash, NULL); |
| 112 | for(i= 0; i < syncState->traceNb; i++) |
| 113 | { |
| 114 | g_hash_table_insert(processingData->traceNumTable, |
| 115 | processingData->traceSetContext->traces[i]->t, |
| 116 | GUINT_TO_POINTER(i)); |
| 117 | } |
| 118 | |
| 119 | processingData->pendingRecv= malloc(sizeof(GHashTable*) * |
| 120 | syncState->traceNb); |
| 121 | for(i= 0; i < syncState->traceNb; i++) |
| 122 | { |
| 123 | processingData->pendingRecv[i]= g_hash_table_new_full(&g_direct_hash, |
| 124 | NULL, NULL, &gdnDestroyEvent); |
| 125 | } |
| 126 | |
| 127 | if (syncState->stats) |
| 128 | { |
| 129 | processingData->stats= calloc(1, sizeof(ProcessingStatsLTTVStandard)); |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | processingData->stats= NULL; |
| 134 | } |
| 135 | |
| 136 | if (syncState->graphsStream) |
| 137 | { |
| 138 | processingData->graphs= malloc(syncState->traceNb * |
| 139 | sizeof(ProcessingGraphsLTTVStandard)); |
| 140 | |
| 141 | for(i= 0; i < syncState->traceNb; i++) |
| 142 | { |
| 143 | LttTrace* traceI= processingData->traceSetContext->traces[i]->t; |
| 144 | |
| 145 | processingData->graphs[i].startFreq= traceI->start_freq; |
| 146 | processingData->graphs[i].freqScale= traceI->freq_scale; |
| 147 | } |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | processingData->graphs= NULL; |
| 152 | } |
| 153 | |
| 154 | registerHooks(processingData->hookListList, |
| 155 | processingData->traceSetContext, &processEventLTTVStandard, syncState, |
| 156 | syncState->matchingModule->canMatch); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /* |
| 161 | * Call the partial processing destroyer, obtain and the factors from |
| 162 | * downstream |
| 163 | * |
| 164 | * Args: |
| 165 | * syncState container for synchronization data. |
| 166 | * |
| 167 | * Returns: |
| 168 | * AllFactors synchronization factors for each trace pair |
| 169 | */ |
| 170 | static AllFactors* finalizeProcessingLTTVStandard(SyncState* const syncState) |
| 171 | { |
| 172 | ProcessingDataLTTVStandard* processingData; |
| 173 | |
| 174 | processingData= (ProcessingDataLTTVStandard*) syncState->processingData; |
| 175 | |
| 176 | partialDestroyProcessingLTTVStandard(syncState); |
| 177 | |
| 178 | return syncState->matchingModule->finalizeMatching(syncState); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /* |
| 183 | * Print statistics related to processing. Must be called after |
| 184 | * finalizeProcessing. |
| 185 | * |
| 186 | * Args: |
| 187 | * syncState container for synchronization data. |
| 188 | */ |
| 189 | static void printProcessingStatsLTTVStandard(SyncState* const syncState) |
| 190 | { |
| 191 | ProcessingDataLTTVStandard* processingData; |
| 192 | |
| 193 | if (!syncState->stats) |
| 194 | { |
| 195 | return; |
| 196 | } |
| 197 | |
| 198 | processingData= (ProcessingDataLTTVStandard*) syncState->processingData; |
| 199 | |
| 200 | printf("LTTV processing stats:\n"); |
| 201 | printf("\treceived frames: %d\n", processingData->stats->totRecv); |
| 202 | printf("\treceived frames that are IP: %d\n", |
| 203 | processingData->stats->totRecvIp); |
| 204 | if (syncState->matchingModule->canMatch[TCP]) |
| 205 | { |
| 206 | printf("\treceived and processed packets that are TCP: %d\n", |
| 207 | processingData->stats->totRecvTCP); |
| 208 | } |
| 209 | if (syncState->matchingModule->canMatch[UDP]) |
| 210 | { |
| 211 | printf("\treceived and processed packets that are UDP: %d\n", |
| 212 | processingData->stats->totRecvUDP); |
| 213 | } |
| 214 | if (syncState->matchingModule->canMatch[TCP]) |
| 215 | { |
| 216 | printf("\tsent packets that are TCP: %d\n", |
| 217 | processingData->stats->totOutE); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | |
| 222 | /* |
| 223 | * Unregister event hooks. Deallocate processingData. |
| 224 | * |
| 225 | * Args: |
| 226 | * syncState: container for synchronization data. |
| 227 | * This function deallocates these processingData members: |
| 228 | * stats |
| 229 | */ |
| 230 | static void destroyProcessingLTTVStandard(SyncState* const syncState) |
| 231 | { |
| 232 | ProcessingDataLTTVStandard* processingData; |
| 233 | |
| 234 | processingData= (ProcessingDataLTTVStandard*) syncState->processingData; |
| 235 | |
| 236 | if (processingData == NULL) |
| 237 | { |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | partialDestroyProcessingLTTVStandard(syncState); |
| 242 | |
| 243 | if (syncState->stats) |
| 244 | { |
| 245 | free(processingData->stats); |
| 246 | } |
| 247 | |
| 248 | if (syncState->graphsStream) |
| 249 | { |
| 250 | free(processingData->graphs); |
| 251 | } |
| 252 | |
| 253 | free(syncState->processingData); |
| 254 | syncState->processingData= NULL; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | /* |
| 259 | * Unregister event hooks. Deallocate some of processingData. |
| 260 | * |
| 261 | * This function can be called right after the events have been processed to |
| 262 | * free some data structures that are not needed for finalization. |
| 263 | * |
| 264 | * Args: |
| 265 | * syncState: container for synchronization data. |
| 266 | * This function deallocates these members: |
| 267 | * traceNumTable |
| 268 | * hookListList |
| 269 | * pendingRecv |
| 270 | */ |
| 271 | static void partialDestroyProcessingLTTVStandard(SyncState* const syncState) |
| 272 | { |
| 273 | unsigned int i; |
| 274 | ProcessingDataLTTVStandard* processingData; |
| 275 | |
| 276 | processingData= (ProcessingDataLTTVStandard*) syncState->processingData; |
| 277 | |
| 278 | if (processingData == NULL || processingData->traceNumTable == NULL) |
| 279 | { |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | g_hash_table_destroy(processingData->traceNumTable); |
| 284 | processingData->traceNumTable= NULL; |
| 285 | |
| 286 | for(i= 0; i < syncState->traceNb; i++) |
| 287 | { |
| 288 | |
| 289 | g_debug("Cleaning up pendingRecv list"); |
| 290 | g_hash_table_destroy(processingData->pendingRecv[i]); |
| 291 | } |
| 292 | free(processingData->pendingRecv); |
| 293 | |
| 294 | unregisterHooks(processingData->hookListList, |
| 295 | processingData->traceSetContext); |
| 296 | } |
| 297 | |
| 298 | |
| 299 | /* |
| 300 | * Lttv hook function that will be called for network events |
| 301 | * |
| 302 | * Args: |
| 303 | * hookData: LttvTraceHook* for the type of event that generated the call |
| 304 | * callData: LttvTracefileContext* at the moment of the event |
| 305 | * |
| 306 | * Returns: |
| 307 | * FALSE Always returns FALSE, meaning to keep processing hooks for |
| 308 | * this event |
| 309 | */ |
| 310 | static gboolean processEventLTTVStandard(void* hookData, void* callData) |
| 311 | { |
| 312 | LttvTraceHook* traceHook; |
| 313 | LttvTracefileContext* tfc; |
| 314 | LttEvent* event; |
| 315 | LttCycleCount tsc; |
| 316 | LttTime time; |
| 317 | WallTime wTime; |
| 318 | LttTrace* trace; |
| 319 | unsigned long traceNum; |
| 320 | struct marker_info* info; |
| 321 | SyncState* syncState; |
| 322 | ProcessingDataLTTVStandard* processingData; |
| 323 | gpointer traceNumP; |
| 324 | |
| 325 | traceHook= (LttvTraceHook*) hookData; |
| 326 | tfc= (LttvTracefileContext*) callData; |
| 327 | trace= tfc->t_context->t; |
| 328 | syncState= (SyncState*) traceHook->hook_data; |
| 329 | processingData= (ProcessingDataLTTVStandard*) syncState->processingData; |
| 330 | event= ltt_tracefile_get_event(tfc->tf); |
| 331 | info= marker_get_info_from_id(tfc->tf->mdata, event->event_id); |
| 332 | tsc= ltt_event_cycle_count(event); |
| 333 | time= ltt_event_time(event); |
| 334 | wTime.seconds= time.tv_sec; |
| 335 | wTime.nanosec= time.tv_nsec; |
| 336 | |
| 337 | g_assert(g_hash_table_lookup_extended(processingData->traceNumTable, |
| 338 | trace, NULL, &traceNumP)); |
| 339 | traceNum= GPOINTER_TO_INT(traceNumP); |
| 340 | |
| 341 | g_debug("Process event: time: %ld.%09ld trace: %ld (%p) name: %s ", |
| 342 | time.tv_sec, time.tv_nsec, traceNum, trace, |
| 343 | g_quark_to_string(info->name)); |
| 344 | |
| 345 | if (info->name == LTT_EVENT_DEV_XMIT_EXTENDED) |
| 346 | { |
| 347 | Event* outE; |
| 348 | |
| 349 | if (!ltt_event_get_unsigned(event, |
| 350 | lttv_trace_get_hook_field(traceHook, 1)) == ETH_P_IP || |
| 351 | !ltt_event_get_unsigned(event, |
| 352 | lttv_trace_get_hook_field(traceHook, 2)) == IPPROTO_TCP) |
| 353 | { |
| 354 | return FALSE; |
| 355 | } |
| 356 | |
| 357 | if (!syncState->matchingModule->canMatch[TCP]) |
| 358 | { |
| 359 | return FALSE; |
| 360 | } |
| 361 | |
| 362 | if (syncState->stats) |
| 363 | { |
| 364 | processingData->stats->totOutE++; |
| 365 | } |
| 366 | |
| 367 | outE= malloc(sizeof(Event)); |
| 368 | outE->traceNum= traceNum; |
| 369 | outE->cpuTime= tsc; |
| 370 | outE->wallTime= wTime; |
| 371 | outE->type= TCP; |
| 372 | outE->copy= ©TCPEvent; |
| 373 | outE->destroy= &destroyTCPEvent; |
| 374 | outE->event.tcpEvent= malloc(sizeof(TCPEvent)); |
| 375 | outE->event.tcpEvent->direction= OUT; |
| 376 | outE->event.tcpEvent->segmentKey= malloc(sizeof(SegmentKey)); |
| 377 | outE->event.tcpEvent->segmentKey->connectionKey.saddr= |
| 378 | htonl(ltt_event_get_unsigned(event, |
| 379 | lttv_trace_get_hook_field(traceHook, 3))); |
| 380 | outE->event.tcpEvent->segmentKey->connectionKey.daddr= |
| 381 | htonl(ltt_event_get_unsigned(event, |
| 382 | lttv_trace_get_hook_field(traceHook, 4))); |
| 383 | outE->event.tcpEvent->segmentKey->tot_len= |
| 384 | ltt_event_get_unsigned(event, lttv_trace_get_hook_field(traceHook, |
| 385 | 5)); |
| 386 | outE->event.tcpEvent->segmentKey->ihl= ltt_event_get_unsigned(event, |
| 387 | lttv_trace_get_hook_field(traceHook, 6)); |
| 388 | outE->event.tcpEvent->segmentKey->connectionKey.source= |
| 389 | ltt_event_get_unsigned(event, lttv_trace_get_hook_field(traceHook, |
| 390 | 7)); |
| 391 | outE->event.tcpEvent->segmentKey->connectionKey.dest= |
| 392 | ltt_event_get_unsigned(event, lttv_trace_get_hook_field(traceHook, |
| 393 | 8)); |
| 394 | outE->event.tcpEvent->segmentKey->seq= ltt_event_get_unsigned(event, |
| 395 | lttv_trace_get_hook_field(traceHook, 9)); |
| 396 | outE->event.tcpEvent->segmentKey->ack_seq= |
| 397 | ltt_event_get_unsigned(event, lttv_trace_get_hook_field(traceHook, |
| 398 | 10)); |
| 399 | outE->event.tcpEvent->segmentKey->doff= ltt_event_get_unsigned(event, |
| 400 | lttv_trace_get_hook_field(traceHook, 11)); |
| 401 | outE->event.tcpEvent->segmentKey->ack= ltt_event_get_unsigned(event, |
| 402 | lttv_trace_get_hook_field(traceHook, 12)); |
| 403 | outE->event.tcpEvent->segmentKey->rst= ltt_event_get_unsigned(event, |
| 404 | lttv_trace_get_hook_field(traceHook, 13)); |
| 405 | outE->event.tcpEvent->segmentKey->syn= ltt_event_get_unsigned(event, |
| 406 | lttv_trace_get_hook_field(traceHook, 14)); |
| 407 | outE->event.tcpEvent->segmentKey->fin= ltt_event_get_unsigned(event, |
| 408 | lttv_trace_get_hook_field(traceHook, 15)); |
| 409 | |
| 410 | syncState->matchingModule->matchEvent(syncState, outE); |
| 411 | |
| 412 | g_debug("Output event done"); |
| 413 | } |
| 414 | else if (info->name == LTT_EVENT_DEV_RECEIVE) |
| 415 | { |
| 416 | guint32 protocol; |
| 417 | |
| 418 | if (syncState->stats) |
| 419 | { |
| 420 | processingData->stats->totRecv++; |
| 421 | } |
| 422 | |
| 423 | protocol= ltt_event_get_unsigned(event, |
| 424 | lttv_trace_get_hook_field(traceHook, 1)); |
| 425 | |
| 426 | if (protocol == ETH_P_IP) |
| 427 | { |
| 428 | Event* inE; |
| 429 | void* skb; |
| 430 | |
| 431 | if (syncState->stats) |
| 432 | { |
| 433 | processingData->stats->totRecvIp++; |
| 434 | } |
| 435 | |
| 436 | inE= malloc(sizeof(Event)); |
| 437 | inE->traceNum= traceNum; |
| 438 | inE->cpuTime= tsc; |
| 439 | inE->wallTime= wTime; |
| 440 | inE->event.tcpEvent= NULL; |
| 441 | inE->copy= ©Event; |
| 442 | inE->destroy= &destroyEvent; |
| 443 | |
| 444 | skb= (void*) (long) ltt_event_get_long_unsigned(event, |
| 445 | lttv_trace_get_hook_field(traceHook, 0)); |
| 446 | g_hash_table_replace(processingData->pendingRecv[traceNum], skb, |
| 447 | inE); |
| 448 | |
| 449 | g_debug("Adding inE %p for skb %p to pendingRecv", inE, skb); |
| 450 | } |
| 451 | } |
| 452 | else if (info->name == LTT_EVENT_TCPV4_RCV_EXTENDED) |
| 453 | { |
| 454 | Event* inE; |
| 455 | void* skb; |
| 456 | |
| 457 | // Search pendingRecv for an event with the same skb |
| 458 | skb= (void*) (long) ltt_event_get_long_unsigned(event, |
| 459 | lttv_trace_get_hook_field(traceHook, 0)); |
| 460 | |
| 461 | inE= (Event*) |
| 462 | g_hash_table_lookup(processingData->pendingRecv[traceNum], skb); |
| 463 | if (inE == NULL) |
| 464 | { |
| 465 | // This should only happen in case of lost events |
| 466 | g_warning("No matching pending receive event found"); |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | if (syncState->stats) |
| 471 | { |
| 472 | processingData->stats->totRecvTCP++; |
| 473 | } |
| 474 | |
| 475 | // If it's there, remove it and proceed with a receive event |
| 476 | g_hash_table_steal(processingData->pendingRecv[traceNum], skb); |
| 477 | |
| 478 | inE->type= TCP; |
| 479 | inE->event.tcpEvent= malloc(sizeof(TCPEvent)); |
| 480 | inE->copy= ©TCPEvent; |
| 481 | inE->destroy= &destroyTCPEvent; |
| 482 | inE->event.tcpEvent->direction= IN; |
| 483 | inE->event.tcpEvent->segmentKey= malloc(sizeof(SegmentKey)); |
| 484 | inE->event.tcpEvent->segmentKey->connectionKey.saddr= |
| 485 | htonl(ltt_event_get_unsigned(event, |
| 486 | lttv_trace_get_hook_field(traceHook, 1))); |
| 487 | inE->event.tcpEvent->segmentKey->connectionKey.daddr= |
| 488 | htonl(ltt_event_get_unsigned(event, |
| 489 | lttv_trace_get_hook_field(traceHook, 2))); |
| 490 | inE->event.tcpEvent->segmentKey->tot_len= |
| 491 | ltt_event_get_unsigned(event, |
| 492 | lttv_trace_get_hook_field(traceHook, 3)); |
| 493 | inE->event.tcpEvent->segmentKey->ihl= |
| 494 | ltt_event_get_unsigned(event, |
| 495 | lttv_trace_get_hook_field(traceHook, 4)); |
| 496 | inE->event.tcpEvent->segmentKey->connectionKey.source= |
| 497 | ltt_event_get_unsigned(event, |
| 498 | lttv_trace_get_hook_field(traceHook, 5)); |
| 499 | inE->event.tcpEvent->segmentKey->connectionKey.dest= |
| 500 | ltt_event_get_unsigned(event, |
| 501 | lttv_trace_get_hook_field(traceHook, 6)); |
| 502 | inE->event.tcpEvent->segmentKey->seq= |
| 503 | ltt_event_get_unsigned(event, |
| 504 | lttv_trace_get_hook_field(traceHook, 7)); |
| 505 | inE->event.tcpEvent->segmentKey->ack_seq= |
| 506 | ltt_event_get_unsigned(event, |
| 507 | lttv_trace_get_hook_field(traceHook, 8)); |
| 508 | inE->event.tcpEvent->segmentKey->doff= |
| 509 | ltt_event_get_unsigned(event, |
| 510 | lttv_trace_get_hook_field(traceHook, 9)); |
| 511 | inE->event.tcpEvent->segmentKey->ack= |
| 512 | ltt_event_get_unsigned(event, |
| 513 | lttv_trace_get_hook_field(traceHook, 10)); |
| 514 | inE->event.tcpEvent->segmentKey->rst= |
| 515 | ltt_event_get_unsigned(event, |
| 516 | lttv_trace_get_hook_field(traceHook, 11)); |
| 517 | inE->event.tcpEvent->segmentKey->syn= |
| 518 | ltt_event_get_unsigned(event, |
| 519 | lttv_trace_get_hook_field(traceHook, 12)); |
| 520 | inE->event.tcpEvent->segmentKey->fin= |
| 521 | ltt_event_get_unsigned(event, |
| 522 | lttv_trace_get_hook_field(traceHook, 13)); |
| 523 | |
| 524 | syncState->matchingModule->matchEvent(syncState, inE); |
| 525 | |
| 526 | g_debug("TCP input event %p for skb %p done", inE, skb); |
| 527 | } |
| 528 | } |
| 529 | else if (info->name == LTT_EVENT_UDPV4_RCV_EXTENDED) |
| 530 | { |
| 531 | Event* inE; |
| 532 | void* skb; |
| 533 | |
| 534 | // Search pendingRecv for an event with the same skb |
| 535 | skb= (void*) (long) ltt_event_get_long_unsigned(event, |
| 536 | lttv_trace_get_hook_field(traceHook, 0)); |
| 537 | |
| 538 | inE= (Event*) |
| 539 | g_hash_table_lookup(processingData->pendingRecv[traceNum], skb); |
| 540 | if (inE == NULL) |
| 541 | { |
| 542 | // This should only happen in case of lost events |
| 543 | g_warning("No matching pending receive event found"); |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | guint64 dataStart; |
| 548 | |
| 549 | if (syncState->stats) |
| 550 | { |
| 551 | processingData->stats->totRecvUDP++; |
| 552 | } |
| 553 | |
| 554 | // If it's there, remove it and proceed with a receive event |
| 555 | g_hash_table_steal(processingData->pendingRecv[traceNum], skb); |
| 556 | |
| 557 | inE->type= UDP; |
| 558 | inE->event.udpEvent= malloc(sizeof(UDPEvent)); |
| 559 | inE->copy= ©UDPEvent; |
| 560 | inE->destroy= &destroyUDPEvent; |
| 561 | inE->event.udpEvent->direction= IN; |
| 562 | inE->event.udpEvent->datagramKey= malloc(sizeof(DatagramKey)); |
| 563 | inE->event.udpEvent->datagramKey->saddr= |
| 564 | htonl(ltt_event_get_unsigned(event, |
| 565 | lttv_trace_get_hook_field(traceHook, 1))); |
| 566 | inE->event.udpEvent->datagramKey->daddr= |
| 567 | htonl(ltt_event_get_unsigned(event, |
| 568 | lttv_trace_get_hook_field(traceHook, 2))); |
| 569 | inE->event.udpEvent->unicast= ltt_event_get_unsigned(event, |
| 570 | lttv_trace_get_hook_field(traceHook, 3)) == 0 ? false : true; |
| 571 | inE->event.udpEvent->datagramKey->ulen= |
| 572 | ltt_event_get_unsigned(event, |
| 573 | lttv_trace_get_hook_field(traceHook, 4)); |
| 574 | inE->event.udpEvent->datagramKey->source= |
| 575 | ltt_event_get_unsigned(event, |
| 576 | lttv_trace_get_hook_field(traceHook, 5)); |
| 577 | inE->event.udpEvent->datagramKey->dest= |
| 578 | ltt_event_get_unsigned(event, |
| 579 | lttv_trace_get_hook_field(traceHook, 6)); |
| 580 | dataStart= ltt_event_get_long_unsigned(event, |
| 581 | lttv_trace_get_hook_field(traceHook, 7)); |
| 582 | g_assert_cmpuint(sizeof(inE->event.udpEvent->datagramKey->dataKey), |
| 583 | ==, sizeof(guint64)); |
| 584 | if (inE->event.udpEvent->datagramKey->ulen - 8 >= |
| 585 | sizeof(inE->event.udpEvent->datagramKey->dataKey)) |
| 586 | { |
| 587 | memcpy(inE->event.udpEvent->datagramKey->dataKey, &dataStart, |
| 588 | sizeof(inE->event.udpEvent->datagramKey->dataKey)); |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | memset(inE->event.udpEvent->datagramKey->dataKey, 0, |
| 593 | sizeof(inE->event.udpEvent->datagramKey->dataKey)); |
| 594 | memcpy(inE->event.udpEvent->datagramKey->dataKey, &dataStart, |
| 595 | inE->event.udpEvent->datagramKey->ulen - 8); |
| 596 | } |
| 597 | |
| 598 | syncState->matchingModule->matchEvent(syncState, inE); |
| 599 | |
| 600 | g_debug("UDP input event %p for skb %p done", inE, skb); |
| 601 | } |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | g_assert_not_reached(); |
| 606 | } |
| 607 | |
| 608 | return FALSE; |
| 609 | } |
| 610 | |
| 611 | |
| 612 | /* |
| 613 | * Write the processing-specific variables in the gnuplot script. |
| 614 | * |
| 615 | * Args: |
| 616 | * syncState: container for synchronization data |
| 617 | * i: trace number |
| 618 | */ |
| 619 | static void writeProcessingGraphVariablesLTTVStandard(SyncState* const |
| 620 | syncState, const unsigned int i) |
| 621 | { |
| 622 | ProcessingDataLTTVStandard* processingData= syncState->processingData; |
| 623 | ProcessingGraphsLTTVStandard* traceI= &processingData->graphs[i]; |
| 624 | |
| 625 | fprintf(syncState->graphsStream, "clock_freq_%u= %.3f\n", i, (double) |
| 626 | traceI->startFreq / traceI->freqScale); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | /* |
| 631 | * Write the processing-specific options in the gnuplot script. |
| 632 | * |
| 633 | * Args: |
| 634 | * syncState: container for synchronization data |
| 635 | * i: first trace number |
| 636 | * j: second trace number, garanteed to be larger than i |
| 637 | */ |
| 638 | static void writeProcessingTraceTraceOptionsLTTVStandard(SyncState* const |
| 639 | syncState, const unsigned int i, const unsigned int j) |
| 640 | { |
| 641 | fprintf(syncState->graphsStream, |
| 642 | "set key inside right bottom\n" |
| 643 | "set xlabel \"Clock %1$u\"\n" |
| 644 | "set xtics nomirror\n" |
| 645 | "set ylabel \"Clock %2$u\"\n" |
| 646 | "set ytics nomirror\n" |
| 647 | "set x2label \"Clock %1$d (s)\"\n" |
| 648 | "set x2range [GPVAL_X_MIN / clock_freq_%1$u : GPVAL_X_MAX / clock_freq_%1$u]\n" |
| 649 | "set x2tics\n" |
| 650 | "set y2label \"Clock %2$d (s)\"\n" |
| 651 | "set y2range [GPVAL_Y_MIN / clock_freq_%2$u : GPVAL_Y_MAX / clock_freq_%2$u]\n" |
| 652 | "set y2tics\n", i, j); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | /* |
| 657 | * Write the processing-specific options in the gnuplot script. |
| 658 | * |
| 659 | * Args: |
| 660 | * syncState: container for synchronization data |
| 661 | * i: first trace number |
| 662 | * j: second trace number, garanteed to be larger than i |
| 663 | */ |
| 664 | static void writeProcessingTraceTimeOptionsLTTVStandard(SyncState* const |
| 665 | syncState, const unsigned int i, const unsigned int j) |
| 666 | { |
| 667 | fprintf(syncState->graphsStream, |
| 668 | "set key inside right bottom\n" |
| 669 | "set xlabel \"Clock %1$u\"\n" |
| 670 | "set xtics nomirror\n" |
| 671 | "set ylabel \"time (s)\"\n" |
| 672 | "set ytics nomirror\n" |
| 673 | "set x2label \"Clock %1$d (s)\"\n" |
| 674 | "set x2range [GPVAL_X_MIN / clock_freq_%1$u : GPVAL_X_MAX / clock_freq_%1$u]\n" |
| 675 | "set x2tics\n", i); |
| 676 | } |