sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@test
|
sl@0
|
19 |
@internalComponent
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <iniparser.h>
|
sl@0
|
23 |
#include <s32file.h>
|
sl@0
|
24 |
#include <hal.h>
|
sl@0
|
25 |
#include <e32math.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
#include "t_perfdata.h"
|
sl@0
|
28 |
#include "t_wservconsts.h"
|
sl@0
|
29 |
|
sl@0
|
30 |
// Strings used when writing results to file to
|
sl@0
|
31 |
// describe the values accordingly.
|
sl@0
|
32 |
// e.g. KPerfDataFrameRate = 24
|
sl@0
|
33 |
// is the calculated frame rate for the measurements taken.
|
sl@0
|
34 |
_LIT(KPerfDataTrimedMean, "KPerfDataTrimedMean");
|
sl@0
|
35 |
_LIT(KPerfDataMaxTime, "KPerfDataMaxTime");
|
sl@0
|
36 |
_LIT(KPerfDataMinTime, "KPerfDataMinTime");
|
sl@0
|
37 |
_LIT(KPerfDataFrameRate, "KPerfDataFrameRate");
|
sl@0
|
38 |
|
sl@0
|
39 |
EXPORT_C CTPerfData* CTPerfData::NewL()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
CTPerfData* self = new(ELeave) CTPerfData();
|
sl@0
|
42 |
CleanupStack::PushL(self);
|
sl@0
|
43 |
self->Construct();
|
sl@0
|
44 |
CleanupStack::Pop(self);
|
sl@0
|
45 |
return self;
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
EXPORT_C void CTPerfData::StartCounter()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
iCounter = User::FastCounter();
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
EXPORT_C void CTPerfData::StopCounterL()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
TUint32 counter = User::FastCounter();
|
sl@0
|
56 |
iResults.AppendL(counter-iCounter);
|
sl@0
|
57 |
iCounter=counter;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
EXPORT_C void CTPerfData::WriteResultsL(const TDesC& aFileName)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
AnalyseResultsL();
|
sl@0
|
63 |
|
sl@0
|
64 |
RFs myFs;
|
sl@0
|
65 |
User::LeaveIfError(myFs.Connect());
|
sl@0
|
66 |
|
sl@0
|
67 |
RFileWriteStream writer;
|
sl@0
|
68 |
writer.PushL(); // writer on cleanup stack
|
sl@0
|
69 |
TInt err = myFs.MkDirAll(aFileName);
|
sl@0
|
70 |
|
sl@0
|
71 |
if (err==KErrNone || err==KErrAlreadyExists)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
User::LeaveIfError(writer.Replace(myFs, aFileName, EFileStreamText|EFileWrite));
|
sl@0
|
74 |
writer.CommitL();
|
sl@0
|
75 |
CleanupStack::PopAndDestroy(&writer); // writer
|
sl@0
|
76 |
|
sl@0
|
77 |
CIniData* myData=CIniData::NewL(aFileName);
|
sl@0
|
78 |
CleanupStack::PushL(myData);
|
sl@0
|
79 |
|
sl@0
|
80 |
TBuf<255> tempStore;
|
sl@0
|
81 |
_LIT(KIntData, "%d");
|
sl@0
|
82 |
tempStore.Format(KIntData,iTrimedMean);
|
sl@0
|
83 |
User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataTrimedMean, tempStore));
|
sl@0
|
84 |
tempStore.Format(KIntData,iMaxTime);
|
sl@0
|
85 |
User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataMaxTime, tempStore));
|
sl@0
|
86 |
tempStore.Format(KIntData,iMinTime);
|
sl@0
|
87 |
User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataMinTime, tempStore));
|
sl@0
|
88 |
_LIT(KRealData, "%4.0f");
|
sl@0
|
89 |
tempStore.Format(KRealData,iFrameRate);
|
sl@0
|
90 |
User::LeaveIfError(myData->AddValue(KDefaultSectionName, KPerfDataFrameRate, tempStore));
|
sl@0
|
91 |
myData->WriteToFileL();
|
sl@0
|
92 |
|
sl@0
|
93 |
CleanupStack::PopAndDestroy(myData);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
else
|
sl@0
|
96 |
{
|
sl@0
|
97 |
CleanupStack::PopAndDestroy(&writer); // writer
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
myFs.Close();
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void CTPerfData::Construct()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
iResults.Reset();
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
CTPerfData::~CTPerfData()
|
sl@0
|
109 |
{
|
sl@0
|
110 |
iResults.Reset();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
void CTPerfData::AnalyseResultsL()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TrimedMeanL();
|
sl@0
|
116 |
MaxTime();
|
sl@0
|
117 |
MinTime();
|
sl@0
|
118 |
FrameRateL();
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
void CTPerfData::TrimedMeanL()
|
sl@0
|
122 |
{
|
sl@0
|
123 |
TInt64 total = 0;
|
sl@0
|
124 |
if (iResults.Count() <= 50)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
RDebug::Print(_L("Not enough results for trimming - need more than 50, but got %d"), iResults.Count());
|
sl@0
|
127 |
iTrimedMean = 0;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
else
|
sl@0
|
130 |
{
|
sl@0
|
131 |
TReal tempVar = iResults.Count() * 0.20;
|
sl@0
|
132 |
TInt32 twentyPercentCount = 0;
|
sl@0
|
133 |
User::LeaveIfError(Math::Int(twentyPercentCount, tempVar));
|
sl@0
|
134 |
|
sl@0
|
135 |
|
sl@0
|
136 |
|
sl@0
|
137 |
for (TInt count = twentyPercentCount; count < iResults.Count()-twentyPercentCount; count++)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
total += iResults[count];
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
iTrimedMean = (static_cast<TUint32>(total/(iResults.Count()-(static_cast<TInt64>(twentyPercentCount)*2))));
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
RDebug::Print(_L("CTPerfData::TrimedMeanL - %d"), iTrimedMean);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
void CTPerfData::MaxTime()
|
sl@0
|
149 |
{
|
sl@0
|
150 |
TUint32 result = iResults[0];
|
sl@0
|
151 |
for(TInt i = 0; i < iResults.Count(); i++)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
if(iResults[i] > result)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
result = iResults[i];
|
sl@0
|
156 |
}
|
sl@0
|
157 |
}
|
sl@0
|
158 |
iMaxTime = result;
|
sl@0
|
159 |
|
sl@0
|
160 |
RDebug::Print(_L("CTPerfData::MaxTime - %d"), iMaxTime);
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
void CTPerfData::MinTime()
|
sl@0
|
164 |
{
|
sl@0
|
165 |
TUint32 result = iResults[0];
|
sl@0
|
166 |
for(TInt i = 0; i < iResults.Count(); i++)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
if(iResults[i] < result)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
result = iResults[i];
|
sl@0
|
171 |
}
|
sl@0
|
172 |
}
|
sl@0
|
173 |
iMinTime = result;
|
sl@0
|
174 |
|
sl@0
|
175 |
RDebug::Print(_L("CTPerfData::MinTime - %d"), iMinTime);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
void CTPerfData::FrameRateL()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
iFrameRate = 0;
|
sl@0
|
181 |
if (iTrimedMean==0)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
TrimedMeanL();
|
sl@0
|
184 |
}
|
sl@0
|
185 |
TInt counterFreq = 1;
|
sl@0
|
186 |
User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, counterFreq));
|
sl@0
|
187 |
|
sl@0
|
188 |
if (iTrimedMean)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
iFrameRate = static_cast<TReal>(counterFreq)/iTrimedMean;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
else
|
sl@0
|
193 |
{
|
sl@0
|
194 |
User::Leave(KErrAbort);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
RDebug::Print(_L("CTPerfData::FrameRate - %4.0f"), iFrameRate);
|
sl@0
|
198 |
}
|