~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/totuning.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****
 
2
*
 
3
* TOra - An Oracle Toolkit for DBA's and developers
 
4
* Copyright (C) 2003-2005 Quest Software, Inc
 
5
* Portions Copyright (C) 2005 Other Contributors
 
6
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation;  only version 2 of
 
10
* the License is valid for this program.
 
11
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
 
17
* You should have received a copy of the GNU General Public License
 
18
* along with this program; if not, write to the Free Software
 
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
*
 
21
*      As a special exception, you have permission to link this program
 
22
*      with the Oracle Client libraries and distribute executables, as long
 
23
*      as you follow the requirements of the GNU GPL in regard to all of the
 
24
*      software in the executable aside from Oracle client libraries.
 
25
*
 
26
*      Specifically you are not permitted to link this program with the
 
27
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 
28
*      And you are not permitted to distribute binaries compiled against
 
29
*      these libraries without written consent from Quest Software, Inc.
 
30
*      Observe that this does not disallow linking to the Qt Free Edition.
 
31
*
 
32
*      You may link this product with any GPL'd Qt library such as Qt/Free
 
33
*
 
34
* All trademarks belong to their respective owners.
 
35
*
 
36
*****/
 
37
 
 
38
#include "tochangeconnection.h"
 
39
#include "toconf.h"
 
40
#include "toconnection.h"
 
41
#include "tomain.h"
 
42
#include "tonoblockquery.h"
 
43
#include "toresultbar.h"
 
44
#include "toresultitem.h"
 
45
#include "toresultline.h"
 
46
#include "toresultlock.h"
 
47
#include "toresultlong.h"
 
48
#include "toresultparam.h"
 
49
#include "toresultpie.h"
 
50
#include "toresultstats.h"
 
51
#include "toresultview.h"
 
52
#include "tosql.h"
 
53
#include "totool.h"
 
54
#include "totuning.h"
 
55
#include "totuningsettingui.h"
 
56
#include "towaitevents.h"
 
57
 
 
58
#ifdef TO_KDE
 
59
#  include <kmenubar.h>
 
60
#endif
 
61
 
 
62
#include <time.h>
 
63
#include <stdio.h>
 
64
 
 
65
#include <qcombobox.h>
 
66
#include <qgrid.h>
 
67
#include <qgroupbox.h>
 
68
#include <qlabel.h>
 
69
#include <qlayout.h>
 
70
#include <qmenubar.h>
 
71
#include <qmessagebox.h>
 
72
#if QT_VERSION > 0x030000
 
73
#  include <qobjectlist.h>
 
74
#else
 
75
#  include <qobjcoll.h>
 
76
#endif
 
77
#include <qpainter.h>
 
78
#include <qscrollview.h>
 
79
#include <qsplitter.h>
 
80
#include <qtabwidget.h>
 
81
#include <qtoolbar.h>
 
82
#include <qtoolbutton.h>
 
83
#include <qvbox.h>
 
84
#include <qworkspace.h>
 
85
 
 
86
#include "totuning.moc"
 
87
#include "totuningoverviewui.moc"
 
88
#include "totuningsettingui.moc"
 
89
 
 
90
#include "icons/refresh.xpm"
 
91
#include "icons/totuning.xpm"
 
92
#include "icons/compile.xpm"
 
93
 
 
94
#define CONF_OVERVIEW "Overview"
 
95
#define CONF_FILEIO   "File I/O"
 
96
#define CONF_WAITS    "Wait events"
 
97
#define CONF_CHART    "chart"
 
98
 
 
99
static std::list<QCString> TabList(void)
 
100
{
 
101
    std::list<QCString> ret;
 
102
    ret.insert(ret.end(), CONF_OVERVIEW);
 
103
    std::list<QCString> val = toSQL::range("toTuning:Charts");
 
104
    QString last;
 
105
    for (std::list<QCString>::iterator i = val.begin();i != val.end();i++)
 
106
    {
 
107
        QStringList parts = QStringList::split(QString::fromLatin1(":"), QString::fromLatin1(*i));
 
108
        if (parts.count() == 3)
 
109
        {
 
110
            parts.append(parts[2]);
 
111
            parts[2] = QString::fromLatin1("Charts");
 
112
        }
 
113
        if (last != parts[2])
 
114
            ret.insert(ret.end(), parts[2].latin1());
 
115
        last = parts[2];
 
116
    }
 
117
    ret.insert(ret.end(), CONF_WAITS);
 
118
    ret.insert(ret.end(), CONF_FILEIO);
 
119
    return ret;
 
120
}
 
121
 
 
122
class toTuningSetup : public toTuningSettingUI, public toSettingTab
 
123
{
 
124
    toTool *Tool;
 
125
public:
 
126
    toTuningSetup(toTool *tool, QWidget* parent = 0, const char* name = 0)
 
127
            : toTuningSettingUI(parent, name), toSettingTab("tuning.html#preferences"), Tool(tool)
 
128
    {
 
129
        std::list<QCString> tabs = TabList();
 
130
        for (std::list<QCString>::iterator i = tabs.begin();i != tabs.end();i++)
 
131
        {
 
132
            QListViewItem *item = new QListViewItem(EnabledTabs, QString::fromLatin1(*i));
 
133
            if (!tool->config(*i, "").isEmpty())
 
134
                item->setSelected(true);
 
135
        }
 
136
        EnabledTabs->setSorting(0);
 
137
    }
 
138
    virtual void saveSetting(void)
 
139
    {
 
140
        for (QListViewItem *item = EnabledTabs->firstChild();item;item = item->nextSibling())
 
141
        {
 
142
            if (item->isSelected() || Tool->config(item->text(0).latin1(), "Undefined") != "Undefined")
 
143
                Tool->setConfig(item->text(0).latin1(), QString::fromLatin1((item->isSelected() ? "Yes" : "")));
 
144
        }
 
145
    }
 
146
};
 
147
 
 
148
class toTuningTool : public toTool
 
149
{
 
150
protected:
 
151
    virtual const char **pictureXPM(void)
 
152
    {
 
153
        return const_cast<const char**>(totuning_xpm);
 
154
    }
 
155
public:
 
156
    toTuningTool()
 
157
            : toTool(30, "Server Tuning")
 
158
    { }
 
159
    virtual const char *menuItem()
 
160
    {
 
161
        return "Server Tuning";
 
162
    }
 
163
    virtual QWidget *toolWindow(QWidget *parent, toConnection &connection)
 
164
    {
 
165
        return new toTuning(parent, connection);
 
166
    }
 
167
    virtual QWidget *configurationTab(QWidget *parent)
 
168
    {
 
169
        return new toTuningSetup(this, parent);
 
170
    }
 
171
    virtual void closeWindow(toConnection &connection){};
 
172
};
 
173
 
 
174
static toTuningTool TuningTool;
 
175
 
 
176
static toSQL SQLDictionaryMiss("toTuning:Indicators:Important ratios:1DictionaryMiss",
 
177
                               "select sum(getmisses)/sum(gets)*100,' %' from v$rowcache",
 
178
                               "Data dictionary row cache miss ratio (%). < 10%-15%");
 
179
 
 
180
static toSQL SQLImportantLibraryCache("toTuning:Indicators:Important ratios:2LibraryCache",
 
181
                                      "select sum(reloads)/sum(pins)*100,' %' from v$librarycache",
 
182
                                      "Library cache (Shared SQL) miss ratio (%). < 1%");
 
183
 
 
184
static toSQL SQLDataCache("toTuning:Indicators:Important ratios:3DataCache",
 
185
                          "SELECT (1-SUM(DECODE(statistic#,40,value,0))/SUM(DECODE(statistic#,38,value,39,value,0)))*100,' %'\n"
 
186
                          "  FROM v$sysstat\n"
 
187
                          " WHERE statistic# IN (38,39,40)",
 
188
                          "Data buffer cache hit ratio (%). > 60% - 70%",
 
189
                          "0800");
 
190
 
 
191
static toSQL SQLDataCache9("toTuning:Indicators:Important ratios:3DataCache",
 
192
                           "SELECT (1-SUM(DECODE(statistic#,42,value,0))/SUM(DECODE(statistic#,40,value,41,value,0)))*100,' %'\n"
 
193
                           "  FROM v$sysstat\n"
 
194
                           " WHERE statistic# IN (40,41,42)",
 
195
                           "",
 
196
                           "0900");
 
197
 
 
198
static toSQL SQLDataCache7("toTuning:Indicators:Important ratios:3DataCache",
 
199
                           "SELECT (1-SUM(DECODE(statistic#,39,value,0))/SUM(DECODE(statistic#,37,value,38,value,0)))*100,' %'\n"
 
200
                           "  FROM v$sysstat\n"
 
201
                           " WHERE statistic# IN (37,38,39)",
 
202
                           "",
 
203
                           "0703");
 
204
 
 
205
static toSQL SQLLogRedo("toTuning:Indicators:Redo log contention:1LogSpace",
 
206
                        "select value from v$sysstat where statistic# = 108",
 
207
                        "Redo log space requests. Close to 0",
 
208
                        "0800");
 
209
 
 
210
static toSQL SQLLogRedo9("toTuning:Indicators:Redo log contention:1LogSpace",
 
211
                         "select value from v$sysstat where statistic# = 122",
 
212
                         "",
 
213
                         "0900");
 
214
 
 
215
static toSQL SQLLogRedo7("toTuning:Indicators:Redo log contention:1LogSpace",
 
216
                         "select value from v$sysstat where statistic# = 94",
 
217
                         "",
 
218
                         "0703");
 
219
 
 
220
static toSQL SQLSystemHeadUndo("toTuning:Indicators:RBS contention:1SystemHeadUndo",
 
221
                               "SELECT count/blocks*100,' %'\n"
 
222
                               "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'system undo header') a,\n"
 
223
                               "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (38,39)) b",
 
224
                               "System undo header waits (%). < 1%",
 
225
                               "0800");
 
226
 
 
227
static toSQL SQLSystemHeadUndo9("toTuning:Indicators:RBS contention:1SystemHeadUndo",
 
228
                                "SELECT count/blocks*100,' %'\n"
 
229
                                "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'system undo header') a,\n"
 
230
                                "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (40,41)) b",
 
231
                                "",
 
232
                                "0900");
 
233
 
 
234
static toSQL SQLSystemHeadUndo7("toTuning:Indicators:RBS contention:1SystemHeadUndo",
 
235
                                "SELECT count/blocks*100,' %'\n"
 
236
                                "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'system undo header') a,\n"
 
237
                                "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (37,38)) b",
 
238
                                "",
 
239
                                "0703");
 
240
 
 
241
static toSQL SQLSystemBlockUndo("toTuning:Indicators:RBS contention:2SystemBlockUndo",
 
242
                                "SELECT count/blocks*100,' %'\n"
 
243
                                "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'system undo block') a,\n"
 
244
                                "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (38,39)) b",
 
245
                                "System undo block waits (%). < 1%",
 
246
                                "0800");
 
247
 
 
248
static toSQL SQLSystemBlockUndo9("toTuning:Indicators:RBS contention:2SystemBlockUndo",
 
249
                                 "SELECT count/blocks*100,' %'\n"
 
250
                                 "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'system undo block') a,\n"
 
251
                                 "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (40,41)) b",
 
252
                                 "",
 
253
                                 "0900");
 
254
 
 
255
static toSQL SQLSystemBlockUndo7("toTuning:Indicators:RBS contention:2SystemBlockUndo",
 
256
                                 "SELECT count/blocks*100,' %'\n"
 
257
                                 "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'system undo block') a,\n"
 
258
                                 "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (37,38)) b",
 
259
                                 "",
 
260
                                 "0703");
 
261
 
 
262
static toSQL SQLHeadUndo("toTuning:Indicators:RBS contention:3HeadUndo",
 
263
                         "SELECT count/blocks*100,' %'\n"
 
264
                         "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'undo header') a,\n"
 
265
                         "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (38,39)) b",
 
266
                         "Undo head waits (%). < 1%",
 
267
                         "0800");
 
268
 
 
269
static toSQL SQLHeadUndo9("toTuning:Indicators:RBS contention:3HeadUndo",
 
270
                          "SELECT count/blocks*100,' %'\n"
 
271
                          "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'undo header') a,\n"
 
272
                          "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (40,41)) b",
 
273
                          "",
 
274
                          "0900");
 
275
 
 
276
static toSQL SQLHeadUndo7("toTuning:Indicators:RBS contention:3HeadUndo",
 
277
                          "SELECT count/blocks*100,' %'\n"
 
278
                          "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'undo header') a,\n"
 
279
                          "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (37,38)) b",
 
280
                          "",
 
281
                          "0703");
 
282
 
 
283
static toSQL SQLBlockUndo("toTuning:Indicators:RBS contention:4BlockUndo",
 
284
                          "SELECT count/blocks*100,' %'\n"
 
285
                          "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'undo block') a,\n"
 
286
                          "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (38,39)) b",
 
287
                          "Undo block waits (%). < 1%",
 
288
                          "0800");
 
289
 
 
290
static toSQL SQLBlockUndo9("toTuning:Indicators:RBS contention:4BlockUndo",
 
291
                           "SELECT count/blocks*100,' %'\n"
 
292
                           "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'undo block') a,\n"
 
293
                           "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (40,41)) b",
 
294
                           "",
 
295
                           "0900");
 
