Control.cpp 1.5 KB
Newer Older
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
/*
 This is part of the OTF library. Copyright by ZIH, TU Dresden 2005-2010.
 Authors: Andreas Knuepfer, Holger Brunst, Ronny Brendel, Thomas Kriebitzsch
*/


#include <iostream>
using namespace std;


#include "Control.h"


Control::Control( OTF_Writer* w, bool _verbose, bool _usefunctiongroups,
		bool _usefilegroups, bool _doSnapshots, bool _doStatistics ) :
		writer( w ), verbose( _verbose ),
		usefunctiongroups( _usefunctiongroups ) {


	nextTime= (uint64_t) -1;
	state= new State( _usefunctiongroups, _usefilegroups, _doSnapshots,
		_doStatistics );
}


Control::~Control() {

    delete state;

}


/** add time stamp where to generate a snapshot */
void Control::addTime( uint64_t time ) {
 
	timestamps.insert( time );
	
	nextTime= *( timestamps.begin() );
}


uint64_t Control::getLastTime() {


	return *(timestamps.rbegin());
}


double Control::checkTime( uint64_t time ) {


	if ( time >= nextTime ) {
	

		if ( verbose ) {
		
			cout << hex << "[" << time << "]" << endl;
		}
	
		//state->printStatistics( time );
		
		state->writeStatistics( writer, nextTime );

		/* write snapshot only when its not the very end of the trace */
		if ( nextTime != getLastTime() ) {
			

			//state->printStack();
			//state->printSends();
			//state->printOpenFiles();
			state->writeSnapshot( writer, nextTime );
		}


		timestamps.erase( nextTime );

		if ( ! timestamps.empty() ) {

			nextTime= *( timestamps.begin() );

		} else {

			nextTime= (uint64_t) -1;
		}
		
		return (double) nextTime;
	}
	
	return (double) time;
}