[svn-commits] r193 - in branches/advisor/src: back/scf/scm front/misc/analyzedb
thial01 at ingres.com
thial01 at ingres.com
Mon Aug 18 02:22:05 PDT 2008
Author: thial01
Date: 2008-08-18 02:22:05 -0700 (Mon, 18 Aug 2008)
New Revision: 193
Modified:
branches/advisor/src/back/scf/scm/workloaddb.sql
branches/advisor/src/front/misc/analyzedb/Analyze.py
branches/advisor/src/front/misc/analyzedb/Config.py
branches/advisor/src/front/misc/analyzedb/Draw.py
branches/advisor/src/front/misc/analyzedb/Present.py
branches/advisor/src/front/misc/analyzedb/analyzedb
branches/advisor/src/front/misc/analyzedb/functions.py
Log:
Adding time frame option to the analyzer client - see #174
Modified: branches/advisor/src/back/scf/scm/workloaddb.sql
===================================================================
--- branches/advisor/src/back/scf/scm/workloaddb.sql 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/back/scf/scm/workloaddb.sql 2008-08-18 09:22:05 UTC (rev 193)
@@ -27,7 +27,7 @@
est_cpu integer4,
est_dio integer4,
pages_touched integer4,
- time integer4,
+ time integer4 not null,
wctime integer4,
primary key (idx, query_key, time)
)
Modified: branches/advisor/src/front/misc/analyzedb/Analyze.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/Analyze.py 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/front/misc/analyzedb/Analyze.py 2008-08-18 09:22:05 UTC (rev 193)
@@ -20,6 +20,7 @@
__workloaddb = False
__time = [0, 0]
__workloadsize = 0
+ __timeframe = ""
def __init__(self, config):
self.__config = config
@@ -28,6 +29,12 @@
""" Start time """
self.__time[0] = time.ctime()
+
+ """ Prepare for analysis within a given time frame """
+ if (self.__config.timefrom):
+ self.__timeframe = " and $.time >= '%s'" % self.__config.timefrom
+ if (self.__config.timeto):
+ self.__timeframe += " and $.time <= '%s'" % self.__config.timeto
self.__userdb = DB(self.__config, self.__config.userdb)
self.__imadb = DB(self.__config, "imadb")
@@ -40,13 +47,15 @@
""" Set the joinop timeout to a high value to give OPF enough time to find better plans """
self.__userdb.execute("set joinop timeout %d" % self.__config.timeout)
- debug("## Start Analyzing...\n")
+ output("## Preparing Analysis...\n")
self.__load_indexes()
self.__load_attributes()
self.__load_tables()
self.__load_workload()
self.__load_statements()
+
+ output("## Start Analyzing...\n")
for statement in self.__statements:
self.__process_statement(statement)
@@ -74,7 +83,7 @@
""" Get all indexes """
results = self.__workloaddb.execute("select \
i.index_id, i.name, i.table_id, i.attribute_id, i.frequency, i.structure, i.data_pages, i.overflow_pages \
- from indexes i where i.database = ?",
+ from indexes i where i.database = ? %s" % self.__timeframe.replace("$", "i"),
(self.__config.userdb,))
for row in results:
@@ -86,7 +95,8 @@
""" Get all attributes """
results = self.__workloaddb.execute("select \
a.attribute_id, a.name, a.table_id, a.frequency, a.statistics, t.name \
- from attributes a, tables t where a.table_id = t.table_id and a.database = t.database and a.database = ?",
+ from attributes a, tables t where a.table_id = t.table_id \
+ and a.database = t.database and a.database = ? %s" % self.__timeframe.replace("$", "a"),
(self.__config.userdb,) )
for row in results:
@@ -99,7 +109,7 @@
results = self.__workloaddb.execute("select \
t.table_id, t.name, t.frequency, t.est_cpu, t.act_cpu, t.est_dio, t.act_dio, \
t.est_tup, t.act_tup, t.structure, t.data_pages, t.overflow_pages \
- from tables t where t.database = ?",
+ from tables t where t.database = ? %s" % self.__timeframe.replace("$", "t"),
(self.__config.userdb,) )
for row in results:
@@ -111,9 +121,10 @@
""" Get workload history data """
results = self.__workloaddb.execute("select \
- query_key, opf_cpu, opf_dio, qef_cpu, qef_dio, est_cpu, est_dio, pages_touched, time, wctime \
- from workload where database = ? \
- order by time",
+ w.query_key, w.opf_cpu, w.opf_dio, w.qef_cpu, w.qef_dio, \
+ w.est_cpu, w.est_dio, w.pages_touched, w.time, w.wctime \
+ from workload w where database = ? %s \
+ order by time" % self.__timeframe.replace("$", "w"),
(self.__config.userdb,) )
for row in results:
@@ -122,7 +133,7 @@
def __load_statements(self):
- result = self.__workloaddb.execute("select count(query_key) from statements");
+ result = self.__workloaddb.execute("select count(query_key) from statements s where 1 = 1 %s" % self.__timeframe.replace("$", "s"));
self.__workloadsize = result[0][0]
"""
@@ -136,8 +147,8 @@
from (select query_key, max(time) as time from workload where database = ? group by query_key) as t \
join workload w on t.query_key = w.query_key and t.time = w.time \
join statements s on s.query_key = w.query_key \
- where s.database = ? and w.database = s.database \
- order by frequency * (opf_cpu+opf_dio+qef_cpu+qef_dio) desc",
+ where s.database = ? and w.database = s.database %s \
+ order by frequency * (opf_cpu+opf_dio+qef_cpu+qef_dio) desc" % self.__timeframe.replace("$", "s"),
(self.__config.userdb, self.__config.userdb) )
count = 1
@@ -162,8 +173,8 @@
""" Get all tables used in this statement """
results = self.__workloaddb.execute("select \
t.table_id from tables t, references r where t.table_id = r.object_id and r.object_type = 0 \
- and r.query_key = ? and r.database = ? and t.database = r.database \
- order by t.frequency desc",
+ and r.query_key = ? and r.database = ? and t.database = r.database %s \
+ order by t.frequency desc" % self.__timeframe.replace("$", "t"),
(statement.query_key, self.__config.userdb))
table_references = []
@@ -182,8 +193,8 @@
results1 = self.__workloaddb.execute("select \
a.attribute_id, a.table_id from attributes a, references r where a.table_id = ? \
and a.table_id = r.table_id and a.attribute_id = r.object_id and r.object_type = 1 \
- and r.query_key = ? and r.database = ? and a.database = r.database \
- order by a.frequency desc",
+ and r.query_key = ? and r.database = ? and a.database = r.database %s \
+ order by a.frequency desc" % self.__timeframe.replace("$", "a"),
(table.id, statement.query_key, self.__config.userdb))
attr_list = []
@@ -199,8 +210,10 @@
""" Get indexes used in this statement """
results = self.__workloaddb.execute("select \
- i.index_id from indexes i, references r where i.index_id = r.object_id and r.object_type = 2 and r.query_key = ? \
- and r.database = ? and i.database = r.database and i.frequency > 0 order by i.frequency desc",
+ i.index_id from indexes i, references r where i.index_id = r.object_id \
+ and r.object_type = 2 and r.query_key = ? %s \
+ and r.database = ? and i.database = r.database \
+ and i.frequency > 0 order by i.frequency desc" % self.__timeframe.replace("$", "i"),
(statement.query_key, self.__config.userdb))
debug(" ## Used indexes:")
@@ -330,7 +343,7 @@
def __test_configuration(self):
- debug("## Testing new configuration")
+ output("## Testing new configuration")
""" Reset joinop timeout to default """
self.__userdb.execute("set joinop timeout")
@@ -386,7 +399,7 @@
results = self.__workloaddb.execute("select \
time, current_connections, current_sessions, max_sessions, total_rows, selects_processed, \
locks_per_tx, max_locks, locks_used, deadlocks, escalated_locks, lock_wait \
- from statistics order by time")
+ from statistics s where 1 = 1 %s order by time" % self.__timeframe.replace("$", "s"))
last_row = False
for row in results:
Modified: branches/advisor/src/front/misc/analyzedb/Config.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/Config.py 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/front/misc/analyzedb/Config.py 2008-08-18 09:22:05 UTC (rev 193)
@@ -8,6 +8,8 @@
querylimit = -1
timeout = 300000
userdb = ""
+ timefrom = False
+ timeto = False
config = Config()
Modified: branches/advisor/src/front/misc/analyzedb/Draw.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/Draw.py 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/front/misc/analyzedb/Draw.py 2008-08-18 09:22:05 UTC (rev 193)
@@ -15,7 +15,6 @@
self.gp.xlabel(xlabel)
self.gp.ylabel(ylabel)
self.gp.title(title)
- """self.gp("set yrange [1:]")"""
self.gp("set logscale y")
self.gp("set key box width 1 below")
Modified: branches/advisor/src/front/misc/analyzedb/Present.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/Present.py 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/front/misc/analyzedb/Present.py 2008-08-18 09:22:05 UTC (rev 193)
@@ -78,7 +78,7 @@
def start(self):
- debug("\n## Starting to prepare presentation")
+ output("\n## Preparing presentation")
self.__draw_graphs()
self.__render()
@@ -100,9 +100,9 @@
hour = [0, 0]
for wkl in self.__results.workload:
runtime.append([wkl.time,
- wkl.wctime])
+ wkl.wctime + 1])
coststime.append([wkl.time,
- (wkl.opf_cpu+wkl.opf_dio+wkl.qef_cpu+wkl.qef_dio) / 1000])
+ (wkl.opf_cpu+wkl.opf_dio+wkl.qef_cpu+wkl.qef_dio) / 1000 + 1])
if wkl.time > hour[0]+3600:
if hour[0] > 0:
usage.append([hour[0], hour[1]])
Modified: branches/advisor/src/front/misc/analyzedb/analyzedb
===================================================================
--- branches/advisor/src/front/misc/analyzedb/analyzedb 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/front/misc/analyzedb/analyzedb 2008-08-18 09:22:05 UTC (rev 193)
@@ -4,6 +4,7 @@
import pprint
import string
import os
+import time
import getopt
try:
""" Adding import path """
@@ -36,6 +37,12 @@
to analyse
(default: -1 = all)
+ --from=DDMMYY:HHMM Start of the analysis time frame
+ (default: no time limit)
+
+ --to=DDMMYY:HHMM End of the analysis time frame
+ (default: no time limit)
+
-t n, --timeout=n sets the joinop timeout in seconds
(default: 300 seconds)
@@ -65,7 +72,8 @@
argv = sys.argv[1:]
try:
- opts, args = getopt.gnu_getopt(argv, "hdl:t:o:v:", ["help", "debug", "limit=", "timeout=", "output=", "vnode="])
+ opts, args = getopt.gnu_getopt(argv, "hdl:t:o:v:",
+ ["help", "debug", "limit=", "timeout=", "output=", "vnode=", "to=", "from="])
except:
showusage()
error("Invalid arguments given")
@@ -89,8 +97,17 @@
error("Timeout needs a number as value")
elif opt in ("-v", "--vnode"):
config.vnode = arg
+ elif opt == "--from":
+ try:
+ config.timefrom = int(time.mktime(time.strptime(arg, "%d%m%y:%H%M")))
+ except:
+ error("Wrong data format - DDMMYY:HHMM expected")
+ elif opt == "--to":
+ try:
+ config.timeto = int(time.mktime(time.strptime(arg, "%d%m%y:%H%M")))
+ except:
+ error("Wrong data format - DDMMYY:HHMM expected")
-
analyze = Analyze(config)
analyze.start()
@@ -99,7 +116,9 @@
present = Present(results)
present.start()
+ output("Done.")
+
main()
Modified: branches/advisor/src/front/misc/analyzedb/functions.py
===================================================================
--- branches/advisor/src/front/misc/analyzedb/functions.py 2008-08-16 12:49:30 UTC (rev 192)
+++ branches/advisor/src/front/misc/analyzedb/functions.py 2008-08-18 09:22:05 UTC (rev 193)
@@ -13,4 +13,3 @@
output("Error: %s" % message)
sys.exit(1)
-
More information about the svn-commits
mailing list