296
 
 
297
static toSQL SQLBlockUndo7("toTuning:Indicators:RBS contention:4BlockUndo",
 
298
                           "SELECT count/blocks*100,' %'\n"
 
299
                           "  FROM (SELECT MAX(count) count FROM v$waitstat WHERE class = 'undo block') a,\n"
 
300
                           "       (SELECT SUM(value) blocks FROM v$sysstat WHERE statistic# IN (37,38)) b",
 
301
                           "",
 
302
                           "0703");
 
303
 
 
304
static toSQL SQLTotalWaits("toTuning:Indicators:RBS contention:5TotalWaits",
 
305
                           "select sum(waits)/sum(gets)*100,' %' from v$rollstat",
 
306
                           "Total RBS waits (%). < 1%");
 
307
 
 
308
static toSQL SQLBusyRate("toTuning:Indicators:MTS contention:1BusyRate",
 
309
                         "SELECT NVL(SUM(busy)/(SUM(busy)+SUM(idle)),0)*100,' %' FROM v$dispatcher",
 
310
                         "Busy rate for dispatchers (%). < 50%");
 
311
 
 
312
static toSQL SQLDispQueue("toTuning:Indicators:MTS contention:2DispQueue",
 
313
                          "SELECT DECODE(NVL(SUM(totalq),0),0, 'No responses', ROUND(SUM(wait)/SUM(totalq),3)) FROM v$queue WHERE type='DISPATCHER'",
 
314
                          "Dispatcher response queues waits (1/100s).");
 
315
 
 
316
static toSQL SQLServerQueue("toTuning:Indicators:MTS contention:3ServerQueue",
 
317
                            "SELECT DECODE (NVL(SUM(totalq),0),0, 'No requests', ROUND(SUM(wait)/SUM(totalq),3)) FROM v$queue WHERE type='COMMON'",
 
318
                            "Server request queue waits (1/100s).");
 
319
 
 
320
static toSQL SQLOptions("toTuning:Options",
 
321
                        "select parameter \"Parameter\",\n"
 
322
                        "       decode(value,'TRUE','Enabled','Disabled') \"Enabled\"\n"
 
323
                        "  from v$option order by parameter",
 
324
                        "Display options available in database");
 
325
 
 
326
static toSQL SQLLicense("toTuning:License",
 
327
                        "select * from v$license",
 
328
                        "Display licenses available for database");
 
329
 
 
330
static toSQL SQLChartsPhysical("toTuning:Charts:1BBPhysical I/O",
 
331
                               "select SYSDATE,\n"
 
332
                               "       sum(decode(statistic#,40,value,0)) \"Physical reads\",\n"
 
333
                               "       sum(decode(statistic#,44,value,0)) \"Physical writes\",\n"
 
334
                               "       sum(decode(statistic#,105,value,0)) \"Redo writes\"\n"
 
335
                               "  from v$sysstat where statistic# in (40,44,105)",
 
336
                               "Generate chart of physical I/O of database.",
 
337
                               "0800");
 
338
 
 
339
static toSQL SQLChartsPhysical9("toTuning:Charts:1BBPhysical I/O",
 
340
                                "select SYSDATE,\n"
 
341
                                "       sum(decode(statistic#,42,value,0)) \"Physical reads\",\n"
 
342
                                "       sum(decode(statistic#,46,value,0)) \"Physical writes\",\n"
 
343
                                "       sum(decode(statistic#,119,value,0)) \"Redo writes\"\n"
 
344
                                "  from v$sysstat where statistic# in (42,46,119)",
 
345
                                "",
 
346
                                "0900");
 
347
 
 
348
static toSQL SQLChartsPhysical7("toTuning:Charts:1BBPhysical I/O",
 
349
                                "select SYSDATE,\n"
 
350
                                "       sum(decode(statistic#,39,value,0)) \"Physical reads\",\n"
 
351
                                "       sum(decode(statistic#,40,value,0)) \"Physical writes\",\n"
 
352
                                "       sum(decode(statistic#,91,value,0)) \"Redo writes\"\n"
 
353
                                "  from v$sysstat where statistic# in (39,40,91)",
 
354
                                "",
 
355
                                "0703");
 
356
 
 
357
static toSQL SQLChartsLogical("toTuning:Charts:2BBLogical I/O",
 
358
                              "select SYSDATE,\n"
 
359
                              "       sum(decode(statistic#,38,value,0)) \"Block gets\",\n"
 
360
                              "       sum(decode(statistic#,39,value,0)) \"Consistent gets\",\n"
 
361
                              "       sum(decode(statistic#,41,value,0)) \"Block changes\",\n"
 
362
                              "       sum(decode(statistic#,42,value,0)) \"Consistent changes\"\n"
 
363
                              "  from v$sysstat where statistic# in (38,39,41,42)",
 
364
                              "Generate chart of physical I/O of database.",
 
365
                              "0800");
 
366
 
 
367
static toSQL SQLChartsLogical9("toTuning:Charts:2BBLogical I/O",
 
368
                               "select SYSDATE,\n"
 
369
                               "       sum(decode(statistic#,40,value,0)) \"Block gets\",\n"
 
370
                               "       sum(decode(statistic#,41,value,0)) \"Consistent gets\",\n"
 
371
                               "       sum(decode(statistic#,43,value,0)) \"Block changes\",\n"
 
372
                               "       sum(decode(statistic#,44,value,0)) \"Consistent changes\"\n"
 
373
                               "  from v$sysstat where statistic# in (40,41,43,44)",
 
374
                               "",
 
375
                               "0900");
 
376
 
 
377
static toSQL SQLChartsLogical7("toTuning:Charts:2BBLogical I/O",
 
378
                               "select SYSDATE,\n"
 
379
                               "       sum(decode(statistic#,37,value,0)) \"Block gets\",\n"
 
380
                               "       sum(decode(statistic#,38,value,0)) \"Consistent gets\",\n"
 
381
                               "       sum(decode(statistic#,43,value,0)) \"Block changes\",\n"
 
382
                               "       sum(decode(statistic#,45,value,0)) \"Consistent changes\"\n"
 
383
                               "  from v$sysstat where statistic# in (37,38,43,45)",
 
384
                               "",
 
385
                               "0703");
 
386
 
 
387
static toSQL SQLChartsWait("toTuning:Charts:3BMWait events",
 
388
                           "select sysdate,\n"
 
389
                           "       cpu*10 \"CPU\",\n"
 
390
                           "       parallel*10 \"Parallel execution\",\n"
 
391
                           "       filewrite*10 \"DB File Write\",\n"
 
392
                           "       writecomplete*10 \"Write Complete\",\n"
 
393
                           "       fileread*10 \"DB File Read\",\n"
 
394
                           "       singleread*10 \"DB Single File Read\",\n"
 
395
                           "       control*10 \"Control File I/O\",\n"
 
396
                           "       direct*10 \"Direct I/O\",\n"
 
397
                           "       log*10 \"Log file\",\n"
 
398
                           "       net*10 \"SQL*Net\"\n"
 
399
                           "  from (select SUM(DECODE(SUBSTR(event,1,2),'PX',time_waited,0))-SUM(DECODE(event,'PX Idle Wait',time_waited,0)) parallel,\n"
 
400
                           "               SUM(DECODE(event,'db file parallel write',time_waited,'db file single write',time_waited,0)) filewrite,\n"
 
401
                           "               SUM(DECODE(event,'write complete waits',time_waited,NULL)) writecomplete,\n"
 
402
                           "               SUM(DECODE(event,'db file parallel read',time_waited,'db file sequential read',time_waited,0)) fileread,\n"
 
403
                           "               SUM(DECODE(event,'db file scattered read',time_waited,0)) singleread,\n"
 
404
                           "               SUM(DECODE(SUBSTR(event,1,12),'control file',time_waited,0)) control,\n"
 
405
                           "               SUM(DECODE(SUBSTR(event,1,11),'direct path',time_waited,0)) direct,\n"
 
406
                           "               SUM(DECODE(SUBSTR(event,1,3),'log',time_waited,0)) log,\n"
 
407
                           "               SUM(DECODE(SUBSTR(event,1,7),'SQL*Net',time_waited,0))-SUM(DECODE(event,'SQL*Net message from client',time_waited,0)) net\n"
 
408
                           "          from v$system_event),\n"
 
409
                           "       (select value*10 cpu from v$sysstat where statistic# = 12)",
 
410
                           "Used to generate chart for system wait time.");
 
411
 
 
412
static toSQL SQLChartsExecution("toTuning:Charts:6LNExecution",
 
413
                                "select SYSDATE,\n"
 
414
                                "       sum(decode(name,'execute count',value,0)) \"Execute\",\n"
 
415
                                "       sum(decode(name,'parse count (hard)',value,0)) \"Hard parse\",\n"
 
416
                                "       sum(decode(name,'parse count (total)',value,0)) \"Parse\",\n"
 
417
                                "       sum(decode(name,'user calls',value,0)) \"Calls\",\n"
 
418
                                "       sum(decode(name,'user commits',value,0))  \"Commit\",\n"
 
419
                                "       sum(decode(name,'user rollbacks',value,0)) \"Rollbacks\"\n"
 
420
                                "  from v$sysstat where name IN ('execute count','parse count (hard)','parse count (total)','user calls','user commits','user rollbacks')",
 
421
                                "Used to generate chart for execution statistics.",
 
422
                                "0800");
 
423
 
 
424
 
 
425
static toSQL SQLChartsExecution7("toTuning:Charts:6LNExecution",
 
426
                                 "select SYSDATE,\n"
 
427
                                 "       sum(decode(statistic#,132,value,0)) \"Execute\",\n"
 
428
                                 "       sum(decode(statistic#,131,value,0)) \"Parse\",\n"
 
429
                                 "       sum(decode(statistic#,6,value,0)) \"Calls\",\n"
 
430
                                 "       sum(decode(statistic#,4,value,0))  \"Commit\",\n"
 
431
                                 "       sum(decode(statistic#,5,value,0)) \"Rollbacks\"\n"
 
432
                                 "  from v$sysstat where statistic# in (132,131,4,5,6)",
 
433
                                 "",
 
434
                                 "0703");
 
435
 
 
436
static toSQL SQLChartsExecutionPie("toTuning:Charts:8PNExecution Total",
 
437
                                   "select value,decode(name,'execute count','Execute','parse count (hard)','Hard parse','parse count (total)','Parse',\n"
 
438
                                   "                              'user calls','Calls','user commits','Commit','user rollbacks','Rollbacks')\n"
 
439
                                   "  from v$sysstat where name IN ('execute count','parse count (hard)','parse count (total)','user calls','user commits','user rollbacks') order by name",
 
440
                                   "Used to generate pie chart for execution statistics.",
 
441
                                   "0800");
 
442
 
 
443
 
 
444
static toSQL SQLChartsExecutionPie7("toTuning:Charts:8PNExecution Total",
 
445
                                    "select value,decode(statistic#,132,'Execute',131,'Parse',\n"
 
446
                                    "                              6,'Calls',4,'Commit',5,'Rollbacks')\n"
 
447
                                    "  from v$sysstat where statistic# in (132,131,6,4,5) order by name",
 
448
                                    "",
 
449
                                    "0703");
 
450
 
 
451
static toSQL SQLChartsClients("toTuning:Charts:4BAClients",
 
452
                              "select sysdate,\n"
 
453
                              "       sum(decode(decode(type,'BACKGROUND','WHATEVER',status),'ACTIVE',1,0)) \"Active\",\n"
 
454
                              "       sum(decode(status,'INACTIVE',1,0)) \"Inactive\",\n"
 
455
                              "       sum(decode(type,'BACKGROUND',1,0)) \"System\"\n"
 
456
                              "  from v$session where sid not in (select nvl(sid,0) from v$px_process)",
 
457
                              "Chart displaying connected clients");
 
458
 
 
459
static toSQL SQLChartsClients8("toTuning:Charts:4BAClients",
 
460
                               "select sysdate,\n"
 
461
                               "       sum(decode(decode(type,'BACKGROUND','WHATEVER',status),'ACTIVE',1,0)) \"Active\",\n"
 
462
                               "       sum(decode(status,'INACTIVE',1,0)) \"Inactive\",\n"
 
463
                               "       sum(decode(type,'BACKGROUND',1,0)) \"System\"\n"
 
464
                               "  from v$session",
 
465
                               "",
 
466
                               "0800");
 
467
 
 
468
static toSQL SQLChartsCacheMisses("toTuning:Charts:5CPCache misses",
 
469
                                  "select sysdate,\n"
 
470
                                  "       pread \"Data buffer cache\",read \"Dictionary row cache\",\n"
 
471
                                  "       getmiss \"Library cache\",gets \" \",\n"
 
472
                                  "       reloads \" \",pins \" \"\n"
 
473
                                  "  from (select 100*SUM(DECODE(statistic#,40,value,0)) pread,SUM(DECODE(statistic#,38,value,39,value,0)) read\n"
 
474
                                  "          from v$sysstat where statistic# IN (38,39,40)) \"Data buffer cache\",\n"
 
475
                                  "       (select 100*sum(getmisses) getmiss,sum(gets) gets from v$rowcache) \"Dictionary row cache\",\n"
 
476
                                  "       (select 100*sum(reloads) reloads,sum(pins) pins from v$librarycache) \"Library cache\"\n",
 
477
                                  "Chart display memory allocation. This is really weird to change, especially since the column names "
 
478
                                  "don't correspond exactly to the column data in the chart. Each group of two are divided with each other before drawn.",
 
479
                                  "0800");
 
