0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
#include "performancediff.h"
|
|
42 |
|
|
43 |
#include "xmldata.h"
|
|
44 |
|
|
45 |
#include <QtXml>
|
|
46 |
|
|
47 |
#include <QFile>
|
|
48 |
#include <QStringList>
|
|
49 |
#include <QDateTime>
|
|
50 |
#include <QtDebug>
|
|
51 |
|
|
52 |
#include <iostream>
|
|
53 |
#include <iomanip>
|
|
54 |
|
|
55 |
|
|
56 |
static const int MIN_TEST_VAL = 20;
|
|
57 |
static const int TEST_EPSILON = 5; //ms
|
|
58 |
|
|
59 |
static void usage(const char *progname)
|
|
60 |
{
|
|
61 |
std::cerr << "Couldn't find 'framework.ini' "
|
|
62 |
<< "file and no output has been specified."<<std::endl;
|
|
63 |
std::cerr << "Usage: "<<progname
|
|
64 |
<< " oldDataDir"
|
|
65 |
<< " newDataDir\n"
|
|
66 |
<< std::endl;
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
PerformanceDiff::PerformanceDiff()
|
|
71 |
: settings(0)
|
|
72 |
{
|
|
73 |
if (QFile::exists("framework.ini")) {
|
|
74 |
settings = new QSettings("framework.ini", QSettings::IniFormat);
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
static void loadEngines(const QString &dirName,
|
|
79 |
QMap<QString, XMLEngine*> &engines)
|
|
80 |
{
|
|
81 |
QDir dir(dirName);
|
|
82 |
dir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
|
|
83 |
QFileInfoList list = dir.entryInfoList();
|
|
84 |
for (int i = 0; i < list.size(); ++i) {
|
|
85 |
QFileInfo fileInfo = list.at(i);
|
|
86 |
QString dataFile = QString("%1/data.xml")
|
|
87 |
.arg(fileInfo.absoluteFilePath());
|
|
88 |
if (QFile::exists(dataFile)) {
|
|
89 |
XMLReader handler;
|
|
90 |
QXmlSimpleReader reader;
|
|
91 |
reader.setContentHandler(&handler);
|
|
92 |
reader.setErrorHandler(&handler);
|
|
93 |
|
|
94 |
QFile file(dataFile);
|
|
95 |
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
96 |
qWarning("Cannot open file '%s', because: %s",
|
|
97 |
qPrintable(dataFile), qPrintable(file.errorString()));
|
|
98 |
continue;
|
|
99 |
}
|
|
100 |
|
|
101 |
QXmlInputSource xmlInputSource(&file);
|
|
102 |
if (reader.parse(xmlInputSource)) {
|
|
103 |
XMLEngine *engine = handler.xmlEngine();
|
|
104 |
engines.insert(engine->name, engine);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
}
|
|
110 |
void PerformanceDiff::run(int argc, char **argv)
|
|
111 |
{
|
|
112 |
processArguments(argc, argv);
|
|
113 |
|
|
114 |
loadEngines(inputDirName, inputEngines);
|
|
115 |
loadEngines(diffDirName, diffEngines);
|
|
116 |
|
|
117 |
if (inputEngines.isEmpty() || diffEngines.isEmpty()) {
|
|
118 |
usage(argv[0]);
|
|
119 |
return;
|
|
120 |
}
|
|
121 |
|
|
122 |
generateDiff();
|
|
123 |
//generateOutput();
|
|
124 |
}
|
|
125 |
|
|
126 |
void PerformanceDiff::processArguments(int argc, char **argv)
|
|
127 |
{
|
|
128 |
if (argc != 3)
|
|
129 |
return;
|
|
130 |
inputDirName = QString(argv[1]);
|
|
131 |
diffDirName = QString(argv[2]);
|
|
132 |
}
|
|
133 |
|
|
134 |
void PerformanceDiff::generateDiff()
|
|
135 |
{
|
|
136 |
qreal totalIn = 0;
|
|
137 |
qreal totalDiff = 0;
|
|
138 |
|
|
139 |
std::cout<<std::setiosflags(std::ios::left)<<std::setw(30)<<"Testcase"
|
|
140 |
<<std::setiosflags(std::ios::right)
|
|
141 |
<<std::setw(10) <<"Before"
|
|
142 |
<<std::setw(15) <<"After"
|
|
143 |
<<std::setw(20) <<"Difference"<<std::endl;
|
|
144 |
std::cout << std::resetiosflags(std::ios::right);
|
|
145 |
std::cout << std::resetiosflags(std::ios::left);
|
|
146 |
std::cout<<std::setfill('-')<<std::setw(75)<<'-'<<std::endl;
|
|
147 |
foreach(XMLEngine *diffEngine, diffEngines) {
|
|
148 |
XMLEngine *inEngine = inputEngines[diffEngine->name];
|
|
149 |
if (!inEngine)
|
|
150 |
continue;
|
|
151 |
foreach(XMLSuite *diffSuite, diffEngine->suites) {
|
|
152 |
XMLSuite *inSuite = inEngine->suites[diffSuite->name];
|
|
153 |
if (!inSuite)
|
|
154 |
continue;
|
|
155 |
|
|
156 |
foreach(XMLFile *diffFile, diffSuite->files) {
|
|
157 |
XMLFile *inFile = inSuite->files[diffFile->name];
|
|
158 |
if (!inFile)
|
|
159 |
continue;
|
|
160 |
|
|
161 |
qreal inAvg = 0;
|
|
162 |
qreal diffAvg = 0;
|
|
163 |
qreal inMin = 0;
|
|
164 |
qreal inMax = 0;
|
|
165 |
foreach(XMLData data, inFile->data) {
|
|
166 |
inAvg = (double(data.timeToRender)/data.iterations);
|
|
167 |
if (!inMin)
|
|
168 |
inMin = data.minElapsed;
|
|
169 |
else if (data.minElapsed < inMin)
|
|
170 |
inMin = data.minElapsed;
|
|
171 |
if (!inMax)
|
|
172 |
inMax = data.maxElapsed;
|
|
173 |
else if (inMax < data.maxElapsed)
|
|
174 |
inMax = data.maxElapsed;
|
|
175 |
}
|
|
176 |
//skipping really small tests
|
|
177 |
if (inAvg < MIN_TEST_VAL) {
|
|
178 |
continue;
|
|
179 |
}
|
|
180 |
|
|
181 |
totalIn += inAvg;
|
|
182 |
foreach(XMLData data, diffFile->data) {
|
|
183 |
diffAvg = (double(data.timeToRender)/data.iterations);
|
|
184 |
}
|
|
185 |
totalDiff += diffAvg;
|
|
186 |
|
|
187 |
QFileInfo fi(diffFile->name);
|
|
188 |
std::cout.width(80);
|
|
189 |
std::cout.setf(std::ios::fixed, std::ios::floatfield);
|
|
190 |
std::cout.setf(std::ios::showpoint);
|
|
191 |
std::cout << std::resetiosflags(std::ios::right);
|
|
192 |
std::cout << std::resetiosflags(std::ios::left);
|
|
193 |
std::cout<<std::setw(30)<<std::setfill('.')<<std::setiosflags(std::ios::left)
|
|
194 |
<<qPrintable(fi.fileName())<<"\t";
|
|
195 |
std::cout<<std::setfill(' ')<<std::setprecision(2)
|
|
196 |
<<std::setiosflags(std::ios::right)
|
|
197 |
<<std::setw(8)<<std::setiosflags(std::ios::right)<<inAvg<<"\t"
|
|
198 |
<<std::setw(8)<<diffAvg<<"\t"
|
|
199 |
<<std::setw(7)<< ((1.0-(diffAvg/inAvg))*100.0) <<"%";
|
|
200 |
if (diffAvg < inMin &&
|
|
201 |
(qAbs(inMin - diffAvg) > TEST_EPSILON)) {
|
|
202 |
std::cout<<" + ("<<inMin<<")";
|
|
203 |
}
|
|
204 |
if (diffAvg > inMax &&
|
|
205 |
(qAbs(diffAvg - inMax) > TEST_EPSILON)) {
|
|
206 |
std::cout<<" - ("<<inMax<<")";
|
|
207 |
}
|
|
208 |
|
|
209 |
std::cout<<std::endl;
|
|
210 |
}
|
|
211 |
}
|
|
212 |
}
|
|
213 |
std::cout << std::resetiosflags(std::ios::right);
|
|
214 |
std::cout << std::resetiosflags(std::ios::left);
|
|
215 |
std::cout<<std::setfill('-')<<std::setw(75)<<'-'<<std::endl;
|
|
216 |
}
|
|
217 |
|
|
218 |
|
|
219 |
|