source: trunk/src/testing/app/bitplay/bpiotest.c @ 4

Revision 4, 4.2 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Copyright (C) 2004 Electronic Visualization Laboratory,
5 * University of Illinois at Chicago
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above
15 *    copyright notice, this list of conditions and the following disclaimer
16 *    in the documentation and/or other materials provided with the distribution.
17 *  * Neither the name of the University of Illinois at Chicago nor
18 *    the names of its contributors may be used to endorse or promote
19 *    products derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/
34 *
35 *****************************************************************************/
36
37#include "bpio.h"
38
39#include <stdio.h>
40#include <fcntl.h>
41#include <stdlib.h>
42#include <string.h>
43#include <errno.h>
44#include <sys/time.h>
45
46off_t totalbytes = 0;
47int nreads = 0;
48int interval = 200;
49int verbose = 0;
50struct timeval then;
51
52int timesink( unsigned char *buf, int nbytes, void *junk )
53{
54    struct timeval now;
55    static struct timeval prev;
56
57    /* if we're too soon, sleep a while */
58    if(junk && *(int *)junk) {
59        int dmsec;
60        gettimeofday(&now, NULL);
61        if(prev.tv_sec == 0)
62            prev = now;
63        dmsec = (now.tv_sec - prev.tv_sec) * 1000 + (now.tv_usec - prev.tv_usec) / 1000;
64        dmsec = *(int *)junk - dmsec - 15;      /* -10 ms since that's clock resolution */
65        if(dmsec > 0)
66            usleep(1000 * dmsec);
67        prev = now;
68    }
69    /* ignore the data, just measure read performance */
70    totalbytes += nbytes;
71    if(nreads % interval == 0) {
72        gettimeofday( &now, NULL );
73        if(nreads > 0) {
74            double dt = (now.tv_usec - then.tv_usec) * 1e-6 + (now.tv_sec - then.tv_sec);
75            if(interval > 0)
76                fprintf(stderr, "%.1f ", 1e-6 * totalbytes / dt);
77            else
78                fprintf(stderr, "%d ", (int)(dt*1000));
79            totalbytes = 0;
80        }
81        then = now;
82    }
83    nreads++;
84    return 0;
85}
86
87
88int
89main( int argc, char *argv[] )
90{
91    bpio_t bpio;
92    char *fname = argv[1];
93    int nfillers = argc>2 ? atoi(argv[2]) : 10;
94    int bufsize = argc>3 ? atoi(argv[3]) : 65536;
95    int nbufseach = argc>4 ? atoi(argv[4]) : 8;
96    int readsize = bufsize;
97    int mstarget = 0;
98
99    if(argc>3 && strchr(argv[3], '/'))
100        readsize = atoi(strchr(argv[3], '/')+1);
101
102    if(argc > 5) interval = atoi(argv[5]);
103    if(argc > 6) mstarget = atoi(argv[6]);
104
105
106    if(fname == NULL) {
107        fprintf(stderr, "Usage: %s  infilename   [nfillthreads  [bufbytes[/readsize]  [nbufsperthread  [printinterval [mstargetrate]]]]]\n\
108Runs concurrently in 'nfillthreads' threads,\n\
109each reading chunks of 'bufbytes' into queues of 'nbufsperthread' such buffers,\n\
110printing MBytes/sec after every 'printinterval' reads.\n\
111Defaults:  %d threads, %d bytes/buffer, %d buffers/thread, printinterval %d\n", argv[0],
112            nfillers, bufsize, nbufseach, interval);
113        exit(1);
114    }
115
116    bpinit( &bpio, nfillers, bufsize, readsize, nbufseach );
117    bpopen( &bpio, argv[1] );
118    bpstart( &bpio, 0 );
119
120    // sleep(2);
121    bpdrain( &bpio, timesink, &mstarget );
122    return 0;
123}
Note: See TracBrowser for help on using the repository browser.