480
 
 
481
static toSQL SQLChartsCacheMisses9("toTuning:Charts:5CPCache misses",
 
482
                                   "select sysdate,\n"
 
483
                                   "       pread \"Data buffer cache\",read \"Dictionary row cache\",\n"
 
484
                                   "       getmiss \"Library cache\",gets \" \",\n"
 
485
                                   "       reloads \" \",pins \" \"\n"
 
486
                                   "  from (select 100*SUM(DECODE(statistic#,42,value,0)) pread,SUM(DECODE(statistic#,40,value,41,value,0)) read\n"
 
487
                                   "          from v$sysstat where statistic# IN (40,41,42)) \"Data buffer cache\",\n"
 
488
                                   "       (select 100*sum(getmisses) getmiss,sum(gets) gets from v$rowcache) \"Dictionary row cache\",\n"
 
489
                                   "       (select 100*sum(reloads) reloads,sum(pins) pins from v$librarycache) \"Library cache\"\n",
 
490
                                   "",
 
491
                                   "0900");
 
492
 
 
493
static toSQL SQLChartsCacheMisses7("toTuning:Charts:5CPCache misses",
 
494
                                   "select sysdate,\n"
 
495
                                   "       pread \"Data buffer cache\",read \"Dictionary row cache\",\n"
 
496
                                   "       getmiss \"Library cache\",gets \" \",\n"
 
497
                                   "       reloads \" \",pins \" \"\n"
 
498
                                   "  from (select 100*SUM(DECODE(statistic#,39,value,0)) pread,SUM(DECODE(statistic#,37,value,38,value,0)) read\n"
 
499
                                   "          from v$sysstat where statistic# IN (37,38,39)) \"Data buffer cache\",\n"
 
500
                                   "       (select 100*sum(getmisses) getmiss,sum(gets) gets from v$rowcache) \"Dictionary row cache\",\n"
 
501
                                   "       (select 100*sum(reloads) reloads,sum(pins) pins from v$librarycache) \"Library cache\"\n",
 
502
                                   "",
 
503
                                   "0703");
 
504
 
 
505
static toSQL SQLChartsRedo("toTuning:Charts:7BSRedo log I/O",
 
506
                           "select SYSDATE,\n"
 
507
                           "       sum(decode(statistic#,101,value,0))/:unit<int> \"Redo size\",\n"
 
508
                           "       sum(decode(statistic#,103,value,0))/:unit<int> \"Redo wastage\"\n"
 
509
                           "  from v$sysstat where statistic# in (101,103)",
 
510
                           "Used to generate chart for redo I/O statistics.",
 
511
                           "0800");
 
512
 
 
513
static toSQL SQLChartsRedo9("toTuning:Charts:7BSRedo log I/O",
 
514
                            "select SYSDATE,\n"
 
515
                            "       sum(decode(statistic#,115,value,0))/:unit<int> \"Redo size\",\n"
 
516
                            "       sum(decode(statistic#,117,value,0))/:unit<int> \"Redo wastage\"\n"
 
517
                            "  from v$sysstat where statistic# in (115,117)",
 
518
                            "",
 
519
                            "0900");
 
520
 
 
521
static toSQL SQLChartsRedo7("toTuning:Charts:7BSRedo log I/O",
 
522
                            "select SYSDATE,\n"
 
523
                            "       sum(decode(statistic#,85,value,0))/:unit<int> \"Redo size\",\n"
 
524
                            "       sum(decode(statistic#,89,value,0))/:unit<int> \"Redo wastage\"\n"
 
525
                            "  from v$sysstat where statistic# in (85,89)",
 
526
                            "",
 
527
                            "0703");
 
528
 
 
529
static toSQL SQLOverviewArchiveWrite("toTuning:Overview:ArchiveWrite",
 
530
                                     "select sysdate,sum(blocks) from v$archived_log",
 
531
                                     "Archive log write",
 
532
                                     "0800");
 
533
 
 
534
static toSQL SQLOverviewArchiveWrite7("toTuning:Overview:ArchiveWrite",
 
535
                                      "select sysdate,0 from sys.dual",
 
536
                                      "",
 
537
                                      "0703");
 
538
 
 
539
static toSQL SQLOverviewBufferHit("toTuning:Overview:BufferHit",
 
540
                                  "SELECT SYSDATE,(1-SUM(DECODE(statistic#,40,value,0))/SUM(DECODE(statistic#,38,value,39,value,0)))*100\n"
 
541
                                  "  FROM v$sysstat\n"
 
542
                                  " WHERE statistic# IN (38,39,40)",
 
543
                                  "Buffer hitrate",
 
544
                                  "0800");
 
545
 
 
546
static toSQL SQLOverviewBufferHit9("toTuning:Overview:BufferHit",
 
547
                                   "SELECT SYSDATE,(1-SUM(DECODE(statistic#,42,value,0))/SUM(DECODE(statistic#,40,value,41,value,0)))*100\n"
 
548
                                   "  FROM v$sysstat\n"
 
549
                                   " WHERE statistic# IN (40,41,42)",
 
550
                                   "",
 
551
                                   "0900");
 
552
 
 
553
static toSQL SQLOverviewBufferHit7("toTuning:Overview:BufferHit",
 
554
                                   "SELECT SYSDATE,(1-SUM(DECODE(statistic#,39,value,0))/SUM(DECODE(statistic#,37,value,38,value,0)))*100\n"
 
555
                                   "  FROM v$sysstat\n"
 
556
                                   " WHERE statistic# IN (37,38,39)",
 
557
                                   "",
 
558
                                   "0703");
 
559
 
 
560
static toSQL SQLOverviewClientInput("toTuning:Overview:ClientInput",
 
561
                                    "select sysdate,value/:f1<int>\n"
 
562
                                    "  from v$sysstat where statistic# = 182",
 
563
                                    "Bytes sent to client",
 
564
                                    "0800");
 
565
 
 
566
static toSQL SQLOverviewClientInput9("toTuning:Overview:ClientInput",
 
567
                                     "select sysdate,value/:f1<int>\n"
 
568
                                     "  from v$sysstat where statistic# = 223",
 
569
                                     "",
 
570
                                     "0900");
 
571
 
 
572
static toSQL SQLOverviewClientInput7("toTuning:Overview:ClientInput",
 
573
                                     "select sysdate,value/:f1<int>\n"
 
574
                                     "  from v$sysstat where statistic# = 134",
 
575
                                     "",
 
576
                                     "0703");
 
577
 
 
578
static toSQL SQLOverviewClientOutput("toTuning:Overview:ClientOutput",
 
579
                                     "select sysdate,value/:f1<int>\n"
 
580
                                     "  from v$sysstat where statistic# = 183",
 
581
                                     "Bytes sent from client",
 
582
                                     "0800");
 
583
 
 
584
static toSQL SQLOverviewClientOutput9("toTuning:Overview:ClientOutput",
 
585
                                      "select sysdate,value/:f1<int>\n"
 
586
                                      "  from v$sysstat where statistic# = 224",
 
587
                                      "",
 
588
                                      "0900");
 
589
 
 
590
static toSQL SQLOverviewClientOutput7("toTuning:Overview:ClientOutput",
 
591
                                      "select sysdate,value/:f1<int>\n"
 
592
                                      "  from v$sysstat where statistic# = 133",
 
593
                                      "",
 
594
                                      "0703");
 
595
 
 
596
static toSQL SQLOverviewExecute("toTuning:Overview:Execute",
 
597
                                "select sysdate,value\n"
 
598
                                "  from v$sysstat where statistic# = 181",
 
599
                                "Execute count",
 
600
                                "0800");
 
601
 
 
602
static toSQL SQLOverviewExecute9("toTuning:Overview:Execute",
 
603
                                 "select sysdate,value\n"
 
604
                                 "  from v$sysstat where statistic# = 222",
 
605
                                 "",
 
606
                                 "0900");
 
607
 
 
608
static toSQL SQLOverviewExecute7("toTuning:Overview:Execute",
 
609
                                 "select sysdate,value\n"
 
610
                                 "  from v$sysstat where statistic# = 132",
 
611
                                 "",
 
612
                                 "0703");
 
613
 
 
614
static toSQL SQLOverviewParse("toTuning:Overview:Parse",
 
615
                              "select sysdate,value\n"
 
616
                              "  from v$sysstat where statistic# = 179",
 
617
                              "Parse count",
 
618
                              "0800");
 
619
 
 
620
static toSQL SQLOverviewParse9("toTuning:Overview:Parse",
 
621
                               "select sysdate,value\n"
 
622
                               "  from v$sysstat where statistic# = 219",
 
623
                               "",
 
624
                               "0900");
 
625
 
 
626
static toSQL SQLOverviewParse7("toTuning:Overview:Parse",
 
627
                               "select sysdate,value\n"
 
628
                               "  from v$sysstat where statistic# = 131",
 
629
                               "",
 
630
                               "0703");
 
631
 
 
632
static toSQL SQLOverviewRedoEntries("toTuning:Overview:RedoEntries",
 
633
                                    "select sysdate,value\n"
 
634
                                    "  from v$sysstat where statistic# = 100",
 
635
                                    "Redo entries",
 
636
                                    "0800");
 
637
 
 
638
static toSQL SQLOverviewRedoEntries9("toTuning:Overview:RedoEntries",
 
639
                                     "select sysdate,value\n"
 
640
                                     "  from v$sysstat where statistic# = 114",
 
641
                                     "",
 
642
                                     "0900");
 
643
 
 
644
static toSQL SQLOverviewRedoEntries7("toTuning:Overview:RedoEntries",
 
645
                                     "select sysdate,value\n"
 
646
                                     "  from v$sysstat where statistic# = 84",
 
647
                                     "",
 
648
                                     "0703");
 
649
 
 
650
static toSQL SQLOverviewRedoBlocks("toTuning:Overview:RedoBlocks",
 
651
                                   "select sysdate,value\n"
 
652
                                   "  from v$sysstat where statistic# = 106",
 
653
                                   "Redo blocks written",
 
654
                                   "0800");
 
655
 
 
656
static toSQL SQLOverviewRedoBlocks9("toTuning:Overview:RedoBlocks",
 
657
                                    "select sysdate,value\n"
 
658
                                    "  from v$sysstat where statistic# = 120",
 
659
                                    "",
 
660
                                    "0900");
 
661
 
 
662
static toSQL SQLOverviewRedoBlocks7("toTuning:Overview:RedoBlocks",
 
663
                                    "select sysdate,value\n"
 
664
                                    "  from v$sysstat where statistic# = 92",
 
665
                                    "",
 
666
                                    "0703");
 
667
 
 
668
static toSQL SQLOverviewLogicalRead("toTuning:Overview:LogicalRead",
 
669
                                    "select sysdate,sum(value)\n"
 
670
                                    "  from v$sysstat where statistic# in (38,39)",
 
671
                                    "Blocks read",
 
672
                                    "0800");
 
673
 
 
674
static toSQL SQLOverviewLogicalRead9("toTuning:Overview:LogicalRead",
 
675
                                     "select sysdate,sum(value)\n"
 
676
                                     "  from v$sysstat where statistic# in (40,41)",
 
677
                                     "",
 
678
                                     "0900");
 
679
 
 
680
static toSQL SQLOverviewLogicalRead7("toTuning:Overview:LogicalRead",
 
681
                                     "select sysdate,sum(value)\n"
 
682
                                     "  from v$sysstat where statistic# in (37,38)",
 
683
                                     "",
 
684
                                     "0703");
 
685
 
 
686
static toSQL SQLOverviewLogicalWrite("toTuning:Overview:LogicalWrite",
 
687
                                     "select sysdate,sum(value)\n"
 
688
                                     "  from v$sysstat where statistic# in (41,42)",
 
689
                                     "Blocks written",
 
690
                                     "0800");
 
691
 
 
692
static toSQL SQLOverviewLogicalWrite9("toTuning:Overview:LogicalWrite",
 
693
                                      "select sysdate,sum(value)\n"
 
694
                                      "  from v$sysstat where statistic# in (43,44)",
 
695
                                      "",
 
696
                                      "0900");
 
697
 
 
698
static toSQL SQLOverviewLogicalWrite7("toTuning:Overview:LogicalWrite",
 
699
                                      "select sysdate,sum(value)\n"
 
700
                                      "  from v$sysstat where statistic# in (43,45)",
 
701
                                      "",
 
702
                                      "0703");
 
703
 
 
704
static toSQL SQLOverviewPhysicalRead("toTuning:Overview:PhysicalRead",
 
705
                                     "select sysdate,value\n"
 
706
                                     "  from v$sysstat where statistic# = 40",
 
707
                                     "Blocks physically read",
 
708
                                     "0800");
 
709
 
 
710
static toSQL SQLOverviewPhysicalRead9("toTuning:Overview:PhysicalRead",
 
711
                                      "select sysdate,value\n"
 
712
                                      "  from v$sysstat where statistic# = 42",
 
713
                                      "",
 
714
                                      "0900");
 
