[svn-commits] r143 - in branches/advisor/src/back/scf: hdr scm

thial01 at ingres.com thial01 at ingres.com
Sun Jul 6 06:17:48 PDT 2008


Author: thial01
Date: 2008-07-06 06:17:48 -0700 (Sun, 06 Jul 2008)
New Revision: 143

Modified:
   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
Log:
Some changes to the monitor daemon - see #174


Modified: branches/advisor/src/back/scf/hdr/scm.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scm.h	2008-07-05 20:56:16 UTC (rev 142)
+++ branches/advisor/src/back/scf/hdr/scm.h	2008-07-06 13:17:48 UTC (rev 143)
@@ -165,6 +165,7 @@
 	i4		object_type;
 	i4		object_id;
 	i4		table_id;	/* Needed to reference the correct attribute */
+	i4		time;
 
 }   SCM_REFERENCE;
 

Modified: branches/advisor/src/back/scf/hdr/scmonitor.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scmonitor.h	2008-07-05 20:56:16 UTC (rev 142)
+++ branches/advisor/src/back/scf/hdr/scmonitor.h	2008-07-06 13:17:48 UTC (rev 143)
@@ -90,15 +90,15 @@
 	i4		object_type;
 	i4		object_id;
 	i4		table_id;
-
+	i4		time;
 }   ESQL_SCM_REFERENCE;
 
 
 typedef struct _ESQL_SCM_STATISTICS
 {
 	char	server[DB_MAXNAME*2];	
-	char	database[DB_MAXNAME];
-	i4		hit_ratio;
+	i4		current_connections;
+	i4		highwater_connections;
 
 }   ESQL_SCM_STATISTICS;
 
@@ -106,21 +106,16 @@
 typedef struct _ESQL_SCM
 {
 	ESQL_SCM_STATEMENT	statements[MAXMONITOR];
-	i4					cur_stm_idx;
 
 	ESQL_SCM_TABLE		tables[MAXMONITOR];
-	i4					cur_tab_idx;
 
 	ESQL_SCM_ATTRIBUTE	attributes[MAXMONITOR];
-	i4					cur_atr_idx;
 
 	ESQL_SCM_INDEX		indexes[MAXMONITOR];
-	i4					cur_idx_idx;
 
 	ESQL_SCM_REFERENCE	references[MAXMONITOR*2];
-	i4					cur_ref_idx;
 	
-	ESQL_SCM_STATISTICS	statistics[MAXMONITOR/2];
+	ESQL_SCM_STATISTICS	statistics[MAXMONITOR];
 	i4					cur_sts_idx;	
 
 	

Modified: branches/advisor/src/back/scf/scm/scmima.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmima.c	2008-07-05 20:56:16 UTC (rev 142)
+++ branches/advisor/src/back/scf/scm/scmima.c	2008-07-06 13:17:48 UTC (rev 143)
@@ -409,6 +409,12 @@
 	CL_OFFSETOF(SCM_REFERENCE, table_id), MOintget, MOnoset,
 	0, MOidata_index
     },    
+    {
+    MO_CDATA_INDEX, "exp.scf.scm.ref.time",
+	MO_SIZEOF_MEMBER(SCM_REFERENCE, time), MO_READ, scm_ref_index_class,
+	CL_OFFSETOF(SCM_REFERENCE, time), MOintget, MOnoset,
+	0, MOidata_index
+    },
     { 0 }
 };
 

Modified: branches/advisor/src/back/scf/scm/scmmain.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmmain.c	2008-07-05 20:56:16 UTC (rev 142)
+++ branches/advisor/src/back/scf/scm/scmmain.c	2008-07-06 13:17:48 UTC (rev 143)
@@ -642,6 +642,10 @@
 	STncpy(reference->database, stm->database, DB_MAXNAME);
 	reference->database[DB_MAXNAME-1] = '\0';
 	
+	SYSTIME now;
+	TMnow(&now);
+	reference->time = now.TM_secs; 	
+	
 	/* Increment the current id */
 	scm->cur_ref_idx++;
         

Modified: branches/advisor/src/back/scf/scm/scmonitor.sc
===================================================================
--- branches/advisor/src/back/scf/scm/scmonitor.sc	2008-07-05 20:56:16 UTC (rev 142)
+++ branches/advisor/src/back/scf/scm/scmonitor.sc	2008-07-06 13:17:48 UTC (rev 143)
@@ -78,7 +78,7 @@
 PROGRAM =	monitordb
 **/
 
-#undef		DEBUG	
+// #define		DEBUG	
 
 /* Global definitions */
 exec sql begin declare section;
@@ -89,9 +89,14 @@
 
 /* How long do we sleep between wake-ups? */
 #define		SLEEP		30000
-/* How often do we wake up until we store data in workload db? */
+/* How often do we wake up until we store data in workload DB? */
 #define		ROUNDS		10
+/* 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) */
+#define		OLDENTRY	60*60*24
 
