Ignore:
Timestamp:
02/08/10 16:43:43 (12 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d026488
Parents:
5511c14
Message:
  • Updated licensing and documentation for several format modules and the format_helper code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_helper.c

    r3fc7948 r238d50a  
    22 * This file is part of libtrace
    33 *
    4  * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand.
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
    57 * Authors: Daniel Lawson
    6  *          Perry Lorier
     8 *          Perry Lorier
     9 *          Shane Alcock
    710 *         
    811 * All rights reserved.
     
    6467#  include <sys/ioctl.h>
    6568
     69/* Generic event function for live capture devices / interfaces */
    6670struct libtrace_eventobj_t trace_event_device(struct libtrace_t *trace,
    6771                                        struct libtrace_packet_t *packet) {
     
    127131#endif
    128132
     133/* Generic event function for trace files */
    129134struct libtrace_eventobj_t trace_event_trace(struct libtrace_t *trace, struct libtrace_packet_t *packet) {
    130135        struct libtrace_eventobj_t event = {0,0,0.0,0};
     
    138143
    139144        if (!trace->event.packet) {
     145                /* There is no packet event waiting for us, so create a new
     146                 * libtrace packet in the event structure and read the next
     147                 * packet into that.
     148                 *
     149                 * If a SLEEP event is reported this time around, the read
     150                 * packet can therefore be saved until the next time this
     151                 * function is called. */
     152
    140153                trace->event.packet = trace_create_packet();
    141154                trace->event.psize=
    142155                        trace_read_packet(trace,trace->event.packet);
    143156                if (trace->event.psize<1) {
    144                         /* return here, the test for
    145                          * event.size will sort out the error
    146                          */
     157                        /* Return here, the test for event.size will sort out
     158                         * the error  */
    147159                        if (trace_is_err(trace)) {
    148160                                trace_perror(trace, "read packet");
     
    155167        }
    156168
     169        /* The goal here is to replicate the inter-packet gaps that are
     170         * present in the trace. */
     171
    157172        ts=trace_get_seconds(trace->event.packet);
    158173
    159         /* Get the adjusted current time */
     174        /* Get the current walltime */
    160175#ifdef WIN32
    161176        _ftime64(&tstruct);
     
    170185       
    171186        if (fabs(trace->event.tdelta)>1e-9) {
    172                 /* adjust for trace delta */
     187                /* Subtract the tdelta from the walltime to get a suitable
     188                 * "relative" time */
    173189                now -= trace->event.tdelta;
    174190
    175                 /* if the trace timestamp is still in the
    176                  * future, return a SLEEP event,
    177                  * otherwise fire the packet
    178                  */
     191                /* If the trace timestamp is still in the future, return a
     192                 * SLEEP event, otherwise return the packet */
    179193                if (ts > now) {
    180194                        event.seconds = ts -
     
    184198                }
    185199        } else {
    186                 /* work out the difference between the
    187                  * start of trace replay, and the first
    188                  * packet in the trace
     200                /* Work out the difference between the walltime at the start
     201                 * of the trace replay and the timestamp of the first packet
     202                 * in the trace. This will be used to convert the walltime
     203                 * into a timeline that is relative to the timestamps in the
     204                 * trace file.
    189205                 */
    190206                trace->event.tdelta = now - ts;
     
    195211       
    196212        /* XXX: Could we do this more efficiently? */
     213
    197214        /* We do a lot of freeing and creating of packet buffers with this
    198215         * method, but at least it works unlike what was here previously */
     
    200217                free(packet->buffer);
    201218        }
    202                
     219       
     220        /* The packet that we had read earlier is now ready to be returned
     221         * to the user - switch all the pointers etc. over */   
    203222        packet->type = trace->event.packet->type;
    204223        packet->trace = trace->event.packet->trace;
     
    232251#endif
    233252
    234 /* open a file or stdin using gzip compression if necessary (and supported)
    235  * @internal
    236  */
     253/* Open a file for reading using the new Libtrace IO system */
    237254io_t *trace_open_file(libtrace_t *trace)
    238255{
     
    244261}
    245262
    246 /* Create a file or write to stdout using compression if requested
    247  * @internal
    248  */
     263/* Open a file for writing using the new Libtrace IO system */
    249264iow_t *trace_open_file_out(libtrace_out_t *trace,int level, int fileflag)
    250265{
     
    256271
    257272
    258 /** Update the libtrace error
     273/** Sets the error status for an input trace
    259274 * @param errcode either an Econstant from libc, or a LIBTRACE_ERROR
    260275 * @param msg a plaintext error message
     
    279294}
    280295
    281 /** Update the libtrace for output traces error
     296/** Sets the error status for an output trace
    282297 * @param errcode either an Econstant from libc, or a LIBTRACE_ERROR
    283298 * @param msg a plaintext error message
     
    302317}
    303318
     319/* Byte swapping functions for various inttypes */
    304320uint64_t byteswap64(uint64_t num)
    305321{
Note: See TracChangeset for help on using the changeset viewer.