715
 
 
716
static toSQL SQLOverviewPhysicalRead7("toTuning:Overview:PhysicalRead",
 
717
                                      "select sysdate,value\n"
 
718
                                      "  from v$sysstat where statistic# = 39",
 
719
                                      "",
 
720
                                      "0703");
 
721
 
 
722
static toSQL SQLOverviewPhysicalWrite("toTuning:Overview:PhysicalWrite",
 
723
                                      "select sysdate,value\n"
 
724
                                      "  from v$sysstat where statistic# = 44",
 
725
                                      "Blocks physically written",
 
726
                                      "0800");
 
727
 
 
728
static toSQL SQLOverviewPhysicalWrite9("toTuning:Overview:PhysicalWrite",
 
729
                                       "select sysdate,value\n"
 
730
                                       "  from v$sysstat where statistic# = 46",
 
731
                                       "",
 
732
                                       "0900");
 
733
 
 
734
static toSQL SQLOverviewPhysicalWrite7("toTuning:Overview:PhysicalWrite",
 
735
                                       "select sysdate,value\n"
 
736
                                       "  from v$sysstat where statistic# = 40",
 
737
                                       "",
 
738
                                       "0703");
 
739
 
 
740
static toSQL SQLOverviewClient("toTuning:Overview:Client",
 
741
                               "select sysdate,\n"
 
742
                               "       sum(decode(status,'INACTIVE',1,0)),\n"
 
743
                               "       sum(decode(status,'ACTIVE',1,0))\n"
 
744
                               "  from v$session\n"
 
745
                               " where type != 'BACKGROUND' and sid not in (select nvl(sid,0) from v$px_process)",
 
746
                               "Information about active/inactive clients");
 
747
 
 
748
static toSQL SQLOverviewClient8("toTuning:Overview:Client",
 
749
                                "select sysdate,\n"
 
750
                                "       sum(decode(status,'INACTIVE',1,0)),\n"
 
751
                                "       sum(decode(status,'ACTIVE',1,0))\n"
 
752
                                "  from v$session\n"
 
753
                                " where type != 'BACKGROUND'",
 
754
                                "",
 
755
                                "0800");
 
756
 
 
757
static toSQL SQLOverviewSGAUsed("toTuning:Overview:SGAUsed",
 
758
                                "select sysdate,100*(total-free)/total\n"
 
759
                                "  from (select sum(value) total from v$sga where name in ('Fixed Size','Variable Size')),\n"
 
760
                                "       (select bytes free from v$sgastat where pool = 'shared pool' and name = 'free memory')",
 
761
                                "SGA used",
 
762
                                "0800");
 
763
 
 
764
static toSQL SQLOverviewSGAUsed7("toTuning:Overview:SGAUsed",
 
765
                                 "select sysdate,100*(total-free)/total\n"
 
766
                                 "  from (select sum(value) total from v$sga where name in ('Fixed Size','Variable Size')),\n"
 
767
                                 "       (select bytes free from v$sgastat where name = 'free memory')",
 
768
                                 "",
 
769
                                 "0703");
 
770
 
 
771
static toSQL SQLOverviewTimescale("toTuning:Overview:Timescale",
 
772
                                  "select sysdate,0 from sys.dual",
 
773
                                  "Get timescale of other graphs");
 
774
 
 
775
static toSQL SQLOverviewFilespace("toTuning:Overview:Filespace",
 
776
                                  "select sum(bytes)/:f1<int>,'Free'\n"
 
777
                                  "  from sys.dba_free_space\n"
 
778
                                  "union\n"
 
779
                                  "select (total-free)/:f1<int>,'Used'\n"
 
780
                                  "  from (select sum(bytes) free from sys.dba_free_space),\n"
 
781
                                  "       (select sum(bytes) total from sys.dba_data_files)",
 
782
                                  "Filespace used");
 
783
 
 
784
void toTuningOverview::setupChart(toResultLine *chart, const QString &title, const QString &postfix, const toSQL &sql)
 
785
{
 
786
    chart->setMinValue(0);
 
787
    chart->showGrid(0);
 
788
    chart->showLegend(false);
 
789
    chart->showAxisLegend(false);
 
790
    chart->setTitle(title);
 
791
    chart->showLast(true);
 
792
    toQList val;
 
793
    if (postfix == QString::fromLatin1("b/s"))
 
794
    {
 
795
        QString unitStr = toConfigurationSingle::Instance().globalConfig(CONF_SIZE_UNIT, DEFAULT_SIZE_UNIT);
 
796
        val.insert(val.end(), toQValue(toSizeDecode(unitStr)));
 
797
        unitStr += QString::fromLatin1("/s");
 
798
        chart->setYPostfix(unitStr);
 
799
    }
 
800
    else
 
801
        chart->setYPostfix(postfix);
 
802
    chart->query(sql, val);
 
803
}
 
804
 
 
805
toTuningOverview::toTuningOverview(QWidget *parent, const char *name, WFlags fl)
 
806
        : toTuningOverviewUI(parent, name, fl)
 
807
{
 
808
    BackgroundGroup->setColumnLayout(1, Horizontal);
 
809
 
 
810
    setupChart(ArchiveWrite, tr("< Archive write"), " " + tr("blocks/s"), SQLOverviewArchiveWrite);
 
811
    setupChart(BufferHit, tr("Hitrate"), QString::fromLatin1("%"), SQLOverviewBufferHit);
 
812
    BufferHit->setMaxValue(100);
 
813
    BufferHit->setFlow(false);
 
814
    setupChart(ClientInput, tr("< Client input"), QString::fromLatin1("b/s"), SQLOverviewClientInput);
 
815
    setupChart(ClientOutput, tr("Client output >"), QString::fromLatin1("b/s"), SQLOverviewClientOutput);
 
816
    setupChart(ExecuteCount, tr("Executes >"), QString::fromLatin1("/s"), SQLOverviewExecute);
 
817
    setupChart(LogWrite, tr("Log writer >"), " " + tr("blocks/s"), SQLOverviewRedoBlocks);
 
818
    setupChart(LogicalChange, tr("Buffer changed >"), tr(" blocks/s"), SQLOverviewLogicalWrite);
 
819
    setupChart(LogicalRead, tr("< Buffer gets"), tr(" blocks/s"), SQLOverviewLogicalRead);
 
820
    setupChart(ParseCount, tr("Parse >"), QString::fromLatin1("/s"), SQLOverviewParse);
 
821
    setupChart(PhysicalRead, tr("< Physical read"), tr(" blocks/s"), SQLOverviewPhysicalRead);
 
822
    setupChart(PhysicalWrite, tr("Physical write >"), tr(" blocks/s"), SQLOverviewPhysicalWrite);
 
823
    setupChart(RedoEntries, tr("Redo entries >"), QString::fromLatin1("/s"), SQLOverviewRedoEntries);
 
824
    setupChart(Timescale, tr("Timescale"), QString::null, SQLOverviewTimescale);
 
825
    Timescale->showAxisLegend(true);
 
826
    Timescale->showLast(false);
 
827
 
 
828
    ClientChart->showGrid(0);
 
829
    ClientChart->showLegend(false);
 
830
    ClientChart->showAxisLegend(false);
 
831
    ClientChart->query(SQLOverviewClient);
 
832
    ClientChart->setFlow(false);
 
833
 
 
834
    SharedUsed->showGrid(0);
 
835
    SharedUsed->showLegend(false);
 
836
    SharedUsed->showAxisLegend(false);
 
837
    SharedUsed->query(SQLOverviewSGAUsed);
 
838
    SharedUsed->setFlow(false);
 
839
    SharedUsed->setMaxValue(100);
 
840
    SharedUsed->setYPostfix(QString::fromLatin1("%"));
 
841
    SharedUsed->showLast(true);
 
842
 
 
843
    try
 
844
    {
 
845
        toQList val;
 
846
        val.insert(val.end(),
 
847
                   toQValue(toSizeDecode(toConfigurationSingle::Instance().globalConfig(CONF_SIZE_UNIT,
 
848
                                         DEFAULT_SIZE_UNIT))));
 
849
        FileUsed->query(toSQL::string(SQLOverviewFilespace, toCurrentConnection(this)), (const toQList)val);
 
850
    }
 
851
    TOCATCH
 
852
    FileUsed->showLegend(false);
 
853
 
 
854
    Done.up();
 
855
    connect(&Poll, SIGNAL(timeout()), this, SLOT(poll()));
 
856
 
 
857
    // Will be called later anyway
 
858
    //refresh();
 
859
}
 
860
 
 
861
toTuningOverview::~toTuningOverview()
 
862
{
 
863
    if (Done.getValue() == 0)
 
864
    {
 
865
        Quit = true;
 
866
        Done.down();
 
867
    }
 
868
}
 
869
 
 
870
void toTuningOverview::stop(void)
 
871
{
 
872
    try
 
873
    {
 
874
        disconnect(toCurrentTool(this)->timer(), SIGNAL(timeout()), this, SLOT(refresh()));
 
875
    }
 
876
    TOCATCH
 
877
 
 
878
    ArchiveWrite->stop();
 
879
    BufferHit->stop();
 
880
    ClientInput->stop();
 
881
    ClientOutput->stop();
 
882
    ExecuteCount->stop();
 
883
    LogWrite->stop();
 
884
    LogicalChange->stop();
 
885
    LogicalRead->stop();
 
886
    ParseCount->stop();
 
887
    PhysicalRead->stop();
 
888
    PhysicalWrite->stop();
 
889
    RedoEntries->stop();
 
890
    Timescale->stop();
 
891
    ClientChart->stop();
 
892
    SharedUsed->stop();
 
893
    FileUsed->stop();
 
894
}
 
895
 
 
896
void toTuningOverview::start(void)
 
897
{
 
898
    try
 
899
    {
 
900
        connect(toCurrentTool(this)->timer(), SIGNAL(timeout()), this, SLOT(refresh()));
 
901
    }
 
902
    TOCATCH
 
903
 
 
904
    ArchiveWrite->start();
 
905
    BufferHit->start();
 
906
    ClientInput->start();
 
907
    ClientOutput->start();
 
908
    ExecuteCount->start();
 
909
    LogWrite->start();
 
910
    LogicalChange->start();
 
911
    LogicalRead->start();
 
912
    ParseCount->start();
 
913
    PhysicalRead->start();
 
914
    PhysicalWrite->start();
 
915
    RedoEntries->start();
 
916
    Timescale->start();
 
917
    ClientChart->start();
 
918
    SharedUsed->start();
 
919
    FileUsed->start();
 
920
}
 
921
 
 
922
static toSQL SQLOverviewArchive("toTuning:Overview:Archive",
 
923
                                "select count(1),\n"
 
924
                                "       nvl(sum(blocks*block_size),0)/:f1<int>\n"
 
925
                                "  from v$archived_log where deleted = 'NO'",
 
926
                                "Information about archive logs",
 
927
                                "0800");
 
928
 
 
929
static toSQL SQLOverviewArchive7("toTuning:Overview:Archive",
 
930
                                 "select 'N/A',\n"
 
931
                                 "       'N/A'\n"
 
932
                                 "  from sys.dual where 0 != :f1<int>",
 
933
                                 "",
 
934
                                 "0703");
 
935
 
 
936
static toSQL SQLOverviewLog("toTuning:Overview:Log",
 
937
                            "select count(1),\n"
 
938
                            "       max(decode(status,'CURRENT',group#,0)),\n"
 
939
                            "       sum(decode(status,'CURRENT',bytes,0))/:f1<int>,\n"
 
940
                            "       sum(bytes)/:f1<int> from v$log\n",
 
941
                            "Information about redo logs");
 
942
 
 
943
static toSQL SQLOverviewTablespaces("toTuning:Overview:Tablespaces",
 
944
                                    "select count(1) from v$tablespace",
 
945
                                    "Number of tablespaces",
 
946
                                    "0800");
 
947
 
 
948
static toSQL SQLOverviewTablespaces7("toTuning:Overview:Tablespaces",
 
949
                                     "select count(1) from sys.dba_tablespaces",
 
950
                                     "",
 
951
                                     "0703");
 
952
 
 
953
static toSQL SQLOverviewSGA("toTuning:Overview:SGA",
 
954
                            "select name,value/:f1<int> from v$sga",
 
955
                            "Information about SGA");
 
956
 
 
957
static toSQL SQLOverviewBackground("toTuning:Overview:Background",
 
958
                                   "select substr(name,1,3),count(1) from v$bgprocess where paddr != '00'\n"
 
959
                                   " group by substr(name,1,3) order by substr(name,1,3)",
 
960
                                   "Background processes");
 
961
 
 
962
static toSQL SQLOverviewDedicated("toTuning:Overview:Dedicated",
 
963
                                  "select count(1) from v$session\n"
 
964
                                  " where type = 'USER' and server = 'DEDICATED'\n"
 
965
                                  "   and sid not in (select nvl(sid,0) from v$px_process)",
 
966
                                  "Dedicated server process",
 
967
                                  "0801");
 
968
 
 
969
static toSQL SQLOverviewDedicated7("toTuning:Overview:Dedicated",
 
970
                                   "select count(1) from v$session where type = 'USER' and server = 'DEDICATED'",
 
971
                                   "",
 
972
                                   "0800");
 
