Changeset 29d4438 for lib/wandio.c


Ignore:
Timestamp:
03/12/10 13:38:28 (12 years ago)
Author:
Perry Lorier <perry@…>
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:
aa0c5c5
Parents:
f6e8d46
Message:

Support an "undocumented" libtraceio debug interface

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/wandio.c

    reda2def r29d4438  
    3838#include <assert.h>
    3939#include <errno.h>
     40#include <inttypes.h>
     41#include <string.h>
    4042
    4143/* This file contains the implementation of the libtrace IO API, which format
     
    4951};
    5052
     53int keep_stats = 0;
     54int force_directio_write = 0;
     55int force_directio_read = 0;
     56int use_threads = 1;
     57
     58uint64_t read_waits = 0;
     59uint64_t write_waits = 0;
     60
     61static void do_option(const char *option)
     62{
     63        if (*option == '\0')
     64                ;
     65        else if (strcmp(option,"stats") == 0)
     66                keep_stats = 1;
     67        else if (strcmp(option,"directwrite") == 0)
     68                force_directio_write = 1;
     69        else if (strcmp(option,"directread") == 0)
     70                force_directio_read  = 1;
     71        else if (strcmp(option,"nothreads") == 0)
     72                use_threads = 0;
     73        else {
     74                fprintf(stderr,"Unknown libtraceio debug option '%s'\n", option);
     75        }
     76}
     77
     78static void parse_env(void)
     79{
     80        const char *str = getenv("LIBTRACEIO");
     81        char option[1024];
     82        const char *ip;
     83        char *op;
     84
     85        if (!str)
     86                return;
     87
     88        for(ip=str, op=option; *ip!='\0' && op < option+sizeof(option); ++ip) {
     89                if (*ip == ',') {
     90                        *op='\0';
     91                        do_option(option);
     92                        op=option;
     93                }
     94                else
     95                        *(op++) = *ip;
     96        }
     97        *op='\0';
     98        do_option(option);
     99}
     100
     101
    51102#define READ_TRACE 0
    52103#define WRITE_TRACE 0
     
    54105io_t *wandio_create(const char *filename)
    55106{
     107        parse_env();
     108
    56109        /* Use a peeking reader to look at the start of the trace file and
    57110         * determine what type of compression may have been used to write
    58111         * the file */
    59        
    60112        io_t *io = peek_open(stdio_open(filename));
    61113        char buffer[1024];
     
    83135        /* Now open a threaded, peekable reader using the appropriate module
    84136         * to read the data */
     137
     138        if (use_threads)
     139                io = thread_open(io);
    85140       
    86         return peek_open(thread_open(io));
     141        return peek_open(io);
    87142}
    88143
     
    128183
    129184void wandio_destroy(io_t *io)
    130 { io->source->close(io); }
     185{
     186        if (keep_stats)
     187                fprintf(stderr,"LIBTRACEIO STATS: %"PRIu64" blocks on read\n", read_waits);
     188        io->source->close(io);
     189}
    131190
    132191iow_t *wandio_wcreate(const char *filename, int compression_level, int flags)
     
    153212#endif
    154213        /* Open a threaded writer */
    155         return thread_wopen(iow);
     214        if (use_threads)
     215                return thread_wopen(iow);
     216        else
     217                return iow;
    156218}
    157219
     
    167229{
    168230        iow->source->close(iow);
    169 }
    170 
     231        if (keep_stats)
     232                fprintf(stderr,"LIBTRACEIO STATS: %"PRIu64" blocks on write\n", write_waits);
     233}
     234
Note: See TracChangeset for help on using the changeset viewer.