+
 /*{
 **
 **  Name: get_statements() -   read statements from IMA
@@ -886,6 +891,194 @@
 
 /*{
 **
+**  Name: get_statistics() -   read statistics from IMA
+**
+**  Description:
+**	Read statistcs data from IMA DB 
+**
+**  Inputs:
+**		none
+**
+**  Outputs:
+**	Returns:
+**	    none
+**	Exceptions:
+**
+**  History:
+**      06-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+get_statistics( VOID ) 
+{
+
+#ifdef DEBUG 
+	SIprintf("get_statistics\n");
+#endif
+
+	exec sql begin declare section;
+		ESQL_SCM_STATISTICS statistics;
+	exec sql end declare section;
+
+   	MEfill(sizeof(ESQL_SCM_STATISTICS), 0, &statistics);
+
+	/* Get all statistics from IMADB for the given db_name */
+	exec sql select * 
+			into :statistics
+			from ima_scm_statistics;
+		
+	if (sqlca.sqlcode != 100 && sqlca.sqlcode != 0)
+	{
+		SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+		PCexit(FAIL);
+	}
+        
+	scm->statistics[scm->cur_sts_idx++] = statistics;
+
+	return;
+}
+
+/*{
+**
+**  Name: put_statistics() -   put statistics to workload db
+**
+**  Description:
+**	Put statistics data to the workload db 
+**
+**  Inputs:
+**		none
+**
+**  Outputs:
+**	Returns:
+**	    none
+**	Exceptions:
+**
+**  History:
+**      06-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+put_statistics( VOID ) 
+{
+
+#ifdef DEBUG 
+	SIprintf("put_statistics\n");
+#endif
+
+	i4		i;
+	exec sql begin declare section;
+		ESQL_SCM_STATISTICS	statistics;
+		i4					time;
+	exec sql end declare section;	
+
+	if (scm->cur_sts_idx == 0) 
+	{
+		return;
+	}
+
+    for (i = 0; i < scm->cur_sts_idx; i++)
+    {
+        
+        /* Use the highest value we've seen so far */
+        if (scm->statistics[i].highwater_connections > statistics.highwater_connections) 
+        {
+        	statistics.highwater_connections = scm->statistics[i].highwater_connections;
+        }
+        
+        /* Use the latest value we've seen */
+        if (i == scm->cur_sts_idx - 1) 
+        {
+        	statistics.current_connections = scm->statistics[i].current_connections;
+        	STprintf(statistics.server, scm->statistics[i].server);
+        }
+	}
+	
+	scm->cur_sts_idx = 0;
+	
+	SYSTIME now;
+	TMnow(&now);
+	time = now.TM_secs; 	
+	
+   	exec sql insert into statistics
+   		values (:statistics, :time);
+        	
+	if (sqlca.sqlcode != 0)
+	{
+		SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+		PCexit(FAIL);
+	}
+    
+	return;
+}
+
+/*{
+**
+**  Name: delete_old() -   remove old entries from workload db
+**
+**  Description:
+**	Deletes old entries from the workload db 
+**
+**  Inputs:
+**		none
+**
+**  Outputs:
+**	Returns:
+**	    none
+**	Exceptions:
+**
+**  History:
+**      06-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+delete_old( VOID ) 
+{
+
+#ifdef DEBUG 
+	SIprintf("delete_old\n");
+#endif
+
+	exec sql begin declare section;
+		i4		time;
+	exec sql end declare section;
+	
+	SYSTIME now;
+	TMnow(&now);
+	time = now.TM_secs;
+	
+	time -= OLDENTRY; 	
+		
+		exec sql delete from statements
+			where database = :db_name
+				and time < :time;
+				
+		exec sql delete from tables
+			where database = :db_name
+				and time < :time;
+
+		exec sql delete from attributes
+			where database = :db_name
+				and time < :time;
+
+		exec sql delete from indexes
+			where database = :db_name
+				and time < :time;
+
+		exec sql delete from references
+			where database = :db_name
+				and time < :time;
+				
+		exec sql delete from statistics
+			where time < :time;
+
+	return;
+}
+
+/*{
+**
 **  Name: main() -   main entry point to the tool.
 **
 **  Description:
@@ -900,7 +1093,6 @@
 **
 **	Diagnostics:
 **		No database name specified.
-**		You are not a valid INGRES user
 **
 **  Inputs:
 **      argc                The command line argument count.
@@ -988,6 +1180,7 @@
 	exec sql set_sql(session = 1);
 	
 	i4	round = 0;
+	i4	delold = 0;
 	
 	/* Main loop */
 	while(1)
@@ -1007,8 +1200,8 @@
 		get_attributes();
 		get_indexes();
 		get_references();
+		get_statistics();
 	
-	
 		if (++round > ROUNDS)
 		{
 #ifdef DEBUG 
@@ -1027,7 +1220,18 @@
 			put_attributes();
 			put_indexes();
 			put_references();
+			put_statistics();
 			
+			/* 
+			** Let's delete old entries
+			** to avoid an infinitely growing DB
+			*/
+			if (++delold > DELOLD)
+			{
+				delete_old();
+				delold = 0;
+			}
+			
 			/* Switch back to IMADB session */
 			exec sql set_sql(session = 1);
 			




More information about the svn-commits mailing list