973
 
 
974
static toSQL SQLOverviewDispatcher("toTuning:Overview:Dispatcher",
 
975
                                   "select count(1) from v$dispatcher",
 
976
                                   "Dispatcher processes");
 
977
 
 
978
static toSQL SQLOverviewParallell("toTuning:Overview:Parallel",
 
979
                                  "select count(1) from v$px_process",
 
980
                                  "Parallel processes",
 
981
                                  "0801");
 
982
 
 
983
static toSQL SQLOverviewParallell8("toTuning:Overview:Parallel",
 
984
                                   "select 'N/A' from sys.dual",
 
985
                                   "",
 
986
                                   "0800");
 
987
 
 
988
static toSQL SQLOverviewShared("toTuning:Overview:Shared",
 
989
                               "select count(1) from v$shared_server",
 
990
                               "Shared processes");
 
991
 
 
992
static toSQL SQLOverviewRound("toTuning:Overview:Roundtime",
 
993
                              "select round(average_wait,2) from v$system_event\n"
 
994
                              " where event in ('SQL*Net message from client',\n"
 
995
                              "                 'SQL*Net message to client') order by event",
 
996
                              "Client roundtime info");
 
997
 
 
998
static toSQL SQLOverviewClientTotal("toTuning:Overview:ClientTotal",
 
999
                                    "select count(1),\n"
 
1000
                                    "       sum(decode(status,'ACTIVE',1,0))\n"
 
1001
                                    "  from v$session\n"
 
1002
                                    " where type != 'BACKGROUND' and sid not in (select nvl(sid,0) from v$px_process)",
 
1003
                                    "Information about total and active clients",
 
1004
                                    "0801");
 
1005
 
 
1006
static toSQL SQLOverviewClientTotal8("toTuning:Overview:ClientTotal",
 
1007
                                     "select count(1),\n"
 
1008
                                     "       sum(decode(status,'ACTIVE',1,0))\n"
 
1009
                                     "  from v$session\n"
 
1010
                                     " where type != 'BACKGROUND'",
 
1011
                                     "",
 
1012
                                     "0800");
 
1013
 
 
1014
static toSQL SQLOverviewDatafiles("toTuning:Overview:Datafiles",
 
1015
                                  "select (select count(1) from v$datafile)+(select count(1) from v$tempfile) from dual",
 
1016
                                  "Number of datafiles",
 
1017
                                  "0800");
 
1018
 
 
1019
static toSQL SQLOverviewDatafiles8("toTuning:Overview:Datafiles",
 
1020
                                   "select count(1) from v$datafile",
 
1021
                                   "",
 
1022
                                   "0800");
 
1023
 
 
1024
static toSQL SQLOverviewDatafiles7("toTuning:Overview:Datafiles",
 
1025
                                   "select count(1) from sys.dba_tablespaces",
 
1026
                                   "",
 
1027
                                   "0703");
 
1028
 
 
1029
void toTuningOverview::overviewQuery::setValue(const QCString &nam, const QString &val)
 
1030
{
 
1031
    if (Parent.Quit)
 
1032
        throw 1;
 
1033
    toLocker lock (Parent.Lock)
 
1034
        ;
 
1035
    Parent.Values[nam] = val;
 
1036
}
 
1037
 
 
1038
void toTuningOverview::overviewQuery::run(void)
 
1039
{
 
1040
    try
 
1041
    {
 
1042
        toQList val;
 
1043
        val.insert(val.end(), toQValue(toSizeDecode(Parent.UnitString)));
 
1044
 
 
1045
        toQList res = toQuery::readQuery(*Parent.Connection, SQLOverviewArchive, val);
 
1046
        QString tmp = toShift(res);
 
1047
        tmp += QString::fromLatin1("/");
 
1048
        tmp += toShift(res);
 
1049
        tmp += Parent.UnitString;
 
1050
        setValue("ArchiveInfo", tmp);
 
1051
 
 
1052
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewRound);
 
1053
        tmp = toShift(res);
 
1054
        tmp += QString::fromLatin1(" ms");
 
1055
        setValue("SendFromClient", tmp);
 
1056
        tmp = toShift(res);
 
1057
        tmp += QString::fromLatin1(" ms");
 
1058
        setValue("SendToClient", tmp);
 
1059
 
 
1060
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewClientTotal);
 
1061
        tmp = toShift(res);
 
1062
        setValue("TotalClient", tmp);
 
1063
        tmp = toShift(res);
 
1064
        setValue("ActiveClient", tmp);
 
1065
 
 
1066
        int totJob = 0;
 
1067
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewDedicated);
 
1068
        tmp = toShift(res);
 
1069
        totJob += tmp.toInt();
 
1070
        setValue("DedicatedServer", tmp);
 
1071
 
 
1072
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewDispatcher);
 
1073
        tmp = toShift(res);
 
1074
        totJob += tmp.toInt();
 
1075
        setValue("DispatcherServer", tmp);
 
1076
 
 
1077
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewShared);
 
1078
        tmp = toShift(res);
 
1079
        totJob += tmp.toInt();
 
1080
        setValue("SharedServer", tmp);
 
1081
 
 
1082
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewParallell);
 
1083
        tmp = toShift(res);
 
1084
        totJob += tmp.toInt();
 
1085
        setValue("ParallellServer", tmp);
 
1086
 
 
1087
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewBackground);
 
1088
        QStringList back;
 
1089
        while (!res.empty())
 
1090
        {
 
1091
            tmp = toShift(res);
 
1092
            if (tmp == QString::fromLatin1("DBW"))
 
1093
                tmp = QString::fromLatin1("DBWR");
 
1094
            else if (tmp == QString::fromLatin1("PMO"))
 
1095
                tmp = QString::fromLatin1("PMON");
 
1096
            else if (tmp == QString::fromLatin1("ARC"))
 
1097
                tmp = QString::fromLatin1("ARCH");
 
1098
            else if (tmp == QString::fromLatin1("CKP"))
 
1099
                tmp = QString::fromLatin1("CKPT");
 
1100
            else if (tmp == QString::fromLatin1("LGW"))
 
1101
                tmp = QString::fromLatin1("LGWR");
 
1102
            else if (tmp == QString::fromLatin1("LMO"))
 
1103
                tmp = QString::fromLatin1("LMON");
 
1104
            else if (tmp == QString::fromLatin1("REC"))
 
1105
                tmp = QString::fromLatin1("RECO");
 
1106
            else if (tmp == QString::fromLatin1("TRW"))
 
1107
                tmp = QString::fromLatin1("TRWR");
 
1108
            else if (tmp == QString::fromLatin1("SMO"))
 
1109
                tmp = QString::fromLatin1("SMON");
 
1110
 
 
1111
            tmp += QString::fromLatin1(": <B>");
 
1112
            QString job = toShift(res);
 
1113
            totJob += job.toInt();
 
1114
            tmp += job;
 
1115
            tmp += QString::fromLatin1("</B>");
 
1116
            back << tmp;
 
1117
        }
 
1118
        setValue("Background", back.join(QString::fromLatin1(",")));
 
1119
        setValue("TotalProcess", QString::number(totJob));
 
1120
 
 
1121
        double tot = 0;
 
1122
        double sql = 0;
 
1123
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewSGA, val);
 
1124
        while (!res.empty())
 
1125
        {
 
1126
            QString nam = toShift(res);
 
1127
            tmp = toShift(res);
 
1128
            if (nam == "Database Buffers" || nam == "Redo Buffers")
 
1129
                setValue(nam.latin1(), tmp + Parent.UnitString);
 
1130
            else if (nam == "Fixed Size" || nam == "Variable Size")
 
1131
                sql += tmp.toDouble();
 
1132
            tot += tmp.toDouble();
 
1133
        }
 
1134
        tmp = toQValue::formatNumber(tot);
 
1135
        tmp += Parent.UnitString;
 
1136
        setValue("SGATotal", tmp);
 
1137
        tmp = toQValue::formatNumber(sql);
 
1138
        tmp += Parent.UnitString;
 
1139
        setValue("SharedSize", tmp);
 
1140
 
 
1141
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewLog, val);
 
1142
        setValue("RedoFiles", toShift(res));
 
1143
        setValue("ActiveRedo", toShift(res));
 
1144
        tmp = toShift(res);
 
1145
        tmp += QString::fromLatin1("/");
 
1146
        tmp += toShift(res);
 
1147
        tmp += Parent.UnitString;
 
1148
        setValue("RedoSize", tmp);
 
1149
 
 
1150
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewTablespaces);
 
1151
        setValue("Tablespaces", toShift(res));
 
1152
 
 
1153
        res = toQuery::readQuery(*Parent.Connection, SQLOverviewDatafiles);
 
1154
        setValue("Files", toShift(res));
 
1155
    }
 
1156
    catch (const QString &str)
 
1157
    {
 
1158
        fprintf(stderr, "Exception occured:\n\n%s\n", (const char *)str.latin1());
 
1159
    }
 
1160
    catch (int)
 
1161
    {}
 
1162
    Parent.Done.up();
 
1163
}
 
1164
 
 
1165
void toTuningOverview::refresh(void)
 
1166
{
 
1167
    try
 
1168
    {
 
1169
        if (Done.getValue() == 1)
 
1170
        {
 
1171
            Done.down();
 
1172
            Quit = false;
 
1173
            Connection = &toCurrentConnection(this);
 
1174
            UnitString = toConfigurationSingle::Instance().globalConfig(CONF_SIZE_UNIT, DEFAULT_SIZE_UNIT);
 
1175
            toThread *thread = new toThread(new overviewQuery(*this));
 
1176
            thread->start();
 
1177
            Poll.start(500);
 
1178
        }
 
1179
    }
 
1180
    TOCATCH
 
1181
}
 
1182
 
 
1183
void toTuningOverview::setValue(QLabel *label, const QCString &nam)
 
1184
{
 
1185
    toLocker lock (Lock)
 
1186
        ;
 
1187
    std::map<QCString, QString>::iterator i = Values.find(nam);
 
1188
    if (i != Values.end())
 
1189
    {
 
1190
        label->setText((*i).second);
 
1191
        Values.erase(i);
 
1192
    }
 
1193
}
 
1194
 
 
1195
void toTuningOverview::poll(void)
 
1196
{
 
1197
    try
 
1198
    {
 
1199
        setValue(ArchiveInfo, "ArchiveInfo");
 
1200
        setValue(SendFromClient, "SendFromClient");
 
1201
        setValue(SendToClient, "SendToClient");
 
1202
        setValue(TotalClient, "TotalClient");
 
1203
        setValue(ActiveClient, "ActiveClient");
 
1204
        setValue(DedicatedServer, "DedicatedServer");
 
1205
        setValue(DispatcherServer, "DispatcherServer");
 
1206
        setValue(SharedServer, "SharedServer");
 
1207
        setValue(ParallellServer, "ParallellServer");
 
1208
 
 
1209
        {
 
1210
            toLocker lock (Lock)
 
1211
                ;
 
1212
            std::map<QCString, QString>::iterator i = Values.find("Background");
 
1213
            if (i != Values.end())
 
1214
            {
 
1215
                std::list<QLabel *>::iterator labIt = Backgrounds.begin();
 
1216
 
 
1217
                QStringList lst = QStringList::split(QString::fromLatin1(","), (*i).second);
 
1218
                for (unsigned int j = 0;j < lst.count();j++)
 
1219
                {
 
1220
                    QLabel *label;
 
1221
                    if (labIt == Backgrounds.end() || *labIt == NULL)
 
1222
                    {
 
1223
                        label = new QLabel(BackgroundGroup);
 
1224
                        label->show();
 
1225
                        if (labIt == Backgrounds.end())
 
1226
                        {
 
1227
                            Backgrounds.insert(Backgrounds.end(), label);
 
1228
                            labIt = Backgrounds.end();
 
1229
                        }
 
1230
                        else
 
1231
                        {
 
1232
                            *labIt = label;
 
1233
                            labIt++;
 
1234
                        }
 
1235
                    }
 
1236
                    else
 
1237
                    {
 
1238
                        label = *labIt;
 
1239
                        labIt++;
 
1240
                    }
 
1241
                    label->setText(lst[j]);
 
1242
                }
 
1243
                while (labIt != Backgrounds.end())
 
1244
                {
 
1245
                    delete *labIt;
 
1246
                    *labIt = NULL;
 
1247
                    labIt++;
 
1248
                }
 
1249
                Values.erase(i);
 
1250
            }
 
1251
        }
 
1252
 
 
1253
        setValue(TotalProcess, "TotalProcess");
 
1254
        setValue(BufferSize, "Database Buffers");
 
1255
        setValue(RedoBuffer, "Redo Buffers");
 
1256
        setValue(SGATotal, "SGATotal");
 
1257
        setValue(SharedSize, "SharedSize");
 
1258
        setValue(RedoFiles, "RedoFiles");
 
1259
        setValue(ActiveRedo, "ActiveRedo");
 
1260
        setValue(RedoSize, "RedoSize");
 
1261
 
 
1262
        std::list<double> &values = FileUsed->values();
 
1263
        std::list<double>::iterator j = values.begin();
 
1264
        if (j != values.end())
 
1265
        {
 
1266
            double size = 0;
 
1267
            double used = 0;
 
1268
            if (j != values.end())
 
1269
                used = size = (*j);
 
1270
            j++;
 
1271
            if (j != values.end())
 
1272
                size += (*j);
 
1273
            QString tmp = toQValue::formatNumber(used);
 
1274
            tmp += QString::fromLatin1("/");
 
1275
            tmp += toQValue::formatNumber(size);
 
1276
            tmp += UnitString;
 
1277
            if (tmp != Filesize->text())
 
1278
                Filesize->setText(tmp);
 
1279
        }
 
1280
 
 
1281
        setValue(Tablespaces, "Tablespaces");
 
1282
        setValue(Files, "Files");
 
1283
        if (Done.getValue() == 1)
 
1284
            Poll.stop();
 
1285
    }
 
1286
    TOCATCH
 
1287
}
 
