Ignore:
Timestamp:
11/08/18 20:11:41 (2 years ago)
Author:
Jacob van Walraven <jacobvw@…>
Branches:
develop
Children:
3687ca2
Parents:
9d5f464
Message:

Tickrate improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/tutorial/ipdist-parallel.c

    r9d5f464 r6984c96  
    1 /* Program reads a trace file and counts the first octet of the source and destination
    2  * address and plots them on a graph using gnuplot.
    3  */
    41#include "libtrace_parallel.h"
    52#include <stdio.h>
     
    4441};
    4542
     43/* interval between outputs */
    4644uint64_t tickrate;
     45
     46static void per_tick(libtrace_t *trace, libtrace_thread_t *thread, void *global, void *tls, uint64_t tick) {
     47
     48        struct addr_result *result = (struct addr_result *)malloc(sizeof(struct addr_result));
     49        /* Proccessing thread local storage */
     50        struct addr_local *local = (struct addr_local *)tls;
     51
     52        /* Populate the result structure from the threads local storage and clear threads local storage*/
     53        int i;
     54        for(i=0;i<256;i++) {
     55                /* Populate results */
     56                result->src[i] = local->src[i];
     57                result->dst[i] = local->dst[i];
     58                /* Clear local storage */
     59                local->src[i] = 0;
     60                local->dst[i] = 0;
     61        }
     62        result->packets = local->packets;
     63        local->packets = 0;
     64
     65        /* Push result to the combiner */
     66        trace_publish_result(trace, thread, tick, (libtrace_generic_t){.ptr=result}, RESULT_USER);
     67}
    4768
    4869/* Start callback function - This is run for each thread when it starts */
     
    122143        struct addr_local *local = (struct addr_local *)tls;
    123144
    124         /* Store the timestamp of the last packet in erf format
    125          * We use the timestamp in the packet for processing non live traces */
    126         local->lastkey = trace_get_erf_timestamp(packet);
    127145        /* Increment the packet count */
    128146        local->packets += 1;
     
    147165                process_ip(ip, local, exclude, 0);
    148166        }
     167
     168        /* If this trace is not live we will manually call "per tick" */
     169        if(!trace_get_information(trace)->live) {
     170                /* get the current packets timestamp */
     171                uint64_t timestamp = trace_get_erf_timestamp(packet);
     172
     173                /* We only want to call per_tick if we are due to output something */
     174                if((timestamp >> 32) >= (local->lastkey >> 32) + (tickrate/1000)) {
     175                        per_tick(trace, thread,global, local, timestamp);
     176                        local->lastkey = timestamp;
     177                }
     178        }
    149179
    150180        /* Return the packet to libtrace */
     
    241271        }
    242272
    243         /* This key is the key that was passed into trace_publish_results */
     273        /* This key is the key that was passed into trace_publish_results
     274         * this will contain the erf timestamp for the packet */
    244275        key = result->key;
    245276
     
    291322        /* Cleanup tally results*/
    292323        free(tally);
    293 }
    294 
    295 static void per_tick(libtrace_t *trace, libtrace_thread_t *thread, void *global, void *tls, uint64_t tick) {
    296 
    297         struct addr_result *result = (struct addr_result *)malloc(sizeof(struct addr_result));
    298         /* Proccessing thread local storage */
    299         struct addr_local *local = (struct addr_local *)tls;
    300 
    301         /* Populate the result structure from the threads local storage and clear threads local storage*/
    302         int i;
    303         for(i=0;i<256;i++) {
    304                 /* Populate results */
    305                 result->src[i] = local->src[i];
    306                 result->dst[i] = local->dst[i];
    307                 /* Clear local storage */
    308                 local->src[i] = 0;
    309                 local->dst[i] = 0;
    310         }
    311         result->packets = local->packets;
    312 
    313         /* only use the tick timestamp if running against a live capture */
    314         uint64_t key;
    315         if(trace_get_information(trace)->live) {
    316                 key = tick;
    317         } else {
    318                 key = local->lastkey;
    319         }
    320 
    321         /* Push result to the combiner */
    322         trace_publish_result(trace, thread, key, (libtrace_generic_t){.ptr=result}, RESULT_USER);
    323324}
    324325
     
    365366        trace_set_hasher(trace, HASHER_BALANCE, NULL, NULL);
    366367
    367         /* Set the tick interval */
    368         trace_set_tick_interval(trace, tickrate);
     368        /* Set the tick interval only if this is a live capture */
     369        if(trace_get_information(trace)->live) {
     370                trace_set_tick_interval(trace, tickrate);
     371        }
    369372        /* Do not buffer the reports */
    370373        trace_set_reporter_thold(trace, 1);
Note: See TracChangeset for help on using the changeset viewer.