/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__JOB_PERF__
#define	__JOB_PERF__


		#include "async/job.h"


namespace GS {
	namespace ASync {

//
struct	JobPerf
{
		Time	slice_duration;
		Time	tasks_duration;

		void	Reset()
		{
			slice_duration.setSec(0);
			tasks_duration.setSec(0);
		}
};

//
template <class Container> void CollectJobsPerf(const Container &jobs, uint count, JobPerf &perf)
{
	if	(count == 0)
		return;

	Time slice_start = jobs[0]->time_start, slice_end = jobs[0]->time_end;

	perf.tasks_duration += jobs[0]->time_end - jobs[0]->time_start;

	for (uint n = 1; n < count; ++n)
	{
		slice_start = Types::Min(jobs[n]->time_start, slice_start);
		slice_end = Types::Max(jobs[n]->time_end, slice_end);

		perf.tasks_duration += jobs[n]->time_end - jobs[n]->time_start;
	}

	perf.slice_duration += slice_end - slice_start;
};

	} // ASync
} // GS


#endif // __JOB_PERF__