1288
 
 
1289
static toSQL SQLLibraryCache("toTuning:LibraryCache",
 
1290
                             "SELECT namespace,\n"
 
1291
                             "       gets \"Gets\",\n"
 
1292
                             "       gethits \"Get Hits\",\n"
 
1293
                             "       to_char(trunc(gethitratio*100,\n"
 
1294
                             "       1))||'%' \"-Ratio\",\n"
 
1295
                             "       pins \"Pins\",\n"
 
1296
                             "       pinhits \"Pin Hits\",\n"
 
1297
                             "       to_char(trunc(pinhitratio*100,\n"
 
1298
                             "       1))||'%' \"-Ratio\"\n"
 
1299
                             "  FROM v$librarycache",
 
1300
                             "Library cache view");
 
1301
 
 
1302
static toSQL SQLControlFiles("toTuning:ControlFileRecords",
 
1303
                             "SELECT type \"Type\",\n"
 
1304
                             "       record_size \"Size\",\n"
 
1305
                             "       records_total \"Total Records\",\n"
 
1306
                             "       records_used \"Used Records\",\n"
 
1307
                             "       round(record_size*records_total/:unt<int>,1)||' '||:unitstr<char[101]> \"-Allocated\",\n"
 
1308
                             "       to_char(round(records_used/records_total*100,1))||'%' \"-Used\",\n"
 
1309
                             "       type \" Sort\"\n"
 
1310
                             "  FROM v$controlfile_record_section\n"
 
1311
                             "UNION\n"
 
1312
                             "SELECT 'TOTAL',\n"
 
1313
                             "        round(avg(record_size),1),\n"
 
1314
                             "        sum(records_total),\n"
 
1315
                             "        sum(records_used),\n"
 
1316
                             "        round(sum(record_size*records_total/:unt<int>),1)||' '||:unitstr<char[101]>,\n"
 
1317
                             "        to_char(round(sum(record_size*records_used)/sum(record_size*records_total)*100,1))||'%' \"-Used\",\n"
 
1318
                             "        'ZZZZZZZZZZZZZ'\n"
 
1319
                             "  FROM v$controlfile_record_section\n"
 
1320
                             "ORDER BY 7",
 
1321
                             "Control file record info");
 
1322
 
 
1323
toTuning::toTuning(QWidget *main, toConnection &connection)
 
1324
        : toToolWidget(TuningTool, "tuning.html", main, connection)
 
1325
{
 
1326
    if (TuningTool.config(CONF_OVERVIEW, "Undefined") == "Undefined")
 
1327
    {
 
1328
        QString def = QString::null;
 
1329
        if (TOMessageBox::warning(toMainWidget(),
 
1330
                                  tr("Enable all tuning statistics"),
 
1331
                                  tr("Are you sure you want to enable all tuning features.\n"
 
1332
                                     "This can put heavy strain on a database and unless you\n"
 
1333
                                     "are the DBA you probably don't want this. Selecting\n"
 
1334
                                     "no here will give you the option to enable or disable\n"
 
1335
                                     "tabs individually as they are needed."),
 
1336
                                  tr("Yes"), tr("&No"), QString::null, 1) == 0)
 
1337
        {
 
1338
            def = "Yes";
 
1339
        }
 
1340
        std::list<QCString> tabs = TabList();
 
1341
        for (std::list<QCString>::iterator i = tabs.begin();i != tabs.end();i++)
 
1342
            TuningTool.setConfig(*i, def);
 
1343
        toConfigurationSingle::Instance().saveConfig();
 
1344
    }
 
1345
 
 
1346
    QToolBar *toolbar = toAllocBar(this, tr("Server Tuning"));
 
1347
 
 
1348
    new QToolButton(QPixmap(const_cast<const char**>(refresh_xpm)),
 
1349
                    tr("Refresh"),
 
1350
                    tr("Refresh"),
 
1351
                    this, SLOT(refresh(void)),
 
1352
                    toolbar);
 
1353
    toolbar->addSeparator();
 
1354
    new QLabel(tr("Refresh") + " ", toolbar, TO_KDE_TOOLBAR_WIDGET);
 
1355
    Refresh = toRefreshCreate(toolbar, TO_KDE_TOOLBAR_WIDGET);
 
1356
    connect(Refresh, SIGNAL(activated(const QString &)), this, SLOT(changeRefresh(const QString &)));
 
1357
    toolbar->addSeparator();
 
1358
    TabButton = new toPopupButton(QPixmap(const_cast<const char**>(compile_xpm)),
 
1359
                                  tr("Enable and disable tuning tabs"),
 
1360
                                  tr("Enable and disable tuning tabs"),
 
1361
                                  toolbar);
 
1362
    TabMenu = new QPopupMenu(TabButton);
 
1363
    TabButton->setPopup(TabMenu);
 
1364
    connect(TabMenu, SIGNAL(aboutToShow()), this, SLOT(showTabMenu()));
 
1365
    connect(TabMenu, SIGNAL(activated(int)), this, SLOT(enableTabMenu(int)));
 
1366
 
 
1367
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
 
1368
    new toChangeConnection(toolbar, TO_KDE_TOOLBAR_WIDGET);
 
1369
 
 
1370
    Tabs = new QTabWidget(this);
 
1371
 
 
1372
    Overview = new toTuningOverview(this, "overview");
 
1373
    Tabs->addTab(Overview, tr("&Overview"));
 
1374
 
 
1375
    try
 
1376
    {
 
1377
        toRefreshParse(timer());
 
1378
        connect(timer(), SIGNAL(timeout()), Overview, SLOT(refresh()));
 
1379
    }
 
1380
    TOCATCH
 
1381
 
 
1382
    QString unitStr = toConfigurationSingle::Instance().globalConfig(CONF_SIZE_UNIT, DEFAULT_SIZE_UNIT);
 
1383
    toQList unit;
 
1384
    unit.insert(unit.end(), toQValue(toSizeDecode(unitStr)));
 
1385
    {
 
1386
        std::list<QCString> val = toSQL::range("toTuning:Charts");
 
1387
        for (std::list<QCString>::iterator i = val.begin();i != val.end();i++)
 
1388
        {
 
1389
            QStringList parts = QStringList::split(QString::fromLatin1(":"), QString::fromLatin1(*i));
 
1390
            if (parts.count() == 3)
 
1391
            {
 
1392
                parts.append(parts[2]);
 
1393
                parts[2] = QString::fromLatin1("Charts");
 
1394
            }
 
1395
            std::map<QCString, QGrid *>::iterator j = Charts.find(QCString(CONF_CHART) + parts[2].latin1());
 
1396
            QGrid *cchart;
 
1397
            if (j == Charts.end())
 
1398
                Charts[QCString(CONF_CHART) + parts[2].latin1()] = cchart = new QGrid(2, Tabs, QCString(CONF_CHART) + parts[2].latin1());
 
1399
            else
 
1400
                cchart = (*j).second;
 
1401
 
 
1402
            if (parts[3].mid(1, 1) == QString::fromLatin1("B"))
 
1403
            {
 
1404
                toResultBar *chart = new toResultBar(cchart);
 
1405
                chart->setTitle(parts[3].mid(3));
 
1406
                toQList par;
 
1407
                if (parts[3].mid(2, 1) == QString::fromLatin1("B"))
 
1408
                    chart->setYPostfix(tr(" blocks/s"));
 
1409
                else if (parts[3].mid(2, 1) == QString::fromLatin1("M"))
 
1410
                    chart->setYPostfix(QString::fromLatin1(" ms/s"));
 
1411
                else if (parts[3].mid(2, 1) == QString::fromLatin1("S"))
 
1412
                {
 
1413
                    par = unit;
 
1414
                    QString t = unitStr;
 
1415
                    t += QString::fromLatin1("/s");
 
1416
                    chart->setYPostfix(t);
 
1417
                }
 
1418
                else if (parts[3].mid(2, 1) == QString::fromLatin1("A"))
 
1419
                    chart->setFlow(false);
 
1420
                else
 
1421
                    chart->setYPostfix(QString::fromLatin1("/s"));
 
1422
                chart->query(toSQL::sql(*i), par);
 
1423
            }
 
1424
            else if (parts[3].mid(1, 1) == QString::fromLatin1("L") || parts[3].mid(1, 1) == QString::fromLatin1("C"))
 
1425
            {
 
1426
                toResultLine *chart;
 
1427
                if (parts[3].mid(1, 1) == QString::fromLatin1("C"))
 
1428
                    chart = new toTuningMiss(cchart);
 
1429
                else
 
1430
                    chart = new toResultLine(cchart);
 
1431
                chart->setTitle(parts[3].mid(3));
 
1432
                toQList par;
 
1433
                if (parts[3].mid(2, 1) == QString::fromLatin1("B"))
 
1434
                    chart->setYPostfix(tr(" blocks/s"));
 
1435
                else if (parts[3].mid(2, 1) == QString::fromLatin1("S"))
 
1436
                {
 
1437
                    par = unit;
 
1438
                    QString t = unitStr;
 
1439
                    t += QString::fromLatin1("/s");
 
1440
                    chart->setYPostfix(t);
 
1441
                }
 
1442
                else if (parts[3].mid(2, 1) == QString::fromLatin1("P"))
 
1443
                {
 
1444
                    chart->setYPostfix(QString::fromLatin1(" %"));
 
1445
                    chart->setMinValue(0);
 
1446
                }
 
1447
                else
 
1448
                    chart->setYPostfix(QString::fromLatin1("/s"));
 
1449
                chart->query(toSQL::sql(*i), par);
 
1450
            }
 
1451
            else if (parts[3].mid(1, 1) == QString::fromLatin1("P"))
 
1452
            {
 
1453
                toResultPie *chart = new toResultPie(cchart);
 
1454
                chart->setTitle(parts[3].mid(3));
 
1455
                if (parts[3].mid(2, 1) == QString::fromLatin1("S"))
 
1456
                {
 
1457
                    chart->query(toSQL::sql(*i), unit);
 
1458
                    chart->setPostfix(unitStr);
 
1459
                }
 
1460
                else
 
1461
                    chart->query(toSQL::sql(*i));
 
1462
            }
 
1463
            else
 
1464
                toStatusMessage(tr("Wrong format of name on chart (%1).").arg(*i));
 
1465
        }
 
1466
    }
 
1467
 
 
1468
    for (std::map<QCString, QGrid *>::iterator k = Charts.begin();k != Charts.end();k++)
 
1469
        Tabs->addTab((*k).second, tr((*k).first.mid(strlen(CONF_CHART))));
 
1470
 
 
1471
    FileIO = new toTuningFileIO(this, "fileio");
 
1472
    connect(this, SIGNAL(connectionChange()), FileIO, SLOT(changeConnection()));
 
1473
 
 
1474
    Waits = new toWaitEvents(this, "waits");
 
1475
    Tabs->addTab(Waits, tr("Wait events"));
 
1476
 
 
1477
    Tabs->addTab(FileIO, tr("&File I/O"));
 
1478
 
 
1479
    Indicators = new toListView(Tabs, "indicators");
 
1480
    Indicators->setRootIsDecorated(true);
 
1481
    Indicators->addColumn(tr("Indicator"));
 
1482
    Indicators->addColumn(tr("Value"));
 
1483
    Indicators->addColumn(tr("Reference"));
 
1484
    Tabs->addTab(Indicators, tr("&Indicators"));
 
1485
 
 
1486
    Statistics = new toResultStats(Tabs, "stats");
 
1487
    Tabs->addTab(Statistics, tr("&Statistics"));
 
1488
 
 
1489
    Parameters = new toResultParam(Tabs, "parameters");
 
1490
    Tabs->addTab(Parameters, tr("&Parameters"));
 
1491
 
 
1492
    BlockingLocks = new toResultLock(Tabs, "locks");
 
1493
    Tabs->addTab(BlockingLocks, tr("&Blocking locks"));
 
1494
 
 
1495
    LibraryCache = new toResultLong(true, false, toQuery::Background, Tabs, "cache");
 
1496
    LibraryCache->setSQL(SQLLibraryCache);
 
1497
    Tabs->addTab(LibraryCache, tr("Library C&ache"));
 
1498
 
 
1499
    ControlFiles = new toResultLong(true, false, toQuery::Background, Tabs, "control");
 
1500
    ControlFiles->setSQL(SQLControlFiles);
 
1501
    Tabs->addTab(ControlFiles, tr("Control Files"));
 
1502
 
 
1503
    Options = new toResultLong(true, false, toQuery::Background, Tabs, "options");
 
1504
    Options->setSQL(SQLOptions);
 
1505
    Tabs->addTab(Options, tr("Optio&ns"));
 
1506
 
 
1507
    Licenses = new toResultItem(2, true, Tabs, "licenses");
 
1508
    Licenses->setSQL(SQLLicense);
 
1509
    Tabs->addTab(Licenses, tr("&Licenses"));
 
1510
 
 
1511
    Tabs->setCurrentPage(0);
 
1512
 
 
1513
    LastTab = NULL;
 
1514
 
 
1515
    connect(Tabs, SIGNAL(currentChanged(QWidget *)), this, SLOT(changeTab(QWidget *)));
 
1516
    ToolMenu = NULL;
 
1517
    connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
 
1518
            this, SLOT(windowActivated(QWidget *)));
 
