1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
//***************************************************************************
/*
* TOra - An Oracle Toolkit for DBA's and developers
* Copyright (C) 2000-2001,2001 Underscore AB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; only version 2 of
* the License is valid for this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* As a special exception, you have permission to link this program
* with the Oracle Client libraries and distribute executables, as long
* as you follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from Oracle client libraries.
*
* Specifically you are not permitted to link this program with the
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
* And you are not permitted to distribute binaries compiled against
* these libraries without written consent from Underscore AB. Observe
* that this does not disallow linking to the Qt Free Edition.
*
* All trademarks belong to their respective owners.
*
****************************************************************************/
#include "utils.h"
#include "toconnection.h"
#include "tonoblockquery.h"
#include "toresultstats.h"
#include "tosql.h"
#include "toresultstats.moc"
toResultStats::toResultStats(bool onlyChanged,int ses,QWidget *parent,
const char *name)
: toResultView(false,false,parent,name),OnlyChanged(onlyChanged)
{
if (!handled())
return;
SessionID=ses;
setSQLName("toResultStats");
System=false;
setup();
}
bool toResultStats::canHandle(toConnection &conn)
{
return toIsOracle(conn);
}
toResultStats::~toResultStats()
{
delete Query;
delete SessionIO;
}
static toSQL SQLSession("toResultStats:Session",
"SELECT MIN(SID) FROM V$MYSTAT",
"Get session id of current session");
toResultStats::toResultStats(bool onlyChanged,QWidget *parent,
const char *name)
: toResultView(false,false,parent,name),OnlyChanged(onlyChanged)
{
if (!handled())
return;
try {
toQuery query(connection(),SQLSession);
SessionID=query.readValue().toInt();
} catch (...) {
SessionID=-1;
}
System=false;
setup();
}
toResultStats::toResultStats(QWidget *parent,const char *name)
: toResultView(false,false,parent,name),OnlyChanged(false)
{
if (!handled())
return;
System=true;
setup();
}
void toResultStats::setup(void)
{
for (int i=0;i<TO_STAT_MAX;i++)
LastValues[i]=0;
addColumn("Name");
if (!OnlyChanged)
addColumn("Value");
addColumn("Delta");
setSorting(0);
setColumnAlignment(1,AlignRight);
setColumnAlignment(2,AlignRight);
Query=SessionIO=NULL;
connect(&Poll,SIGNAL(timeout()),this,SLOT(poll()));
}
static toSQL SQLStatistics("toResultStats:Statistics",
"SELECT Statistic#,Value FROM V$SesStat WHERE SID = :f1<int>",
"Get statistics for session, must have same number of columns");
static toSQL SQLSessionIO("toResultStats:SessionIO",
"SELECT Block_Gets \"block gets\",\n"
" Block_Changes \"block changes\",\n"
" Consistent_Changes \"consistent changes\"\n"
" FROM v$sess_io\n"
" WHERE SID = :f1<int>",
"Get session IO, must have same binds");
static toSQL SQLSystemStatistics("toResultStats:SystemStatistics",
"SELECT Statistic#,Value FROM v$sysstat",
"Get system statistics, must have same number of columns");
void toResultStats::resetStats(void)
{
if (!handled())
return;
toBusy busy;
try {
toConnection &conn=connection();
toQList args;
if (!System)
args.insert(args.end(),SessionID);
toQuery query(conn,System?SQLSystemStatistics:SQLStatistics,args);
while(!query.eof()) {
int id;
double value;
id=query.readValue().toInt();
value=query.readValue().toDouble();
id+=TO_STAT_BLOCKS;
if (id<TO_STAT_MAX+TO_STAT_BLOCKS)
LastValues[id]=value;
}
if (!System) {
toQuery queryio(conn,SQLSessionIO,args);
int id=0;
while(!queryio.eof()) {
double value;
value=queryio.readValue().toDouble();
LastValues[id]=value;
id++;
}
}
} TOCATCH
}
void toResultStats::changeSession(toQuery &query)
{
if (!handled())
return;
if (System)
throw QString("Can't change session on system statistics");
try {
toQList args;
query.execute(SQLSession,args);
SessionID=query.readValue().toInt();
emit sessionChanged(SessionID);
emit sessionChanged(QString::number(SessionID));
resetStats();
refreshStats(true);
} TOCATCH
}
void toResultStats::changeSession(int ses)
{
if (!handled())
return;
if (System)
throw QString("Can't change session on system statistics");
if (SessionID!=ses) {
SessionID=ses;
emit sessionChanged(SessionID);
emit sessionChanged(QString::number(SessionID));
resetStats();
}
refreshStats();
}
static toSQL SQLStatisticName("toResultStats:StatisticName",
"SELECT b.Name,a.Statistic#,a.Value\n"
" FROM V$SesStat a,V$StatName b\n"
" WHERE a.SID = :f1<int> AND a.statistic# = b.statistic#\n",
"Get statistics and their names for session, must have same number of columns");
static toSQL SQLSystemStatisticName("toResultStats:SystemStatisticName",
"SELECT Name,Statistic#,Value\n"
" FROM v$sysstat\n",
"Get statistics and their names for system statistics, must have same number of columns");
void toResultStats::addValue(bool reset,int id,const QString &name,double value)
{
QString delta;
QString absVal;
if (value!=0) {
absVal.sprintf("%.15g",value);
if (id<TO_STAT_MAX+TO_STAT_BLOCKS) {
delta.sprintf("%.15g",value-LastValues[id]);
if (value!=LastValues[id]||!OnlyChanged) {
toResultViewItem *item=new toResultViewItem(this,NULL);
if (reset)
LastValues[id]=value;
item->setText(0,name);
if (OnlyChanged)
item->setText(1,delta);
else {
item->setText(1,absVal);
item->setText(2,delta);
}
item->setText(3,QString::number(++Row));
}
}
}
}
void toResultStats::refreshStats(bool reset)
{
if (!handled()||Query||SessionIO)
return;
try {
clear();
Row=0;
toConnection &conn=connection();
toQList args;
if (!System)
args.insert(args.end(),SessionID);
Query=new toNoBlockQuery(conn,
toQuery::Background,
toSQL::string(System?SQLSystemStatisticName:SQLStatisticName,
connection()),
args);
if (!System)
SessionIO=new toNoBlockQuery(conn,toQuery::Background,
toSQL::string(SQLSessionIO,connection()),
args);
Poll.start(100);
Reset=reset;
} TOCATCH
}
void toResultStats::poll(void)
{
try {
if (!toCheckModal(this))
return;
bool done=true;
if (Query&&Query->poll()) {
while(Query->poll()&&!Query->eof()) {
QString name=Query->readValue();
int id=Query->readValue().toInt();
double value=Query->readValue().toDouble();
addValue(Reset,id,name,value);
}
if (Query->eof()) {
delete Query;
Query=NULL;
} else
done=false;
} else if (Query)
done=false;
if (SessionIO&&SessionIO->poll()) {
int id=0;
toQDescList description=SessionIO->describe();
toQDescList::iterator i=description.begin();
while(!SessionIO->eof()) {
addValue(Reset,id,(*i).Name,SessionIO->readValue().toDouble());
id++;
if (i==description.end())
i=description.begin();
else
i++;
}
delete SessionIO;
SessionIO=NULL;
} else if (SessionIO)
done=false;
if (done)
Poll.stop();
} catch(const QString &exc) {
delete Query;
Query=NULL;
delete SessionIO;
SessionIO=NULL;
Poll.stop();
toStatusMessage(exc);
}
}
|