os/kernelhwsrv/kerneltest/e32test/benchmark/overhead.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/benchmark/overhead.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32test.h>
    1.20 +
    1.21 +#include "bm_suite.h"
    1.22 +
    1.23 +class Overhead : public BMProgram
    1.24 +	{
    1.25 +	typedef void (*MeasurementFunc)(TBMResult*, TBMUInt64 aIter);
    1.26 +	struct Measurement 
    1.27 +		{
    1.28 +		MeasurementFunc iFunc;
    1.29 +		TPtrC			iName;
    1.30 +
    1.31 +		Measurement(MeasurementFunc aFunc, const TDesC&	aName) : iFunc(aFunc), iName(aName) {}
    1.32 +		};
    1.33 +public :
    1.34 +	Overhead() : BMProgram(_L("Overhead"))
    1.35 +		{}
    1.36 +	virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount);
    1.37 +private:
    1.38 +	static TBMResult iResults[];
    1.39 +	static Measurement iMeasurements[];
    1.40 +
    1.41 +	static void TimerStampOverhead(TBMResult*, TBMUInt64 aIter);
    1.42 +	};
    1.43 +
    1.44 +Overhead::Measurement Overhead::iMeasurements[] =
    1.45 +	{
    1.46 +	Measurement(&Overhead::TimerStampOverhead, _L("Getting Timer Stamp Overhead"))
    1.47 +	};
    1.48 +TBMResult Overhead::iResults[sizeof(Overhead::iMeasurements)/sizeof(Overhead::iMeasurements[0])];
    1.49 +
    1.50 +static Overhead overhead;
    1.51 +
    1.52 +void Overhead::TimerStampOverhead(TBMResult* aResult, TBMUInt64 aIter)
    1.53 +	{
    1.54 +	for (TBMUInt64 i = 0; i < aIter; ++i)
    1.55 +		{		
    1.56 +		TBMTicks t1, t2;
    1.57 +		::bmTimer.Stamp(&t1);
    1.58 +		::bmTimer.Stamp(&t2);
    1.59 +		aResult->Cumulate(TBMTicksDelta(t1, t2));
    1.60 +		//
    1.61 +		// Enable other threads to run
    1.62 +		//
    1.63 +		TInt prio = BMProgram::SetAbsPriority(RThread(), overhead.iOrigAbsPriority);
    1.64 +		BMProgram::SetAbsPriority(RThread(), prio);	
    1.65 +		}
    1.66 +	}
    1.67 +						
    1.68 +TBMResult* Overhead::Run(TBMUInt64 aIter, TInt* aCount)
    1.69 +	{
    1.70 +	TInt count = sizeof(iResults)/sizeof(iResults[0]);
    1.71 +
    1.72 +	for (TInt i = 0; i < count; ++i)
    1.73 +		{
    1.74 +		iResults[i].Reset(iMeasurements[i].iName);
    1.75 +		iMeasurements[i].iFunc(&iResults[i], aIter);
    1.76 +		iResults[i].Update();
    1.77 +		}
    1.78 +	
    1.79 +	*aCount = count;
    1.80 +	return iResults;
    1.81 +	}
    1.82 +
    1.83 +void AddOverhead()
    1.84 +	{
    1.85 +	BMProgram* next = bmSuite;
    1.86 +	bmSuite=(BMProgram*)&overhead;
    1.87 +	bmSuite->Next()=next;
    1.88 +	}