1519
 
 
1520
    std::list<QCString> tabs = TabList();
 
1521
    for (std::list<QCString>::iterator i = tabs.begin();i != tabs.end();i++)
 
1522
        if (TuningTool.config(*i, "").isEmpty())
 
1523
            enableTab(*i, false);
 
1524
 
 
1525
    refresh();
 
1526
    setFocusProxy(Tabs);
 
1527
}
 
1528
 
 
1529
QWidget *toTuning::tabWidget(const QCString &name)
 
1530
{
 
1531
    QWidget *widget = NULL;
 
1532
    if (name == CONF_OVERVIEW)
 
1533
    {
 
1534
        widget = Overview;
 
1535
    }
 
1536
    else if (name == CONF_FILEIO)
 
1537
    {
 
1538
        widget = FileIO;
 
1539
    }
 
1540
    else if (name == CONF_WAITS)
 
1541
    {
 
1542
        widget = Waits;
 
1543
    }
 
1544
    else if (Charts.find(CONF_CHART + name) != Charts.end())
 
1545
    {
 
1546
        widget = Charts[CONF_CHART + name];
 
1547
    }
 
1548
    return widget;
 
1549
}
 
1550
 
 
1551
void toTuning::showTabMenu(void)
 
1552
{
 
1553
    int id = 1;
 
1554
    TabMenu->clear();
 
1555
    std::list<QCString> tab = TabList();
 
1556
    for (std::list<QCString>::iterator i = tab.begin();i != tab.end();i++)
 
1557
    {
 
1558
        id++;
 
1559
        TabMenu->insertItem(tr(*i), id);
 
1560
        QWidget *widget = tabWidget(*i);
 
1561
        if (widget && Tabs->isTabEnabled(widget))
 
1562
            TabMenu->setItemChecked(id, true);
 
1563
    }
 
1564
}
 
1565
 
 
1566
void toTuning::enableTabMenu(int selid)
 
1567
{
 
1568
    std::list<QCString> tab = TabList();
 
1569
    int id = 1;
 
1570
    for (std::list<QCString>::iterator i = tab.begin();i != tab.end();i++)
 
1571
    {
 
1572
        id++;
 
1573
        if (selid == id)
 
1574
        {
 
1575
            QWidget *widget = tabWidget(*i);
 
1576
            if (widget)
 
1577
                enableTab(*i, !Tabs->isTabEnabled(widget));
 
1578
            break;
 
1579
        }
 
1580
    }
 
1581
}
 
1582
 
 
1583
void toTuning::enableTab(const QCString &name, bool enable)
 
1584
{
 
1585
    QWidget *widget = NULL;
 
1586
    if (name == CONF_OVERVIEW)
 
1587
    {
 
1588
        if (enable)
 
1589
            Overview->start();
 
1590
        else
 
1591
            Overview->stop();
 
1592
        widget = Overview;
 
1593
    }
 
1594
    else if (Charts.find(QCString(CONF_CHART) + name) != Charts.end())
 
1595
    {
 
1596
        QGrid *chart = Charts[QCString(CONF_CHART) + name];
 
1597
        QObjectList *childs = (QObjectList *)chart->children();
 
1598
        for (unsigned int i = 0;i < childs->count();i++)
 
1599
        {
 
1600
            toResultLine *line = dynamic_cast<toResultLine *>(childs->at(i));
 
1601
            if (line)
 
1602
            {
 
1603
                if (enable)
 
1604
                    line->start();
 
1605
                else
 
1606
                    line->stop();
 
1607
            }
 
1608
            toResultBar *bar = dynamic_cast<toResultBar *>(childs->at(i));
 
1609
            if (bar)
 
1610
            {
 
1611
                if (enable)
 
1612
                    bar->start();
 
1613
                else
 
1614
                    bar->stop();
 
1615
            }
 
1616
            toResultPie *pie = dynamic_cast<toResultPie *>(childs->at(i));
 
1617
            if (pie)
 
1618
            {
 
1619
                if (enable)
 
1620
                    pie->start();
 
1621
                else
 
1622
                    pie->stop();
 
1623
            }
 
1624
        }
 
1625
        widget = chart;
 
1626
    }
 
1627
    else if (name == CONF_WAITS)
 
1628
    {
 
1629
        if (enable)
 
1630
            Waits->start();
 
1631
        else
 
1632
            Waits->stop();
 
1633
        widget = Waits;
 
1634
    }
 
1635
    else if (name == CONF_FILEIO)
 
1636
    {
 
1637
        if (enable)
 
1638
            FileIO->start();
 
1639
        else
 
1640
            FileIO->stop();
 
1641
        widget = FileIO;
 
1642
    }
 
1643
    if (widget)
 
1644
        Tabs->setTabEnabled(widget, enable);
 
1645
}
 
1646
 
 
1647
void toTuning::changeTab(QWidget *widget)
 
1648
{
 
1649
    if (LastTab == widget)
 
1650
        return ;
 
1651
    refresh();
 
1652
}
 
1653
 
 
1654
void toTuning::windowActivated(QWidget *widget)
 
1655
{
 
1656
    if (widget == this)
 
1657
    {
 
1658
        if (!ToolMenu)
 
1659
        {
 
1660
            ToolMenu = new QPopupMenu(this);
 
1661
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(refresh_xpm)), tr("&Refresh"), this, SLOT(refresh(void)),
 
1662
                                 toKeySequence(tr("F5", "Tuning|Refresh")));
 
1663
            ToolMenu->insertItem(tr("&Change Refresh"), Refresh, SLOT(setFocus(void)),
 
1664
                                 toKeySequence(tr("Alt+R", "Tuning|Change refresh")));
 
1665
            toMainWidget()->menuBar()->insertItem(tr("&Tuning"), ToolMenu, -1, toToolMenuIndex());
 
1666
        }
 
1667
    }
 
1668
    else
 
1669
    {
 
1670
        delete ToolMenu;
 
1671
        ToolMenu = NULL;
 
1672
    }
 
1673
}
 
1674
 
 
1675
void toTuning::changeRefresh(const QString &str)
 
1676
{
 
1677
    try
 
1678
    {
 
1679
        toRefreshParse(timer(), str);
 
1680
    }
 
1681
    TOCATCH
 
1682
}
 
1683
 
 
1684
void toTuning::refresh(void)
 
1685
{
 
1686
    LastTab = Tabs->currentPage();
 
1687
    if (LastTab == Overview)
 
1688
    {
 
1689
        Overview->refresh();
 
1690
    }
 
1691
    else if (LastTab == Indicators)
 
1692
    {
 
1693
        Indicators->clear();
 
1694
        std::list<QCString> val = toSQL::range("toTuning:Indicators");
 
1695
        QListViewItem *parent = NULL;
 
1696
        QListViewItem *last = NULL;
 
1697
        for (std::list<QCString>::iterator i = val.begin();i != val.end();i++)
 
1698
        {
 
1699
            try
 
1700
            {
 
1701
                toQList val = toQuery::readQuery(connection(), toSQL::string(*i, connection()));
 
1702
                QStringList parts = QStringList::split(QString::fromLatin1(":"), *i);
 
1703
                if (!parent || parent->text(0) != parts[2])
 
1704
                {
 
1705
                    parent = new toResultViewItem(Indicators, NULL, parts[2]);
 
1706
                    parent->setOpen(true);
 
1707
                    last = NULL;
 
1708
                }
 
1709
                QStringList dsc = QStringList::split(QString::fromLatin1("."), toSQL::description(*i));
 
1710
                QString first = dsc[0];
 
1711
                first += QString::fromLatin1(".");
 
1712
                last = new toResultViewItem(parent, last, first);
 
1713
                QString str;
 
1714
                for (toQList::iterator j = val.begin();j != val.end();j++)
 
1715
                    str += *j;
 
1716
                last->setText(1, str);
 
1717
                if (dsc.count() > 1)
 
1718
                    last->setText(2, dsc[1]);
 
1719
            }
 
1720
            TOCATCH
 
1721
        }
 
1722
    }
 
1723
    else if (LastTab == Waits)
 
1724
        Waits->refresh();
 
1725
    else if (LastTab == Statistics)
 
1726
        Statistics->refreshStats();
 
1727
    else if (LastTab == Parameters)
 
1728
        Parameters->refresh();
 
1729
    else if (LastTab == BlockingLocks)
 
1730
        BlockingLocks->refresh();
 
1731
    else if (LastTab == LibraryCache)
 
1732
        LibraryCache->refresh();
 
1733
    else if (LastTab == ControlFiles)
 
1734
    {
 
1735
        QString unit = toConfigurationSingle::Instance().globalConfig(CONF_SIZE_UNIT, DEFAULT_SIZE_UNIT);
 
1736
        ControlFiles->changeParams(QString::number(toSizeDecode(unit)), unit);
 
1737
    }
 
1738
    else if (LastTab == Options)
 
1739
        Options->refresh();
 
1740
    else if (LastTab == Licenses)
 
1741
        Licenses->refresh();
 
1742
}
 
1743
 
 
1744
void toTuning::exportData(std::map<QCString, QString> &data, const QCString &prefix)
 
1745
{
 
1746
    toToolWidget::exportData(data, prefix);
 
1747
    std::list<QCString> ret = TabList();
 
1748
    for (std::list<QCString>::iterator i = ret.begin();i != ret.end();i++)
 
1749
    {
 
1750
        QWidget *widget = tabWidget(*i);
 
1751
        if (widget)
 
1752
        {
 
1753
            if (!Tabs->isTabEnabled(widget))
 
1754
                data[prefix + ":" + *i] = QString::fromLatin1("Disabled");
 
1755
        }
 
1756
    }
 
1757
    data[prefix + ":Current"] = Tabs->currentPage()->name();
 
1758
 
 
1759
    Waits->exportData(data, prefix + ":Waits");
 
1760
}
 
1761
 
 
1762
void toTuning::importData(std::map<QCString, QString> &data, const QCString &prefix)
 
1763
{
 
1764
    toToolWidget::importData(data, prefix);
 
1765
    std::list<QCString> ret = TabList();
 
1766
    for (std::list<QCString>::iterator i = ret.begin();i != ret.end();i++)
 
1767
        enableTab(*i, data[prefix + ":" + (*i)].isEmpty());
 
1768
    QWidget *chld = (QWidget *)child(data[prefix + ":Current"]);
 
1769
    if (chld)
 
1770
        Tabs->showPage(chld);
 
1771
    Waits->importData(data, prefix + ":Waits");
 
1772
}
 
1773
 
 
1774
static toSQL SQLFileIO("toTuning:FileIO",
 
1775
                       "select a.name,b.name,sysdate,\n"
 
1776
                       "       c.phyrds,c.phywrts,c.phyblkrd,c.phyblkwrt,\n"
 
1777
                       "       c.avgiotim*10,c.miniotim*10,c.maxiortm*10,c.maxiowtm*10\n"
 
1778
                       "  from v$tablespace a,v$datafile b,v$filestat c\n"
 
1779
                       " where a.ts# = b.ts# and b.file# = c.file#\n"
 
1780
                       "union\n",
 
1781
                       "select a.name,b.name,sysdate,\n"
 
1782
                       "       c.phyrds,c.phywrts,c.phyblkrd,c.phyblkwrt,\n"
 
1783
                       "       c.avgiotim*10,c.miniotim*10,c.maxiortm*10,c.maxiowtm*10\n"
 
1784
                       "  from v$tablespace a,v$tempfile b,v$tempstat c\n"
 
1785
                       " where a.ts# = b.ts# and b.file# = c.file#\n"
 
1786
                       " order by 1,2",
 
1787
                       "Get file for files and tablespaces. Must have same columns.",
 
1788
                       "0801");
 
1789
 
 
1790
static toSQL SQLFileIO8("toTuning:FileIO",
 
1791
                        "select a.name,b.name,sysdate,\n"
 
1792
                        "       c.phyrds,c.phywrts,c.phyblkrd,c.phyblkwrt,\n"
 
1793
                        "       c.avgiotim*10,c.miniotim*10,c.maxiortm*10,c.maxiowtm*10\n"
 
1794
                        "  from v$tablespace a,v$datafile b,v$filestat c\n"
 
1795
                        " where a.ts# = b.ts# and b.file# = c.file#\n"
 
1796
                        " order by a.name",
 
1797
                        "",
 
1798
                        "0800");
 
1799
 
 
1800
toTuningFileIO::toTuningFileIO(QWidget *parent, const char *name, WFlags fl)
 
1801
        : QScrollView(parent, name, fl)
 
