コード例 #1
0
ファイル: otf2vtf.c プロジェクト: hpc/cce-mpi-openmpi-1.4.3
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);
}
コード例 #2
0
ファイル: otf2sqlite.cpp プロジェクト: HTOKORG/grappa
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; 
}