~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kwin/tools/decobenchmark/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * Copyright (c) 2005 Sandro Giessl <sandro@giessl.com>
 
4
 * Copyright (c) 2005 Luciano Montanaro <mikelima@cirulla.net>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include <QTimer>
 
22
 
 
23
#include <kdebug.h>
 
24
#include <kconfig.h>
 
25
#include <kdecoration_plugins_p.h>
 
26
#include <kdecorationfactory.h>
 
27
 
 
28
#include <time.h>
 
29
#include <sys/timeb.h>
 
30
#include <iostream>
 
31
 
 
32
 
 
33
#include <kaboutdata.h>
 
34
#include <kapplication.h>
 
35
#include <kcmdlineargs.h>
 
36
 
 
37
#include "preview.h"
 
38
#include "main.h"
 
39
 
 
40
DecoBenchApplication::DecoBenchApplication(const QString &library, Tests tests, int count) :
 
41
                m_tests(tests),
 
42
                m_count(count)
 
43
{
 
44
        KConfig kwinConfig("kwinrc");
 
45
        kwinConfig.setGroup("Style");
 
46
 
 
47
        plugins = new KDecorationPreviewPlugins( &kwinConfig );
 
48
        preview = new KDecorationPreview( plugins, 0 );
 
49
 
 
50
        if (plugins->loadPlugin(library) )
 
51
                kDebug() << "Decoration library " << library << " loaded...";
 
52
        else
 
53
                kError() << "Error loading decoration library " << library << "!" << endl;
 
54
 
 
55
        if (preview->recreateDecoration() )
 
56
                kDebug() << "Decoration created...";
 
57
        else
 
58
                kError() << "Error creating decoration!" << endl;
 
59
 
 
60
        preview->show();
 
61
}
 
62
 
 
63
DecoBenchApplication::~DecoBenchApplication()
 
64
{
 
65
        delete preview;
 
66
        delete plugins;
 
67
}
 
68
 
 
69
void DecoBenchApplication::executeTest()
 
70
{
 
71
        clock_t stime = clock();
 
72
        timeb astart, aend;
 
73
        ftime(&astart);
 
74
 
 
75
        if (m_tests == AllTests || m_tests == RepaintTest)
 
76
                preview->performRepaintTest(m_count);
 
77
        if (m_tests == AllTests || m_tests == CaptionTest)
 
78
                preview->performCaptionTest(m_count);
 
79
        if (m_tests == AllTests || m_tests == ResizeTest)
 
80
                preview->performResizeTest(m_count);
 
81
        if (m_tests == AllTests || m_tests == RecreationTest)
 
82
                preview->performRecreationTest(m_count);
 
83
 
 
84
        clock_t etime = clock();
 
85
        ftime(&aend);
 
86
 
 
87
        long long time_diff = (aend.time - astart.time)*1000+aend.millitm - astart.millitm;
 
88
        kDebug() << "Total:" << (float(time_diff)/1000);
 
89
        quit();
 
90
}
 
91
 
 
92
int main(int argc, char** argv)
 
93
{
 
94
        QString style = "keramik";
 
95
        // KApplication app(argc, argv);
 
96
        KAboutData about("decobenchmark", 0, ki18n("DecoBenchmark"), "0.1", ki18n("kwin decoration performance tester..."), KAboutData::License_LGPL, ki18n("(C) 2005 Sandro Giessl"));
 
97
        KCmdLineArgs::init(argc, argv, &about);
 
98
 
 
99
        KCmdLineOptions options;
 
100
        options.add("+decoration", ki18n("Decoration library to use, such as kwin3_plastik."));
 
101
        options.add("+tests", ki18n("Which test should be executed ('all', 'repaint', 'caption', 'resize', 'recreation')"));
 
102
        options.add("+repetitions", ki18n("Number of test repetitions."));
 
103
        KCmdLineArgs::addCmdLineOptions( options );
 
104
 
 
105
        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
106
 
 
107
        if (args->count() != 3)
 
108
                KCmdLineArgs::usage("Wrong number of arguments!");
 
109
 
 
110
        QString library = QString(args->arg(0) );
 
111
        QString t = QString(args->arg(1) );
 
112
        int count = QString(args->arg(2) ).toInt();
 
113
 
 
114
        Tests test;
 
115
        if (t == "all")
 
116
                test = AllTests;
 
117
        else if (t == "repaint")
 
118
                test = RepaintTest;
 
119
        else if (t == "caption")
 
120
                test = CaptionTest;
 
121
        else if (t == "resize")
 
122
                test = ResizeTest;
 
123
        else if (t == "recreation")
 
124
                test = RecreationTest;
 
125
        else
 
126
                KCmdLineArgs::usage("Specify a valid test!");
 
127
 
 
128
        DecoBenchApplication app(library, test, count);
 
129
 
 
130
        QTimer::singleShot(0, &app, SLOT(executeTest()));
 
131
        app.exec();
 
132
}
 
133
#include "main.moc"
 
134
 
 
135
// kate: space-indent off; tab-width 4;