1802
{
 
1803
    try
 
1804
    {
 
1805
        connect(toCurrentTool(this)->timer(), SIGNAL(timeout()), this, SLOT(refresh()));
 
1806
 
 
1807
        viewport()->setBackgroundColor(qApp->palette().active().background());
 
1808
 
 
1809
        QVBox *Box = new QVBox(this->viewport());
 
1810
        addChild(Box);
 
1811
 
 
1812
        QComboBox *combo = new QComboBox(Box);
 
1813
        combo->insertItem(tr("File I/O"));
 
1814
        combo->insertItem(tr("File timing"));
 
1815
        if (toCurrentConnection(this).version() >= "0800")
 
1816
        {
 
1817
            combo->insertItem(tr("Tablespace I/O"));
 
1818
            combo->insertItem(tr("Tablespace timing"));
 
1819
        }
 
1820
        connect(combo, SIGNAL(activated(int)), this, SLOT(changeCharts(int)));
 
1821
 
 
1822
        FileReads = new QGrid(2, Box);
 
1823
        FileTime = new QGrid(2, Box);
 
1824
        TablespaceReads = new QGrid(2, Box);
 
1825
        TablespaceTime = new QGrid(2, Box);
 
1826
 
 
1827
        FileReads->setFixedWidth(viewport()->width() - 30);
 
1828
        FileTime->setFixedWidth(viewport()->width() - 30);
 
1829
        TablespaceReads->setFixedWidth(viewport()->width() - 30);
 
1830
        TablespaceTime->setFixedWidth(viewport()->width() - 30);
 
1831
        changeCharts(0);
 
1832
        CurrentStamp = 0;
 
1833
        connect(&Poll, SIGNAL(timeout()), this, SLOT(poll()));
 
1834
        Query = NULL;
 
1835
        refresh();
 
1836
    }
 
1837
    TOCATCH
 
1838
}
 
1839
 
 
1840
toTuningFileIO::~toTuningFileIO()
 
1841
{
 
1842
    delete Query;
 
1843
}
 
1844
 
 
1845
void toTuningFileIO::changeCharts(int val)
 
1846
{
 
1847
    FileReads->hide();
 
1848
    FileTime->hide();
 
1849
    TablespaceReads->hide();
 
1850
    TablespaceTime->hide();
 
1851
    switch (val)
 
1852
    {
 
1853
    case 0:
 
1854
        FileReads->show();
 
1855
        break;
 
1856
    case 1:
 
1857
        FileTime->show();
 
1858
        break;
 
1859
    case 2:
 
1860
        TablespaceReads->show();
 
1861
        break;
 
1862
    case 3:
 
1863
        TablespaceTime->show();
 
1864
        break;
 
1865
    }
 
1866
}
 
1867
 
 
1868
void toTuningFileIO::allocCharts(const QString &name)
 
1869
{
 
1870
    std::list<QString> labels;
 
1871
    labels.insert(labels.end(), tr("Reads"));
 
1872
    labels.insert(labels.end(), tr("Blocks Read"));
 
1873
    labels.insert(labels.end(), tr("Writes"));
 
1874
    labels.insert(labels.end(), tr("Blocks Written"));
 
1875
    std::list<QString> labelTime;
 
1876
    labelTime.insert(labelTime.end(), tr("Average"));
 
1877
    labelTime.insert(labelTime.end(), tr("Minimum"));
 
1878
    labelTime.insert(labelTime.end(), tr("Maximum Read"));
 
1879
    labelTime.insert(labelTime.end(), tr("Maximum Write"));
 
1880
 
 
1881
    toResultBar *barchart;
 
1882
    if (name.startsWith(QString::fromLatin1("tspc:")))
 
1883
        barchart = new toResultBar(TablespaceReads);
 
1884
    else
 
1885
        barchart = new toResultBar(FileReads);
 
1886
    ReadsCharts[name] = barchart;
 
1887
    barchart->setTitle(name.mid(5));
 
1888
    barchart->setMinimumSize(200, 170);
 
1889
    barchart->setYPostfix(tr("blocks/s"));
 
1890
    barchart->setLabels(labels);
 
1891
    barchart->setSQLName(QString::fromLatin1("toTuning:FileIO:Reads:" + name));
 
1892
    barchart->show();
 
1893
 
 
1894
    toResultLine *linechart;
 
1895
    if (name.startsWith(QString::fromLatin1("tspc:")))
 
1896
        linechart = new toResultLine(TablespaceTime);
 
1897
    else
 
1898
        linechart = new toResultLine(FileTime);
 
1899
    TimeCharts[name] = linechart;
 
1900
    linechart->setTitle(name.mid(5));
 
1901
    linechart->setMinimumSize(200, 170);
 
1902
    linechart->setYPostfix(QString::fromLatin1("ms"));
 
1903
    linechart->setLabels(labelTime);
 
1904
    linechart->setSQLName(QString::fromLatin1("toTuning:FileIO:Time:" + name));
 
1905
    linechart->show();
 
1906
}
 
1907
 
 
1908
void toTuningFileIO::saveSample(const QString &name, const QString &label,
 
1909
                                double reads, double writes,
 
1910
                                double readBlk, double writeBlk,
 
1911
                                double avgTim, double minTim,
 
1912
                                double maxRead, double maxWrite)
 
1913
{
 
1914
    if (CurrentStamp != LastStamp)
 
1915
    {
 
1916
 
 
1917
        std::list<double> vals;
 
1918
        vals.insert(vals.end(), reads);
 
1919
        vals.insert(vals.end(), writes);
 
1920
        vals.insert(vals.end(), readBlk);
 
1921
        vals.insert(vals.end(), writeBlk);
 
1922
 
 
1923
        std::list<double> last = LastValues[name];
 
1924
        std::list<double> dispVal;
 
1925
        if (!last.empty())
 
1926
        {
 
1927
            std::list<double>::iterator i = vals.begin();
 
1928
            std::list<double>::iterator j = last.begin();
 
1929
            while (i != vals.end() && j != last.end())
 
1930
            {
 
1931
                dispVal.insert(dispVal.end(), (*i - *j) / (CurrentStamp - LastStamp));
 
1932
                i++;
 
1933
                j++;
 
1934
            }
 
1935
        }
 
1936
        LastValues[name] = vals;
 
1937
 
 
1938
        if (ReadsCharts.find(name) == ReadsCharts.end())
 
1939
            allocCharts(name);
 
1940
 
 
1941
        if (!dispVal.empty())
 
1942
        {
 
1943
            toBarChart *chart = ReadsCharts[name];
 
1944
            chart->addValues(dispVal, label);
 
1945
        }
 
1946
 
 
1947
        vals.clear();
 
1948
        vals.insert(vals.end(), avgTim);
 
1949
        vals.insert(vals.end(), minTim);
 
1950
        vals.insert(vals.end(), maxRead);
 
1951
        vals.insert(vals.end(), maxWrite);
 
1952
 
 
1953
        toLineChart *chart = TimeCharts[name];
 
1954
        chart->addValues(vals, label);
 
1955
    }
 
1956
}
 
1957
 
 
1958
void toTuningFileIO::refresh(void)
 
1959
{
 
1960
    if (!Query)
 
1961
    {
 
1962
        try
 
1963
        {
 
1964
            toConnection &conn = toCurrentConnection(this);
 
1965
            if (conn.version() < "0800")
 
1966
                return ;
 
1967
            toQList par;
 
1968
            LastStamp = CurrentStamp;
 
1969
            CurrentStamp = time(NULL);
 
1970
            Query = new toNoBlockQuery(conn, toQuery::Background, toSQL::string(SQLFileIO, conn), par);
 
1971
            LastTablespace = QString::null;
 
1972
 
 
1973
            Poll.start(100);
 
1974
        }
 
1975
        TOCATCH
 
1976
    }
 
1977
}
 
1978
 
 
1979
void toTuningFileIO::poll(void)
 
1980
{
 
1981
    try
 
1982
    {
 
1983
        if (Query && Query->poll())
 
1984
        {
 
1985
            QString tablespace;
 
1986
            QString datafile;
 
1987
            QString timestr;
 
1988
            while (Query->poll())
 
1989
            {
 
1990
                if (!Query->eof())
 
1991
                {
 
1992
                    tablespace = Query->readValueNull();
 
1993
                    datafile = Query->readValueNull();
 
1994
                    timestr = Query->readValueNull();
 
1995
                }
 
1996
                else
 
1997
                    tablespace = QString::null;
 
1998
                if (tablespace != LastTablespace)
 
1999
                {
 
2000
                    if (!LastTablespace.isNull())
 
2001
                    {
 
2002
                        QString name = QString::fromLatin1("tspc:");
 
2003
                        name += LastTablespace;
 
2004
 
 
2005
                        saveSample(name, timestr,
 
2006
                                   TblReads, TblWrites, TblReadBlk, TblWriteBlk,
 
2007
                                   TblAvg, TblMin, TblMaxRead, TblMaxWrite);
 
2008
                    }
 
2009
 
 
2010
                    TblReads = TblWrites = TblReadBlk = TblWriteBlk = TblAvg = TblMin = TblMaxRead = TblMaxWrite = 0;
 
2011
                    LastTablespace = tablespace;
 
2012
                }
 
2013
                if (Query->eof())
 
2014
                    break;
 
2015
 
 
2016
                double reads = Query->readValueNull().toDouble();
 
2017
                double writes = Query->readValueNull().toDouble();
 
2018
                double readBlk = Query->readValueNull().toDouble();
 
2019
                double writeBlk = Query->readValueNull().toDouble();
 
2020
                double avgTim = Query->readValueNull().toDouble();
 
2021
                double minTim = Query->readValueNull().toDouble();
 
2022
                double maxRead = Query->readValueNull().toDouble();
 
2023
                double maxWrite = Query->readValueNull().toDouble();
 
2024
 
 
2025
                TblReads += reads;
 
2026
                TblWrites += writes;
 
2027
                TblReadBlk += readBlk;
 
2028
                TblWriteBlk += writeBlk;
 
2029
                TblAvg += avgTim;
 
2030
                TblMin += minTim;
 
2031
                TblMaxRead += maxRead;
 
2032
                TblMaxWrite += maxWrite;
 
2033
 
 
2034
                QString name = QString::fromLatin1("file:");
 
2035
                name += datafile;
 
2036
 
 
2037
                saveSample(name, timestr,
 
2038
                           reads, writes, readBlk, writeBlk,
 
2039
                           avgTim, minTim, maxRead, maxWrite);
 
2040
            }
 
2041
            if (Query->eof())
 
2042
            {
 
2043
                Poll.stop();
 
2044
                delete Query;
 
2045
                Query = NULL;
 
2046
            }
 
2047
        }
 
2048
    }
 
2049
    TOCATCH
 
2050
}
 
2051
 
 
2052
void toTuningFileIO::resizeEvent(QResizeEvent *e)
 
2053
{
 
2054
    QScrollView::resizeEvent(e);
 
2055
 
 
2056
    FileReads->setFixedWidth(viewport()->width() - 30);
 
2057
    FileTime->setFixedWidth(viewport()->width() - 30);
 
2058
    TablespaceReads->setFixedWidth(viewport()->width() - 30);
 
2059
    TablespaceTime->setFixedWidth(viewport()->width() - 30);
 
2060
}
 
2061
 
 
2062
void toTuningFileIO::changeConnection(void)
 
2063
{
 
2064
    {
 
2065
        for (std::map<QString, toBarChart *>::iterator i = ReadsCharts.begin();
 
2066
                i != ReadsCharts.end();i++)
 
2067
            delete (*i).second;
 
2068
    }
 
2069
    ReadsCharts.clear();
 
2070
    for (std::map<QString, toLineChart *>::iterator i = TimeCharts.begin();
 
2071
            i != TimeCharts.end();i++)
 
2072
        delete (*i).second;
 
2073
    TimeCharts.clear();
 
2074
    LastValues.clear();
 
2075
    refresh();
 
2076
}
 
2077
 
 
2078
toTuningMiss::toTuningMiss(QWidget *parent, const char *name)
 
2079
        : toResultLine(parent, name)
 
2080
{}
 
2081
 
 
2082
std::list<double> toTuningMiss::transform(std::list<double> &inp)
 
2083
{
 
2084
    std::list<double> ret;
 
2085
    for (std::list<double>::iterator i = inp.begin();i != inp.end();i++)
 
2086
    {
 
2087
        double first = *i;
 
2088
        i++;
 
2089
        if (i != inp.end())
 
2090
        {
 
2091
            double second = *i;
 
2092
            if (second == 0)
 
2093
                ret.insert(ret.end(), 0);
 
2094
            else
 
2095
                ret.insert(ret.end(), first / second);
 
2096
        }
 
2097
    }
 
2098
    return ret;
 
2099
}
 
2100
 
 
2101
void toTuningFileIO::stop(void)
 
2102
{
 
2103
    try
 
2104
    {
 
2105
        disconnect(toCurrentTool(this)->timer(), SIGNAL(timeout()), this, SLOT(refresh()));
 
2106
    }
 
2107
    TOCATCH
 
2108
}
 
2109
 
 
2110
void toTuningFileIO::start(void)
 
2111
{
 
2112
    try
 
2113
    {
 
2114
        connect(toCurrentTool(this)->timer(), SIGNAL(timeout()), this, SLOT(refresh()));
 
2115
    }
 
2116
    TOCATCH
 
2117
}