#include "stdafx.h"

#ifdef _MSC_VER
#pragma hdrstop
#endif

using namespace std;

#include "../../Kernel/kernelincludes.h"

#include "defaults.h"
#include "TimeStamp.h"

TimeStamp::TimeStamp(void)
{
	time.resize( TS_number, 0 );
	runtime.resize( TS_number, 0 );
	running.resize( TS_number, false );
}

TimeStamp::~TimeStamp(void)
{
}

void TimeStamp::start( unsigned int stamp )
{
	if ( running[stamp] ) throw RuntimeException( "TimeStamp:: Starting running process" );
	runtime[stamp] = GetMyCPUTime();
	running[stamp] = true;
}

float TimeStamp::stop( unsigned int stamp )
{
	if ( !running[stamp] ) throw RuntimeException( "TimeStamp:: Stopping not running process" );
	time[stamp] += GetMyCPUTime() - runtime[stamp];
	running[stamp] = false;
	return time[stamp];
}

void TimeStamp::DumpTimeStamps( char *fn )
{
	ofstream f;
	unsigned int i;

	f.open(fn);
	for ( i = 0; i < TS_number; i++ )
		f << time[i] << endl;
	f.close();
}

