[svn-commits] r185 - in branches/advisor/src/back/scf: hdr scm
thial01 at ingres.com
thial01 at ingres.com
Mon Aug 11 08:41:02 PDT 2008
Author: thial01
Date: 2008-08-11 08:41:02 -0700 (Mon, 11 Aug 2008)
New Revision: 185
Modified:
branches/advisor/src/back/scf/hdr/scd.h
branches/advisor/src/back/scf/hdr/scm.h
branches/advisor/src/back/scf/hdr/scmonitor.h
branches/advisor/src/back/scf/scm/scmima.c
branches/advisor/src/back/scf/scm/scmmain.c
branches/advisor/src/back/scf/scm/scmonitor.sc
branches/advisor/src/back/scf/scm/workloaddb.sql
Log:
Changing monitoring logic to include workload history - see #174
Modified: branches/advisor/src/back/scf/hdr/scd.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scd.h 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/hdr/scd.h 2008-08-11 15:41:02 UTC (rev 185)
@@ -111,7 +111,8 @@
/* This portion of the block is used by SCF */
SCS_SSCB scb_sscb; /* information for SCF */
SCC_CSCB scb_cscb; /* information used for communication */
- u_i4 scm_current_stmt; /* keeps the current statement id for scm */
+ PTR scm_current_stmt; /* keeps the current statement for scm */
+ /* Use PTR here so that we don't need scm.h */
}; /* typedef appears in forward section as well */
# ifdef __DECC
# pragma member_alignment restore
Modified: branches/advisor/src/back/scf/hdr/scm.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scm.h 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/hdr/scm.h 2008-08-11 15:41:02 UTC (rev 185)
@@ -16,18 +16,24 @@
**/
/*
-** Defines the maximum number of elements in the monitor arrays until
-** the they wrap around and overwrite the oldest values to form a
-** moving window
+** Defines the maximum number of elements in statements, tables,
+** attributes and indexes arrays until the they wrap around and
+** overwrite the oldest values to form a moving window
*/
-#define MAXMONITOR 500
+#define MAXMONITOR 500
/*
+** Defines the maximum number of workload entries to log the
+** history of statements executed
+*/
+#define MAXWORKLOAD 10000
+/*
** Defines the maximum length of query text to be stored
*/
#define MAXQUERYLEN 1000
/* IMA index definitions */
static char scm_stm_index_class[] = "exp.scf.scm.stm.index";
+static char scm_wkl_index_class[] = "exp.scf.scm.wkl.index";
static char scm_tab_index_class[] = "exp.scf.scm.tab.index";
static char scm_atr_index_class[] = "exp.scf.scm.atr.index";
static char scm_idx_index_class[] = "exp.scf.scm.idx.index";
@@ -49,7 +55,24 @@
char database[DB_MAXNAME];
u_i4 query_key;
char query_text[MAXQUERYLEN];
- u_i4 frequency;
+ i4 frequency;
+} SCM_STATEMENT;
+
+/*}
+** Name: SCM_WORKLOAD - Structure to hold workload data for monitoring
+**
+** Description:
+** This structure contains the sequence of statements
+** in the workload together with their cost data
+**
+** History:
+** 11-Aug-2008 (thial01)
+** Structur created
+*/
+typedef struct _SCM_WORKLOAD
+{
+ char database[DB_MAXNAME];
+ u_i4 query_key;
u_i4 opf_cpu;
u_i4 opf_dio;
u_i4 qef_cpu;
@@ -59,7 +82,7 @@
u_i4 pages_touched;
i4 time;
i4 wctime;
-} SCM_STATEMENT;
+} SCM_WORKLOAD;
/*}
** Name: SCM_TABLE - Structure to hold table data for monitoring
@@ -213,6 +236,9 @@
i4 cur_stm_idx; /* The position in the array */
/* Needed because of moving window */
+ SCM_WORKLOAD *workload[MAXWORKLOAD];
+ i4 cur_wkl_idx; /* The position in the array */
+
SCM_TABLE *tables[MAXMONITOR];
i4 cur_tab_idx; /* The position in the array */
Modified: branches/advisor/src/back/scf/hdr/scmonitor.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scmonitor.h 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/hdr/scmonitor.h 2008-08-11 15:41:02 UTC (rev 185)
@@ -23,6 +23,13 @@
u_i4 query_key;
char query_text[MAXQUERYLEN];
u_i4 frequency;
+} ESQL_SCM_STATEMENT;
+
+typedef struct _ESQL_SCM_WORKLOAD
+{
+ char server[DB_MAXNAME*2];
+ char database[DB_MAXNAME];
+ u_i4 query_key;
u_i4 opf_cpu;
u_i4 opf_dio;
u_i4 qef_cpu;
@@ -32,9 +39,8 @@
u_i4 pages_touched;
i4 time;
i4 wctime;
-} ESQL_SCM_STATEMENT;
+} ESQL_SCM_WORKLOAD;
-
typedef struct _ESQL_SCM_TABLE
{
char server[DB_MAXNAME*2];
@@ -115,6 +121,8 @@
typedef struct _ESQL_SCM
{
ESQL_SCM_STATEMENT statements[MAXMONITOR];
+
+ ESQL_SCM_WORKLOAD workload[MAXWORKLOAD];
ESQL_SCM_TABLE tables[MAXMONITOR];
Modified: branches/advisor/src/back/scf/scm/scmima.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmima.c 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/scm/scmima.c 2008-08-11 15:41:02 UTC (rev 185)
@@ -101,58 +101,81 @@
CL_OFFSETOF(SCM_STATEMENT, frequency), MOuintget, MOnoset,
0, MOidata_index
},
+ { 0 }
+};
+
+static MO_CLASS_DEF scf_scm_wkl_classes[] =
+{
+ {
+ MO_CDATA_CLASSID|MO_CDATA_INDEX, scm_wkl_index_class,
+ 0, MO_READ, 0,
+ 0, MOpvget, MOnoset,
+ 0, MOidata_index
+ },
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.opf_cpu",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, opf_cpu), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, opf_cpu), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.query_key",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, query_key), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, query_key), MOuintget, MOnoset,
0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.opf_dio",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, opf_dio), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, opf_dio), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.database",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, database), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, database), MOstrget, MOnoset,
0, MOidata_index
+ },
+ {
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.opf_cpu",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, opf_cpu), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, opf_cpu), MOuintget, MOnoset,
+ 0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.qef_cpu",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, qef_cpu), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, qef_cpu), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.opf_dio",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, opf_dio), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, opf_dio), MOuintget, MOnoset,
0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.qef_dio",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, qef_dio), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, qef_dio), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.qef_cpu",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, qef_cpu), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, qef_cpu), MOuintget, MOnoset,
0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.est_cpu",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, est_cpu), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, est_cpu), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.qef_dio",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, qef_dio), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, qef_dio), MOuintget, MOnoset,
0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.est_dio",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, est_dio), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, est_dio), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.est_cpu",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, est_cpu), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, est_cpu), MOuintget, MOnoset,
0, MOidata_index
+ },
+ {
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.est_dio",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, est_dio), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, est_dio), MOuintget, MOnoset,
+ 0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.pages_touched",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, pages_touched), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, pages_touched), MOuintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.pages_touched",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, pages_touched), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, pages_touched), MOuintget, MOnoset,
0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.time",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, time), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, time), MOintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.time",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, time), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, time), MOintget, MOnoset,
0, MOidata_index
},
{
- MO_CDATA_INDEX, "exp.scf.scm.stm.wctime",
- MO_SIZEOF_MEMBER(SCM_STATEMENT, wctime), MO_READ, scm_stm_index_class,
- CL_OFFSETOF(SCM_STATEMENT, wctime), MOintget, MOnoset,
+ MO_CDATA_INDEX, "exp.scf.scm.wkl.wctime",
+ MO_SIZEOF_MEMBER(SCM_WORKLOAD, wctime), MO_READ, scm_wkl_index_class,
+ CL_OFFSETOF(SCM_WORKLOAD, wctime), MOintget, MOnoset,
0, MOidata_index
},
{ 0 }
@@ -484,16 +507,11 @@
/* Make the MO classes known to MO */
MOclassdef(MAXI2, scf_scm_stm_classes);
+ MOclassdef(MAXI2, scf_scm_wkl_classes);
MOclassdef(MAXI2, scf_scm_tab_classes);
MOclassdef(MAXI2, scf_scm_atr_classes);
MOclassdef(MAXI2, scf_scm_idx_classes);
MOclassdef(MAXI2, scf_scm_ref_classes);
MOclassdef(MAXI2, scf_scm_ana_classes);
-
- /* Attach the singelton analyzer struct at server startup */
-/* char buf[80];
- MOptrout(0, (PTR)&Sc_main_cb->scm.analyze, sizeof(buf), buf);
- MOattach(MO_INSTANCE_VAR, scm_ana_index_class, buf, (PTR)&Sc_main_cb->scm.analyze);
- */
}
Modified: branches/advisor/src/back/scf/scm/scmmain.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmmain.c 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/scm/scmmain.c 2008-08-11 15:41:02 UTC (rev 185)
@@ -232,7 +232,8 @@
** Name: scm_get_cur_stmt - Get the current statement
**
** Description:
-** This functions returns the current statement
+** This functions returns a pointer to the the current
+** workload entry / statement being processed
**
** Inputs:
** none.
@@ -241,20 +242,17 @@
** none.
**
** Returns:
-** statement the struct of the current statement
+** workload the struct of the workload entry
**
** History:
** 24-Jun-2008 (thial01)
** created
*/
-SCM_STATEMENT*
+SCM_WORKLOAD*
scm_get_cur_stmt( VOID )
{
SCD_SCB *scb;
- SCM_STATEMENT *stmt;
- u_i4 key;
- char *db_name;
scb = scm_get_scb();
@@ -263,14 +261,8 @@
return NULL;
}
- db_name = scb->scb_sscb.sscb_ics.ics_dbname.db_db_name;
- key = scb->scm_current_stmt;
-
- /* Look up the key in the list of logged statements */
- stmt = scm_stmt_lookup(db_name, key);
-
- return stmt;
-
+ return (SCM_WORKLOAD*)scb->scm_current_stmt;
+
}
/*{
@@ -302,38 +294,55 @@
u_i4 hashkey;
SCM *scm;
SCM_STATEMENT *statement;
+ SCM_WORKLOAD *workload;
SCD_SCB *scb;
scb = scm_get_scb();
+ /* Reset the current statement */
+ scb->scm_current_stmt = NULL;
+
if (scm_check_analyze(scb))
{
/*
** The analyzer is running.
- ** Don't log anything - just clear the list
- ** of virtual indexes from the last statement
+ ** Don't log anything - just clear the struct
*/
- Sc_main_cb->scm.analyze.vindexes[0] = '\0';
+ MEfill(sizeof(SCM_ANALYZE), 0, &Sc_main_cb->scm.analyze);
return;
}
- scm = &Sc_main_cb->scm;
+ /* Name of the database we're connected to */
+ db_name = scb->scb_sscb.sscb_ics.ics_dbname.db_db_name;
+ /*
+ ** Check if this is a database where we don't want to log queries.
+ ** We're trying to be a little bit efficient here - i.e. we want to
+ ** avoid a string comparison
+ */
+ if ( db_name[0] == 'w'
+ ||
+ db_name[0] == 'i')
+ {
+ if ( STncmp(db_name, "workloaddb", DB_MAXNAME-1)
+ ||
+ STncmp(db_name, "imadb", DB_MAXNAME-1)
+ ||
+ STncmp(db_name, "iidbdb", DB_MAXNAME-1) )
+ {
+ /* Don't log this query */
+ return;
+ }
+ }
+
/* Plain text of the current query */
- query_text = scb->cs_scb.cs_diag_qry;
+ query_text = scb->cs_scb.cs_diag_qry;
- /* Name of the database we're connected to */
- db_name = scb->scb_sscb.sscb_ics.ics_dbname.db_db_name;
+ scm = &Sc_main_cb->scm;
/* The hash key of the statement */
hashkey = scm_hash(query_text);
- /*
- ** Place it into the session control block so that
- ** we always know what query we currently process
- */
- scb->scm_current_stmt = hashkey;
-
/* Look if we saw this query before */
statement = (SCM_STATEMENT*)scm_stmt_lookup(db_name, hashkey);
@@ -395,14 +404,69 @@
}
- /* Increment the counter */
- statement->frequency += 1;
- /* And update the time we saw the query */
+ /* How often did we saw this query */
+ statement->frequency++;
+
+ /*
+ ** Now create a new workload entry for this statement
+ ** but first let's see if we reached the boundary of the array
+ */
+ if (scm->cur_wkl_idx >= MAXMONITOR)
+ {
+ /*
+ ** Let's wrap around and start overwriting
+ ** the oldest entries in the array
+ */
+ scm->cur_wkl_idx = 0;
+
+ }
+
+ /* Second see if we need to overwrite an old workload entry */
+ SCM_WORKLOAD *old_wkl;
+ old_wkl = scm->workload[scm->cur_wkl_idx];
+ if (old_wkl != NULL)
+ {
+ MEfill(sizeof(SCM_WORKLOAD), 0, old_wkl);
+ workload = old_wkl;
+ } else {
+
+ workload = (SCM_WORKLOAD*)MEreqmem(0, sizeof(SCM_WORKLOAD),TRUE,&status);
+
+ if (status)
+ {
+ return;
+ }
+
+ /* And now attach the new workload entry to IMA */
+ char buf[80];
+ MOptrout(0, (PTR)workload, sizeof(buf), buf);
+ MOattach(MO_INSTANCE_VAR, scm_wkl_index_class, buf, (PTR)workload);
+
+ scm->workload[scm->cur_wkl_idx] = workload;
+ }
+
+ scm->cur_wkl_idx++;
+
+ workload->query_key = hashkey;
+ STncpy(workload->database, db_name, DB_MAXNAME);
+ workload->database[DB_MAXNAME-1] = '\0';
+
+ /* Set the time we saw the query */
SYSTIME now;
TMnow(&now);
- statement->time = now.TM_secs;
- /* And reset the wallclock for this query */
- statement->wctime = -1;
+ workload->time = now.TM_secs;
+ /*
+ ** And set the wallclock for this query to -1 so that
+ ** the analyzer knows if this query has completed
+ */
+ workload->wctime = -1;
+
+ /*
+ ** Place the pointer to the workload entry
+ ** into the session control block so that
+ ** we always know what query we currently process
+ */
+ scb->scm_current_stmt = (PTR)workload;
return;
@@ -435,7 +499,7 @@
TIMERSTAT *end )
{
- SCM_STATEMENT *stm;
+ SCM_WORKLOAD *stm;
/* Get the struct of the current statement */
stm = scm_get_cur_stmt();
@@ -481,7 +545,7 @@
TIMERSTAT *end )
{
- SCM_STATEMENT *stm;
+ SCM_WORKLOAD *stm;
/* Get the struct of the current statement */
stm = scm_get_cur_stmt();
@@ -556,7 +620,7 @@
return;
}
- SCM_STATEMENT *stm;
+ SCM_WORKLOAD *stm;
/* Get the struct of the current statement */
stm = scm_get_cur_stmt();
@@ -602,14 +666,19 @@
{
DB_STATUS status;
SCM *scm;
- SCM_STATEMENT *stm;
+ SCM_WORKLOAD *stm;
SCM_REFERENCE *references, *reference;
i4 i;
scm = &Sc_main_cb->scm;
- stm = NULL;
+ stm = scm_get_cur_stmt();
+ if (stm == NULL)
+ {
+ return;
+ }
+
/* See if we got this reference before */
for (i = 0; i < MAXMONITOR*2; i++)
{
@@ -623,54 +692,26 @@
&&
scm->references[i]->object_id == object_id
&&
- scm->references[i]->table_id == table_id )
+ scm->references[i]->table_id == table_id
+ &&
+ scm->references[i]->query_key == stm->query_key
+ &&
+ STncmp(scm->references[i]->database, stm->database, DB_MAXNAME-1) == 0 )
{
-
/*
- ** We may have found it.
- ** Now let's get the current statement
- ** for more comparisons
+ ** We found it.
+ ** We don't need to log it again
+ ** so we just return
*/
+ return;
- if (stm == NULL)
- {
- stm = scm_get_cur_stmt();
- }
-
- /* Still NULL? */
- if (stm == NULL)
- {
- /* Error - return without complaining */
- return;
- }
-
- if (
- scm->references[i]->query_key == stm->query_key
- &&
- STncmp(scm->references[i]->database, stm->database, DB_MAXNAME-1) == 0 )
- {
- /*
- ** We found it.
- ** We don't need to log it again
- ** so we just return
- */
- return;
- }
-
}
}
+ /* Log a new reference. */
+
/*
- ** Log a new reference.
- ** But we may already have the current statement
- */
- if (stm == NULL)
- {
- stm = scm_get_cur_stmt();
- }
-
- /*
** Now let's attach it to the monitor
** But first let's see if we reached the boundary of the array
*/
@@ -927,7 +968,10 @@
scb = scm_get_scb();
- if (scm_check_analyze(scb))
+ /* We are either in analyzer phase or do not log this query */
+ if ( scm_get_cur_stmt() == NULL
+ ||
+ scm_check_analyze(scb) )
{
return;
}
@@ -1001,7 +1045,10 @@
scb = scm_get_scb();
- if (scm_check_analyze(scb))
+ /* We are either in analyzer phase or do not log this query */
+ if ( scm_get_cur_stmt() == NULL
+ ||
+ scm_check_analyze(scb) )
{
return;
}
@@ -1149,7 +1196,10 @@
scb = scm_get_scb();
- if (scm_check_analyze(scb))
+ /* We are either in analyzer phase or do not log this query */
+ if ( scm_get_cur_stmt() == NULL
+ ||
+ scm_check_analyze(scb) )
{
return;
}
@@ -1227,7 +1277,10 @@
scb = scm_get_scb();
- if (scm_check_analyze(scb))
+ /* We are either in analyzer phase or do not log this query */
+ if ( scm_get_cur_stmt() == NULL
+ ||
+ scm_check_analyze(scb) )
{
return;
}
@@ -1364,7 +1417,10 @@
scb = scm_get_scb();
- if (scm_check_analyze(scb))
+ /* We are either in analyzer phase or do not log this query */
+ if ( scm_get_cur_stmt() == NULL
+ ||
+ scm_check_analyze(scb) )
{
return;
}
Modified: branches/advisor/src/back/scf/scm/scmonitor.sc
===================================================================
--- branches/advisor/src/back/scf/scm/scmonitor.sc 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/scm/scmonitor.sc 2008-08-11 15:41:02 UTC (rev 185)
@@ -71,7 +71,7 @@
**
**/
-// #define DEBUG
+#define DEBUG
/* Global definitions */
exec sql begin declare section;
@@ -81,9 +81,9 @@
exec sql end declare section;
/* How long do we sleep between wake-ups? */
-#define SLEEP 30000
+#define SLEEP 5000
/* How often do we wake up until we store data in workload DB? */
-#define ROUNDS 5
+#define ROUNDS 1
/* How often do we store until we delete old entries from the workload DB? */
#define DELOLD 5
/* And how old are the entries we delete (in seconds) */
@@ -124,13 +124,10 @@
/*
** Get all statements from IMADB for the given db_name
- ** but only those that have wallclock > -1
- ** i.e. those that have are done with execution
*/
exec sql declare stm cursor for
select * from ima_scm_statements
- where database = :db_name
- and wctime > -1;
+ where database = :db_name;
exec sql open stm for readonly;
@@ -191,7 +188,7 @@
i4 i;
exec sql begin declare section;
ESQL_SCM_STATEMENT statement;
- i4 time;
+ i4 frequency;
exec sql end declare section;
for (i = 0; i < MAXMONITOR; i++)
@@ -208,34 +205,26 @@
statement = scm->statements[i];
- time = 0;
+ frequency = 0;
- exec sql select time
- into :time
+ exec sql select frequency
+ into :frequency
from statements
where database = :db_name
and query_key = :statement.query_key;
/*
** Let's see if we saw this before
- ** and the timestamp is new so that
+ ** and the frequency is higher so that
** we need to update it or not
*/
- if (time > 0)
+ if (frequency > 0)
{
- if (statement.time > time)
+ if (statement.frequency > frequency)
{
exec sql update statements
set
- frequency = :statement.frequency,
- opf_cpu = :statement.opf_cpu,
- opf_dio = :statement.opf_dio,
- qef_cpu = :statement.qef_cpu,
- qef_dio = :statement.qef_dio,
- est_cpu = :statement.est_cpu,
- est_dio = :statement.est_dio,
- pages_touched = :statement.pages_touched,
- time = :statement.time
+ frequency = :statement.frequency
where database = :db_name
and query_key = :statement.query_key;
}
@@ -259,6 +248,152 @@
/*{
**
+** Name: get_workload() - read workload entries from IMA
+**
+** Description:
+** Read workload data from IMA DB
+**
+** Inputs:
+** none
+**
+** Outputs:
+** Returns:
+** none
+** Exceptions:
+**
+** History:
+** 11-Aug-2008 (thial01)
+** Created
+*/
+
+VOID
+get_workload( VOID )
+{
+
+#ifdef DEBUG
+ SIprintf("get_workload\n");
+#endif
+
+ exec sql begin declare section;
+ ESQL_SCM_WORKLOAD workload;
+ exec sql end declare section;
+
+ /*
+ ** Get all workload entries from IMADB for the given db_name
+ ** but only those that have wallclock > -1
+ ** i.e. those that have are done with execution
+ */
+ exec sql declare wkl cursor for
+ select * from ima_scm_workload
+ where database = :db_name
+ and wctime > -1;
+
+ exec sql open wkl for readonly;
+
+ i4 i = 0;
+
+ for (;;)
+ {
+ MEfill(sizeof(ESQL_SCM_WORKLOAD), 0, &workload);
+
+ exec sql fetch wkl into :workload;
+ if (sqlca.sqlcode == 100)
+ {
+ break;
+ }
+ else if (sqlca.sqlcode != 0)
+ {
+ SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+ PCexit(FAIL);
+ }
+
+ scm->workload[i++] = workload;
+
+ }
+
+ exec sql close stm;
+
+ return;
+}
+
+/*{
+**
+** Name: put_workload() - put workload entries to workload db
+**
+** Description:
+** Put workload data to the workload db
+**
+** Inputs:
+** none
+**
+** Outputs:
+** Returns:
+** none
+** Exceptions:
+**
+** History:
+** 11-Aug-2008 (thial01)
+** Created
+*/
+
+VOID
+put_workload( VOID )
+{
+
+#ifdef DEBUG
+ SIprintf("put_workload\n");
+#endif
+
+ i4 i;
+ exec sql begin declare section;
+ ESQL_SCM_WORKLOAD workload;
+ i4 count;
+ exec sql end declare section;
+
+ for (i = 0; i < MAXMONITOR; i++)
+ {
+ /*
+ ** We cannot check for workload == null here
+ ** as it is already allocated.
+ ** So use the server member instead
+ */
+ if (scm->workload[i].server[0] == '\0')
+ {
+ return;
+ }
+
+ workload = scm->workload[i];
+
+ count = 0;
+
+ exec sql select count(*)
+ into :count
+ from workload
+ where database = :db_name
+ and query_key = :workload.query_key;
+
+ /*
+ ** Let's see if we saw this before
+ */
+ if (count == 0)
+ {
+ exec sql insert into workload
+ values (:workload);
+ }
+
+ if (sqlca.sqlcode != 0)
+ {
+ SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+ PCexit(FAIL);
+ }
+
+ }
+
+ return;
+}
+
+/*{
+**
** Name: get_tables() - read tables from IMA
**
** Description:
@@ -1073,9 +1208,15 @@
time -= OLDENTRY;
+ exec sql delete from workload
+ where database = :db_name
+ and time < :time;
+
exec sql delete from statements
where database = :db_name
- and time < :time;
+ and query_key not in
+ (select query_key from workload
+ where database = :db_name);
exec sql delete from tables
where database = :db_name
@@ -1216,6 +1357,7 @@
** the esql preprocessor is a bit tricky
*/
get_statements();
+ get_workload();
get_tables();
get_attributes();
get_indexes();
@@ -1236,6 +1378,7 @@
exec sql set_sql(session = 2);
put_statements();
+ put_workload();
put_tables();
put_attributes();
put_indexes();
@@ -1256,7 +1399,10 @@
exec sql set_sql(session = 1);
}
-
+
+#ifdef DEBUG
+ SIprintf("Sleeping %d milliseconds\n", SLEEP);
+#endif
PCsleep(SLEEP);
/*
Modified: branches/advisor/src/back/scf/scm/workloaddb.sql
===================================================================
--- branches/advisor/src/back/scf/scm/workloaddb.sql 2008-08-09 17:11:11 UTC (rev 184)
+++ branches/advisor/src/back/scf/scm/workloaddb.sql 2008-08-11 15:41:02 UTC (rev 185)
@@ -6,6 +6,18 @@
query_key integer4 not null,
query_text varchar(1000) not null,
frequency integer4,
+ primary key (database, query_key)
+)
+\p\g
+
+modify statements to btree\p\g
+
+drop table workload\p\g
+
+create table workload (
+ server varchar(64) not null,
+ database varchar(32) not null,
+ query_key integer4 not null,
opf_cpu integer4,
opf_dio integer4,
qef_cpu integer4,
@@ -14,13 +26,10 @@
est_dio integer4,
pages_touched integer4,
time integer4,
- wctime integer4,
- primary key (database, query_key)
+ wctime integer4
)
\p\g
-modify statements to btree\p\g
-
drop table tables\p\g
create table tables (
@@ -112,10 +121,7 @@
deadlocks integer4 not null,
escalated_locks integer4 not null,
lock_wait integer4 not null,
- time integer4 not null,
- primary key(time)
+ time integer4 not null
)
\p\g
-modify statistics to btree\p\g
-
More information about the svn-commits
mailing list