int readDefProc(string filename) { /*---------------------------------------------------------*/ /*Creates a new OTF_Stream_Reader to read all definitions */ /*of a trace and write them into a new datatype. */ /*---------------------------------------------------------*/ OTF_RStream* rstream; OTF_FileManager* myManager; OTF_HandlerArray* myHandlers; myManager= OTF_FileManager_open( 100 ); assert( myManager ); myHandlers = OTF_HandlerArray_open(); assert( myHandlers ); rstream = OTF_RStream_open( filename.c_str(), 0, myManager ); assert( rstream ); OTF_HandlerArray_setHandler( myHandlers, (OTF_FunctionPointer*) handleDefProcesses, OTF_DEFPROCESS_RECORD ); OTF_RStream_readDefinitions( rstream, myHandlers ); OTF_RStream_close( rstream ); OTF_HandlerArray_close( myHandlers ); OTF_FileManager_close( myManager ); return 0; }
int main ( int argc, char** argv ) { OTF_Reader* reader = NULL; OTF_HandlerArray* handlers; OTF_FileManager* manager; OTF_MasterControl* mc; OTF_MapEntry* mapentry; int read_stats= 0; int read_snaps= 0; int nstreams = 1; int nfiles = 200; int longformat = 0; int showprogress= 0; int i; int readerbuffersize = 1024 * 1024; int writerbuffersize = 1024 * 1024; OTF_FileCompression compression= 0; fcbT fcb; char* infile= NULL; char* outfile= NULL; uint64_t minbytes; uint64_t maxbytes; uint64_t curbytes; uint64_t minbytestmp; uint64_t maxbytestmp; uint64_t curbytestmp; uint64_t recordsperupdate; uint64_t totalbytes; uint32_t progress_counter= 0; uint64_t retde; uint64_t retma; uint64_t retev; uint64_t retst; uint64_t retsn; fcb.error= 0; if ( 1 >= argc ) { SHOW_HELPTEXT; return 0; } for ( i = 1; i < argc; i++ ) { if ( ( 0 == strcmp( "-i", argv[i] ) ) && ( i+1 < argc ) ) { infile= argv[i+1]; ++i; } else if ( ( 0 == strcmp( "-n", argv[i] ) ) && ( i+1 < argc ) ) { nstreams = atoi( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-rb", argv[i] ) ) && ( i+1 < argc ) ) { readerbuffersize = atoi( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-wb", argv[i] ) ) && ( i+1 < argc ) ) { writerbuffersize = 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( "-o", argv[i] ) ) && ( i+1 < argc ) ) { outfile= argv[i+1]; ++i; } else if ( 0 == strcmp( "-stats", argv[i] ) ) { read_stats= 1; } else if ( 0 == strcmp( "-snaps", argv[i] ) ) { read_snaps= 1; } else if ( ( 0 == strcmp( "-z", argv[i] ) ) && ( i+1 < argc ) ) { compression= atoi( argv[i+1] ); ++i; } else if ( 0 == strcmp( "-l", argv[i] ) ) { longformat = 1; } else if ( 0 == strcmp( "-p", argv[i] ) ) { showprogress= 1; } 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] ) { infile= argv[i]; } else { fprintf( stderr, "ERROR: Unknown option: '%s'\n", argv[i] ); exit(1); } } } if ( nfiles < 1 ) { fprintf( stderr, "ERROR: less than 1 filehandle is not permitted\n" ); exit(1); } if ( nstreams < 0 ) { fprintf( stderr, "ERROR: less than 0 stream is not permitted\n" ); exit(1); } if ( NULL == infile ) { fprintf( stderr, "ERROR: no input file specified\n" ); exit(1); } if ( NULL == outfile ) { /* fprintf( stderr, "ERROR: no output file has been specified\n" ); exit(1); */ outfile= "out.otf"; } handlers = OTF_HandlerArray_open(); manager= OTF_FileManager_open( nfiles ); if( NULL == manager) { fprintf( stderr, "Error: Unable to initialize File Manager. aborting\n" ); exit(1); } reader = OTF_Reader_open( infile, manager ); if ( NULL == reader ) { fprintf( stderr, "Error: Unable to open '%s'. aborting\n", infile ); OTF_FileManager_close( manager ); OTF_HandlerArray_close( handlers ); exit(1); } OTF_Reader_setBufferSizes( reader, readerbuffersize ); fcb.writer = OTF_Writer_open( outfile, nstreams, manager ); OTF_Writer_setBufferSizes( fcb.writer, writerbuffersize ); OTF_Writer_setCompression( fcb.writer, compression ); if( longformat ) OTF_Writer_setFormat( fcb.writer, OTF_WSTREAM_FORMAT_LONG ); else OTF_Writer_setFormat( fcb.writer, OTF_WSTREAM_FORMAT_SHORT ); mc = OTF_Reader_getMasterControl( reader ); /* set your own handler functions */ OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefinitionComment, OTF_DEFINITIONCOMMENT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFINITIONCOMMENT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefTimerResolution, OTF_DEFTIMERRESOLUTION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFTIMERRESOLUTION_RECORD); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefProcess, OTF_DEFPROCESS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFPROCESS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefProcessGroup, OTF_DEFPROCESSGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFPROCESSGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefAttributeList, OTF_DEFATTRLIST_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFATTRLIST_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefProcessOrGroupAttributes, OTF_DEFPROCESSORGROUPATTR_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFPROCESSORGROUPATTR_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefFunction, OTF_DEFFUNCTION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFFUNCTION_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefFunctionGroup, OTF_DEFFUNCTIONGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFFUNCTIONGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefCollectiveOperation, OTF_DEFCOLLOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFCOLLOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefCounter, OTF_DEFCOUNTER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFCOUNTER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefCounterGroup, OTF_DEFCOUNTERGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFCOUNTERGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefScl, OTF_DEFSCL_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFSCL_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefSclFile, OTF_DEFSCLFILE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFSCLFILE_RECORD ); /* OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefversion, OTF_DEFVERSION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFVERSION_RECORD ); */ OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefCreator, OTF_DEFCREATOR_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFCREATOR_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefFile, OTF_DEFFILE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFFILE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefFileGroup, OTF_DEFFILEGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFFILEGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefKeyValue, OTF_DEFKEYVALUE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFKEYVALUE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefTimeRange, OTF_DEFTIMERANGE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFTIMERANGE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefCounterAssignments, OTF_DEFCOUNTERASSIGNMENTS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFCOUNTERASSIGNMENTS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleNoOp, OTF_NOOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_NOOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEventComment, OTF_EVENTCOMMENT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_EVENTCOMMENT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleCounter, OTF_COUNTER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_COUNTER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEnter, OTF_ENTER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_ENTER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleCollectiveOperation, OTF_COLLOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_COLLOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleBeginCollectiveOperation, OTF_BEGINCOLLOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_BEGINCOLLOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEndCollectiveOperation, OTF_ENDCOLLOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_ENDCOLLOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleRecvMsg, OTF_RECEIVE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_RECEIVE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleSendMsg, OTF_SEND_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_SEND_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleLeave, OTF_LEAVE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_LEAVE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleBeginProcess, OTF_BEGINPROCESS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_BEGINPROCESS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEndProcess, OTF_ENDPROCESS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_ENDPROCESS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleFileOperation, OTF_FILEOPERATION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_FILEOPERATION_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleBeginFileOperation, OTF_BEGINFILEOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_BEGINFILEOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEndFileOperation, OTF_ENDFILEOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_ENDFILEOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleRMAPut, OTF_RMAPUT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_RMAPUT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleRMAPutRemoteEnd, OTF_RMAPUTRE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_RMAPUTRE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleRMAGet, OTF_RMAGET_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_RMAGET_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleRMAEnd, OTF_RMAEND_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_RMAEND_RECORD ); /* snapshot records */ OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleSnapshotComment, OTF_SNAPSHOTCOMMENT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_SNAPSHOTCOMMENT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEnterSnapshot, OTF_ENTERSNAPSHOT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_ENTERSNAPSHOT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleSendSnapshot, OTF_SENDSNAPSHOT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_SENDSNAPSHOT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleOpenFileSnapshot, OTF_OPENFILESNAPSHOT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_OPENFILESNAPSHOT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleBeginCollopSnapshot, OTF_BEGINCOLLOPSNAPSHOT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_BEGINCOLLOPSNAPSHOT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleBeginFileOpSnapshot, OTF_BEGINFILEOPSNAPSHOT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_BEGINFILEOPSNAPSHOT_RECORD ); /* summary records */ OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleSummaryComment, OTF_SUMMARYCOMMENT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_SUMMARYCOMMENT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleFunctionSummary, OTF_FUNCTIONSUMMARY_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_FUNCTIONSUMMARY_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleFunctionGroupSummary, OTF_FUNCTIONGROUPSUMMARY_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_FUNCTIONGROUPSUMMARY_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleMessageSummary, OTF_MESSAGESUMMARY_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_MESSAGESUMMARY_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleCollopSummary, OTF_COLLOPSUMMARY_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_COLLOPSUMMARY_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleFileOperationSummary, OTF_FILEOPERATIONSUMMARY_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_FILEOPERATIONSUMMARY_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleFileGroupOperationSummary, OTF_FILEGROUPOPERATIONSUMMARY_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_FILEGROUPOPERATIONSUMMARY_RECORD ); /* marker record types */ OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefMarker, OTF_DEFMARKER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_DEFMARKER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleMarker, OTF_MARKER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_MARKER_RECORD ); /* misc records */ OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleUnknown, OTF_UNKNOWN_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fcb, OTF_UNKNOWN_RECORD ); /* ask the mastercontrol for the number of streams and create the * streaminfos array */ fcb.nstreaminfos = 0; while ( 0 != OTF_MasterControl_getEntryByIndex( mc, fcb.nstreaminfos )) { fcb.nstreaminfos++; } fcb.hash = hash_new (); /* global stream yourself, because he isnt in the mapping */ hash_add( fcb.hash, 0 ); /* add all streams to the hash */ for( i = 0; i < fcb.nstreaminfos; i++ ) { mapentry = OTF_MasterControl_getEntryByIndex( mc, i ); hash_add( fcb.hash, mapentry->argument ); } /* read definitions */ retde= OTF_Reader_readDefinitions( reader, handlers ); if( OTF_READ_ERROR == retde || 1 == fcb.error ) { fprintf( stderr, "Error while reading definitions. aborting\n" ); FINISH_EVERYTHING; exit(1); } /* read markers */ retma= OTF_Reader_readMarkers( reader, handlers ); if( OTF_READ_ERROR == retma || 1 == fcb.error ) { fprintf( stderr, "Error while reading marker records. aborting\n" ); FINISH_EVERYTHING; exit(1); } if ( 0 == showprogress ) { /* do not show the progress */ /* read events */ retev= OTF_Reader_readEvents( reader, handlers ); if( OTF_READ_ERROR == retev ) { fprintf( stderr, "Error while reading events. aborting\n" ); FINISH_EVERYTHING; exit(1); } /* read stats */ if ( 1 == read_stats ) { retst= OTF_Reader_readStatistics( reader, handlers ); if( OTF_READ_ERROR == retst ) { fprintf( stderr, "Error while reading statistics. aborting\n" ); FINISH_EVERYTHING; exit(1); } } /* read snaps */ if ( 1 == read_snaps ) { retsn= OTF_Reader_readSnapshots( reader, handlers ); if( OTF_READ_ERROR == retsn ) { fprintf( stderr, "Error while reading snapshots. aborting\n" ); FINISH_EVERYTHING; exit(1); } } } else { /* show progress */ initProgressDisplay(); /* calculate how many records will be read */ minbytes= 0; curbytes= 0; maxbytes= 0; OTF_Reader_setRecordLimit( reader, 0 ); retev= OTF_Reader_readEvents( reader, handlers ); if( OTF_READ_ERROR == retev ) { fprintf( stderr, "Error while reading events. aborting\n" ); FINISH_EVERYTHING; exit(1); } if ( 1 == read_stats ) { retst= OTF_Reader_readStatistics( reader, handlers ); if( OTF_READ_ERROR == retst ) { fprintf( stderr, "Error while reading statistics. aborting\n" ); FINISH_EVERYTHING; exit(1); } } if ( 1 == read_snaps ) { retsn= OTF_Reader_readSnapshots( reader, handlers ); if( OTF_READ_ERROR == retsn ) { fprintf( stderr, "Error while reading snapshots. aborting\n" ); FINISH_EVERYTHING; exit(1); } } OTF_Reader_eventBytesProgress( reader, &minbytestmp, &curbytestmp, &maxbytestmp ); minbytes+= minbytestmp; maxbytes+= maxbytestmp; if ( 1 == read_stats ) { OTF_Reader_statisticBytesProgress( reader, &minbytestmp, &curbytestmp, &maxbytestmp ); minbytes+= minbytestmp; maxbytes+= maxbytestmp; } /* read snaps */ if ( 1 == read_snaps ) { OTF_Reader_snapshotBytesProgress( reader, &minbytestmp, &curbytestmp, &maxbytestmp ); minbytes+= minbytestmp; maxbytes+= maxbytestmp; } curbytes= 0; totalbytes= maxbytes - minbytes; /* fixed number of records per update in order to provide frequent update */ recordsperupdate= 100000; OTF_Reader_setRecordLimit( reader, recordsperupdate ); while ( 0 != ( retev= OTF_Reader_readEvents( reader, handlers ) ) ) { if( OTF_READ_ERROR == retev ) { fprintf( stderr, "Error while reading events. aborting\n" ); FINISH_EVERYTHING; exit(1); } OTF_Reader_eventBytesProgress( reader, &minbytestmp, &curbytestmp, &maxbytestmp ); curbytes += curbytestmp - minbytestmp - curbytes; updateProgressDisplay( progress_counter++, totalbytes, curbytes ); } /* read stats */ while ( ( 1 == read_stats ) && ( 0 != ( retst= OTF_Reader_readStatistics( reader, handlers ) ) ) ) { if( OTF_READ_ERROR == retst ) { fprintf( stderr, "Error while reading statistics. aborting\n" ); FINISH_EVERYTHING; exit(1); } OTF_Reader_statisticBytesProgress( reader, &minbytestmp, &curbytestmp, &maxbytestmp ); curbytes += curbytestmp - minbytestmp - curbytes; updateProgressDisplay( progress_counter++, totalbytes, curbytes ); } /* read snaps */ while ( ( 1 == read_snaps ) && ( 0 != ( retsn= OTF_Reader_readSnapshots( reader, handlers ) ) ) ) { if( OTF_READ_ERROR == retsn ) { fprintf( stderr, "Error while reading snapshots. aborting\n" ); FINISH_EVERYTHING; exit(1); } OTF_Reader_snapshotBytesProgress( reader, &minbytestmp, &curbytestmp, &maxbytestmp ); curbytes += curbytestmp - minbytestmp - curbytes; updateProgressDisplay( progress_counter++, totalbytes, curbytes ); } finishProgressDisplay(); } FINISH_EVERYTHING; return 0; }
int main (int argc, char **argv) { #ifdef HAVE_VTF3 fcbT fha; int i; int numcpus; char* inputFile = NULL; char* outputFile = NULL; int buffersize= 1024; OTF_FileManager* manager; OTF_Reader* reader; OTF_HandlerArray* handlers; nodeT* p_root; int format= VTF3_FILEFORMAT_STD_ASCII; handlers = OTF_HandlerArray_open(); /* argument handling */ if ( 1 >= argc ) { SHOW_HELPTEXT; exit(0); } for ( i = 1; i < argc; i++ ) { if( 0 == strcmp( "-i", argv[i] ) ) { if( i+1 < argc ) { inputFile= strdup( argv[i+1] ); ++i; } } else if ( 0 == strcmp( "-o", argv[i] ) ) { if( i+1 < argc ) { outputFile = argv[i+1]; ++i; } } else if( ( 0 == strcmp( "-b", argv[i] ) ) && ( i+1 < argc ) ) { buffersize = atoi( argv[i+1] ); ++i; } else if ( 0 == strcmp( "--help", argv[i] ) || 0 == strcmp( "-h", argv[i] ) ) { SHOW_HELPTEXT; exit(0); } else if ( 0 == strcmp( "-A", argv[i] ) ) { format= VTF3_FILEFORMAT_STD_ASCII; } else if ( 0 == strcmp( "-B", argv[i] ) ) { format= VTF3_FILEFORMAT_STD_BINARY; } else if ( 0 == strcmp( "-V", argv[i] ) ) { printf( "%u.%u.%u \"%s\"\n", OTF_VERSION_MAYOR, OTF_VERSION_MINOR, OTF_VERSION_SUB, OTF_VERSION_STRING); exit( 0 ); } else { if ( '-' != argv[i][0] ) { inputFile= strdup( argv[i] ); } else { fprintf( stderr, "ERROR: Unknown argument.\n" ); exit(1); } } } if ( NULL == inputFile ) { printf( " no input file specified\n" ); exit(1); } if ( NULL == outputFile ) { printf( " no output file specified\n" ); exit(1); } /* open filemanager */ manager= OTF_FileManager_open( 100 ); assert( NULL != manager ); /* Open OTF Reader */ reader = OTF_Reader_open( inputFile, manager ); if( NULL == reader ) { fprintf( stderr, "cannot open input trace '%s'\n", inputFile ); exit( 1 ); } OTF_Reader_setBufferSizes( reader, buffersize ); free( inputFile ); /* Initialize VTF3. */ (void) VTF3_InitTables (); fha.fcb = VTF3_OpenFileOutput ( outputFile, format, 0); assert( 0 != fha.fcb ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefinitionComment, OTF_DEFINITIONCOMMENT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFINITIONCOMMENT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDeftimerresolution, OTF_DEFTIMERRESOLUTION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFTIMERRESOLUTION_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefprocess, OTF_DEFPROCESS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFPROCESS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefprocessgroup, OTF_DEFPROCESSGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFPROCESSGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDeffunction, OTF_DEFFUNCTION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFFUNCTION_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDeffunctiongroup, OTF_DEFFUNCTIONGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFFUNCTIONGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefcounter, OTF_DEFCOUNTER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFCOUNTER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefcountergroup, OTF_DEFCOUNTERGROUP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFCOUNTERGROUP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefCollectiveOperation, OTF_DEFCOLLOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFCOLLOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefscl, OTF_DEFSCL_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFSCL_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefsclfile, OTF_DEFSCLFILE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFSCLFILE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleDefFile, OTF_DEFFILE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_DEFFILE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEventComment, OTF_EVENTCOMMENT_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_EVENTCOMMENT_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleCounter, OTF_COUNTER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_COUNTER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEnter, OTF_ENTER_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_ENTER_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleCollectiveOperation, OTF_COLLOP_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_COLLOP_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleRecvmsg, OTF_RECEIVE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_RECEIVE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleSendmsg, OTF_SEND_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_SEND_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleLeave, OTF_LEAVE_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_LEAVE_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleBeginProcess, OTF_BEGINPROCESS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_BEGINPROCESS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleEndProcess, OTF_ENDPROCESS_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_ENDPROCESS_RECORD ); OTF_HandlerArray_setHandler( handlers, (OTF_FunctionPointer*) handleFileOperation, OTF_FILEOPERATION_RECORD ); OTF_HandlerArray_setFirstHandlerArg( handlers, &fha, OTF_FILEOPERATION_RECORD ); /***************/ treehash_init( &p_root, &fha.p_hashtab); fha.FileIOQueue= FileIOEndQueue_init(); /***************/ VTF3_WriteDefversion( fha.fcb, OTF2VTF3VERSION); VTF3_WriteDefcreator( fha.fcb, OTF2VTF3CREATOR ); OTF_Reader_readDefinitions( reader, handlers ); /***************/ numcpus = 0; /* indicate the processes */ for( i = 0; i < p_root->childrensize; i++ ) { numcpus = treehash_createindices( numcpus, p_root->p_children[i] ); } if ( numcpus == 0) { fprintf( stderr, "There are no cpus.\n" ); exit(1); } /* write VTF3_syscpunum-record */ VTF3_WriteDefsyscpunums( fha.fcb, 1, &numcpus ); /* write VFT3_cpuname-records */ for( i = 0; i < p_root->childrensize; i++ ) { writenames_recursive( fha.fcb, p_root->p_children[i] ); } /***************/ OTF_Reader_readEvents( reader, handlers ); /***************/ FileIOEndQueue_finish( &fha.FileIOQueue ); treehash_deleteall( fha.p_hashtab ); /***************/ /* Close all devices. */ (void) VTF3_Close ( fha.fcb ); OTF_Reader_close( reader ); OTF_HandlerArray_close( handlers ); OTF_FileManager_close( manager ); #else /* HAVE_VTF3 */ fprintf( stderr, "VTF3 not available, otf2vtf deactivated\n" ); #endif /* HAVE_VTF3 */ return (0); }
int main (int argc, char **argv) { char* inputFile = NULL; char* outputFile = NULL; unsigned int nstreams= 0; unsigned int maxfilehandles = 250; void *fcbin; fcbT fcb; int nrectypes; int *recordtypes; int i; int a; VTF3_handler_t *handlers; void **firsthandlerargs; size_t bytesread; OTF_FileManager* manager= NULL; int buffersize = 1024 * 1024; OTF_FileCompression compression= OTF_FILECOMPRESSION_UNCOMPRESSED; char iofile[128]; fcb.ioonly= 0; /* argument handling */ if ( 1 >= argc ) { SHOW_HELPTEXT; exit(0); } for ( i = 1; i < argc; i++ ) { if ( ( 0 == strcmp( "-i", argv[i] ) ) && ( i+1 < argc ) ) { inputFile= argv[i+1]; ++i; } else if ( ( 0 == strcmp( "-o", argv[i] ) ) && ( i+1 < argc ) ) { fcb.outputFile= strdup( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-n", argv[i] ) ) && ( i+1 < argc ) ) { nstreams = atoi( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-f", argv[i] ) ) && ( i+1 < argc ) ) { maxfilehandles = atoi( argv[i+1] ); ++i; } else if ( ( 0 == strcmp( "-b", argv[i] ) ) && ( i+1 < argc ) ) { buffersize = atoi( argv[i+1] ); ++i; } else if ( 0 == strcmp( "-io", argv[i] ) ) { fcb.ioonly= 1; } else if ( ( 0 == strcmp( "-z", argv[i] ) ) && ( i+1 < argc ) ) { compression= atoi( argv [i+1] ); ++i; } else if ( 0 == strcmp( "--help", argv[i] ) || 0 == strcmp( "-h", argv[i] ) ) { SHOW_HELPTEXT; exit(0); } else if ( 0 == strcmp( "-V", argv[i] ) ) { printf( "%u.%u.%u \"%s\"\n", OTF_VERSION_MAYOR, OTF_VERSION_MINOR, OTF_VERSION_SUB, OTF_VERSION_STRING); exit( 0 ); } else { if ( '-' != argv[i][0] ) { inputFile= argv[i]; } else { fprintf( stderr, "ERROR: Unknown option '%s'\n", argv[i] ); exit(1); } } } /* check parameters */ if ( NULL == inputFile ) { printf( " no input file specified\n" ); exit(1); } if ( NULL == outputFile ) { /* printf( " no output file specified\n" ); exit(1); */ outputFile= strdup( "out.otf" ); } if ( maxfilehandles < 1 ) { printf( " there must be at least 1 available filehandle\n" ); exit(1); } fcb.processes= NULL; fcb.processcount= 0; fcb.threadnums= 0; fcb.processgroups= NULL; fcb.processgroupcount= 0; fcb.reservedIds= NULL; fcb.reservedIdsc= 0; fcb.pghash= initHash(); fcb.handleid= 0; /* Open FileManager */ if( 0 == fcb.ioonly ) { manager= OTF_FileManager_open( maxfilehandles ); assert( NULL != manager ); /* Open OTF Writer */ fcb.outputFile= OTF_stripFilename( fcb.outputFile ); fcb.writer = OTF_Writer_open( fcb.outputFile, nstreams, manager ); OTF_Writer_setBufferSizes( fcb.writer, buffersize ); OTF_Writer_setCompression( fcb.writer, compression ); } /* Initialize VTF3. */ (void) VTF3_InitTables (); /* Again, how many different record types do exist ? */ nrectypes = VTF3_GetRecTypeArrayDim (); /* Allocate three auxiliary arrays for the record types, the record handler entry point pointers and some data. */ recordtypes = (int *) malloc ((size_t) nrectypes * sizeof (int)); handlers = (VTF3_handler_t *) malloc ((size_t) nrectypes * sizeof (VTF3_handler_t)); firsthandlerargs = (void **) malloc ((size_t) nrectypes * sizeof (void *)); /* Store the record types onto the appropriate array. Pay attention, the caller does not know their ordering scheme. */ (void) VTF3_GetRecTypeArray (recordtypes); /* What follows, this is the final handler table setup. */ if( 0 == fcb.ioonly ) { for (i = 0; i < nrectypes; i++) { if ( VTF3_RECTYPE_CLSTRREGVAL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleClstrregval; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_COMMENT == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleComment; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_CPUREGVAL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleCpuregval; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFACT == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefact; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFACT_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefact_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLKPERIOD == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclkperiod; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLSTR == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclstr; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLSTRREG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclstrreg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCLSTRREGCLASS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefclstrregclass; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCOMMUNICATOR == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcommunicator; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUGRP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpugrp; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUNAME == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpuname; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUREG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpureg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFCPUREGCLASS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefcpuregclass; firsthandlerargs[i] = &fcb; continue; } /* if ( VTF3_RECTYPE_DEFCREATOR == recordtypes[i] ) { */ /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ /* handlers[i] = (VTF3_handler_t) handleDefcreator; firsthandlerargs[i] = &fcb; continue; } */ if ( VTF3_RECTYPE_DEFGLOBALOP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefglobalop; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFIOFILE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefiofile; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFKPARREG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefkparreg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFMSGNAME == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefmsgname; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFOPENMPNAME == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefopenmpname; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFOPENMPTYPE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefopenmptype; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFPATTERN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefpattern; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFPATTERNSHAPE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefpatternshape; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFREDFUNC_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefredfunc_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSAMP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsamp; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSAMPCLASS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsampclass; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSCL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefscl; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSCLFILE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsclfile; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSTATE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefstate; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSTATE_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefstate_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSYSCPUNAMES == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsyscpunames; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFSYSCPUNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsyscpunums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFTHREADNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefthreadnums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFTIMEOFFSET == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDeftimeoffset; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFUNMERGED == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefunmerged; firsthandlerargs[i] = &fcb; continue; } /* if ( VTF3_RECTYPE_DEFVERSION == recordtypes[i] ) { */ /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ /* handlers[i] = (VTF3_handler_t) handleDefversion; firsthandlerargs[i] = writer; continue; } */ if ( VTF3_RECTYPE_DOWNTO == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDownto; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_EXCHANGE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleExchange; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_EXCHANGE_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleExchange_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOBEGIN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileiobegin; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOEND == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileioend; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_GLOBALOP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleGlobalop; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_KPARREGBARSUM == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleKparregbarsum; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_KPARREGBEGIN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleKparregbegin; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_KPARREGEND == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleKparregend; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_MUTEXACQUIRE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleMutexacquire; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_MUTEXRELEASE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleMutexrelease; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_OPENMPENTER == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleOpenmpenter; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_OPENMPLEAVE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleOpenmpleave; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_PATTERN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handlePattern; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_RECVMSG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleRecvmsg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_SAMP == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleSamp; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_SENDMSG == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleSendmsg; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_SRCINFO_OBSOL == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleSrcinfo_obsol; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_UNRECOGNIZABLE == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleUnrecognizable; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_UPFROM == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleUpfrom; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_UPTO == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleUpto; firsthandlerargs[i] = &fcb; continue; } } } else { /* 1 == fcb.ioonly */ for (i = 0; i < nrectypes; i++) { if ( VTF3_RECTYPE_DEFSYSCPUNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefsyscpunums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_DEFTHREADNUMS == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleDefthreadnums; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOBEGIN == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileiobegin; firsthandlerargs[i] = &fcb; continue; } if ( VTF3_RECTYPE_FILEIOEND == recordtypes[i] ) { /* Replace the predefined copy handler by our own one, do not forget to redirect the first argument, too. */ handlers[i] = (VTF3_handler_t) handleFileioend; firsthandlerargs[i] = &fcb; continue; } } } /* Open the input device */ fcbin = VTF3_OpenFileInput ( inputFile, handlers, firsthandlerargs, 0); /* Free the auxiliary arrays. */ (void) free (firsthandlerargs); (void) free (handlers); (void) free (recordtypes); if ( NULL == fcbin ) { fprintf( stderr, "cannot open input file '%s'\n", inputFile ); exit( 1 ); } /* Now push the operation to portion-wise process the input file contents. */ if( 0 == fcb.ioonly ) { OTF_Writer_writeDefCreator( fcb.writer, 0, VTF32OTFCREATOR ); /* generate a standardfile group - vampir needs a filegroup(communicator) group 0 would be invalid */ OTF_Writer_writeDefFileGroup( fcb.writer, 0, 1, "Default" ); } do { bytesread = VTF3_ReadFileInputLtdBytes (fcbin, 50000); } while (bytesread != 0); if ( NULL == fcb.processes ) { fprintf( stderr, "ERROR: Missing NCPU record\n" ); exit(1); } /* create defprocess records with thread hierarchie */ if( 0 == fcb.ioonly ) { for( i = 0; i < fcb.processcount; i++ ) { OTF_Writer_writeDefProcess( fcb.writer, 0, i + 1, fcb.processes[i][0].name, 0); for( a = 1; a < fcb.threadnums[i]; ++a ) { OTF_Writer_writeDefProcess( fcb.writer, 0, (i + 1) + (a << 16), fcb.processes[i][a].name, i + 1); } } } /* create defprocessgroup records */ for( i= 0;i < (int)fcb.processgroupcount; ++i ) { if( 0 == fcb.ioonly ) { OTF_Writer_writeDefProcessGroup( fcb.writer, 0 /* uint32_t stream */, fcb.processgroups[i].id /* uint32_t procGroup */, fcb.processgroups[i].name /* const char* name */, fcb.processgroups[i].size /* uint32_t numberOfProcs */, fcb.processgroups[i].procs /* const uint32_t* procs */ ); } free( fcb.processgroups[i].procs ); free( fcb.processgroups[i].name ); } free( fcb.processgroups ); /* free process-array */ for( i = 0; i < fcb.processcount; ++i ) { for( a = 0; a < fcb.threadnums[i]; ++a ) { writeFileIOBuffer( i + (a<<16)/*cpuid*/, &fcb.processes[i][a], fcb.outputFile ); /* delete iofiles */ if( 0 == fcb.ioonly ) { sprintf( iofile, "%s.%i.io", fcb.outputFile, i + (a<<16) ); unlink( iofile ); } Stack_delete( fcb.processes[i][a].stack ); if ( 0 != fcb.processes[i][a].name ) { free( fcb.processes[i][a].name ); } } free( fcb.processes[i] ); } free( fcb.processes ); /* Close all devices. */ (void) VTF3_Close (fcbin); if( 0 == fcb.ioonly ) { OTF_Writer_close( fcb.writer ); OTF_FileManager_close( manager ); } closeHash( fcb.pghash ); free( fcb.outputFile ); return 0; }
int main(int argc, char** argv) { const char* namestub; uint64_t num_events = 100000000; /* 1E9 events */ uint64_t i; uint64_t time = 0; struct timespec start_ts; struct timespec end_ts; double secs; int com_rank, com_size; OTF_FileManager* manager; OTF_WStream* wstream; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &com_rank); MPI_Comm_size(MPI_COMM_WORLD, &com_size); if (argc > 1) { namestub = argv[1]; } else { fprintf(stderr, "No filenamestub was given!\n"); exit(1); } if (argc > 2) { num_events = atol(argv[2]); } manager = OTF_FileManager_open(4); assert(manager); wstream = OTF_WStream_open(namestub, com_rank + 1, manager); assert(wstream); clock_gettime(CLOCK_REALTIME, &start_ts); printf("[%i] Starting to send %lli events\n", com_rank, (long long int)num_events / com_size); for(i = 0; i < num_events / 2 / com_size; i++) { OTF_WStream_writeEnter(wstream, time++, com_size + 1, com_rank + 1, 0); OTF_WStream_writeLeave(wstream, time++, com_size + 1, com_rank + 1, 0); } OTF_WStream_close(wstream); MPI_Barrier(MPI_COMM_WORLD); clock_gettime(CLOCK_REALTIME, &end_ts); /* write master control file */ if (com_rank == 0) { OTF_MasterControl* master = OTF_MasterControl_new(manager); assert(master != NULL); for (i = 1; i <= (uint64_t)com_size; i++) { OTF_MasterControl_append(master, i, i); } OTF_MasterControl_write(master, namestub); OTF_MasterControl_close(master); } secs = (end_ts.tv_sec - start_ts.tv_sec) + (end_ts.tv_nsec - start_ts.tv_nsec) / 1E9; printf("Finished: %li events written in %1.5f secs\n--> %5.3f events per second\n", num_events, secs, num_events / secs); OTF_FileManager_close(manager); MPI_Finalize(); return 0; }
int main( int argc, char** argv ) { google::ParseCommandLineFlags( &argc, &argv, true); google::InitGoogleLogging( argv[0] ); FLAGS_logtostderr = 1; FLAGS_v = 1; LOG(INFO) << "Starting!"; OTF_FileManager * manager = OTF_FileManager_open( 100 ); // limit to 100 filehandles CHECK_NOTNULL( manager ); CHECK_NE( FLAGS_otf, "" ) << "Please specify input OTF file"; reader = OTF_Reader_open( FLAGS_otf.c_str(), manager ); CHECK_NOTNULL( reader ); OTF_Reader_setBufferSizes( reader, FLAGS_buffer_size ); if( FLAGS_db != "" ) { auto retval = sqlite3_open( FLAGS_db.c_str(), &db ); if( retval ) { LOG(FATAL) << "Can't open db " << FLAGS_db << ": " << sqlite3_errmsg(db); } std::stringstream ss; ss << "CREATE TABLE IF NOT EXISTS " << FLAGS_table << "(" << " TIME INT8 PRIMARY KEY NOT NULL," << " COUNTER_NAME TEXT," << " PROCESS INT," << " INT_VALUE INT8," << " DOUBLE_VALUE REAL);"; sqlite_exec( db, ss.str().c_str(), NULL, NULL ); sqlite_exec(db, "BEGIN TRANSACTION", NULL, NULL); std::stringstream ss2; ss2 << "INSERT OR IGNORE INTO " << FLAGS_table << " VALUES (?, ?, ?, ?, ?);"; sqlite_prepare( db, ss2.str().c_str(), -1, &stmt ); } if( -1 != FLAGS_max_time ) { OTF_Reader_setTimeInterval( reader, FLAGS_min_time, FLAGS_max_time ); } OTF_HandlerArray * handlers = OTF_HandlerArray_open(); CHECK_NOTNULL( handlers ); // register handlers to do whatever you want. // many handlers can be registered; full list here: // http://wwwpub.zih.tu-dresden.de/~jurenz/otf/api/current/OTF__Definitions_8h.html register_otf_handler( handlers, OTF_DEFCOUNTER_RECORD, defcounter_handler ); register_otf_handler( handlers, OTF_COUNTER_RECORD, counter_handler ); register_otf_handler( handlers, OTF_DEFTIMERRESOLUTION_RECORD, handle_time_resolution ); uint64_t read; read = OTF_Reader_readDefinitions( reader, handlers ); LOG(INFO) << "Read " << read << " definitions"; read = OTF_Reader_readEvents( reader, handlers ); LOG(INFO) << "Read " << read << " events"; read = OTF_Reader_readStatistics( reader, handlers ); LOG(INFO) << "Read " << read << " statistics"; read = OTF_Reader_readSnapshots( reader, handlers ); LOG(INFO) << "Read " << read << " snapshots"; read = OTF_Reader_readMarkers( reader, handlers ); LOG(INFO) << "Read " << read << " markers"; sqlite_exec(db, "COMMIT TRANSACTION", NULL, NULL); LOG(INFO) << "Done."; if( stmt ) sqlite3_finalize( stmt ); if( db ) sqlite3_close( db ); OTF_Reader_close( reader ); OTF_HandlerArray_close( handlers ); OTF_FileManager_close( manager ); return 0; }