os/graphics/windowing/windowserver/test/t_integ/src/t_perfdata.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_perfdata.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,198 @@
     1.4 +// Copyright (c) 2007-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 "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 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent
    1.23 +*/
    1.24 +
    1.25 +#include <iniparser.h>
    1.26 +#include <s32file.h>
    1.27 +#include <hal.h>
    1.28 +#include <e32math.h>
    1.29 +
    1.30 +#include "t_perfdata.h"
    1.31 +#include "t_wservconsts.h"
    1.32 +
    1.33 +// Strings used when writing results to file to
    1.34 +// describe the values accordingly.
    1.35 +// e.g. KPerfDataFrameRate = 24
    1.36 +// is the calculated frame rate for the measurements taken.
    1.37 +_LIT(KPerfDataTrimedMean, "KPerfDataTrimedMean");
    1.38 +_LIT(KPerfDataMaxTime,    "KPerfDataMaxTime");
    1.39 +_LIT(KPerfDataMinTime,    "KPerfDataMinTime");
    1.40 +_LIT(KPerfDataFrameRate,  "KPerfDataFrameRate");
    1.41 +
    1.42 +EXPORT_C CTPerfData*  CTPerfData::NewL()
    1.43 +	{
    1.44 +	CTPerfData* self = new(ELeave) CTPerfData();
    1.45 +	CleanupStack::PushL(self);
    1.46 +	self->Construct();
    1.47 +	CleanupStack::Pop(self);
    1.48 +	return self;
    1.49 +	}
    1.50 +
    1.51 +EXPORT_C void CTPerfData::StartCounter()
    1.52 +	{
    1.53 +	iCounter = User::FastCounter();
    1.54 +	}
    1.55 +
    1.56 +EXPORT_C void CTPerfData::StopCounterL()
    1.57 +	{
    1.58 +	TUint32 counter = User::FastCounter();
    1.59 +	iResults.AppendL(counter-iCounter);
    1.60 +	iCounter=counter;
    1.61 +	}
    1.62 +
    1.63 +EXPORT_C void CTPerfData::WriteResultsL(const TDesC& aFileName)
    1.64 +	{
    1.65 +	AnalyseResultsL();
    1.66 +
    1.67 +	RFs myFs;
    1.68 +	User::LeaveIfError(myFs.Connect());
    1.69 +
    1.70 +	RFileWriteStream writer;
    1.71 +	writer.PushL(); // writer on cleanup stack
    1.72 +	TInt err = myFs.MkDirAll(aFileName);
    1.73 +
    1.74 +	if (err==KErrNone || err==KErrAlreadyExists)
    1.75 +		{
    1.76 +		User::LeaveIfError(writer.Replace(myFs, aFileName, EFileStreamText|EFileWrite));
    1.77 +		writer.CommitL();
    1.78 +		CleanupStack::PopAndDestroy(&writer); // writer
    1.79 +
    1.80 +		CIniData* myData=CIniData::NewL(aFileName);
    1.81 +		CleanupStack::PushL(myData);
    1.82 +
    1.83 +		TBuf<255> tempStore;
    1.84 +		_LIT(KIntData, "%d");
    1.85 +		tempStore.Format(KIntData,iTrimedMean);
    1.86 +		User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataTrimedMean, tempStore));
    1.87 +		tempStore.Format(KIntData,iMaxTime);
    1.88 +		User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataMaxTime, tempStore));
    1.89 +		tempStore.Format(KIntData,iMinTime);
    1.90 +		User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataMinTime, tempStore));
    1.91 +		_LIT(KRealData, "%4.0f");
    1.92 +		tempStore.Format(KRealData,iFrameRate);
    1.93 +		User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataFrameRate, tempStore));
    1.94 +		myData->WriteToFileL();
    1.95 +
    1.96 +		CleanupStack::PopAndDestroy(myData);
    1.97 +		}
    1.98 +	else
    1.99 +		{
   1.100 +		CleanupStack::PopAndDestroy(&writer); // writer
   1.101 +		}
   1.102 +
   1.103 +	myFs.Close();
   1.104 +	}
   1.105 +
   1.106 +void CTPerfData::Construct()
   1.107 +	{
   1.108 +	iResults.Reset();
   1.109 +	}
   1.110 +
   1.111 +CTPerfData::~CTPerfData()
   1.112 +	{
   1.113 +	iResults.Reset();
   1.114 +	}
   1.115 +
   1.116 +void CTPerfData::AnalyseResultsL()
   1.117 +	{
   1.118 +	TrimedMeanL();
   1.119 +	MaxTime();
   1.120 +	MinTime();
   1.121 +	FrameRateL();
   1.122 +	}
   1.123 +
   1.124 +void CTPerfData::TrimedMeanL()
   1.125 +	{
   1.126 +	TInt64 total = 0;
   1.127 +	if (iResults.Count() <= 50)
   1.128 +		{
   1.129 +		RDebug::Print(_L("Not enough results for trimming - need more than 50, but got %d"), iResults.Count());
   1.130 +		iTrimedMean = 0;
   1.131 +		}
   1.132 +	else
   1.133 +		{
   1.134 +		TReal tempVar = iResults.Count() * 0.20;
   1.135 +		TInt32 twentyPercentCount = 0;
   1.136 +		User::LeaveIfError(Math::Int(twentyPercentCount, tempVar));
   1.137 +
   1.138 +
   1.139 +
   1.140 +		for (TInt count = twentyPercentCount; count < iResults.Count()-twentyPercentCount; count++)
   1.141 +			{
   1.142 +			total += iResults[count];
   1.143 +			}
   1.144 +
   1.145 +		iTrimedMean = (static_cast<TUint32>(total/(iResults.Count()-(static_cast<TInt64>(twentyPercentCount)*2))));
   1.146 +		}
   1.147 +
   1.148 +	RDebug::Print(_L("CTPerfData::TrimedMeanL - %d"), iTrimedMean);
   1.149 +	}
   1.150 +
   1.151 +void CTPerfData::MaxTime()
   1.152 +	{
   1.153 +	TUint32 result = iResults[0];
   1.154 +	for(TInt i = 0; i < iResults.Count(); i++)
   1.155 +		{
   1.156 +		if(iResults[i] > result)
   1.157 +			{
   1.158 +			result = iResults[i];
   1.159 +			}
   1.160 +		}
   1.161 +	iMaxTime = result;
   1.162 +
   1.163 +	RDebug::Print(_L("CTPerfData::MaxTime - %d"), iMaxTime);
   1.164 +	}
   1.165 +
   1.166 +void CTPerfData::MinTime()
   1.167 +	{
   1.168 +	TUint32 result = iResults[0];
   1.169 +	for(TInt i = 0; i < iResults.Count(); i++)
   1.170 +		{
   1.171 +		if(iResults[i] < result)
   1.172 +			{
   1.173 +			result = iResults[i];
   1.174 +			}
   1.175 +		}
   1.176 +	iMinTime = result;
   1.177 +
   1.178 +	RDebug::Print(_L("CTPerfData::MinTime - %d"), iMinTime);
   1.179 +	}
   1.180 +
   1.181 +void CTPerfData::FrameRateL()
   1.182 +	{
   1.183 +	iFrameRate = 0;
   1.184 +	if (iTrimedMean==0)
   1.185 +		{
   1.186 +		TrimedMeanL();
   1.187 +		}
   1.188 +	TInt counterFreq = 1;
   1.189 +	User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, counterFreq));
   1.190 +
   1.191 +	if (iTrimedMean)
   1.192 +		{
   1.193 +		iFrameRate = static_cast<TReal>(counterFreq)/iTrimedMean;
   1.194 +		}
   1.195 +	else
   1.196 +		{
   1.197 +		User::Leave(KErrAbort);
   1.198 +		}
   1.199 +
   1.200 +	RDebug::Print(_L("CTPerfData::FrameRate - %4.0f"), iFrameRate);
   1.201 +	}