1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
/*
This test reads a trace file and shows the following after each reading step:
- total read records
- read duration
- total read duration
- byte progress
- time progress
Usage:
progress_otf <inputfile> [#filemanagers] [#recordlimit]
Default options:
#filemanagers = 32
#recordlimit = 10000
*/
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "otf.h"
#define SHOW_HELPTEXT { \
int l = 0; while( Helptext[l] ) { printf( "%s", Helptext[l++] ); } }
static const char* Helptext[] = {
" \n",
" otfprogress - shwo reading progress of OTF for testing purposes. \n",
" \n",
" otfprogress [Options] <input file name> \n",
" \n",
" options: \n",
" -h, --help show this help message \n",
" -V show OTF version \n",
" -f <n> set max number of filehandles available \n",
" -rb <size> set buffersize of the reader \n",
" -rl <size> record limit per read call \n",
" \n",
" \n", NULL };
static uint64_t get_time( void );
int main( int argc, char** argv )
{
OTF_FileManager* manager;
OTF_Reader* reader;
OTF_HandlerArray* handlers;
char* input_file = "";
uint32_t nfiles = 32;
uint64_t record_limit = 10000;
uint64_t readerbuffersize = 1024 * 1024;
int i;
if ( 1 >= argc ) {
SHOW_HELPTEXT;
return 0;
}
for ( i = 1; i < argc; i++ ) {
if ( ( 0 == strcmp( "-i", argv[i] ) ) && ( i+1 < argc ) ) {
input_file= argv[i+1];
++i;
} else if ( ( 0 == strcmp( "-rb", argv[i] ) ) && ( i+1 < argc ) ) {
readerbuffersize = atoi( argv[i+1] );
++i;
} else if ( ( 0 == strcmp( "-rl", argv[i] ) ) && ( i+1 < argc ) ) {
record_limit = atoi( argv[i+1] );
++i;
} else if ( ( 0 == strcmp( "-f", argv[i] ) ) && ( i+1 < argc ) ) {
nfiles = atoi( argv[i+1] );
++i;
} else if ( 0 == strcmp( "--help", argv[i] ) ||
0 == strcmp( "-h", argv[i] ) ) {
SHOW_HELPTEXT;
return 0;
} else if ( 0 == strcmp( "-V", argv[i] ) ) {
printf( "%u.%u.%u \"%s\"\n", OTF_VERSION_MAJOR, OTF_VERSION_MINOR,
OTF_VERSION_SUB, OTF_VERSION_STRING);
exit( 0 );
} else {
if ( '-' != argv[i][0] ) {
input_file= argv[i];
} else{
fprintf( stderr, "ERROR: Unknown option: '%s'\n", argv[i] );
exit(1);
}
}
}
manager = OTF_FileManager_open( nfiles );
assert( manager );
handlers = OTF_HandlerArray_open();
assert( handlers );
reader = OTF_Reader_open( input_file, manager );
assert( reader );
OTF_Reader_setBufferSizes( reader, readerbuffersize );
OTF_Reader_setRecordLimit( reader, record_limit );
/* OTF_HandlerArray_setHandler(...) */
printf( "input trace file : %s\n", argv[1] );
printf( "file num: %u\n", nfiles );
printf( "read buffer sizes: %llu\n", (unsigned long long int)readerbuffersize );
printf( "max. record limit: %lli\n\n", (long long int) record_limit );
printf( " tot. read read tot. read progress (%%)\n" );
printf( " records duration (s) duration (s) byte time\n" );
while( 1 )
{
uint64_t minb = 0;
uint64_t curb = 0;
uint64_t maxb = 0;
uint64_t mint = 0;
uint64_t curt = 0;
uint64_t maxt = 0;
uint64_t read_rc;
uint8_t ret;
uint64_t read_start;
static uint64_t read_records_tot = 0;
static uint64_t read_duration_tot = 0;
uint64_t read_duration;
double progress_bytes= 0.0;
double progress_times= 0.0;
read_start = get_time();
read_rc = OTF_Reader_readEvents( reader, handlers );
read_duration = get_time() - read_start;
if ( read_rc == 0 || read_rc == OTF_READ_ERROR )
break;
read_records_tot += read_rc;
read_duration_tot += read_duration;
ret= OTF_Reader_eventBytesProgress( reader, &minb, &curb, &maxb );
if( ret == 1 && minb < curb && curb <= maxb ) {
progress_bytes= ( (double)( curb - minb ) / (double)( maxb - minb ) ) * 100.0;
}
ret= OTF_Reader_eventTimeProgress( reader, &mint, &curt, &maxt );
if( ret == 1 && mint < curt && curt <= maxt ) {
progress_times= ( (double)( curt - mint ) / (double)( maxt - mint ) ) * 100.0;
}
printf( "%12lli%16.5f%15.5f%9.2f%9.2f\t\tb: %llu <= %llu <= %llu, \t\t t: %llu <= %llu <= %llu \n",
(long long int)read_records_tot, (double)( read_duration / 1e6 ),
(double)(read_duration_tot / 1e6),
progress_bytes, progress_times,
(unsigned long long int)minb, (unsigned long long int)curb,
(unsigned long long int)maxb, (unsigned long long int)mint,
(unsigned long long int)curt, (unsigned long long int)maxt );
}
OTF_Reader_close( reader );
OTF_HandlerArray_close( handlers );
OTF_FileManager_close( manager );
return 0;
}
static uint64_t get_time()
{
struct timeval tv;
gettimeofday( &tv, NULL );
return (uint64_t)(tv.tv_sec * 1e6 + tv.tv_usec);
}
|