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