Changeset cc9c9de for lib


Ignore:
Timestamp:
05/18/18 11:39:59 (3 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
cachetimestamps, develop, etsilive, master, rc-4.0.4, ringdecrementfix, ringperformance
Children:
1e0a804
Parents:
e732393
git-author:
Shane Alcock <salcock@…> (04/17/18 16:45:58)
git-committer:
Shane Alcock <salcock@…> (05/18/18 11:39:59)
Message:

Add new config option for trace_event() -- REPLAY_SPEEDUP

This allows users to specify a "speedup factor" when using
trace_event() to replay trace files, i.e. all inter-packet
gaps will be divided by the speedup factor. This allows traces
to be replayed faster, while still preserving the same relative
gaps between packets.

Location:
lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dag25.c

    ra857389 rcc9c9de  
    608608                return -1;
    609609        case TRACE_OPTION_EVENT_REALTIME:
     610        case TRACE_OPTION_REPLAY_SPEEDUP:
    610611                /* Live capture is always going to be realtime */
    611612                return -1;
  • lib/format_helper.c

    r633339d rcc9c9de  
    127127        double ts;
    128128        double now;
     129        double sincebeginnow = 0;
     130        double sincebegintrace = 0;
     131
    129132#ifdef WIN32
    130133        struct __timeb64 tstruct;
     
    182185
    183186       
    184         if (fabs(trace->event.tdelta)>1e-9) {
    185                 /* Subtract the tdelta from the walltime to get a suitable
     187        if (fabs(trace->event.first_now)>1e-9) {
     188                /* Subtract the tdelta from the starting times to get a suitable
    186189                 * "relative" time */
    187                 now -= trace->event.tdelta;
     190                sincebeginnow = (now - trace->event.first_now);
     191                sincebegintrace = (ts - trace->event.first_ts);
    188192
    189193                /* If the trace timestamp is still in the future, return a
    190194                 * SLEEP event, otherwise return the packet */
    191                 if (ts > now) {
    192                         event.seconds = ts -
    193                                 trace->event.trace_last_ts;
    194                         trace->event.trace_last_ts = ts;
     195                if (sincebeginnow <= sincebegintrace / trace->replayspeedup) {
     196                        event.seconds = ((sincebegintrace / trace->replayspeedup) - sincebeginnow);
    195197                        event.type = TRACE_EVENT_SLEEP;
    196198                        trace->event.waiting = true;
     
    204206                 * trace file.
    205207                 */
    206                 trace->event.tdelta = now - ts;
     208                trace->event.first_now = now;
     209                trace->event.first_ts = ts;
    207210        }
    208211
     
    219222        event.type = TRACE_EVENT_PACKET;
    220223
    221         trace->event.trace_last_ts = ts;
    222224        trace->event.waiting = false;
    223225
  • lib/format_linux_common.c

    rd47ca18 rcc9c9de  
    164164                        /* Live captures are always going to be in trace time */
    165165                        break;
     166                case TRACE_OPTION_REPLAY_SPEEDUP:
     167                        break;
    166168                /* Avoid default: so that future options will cause a warning
    167169                 * here to remind us to implement it, or flag it as
  • lib/format_pcapfile.c

    r5a70a80 rcc9c9de  
    257257                case TRACE_OPTION_FILTER:
    258258                case TRACE_OPTION_HASHER:
     259                case TRACE_OPTION_REPLAY_SPEEDUP:
    259260                        /* All these are either unsupported or handled
    260261                         * by trace_config */
  • lib/format_pcapng.c

    r2c457ec rcc9c9de  
    260260                case TRACE_OPTION_FILTER:
    261261                case TRACE_OPTION_HASHER:
     262                case TRACE_OPTION_REPLAY_SPEEDUP:
    262263                        break;
    263264        }
  • lib/libtrace.h.in

    r991ff43 rcc9c9de  
    13201320        /** The hasher function for a parallel libtrace. It is recommended to
    13211321         * access this option via trace_set_hasher(). */
    1322         TRACE_OPTION_HASHER
     1322        TRACE_OPTION_HASHER,
     1323
     1324        /** Speed up trace file replays (via trace_event()) by this factor */
     1325        TRACE_OPTION_REPLAY_SPEEDUP,
    13231326} trace_option_t;
    13241327
  • lib/libtrace_int.h

    rdf87f00 rcc9c9de  
    152152//#define RP_BUFSIZE 65536U
    153153
     154#define LIBTRACE_MAX_REPLAY_SPEEDUP 1000
     155
    154156/** Data about the most recent event from a trace file */
    155157struct libtrace_event_status_t {
    156158        /** A libtrace packet to store the packet when a PACKET event occurs */
    157159        libtrace_packet_t *packet;
    158         /** Time between the timestamp for the current packet and the current
    159          * walltime */
    160         double tdelta;
    161         /** The timestamp of the previous PACKET event */
    162         double trace_last_ts;
     160
     161        /* The walltime when we processed the first packet from the trace */
     162        double first_now;
     163
     164        /* The tracetime of the first packet in the trace */
     165        double first_ts;
     166
    163167        /** The size of the current PACKET event */
    164168        int psize;
     
    313317         * used only if the capture format does not support snapping natively */
    314318        size_t snaplen;                 
     319        /** Speed up the packet rate when using trace_event() to process trace
     320         * files by this factor. */
     321        int replayspeedup;
    315322        /** Count of the number of packets returned to the libtrace user */
    316323        uint64_t accepted_packets;
  • lib/trace.c

    re732393 rcc9c9de  
    251251        libtrace->format=NULL;
    252252
    253         libtrace->event.tdelta = 0.0;
    254253        libtrace->event.packet = NULL;
    255254        libtrace->event.psize = 0;
    256         libtrace->event.trace_last_ts = 0.0;
     255        libtrace->event.first_ts = 0.0;
     256        libtrace->event.first_now = 0.0;
    257257        libtrace->event.waiting = false;
    258258        libtrace->filter = NULL;
    259259        libtrace->snaplen = 0;
     260        libtrace->replayspeedup = 1;
    260261        libtrace->started=false;
    261262        libtrace->uridata = NULL;
     
    378379        libtrace->format=NULL;
    379380
    380         libtrace->event.tdelta = 0.0;
    381381        libtrace->event.packet = NULL;
    382382        libtrace->event.psize = 0;
    383         libtrace->event.trace_last_ts = 0.0;
     383        libtrace->event.first_ts = 0;
     384        libtrace->event.first_now = 0;
    384385        libtrace->filter = NULL;
    385386        libtrace->snaplen = 0;
     
    595596         * deal with some options itself, so give that a go */
    596597        switch(option) {
     598                case TRACE_OPTION_REPLAY_SPEEDUP:
     599                        /* Clear the error if there was one */
     600                        if (trace_is_err(libtrace)) {
     601                                trace_get_err(libtrace);
     602                        }
     603                        if (*(int*)value<1
     604                                || *(int*)value>LIBTRACE_MAX_REPLAY_SPEEDUP) {
     605                                trace_set_err(libtrace,TRACE_ERR_BAD_STATE,
     606                                        "Invalid replay speed");
     607                        }
     608                        libtrace->replayspeedup=*(int*)value;
     609                        return 0;
     610
    597611                case TRACE_OPTION_SNAPLEN:
    598612                        /* Clear the error if there was one */
Note: See TracChangeset for help on using the changeset viewer.