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

thial01 at ingres.com thial01 at ingres.com
Fri Jul 4 08:42:43 PDT 2008


Author: thial01
Date: 2008-07-04 08:42:43 -0700 (Fri, 04 Jul 2008)
New Revision: 141

Added:
   branches/advisor/src/back/scf/hdr/scmonitor.h
Modified:
   branches/advisor/src/back/scf/hdr/scm.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:
Chaning memory management in the monitor code and continuing work on the daemon - see #174


Modified: branches/advisor/src/back/scf/hdr/scm.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scm.h	2008-07-03 15:22:01 UTC (rev 140)
+++ branches/advisor/src/back/scf/hdr/scm.h	2008-07-04 15:42:43 UTC (rev 141)
@@ -4,7 +4,7 @@
 */
 
 /**
-** Name: SCMMONITOR.H - This file contains the structs used by the design analyzer
+** Name: SCM.H - This file contains the structs used by the design analyzer
 ** 
 ** Description:
 **      This file contains the definitions of the structures used to
@@ -57,6 +57,7 @@
 	u_i4		est_cpu;
 	u_i4		est_dio;
 	u_i4		pages_touched;
+	i4			time;
 }   SCM_STATEMENT;
 
 /*}

Added: branches/advisor/src/back/scf/hdr/scmonitor.h
===================================================================
--- branches/advisor/src/back/scf/hdr/scmonitor.h	                        (rev 0)
+++ branches/advisor/src/back/scf/hdr/scmonitor.h	2008-07-04 15:42:43 UTC (rev 141)
@@ -0,0 +1,128 @@
+/*
+** Copyright (c) 2008 Ingres Corporation
+**
+*/
+
+/**
+** Name: SCMONITOR.HL - This file contains the structs used by the monitor daemon
+** 
+** Description:
+**      This file contains the esql definitions of the structures used by
+**      the monitor daemon.
+**	This is more or less a copy of scm.h but for esql 
+**
+** History:
+**	04-Jul-2008 (thial01)
+**	    File created
+**/
+
+typedef struct _ESQL_SCM_STATEMENT
+{
+	char		server[DB_MAXNAME*2];
+	char		database[DB_MAXNAME];
+	u_i4		query_key;
+	char		query_text[MAXQUERYLEN];
+	u_i4		frequency;
+	u_i4		opf_cpu;
+	u_i4		opf_dio;
+	u_i4		qef_cpu;
+	u_i4		qef_dio;
+	u_i4		est_cpu;
+	u_i4		est_dio;
+	u_i4		pages_touched;
+	i4			time;
+}   ESQL_SCM_STATEMENT;
+
+
+typedef struct _ESQL_SCM_TABLE
+{
+	char		server[DB_MAXNAME*2];	
+	char		database[DB_MAXNAME];
+	i4			table_id;
+	char		name[DB_MAXNAME];
+	u_i4		frequency;
+	char		statistics;
+	u_i4		est_cpu;
+	u_i4		act_cpu;
+	u_i4		est_dio;
+	u_i4		act_dio;
+	u_i4		est_tup;
+	u_i4		act_tup;
+	i4			structure;
+	u_i4		data_pages;
+	u_i4		overflow_pages;
+
+}   ESQL_SCM_TABLE;
+
+typedef struct _ESQL_SCM_ATTRIBUTE
+{
+	char	server[DB_MAXNAME*2];
+	char	database[DB_MAXNAME];
+	i4		attribute_id;
+	char	name[DB_MAXNAME];
+	i4		table_id;
+	u_i4	frequency;
+
+}   ESQL_SCM_ATTRIBUTE;
+
+
+typedef struct _ESQL_SCM_INDEX
+{
+	char		server[DB_MAXNAME*2];
+	char		database[DB_MAXNAME];
+	i4			index_id;
+	char		name[DB_MAXNAME];
+	i4			table_id;
+	i4			attribute_id;
+	u_i4		frequency;
+	i4			structure;
+	u_i4		data_pages;
+	u_i4		overflow_pages;
+
+}   ESQL_SCM_INDEX;
+
+
+typedef struct _ESQL_SCM_REFERENCE
+{
+	char	server[DB_MAXNAME*2];	
+	char	database[DB_MAXNAME];
+	u_i4	query_key;
+	i4		object_type;
+	i4		object_id;
+	i4		table_id;
+
+}   ESQL_SCM_REFERENCE;
+
+
+typedef struct _ESQL_SCM_STATISTICS
+{
+	char	server[DB_MAXNAME*2];	
+	char	database[DB_MAXNAME];
+	i4		hit_ratio;
+
+}   ESQL_SCM_STATISTICS;
+
+
+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];
+	i4					cur_sts_idx;	
+
+	
+}   ESQL_SCM;
+

Modified: branches/advisor/src/back/scf/scm/scmima.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmima.c	2008-07-03 15:22:01 UTC (rev 140)
+++ branches/advisor/src/back/scf/scm/scmima.c	2008-07-04 15:42:43 UTC (rev 141)
@@ -78,7 +78,7 @@
 	0, MOidata_index
     },
     {
-    MO_CDATA_INDEX, "exp.scf.scm.stm.hash",
+    MO_CDATA_INDEX, "exp.scf.scm.stm.query_key",
 	MO_SIZEOF_MEMBER(SCM_STATEMENT, query_key), MO_READ, scm_stm_index_class,
 	CL_OFFSETOF(SCM_STATEMENT, query_key), MOuintget, MOnoset,
 	0, MOidata_index
@@ -143,6 +143,12 @@
 	CL_OFFSETOF(SCM_STATEMENT, 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,
+	0, MOidata_index
+    },    
     { 0 }
 };
 
@@ -155,7 +161,7 @@
 	0, MOidata_index
     },
     {
-    MO_CDATA_INDEX, "exp.scf.scm.tab.id",
+    MO_CDATA_INDEX, "exp.scf.scm.tab.table_id",
 	MO_SIZEOF_MEMBER(SCM_TABLE, table_id), MO_READ, scm_tab_index_class,
 	CL_OFFSETOF(SCM_TABLE, table_id), MOintget, MOnoset,
 	0, MOidata_index
@@ -244,7 +250,7 @@
 	0, MOidata_index
     },
     {
-    MO_CDATA_INDEX, "exp.scf.scm.atr.id",
+    MO_CDATA_INDEX, "exp.scf.scm.atr.attribute_id",
 	MO_SIZEOF_MEMBER(SCM_ATTRIBUTE, attribute_id), MO_READ, scm_atr_index_class,
 	CL_OFFSETOF(SCM_ATTRIBUTE, attribute_id), MOintget, MOnoset,
 	0, MOidata_index
@@ -285,9 +291,9 @@
 	0, MOidata_index
     },
     {
-    MO_CDATA_INDEX, "exp.scf.scm.idx.id",
-	MO_SIZEOF_MEMBER(SCM_INDEX, attribute_id), MO_READ, scm_idx_index_class,
-	CL_OFFSETOF(SCM_INDEX, attribute_id), MOintget, MOnoset,
+    MO_CDATA_INDEX, "exp.scf.scm.idx.attribute_id",
+	MO_SIZEOF_MEMBER(SCM_INDEX, index_id), MO_READ, scm_idx_index_class,
+	CL_OFFSETOF(SCM_INDEX, index_id), MOintget, MOnoset,
 	0, MOidata_index
     },
     {

Modified: branches/advisor/src/back/scf/scm/scmmain.c
===================================================================
--- branches/advisor/src/back/scf/scm/scmmain.c	2008-07-03 15:22:01 UTC (rev 140)
+++ branches/advisor/src/back/scf/scm/scmmain.c	2008-07-04 15:42:43 UTC (rev 141)
@@ -292,25 +292,7 @@
 	if (!statement)
 	{
 		
-		statement = (SCM_STATEMENT*)MEreqmem(0, sizeof(SCM_STATEMENT),TRUE,&status);
-    
-		if (status)
-		{
-			/*
-			** We silently ignore the error.
-			** A failure in the monitor shouldn't stop query execution
-			*/ 
-			return;
-		}
-    
-        statement->query_key = hashkey;
-        STncpy(statement->database, db_name, DB_MAXNAME);
-        STncpy(statement->query_text, query_text, MAXQUERYLEN);
-        statement->database[DB_MAXNAME-1] = '\0';
-        statement->query_text[MAXQUERYLEN-1] = '\0';
-        statement->frequency = 1;
-        
-        /*
+		/*
         ** Now let's attach it to the monitor
         ** But first let's see if we reached the boundary of the array
         */
@@ -324,32 +306,52 @@
         	        	
         }
         	
-        /* Second see if we need to remove an old statement from memory */
+        /* Second see if we need to overwrite an old statement */
        	SCM_STATEMENT *old_stm;
        	old_stm = scm->statements[scm->cur_stm_idx];
        	if (old_stm != NULL) 
        	{
+        	MEfill(sizeof(SCM_STATEMENT), 0, old_stm);
+        	statement = old_stm;
+        } else {
+
+    		statement = (SCM_STATEMENT*)MEreqmem(0, sizeof(SCM_STATEMENT),TRUE,&status);
+        
+    		if (status)
+    		{
+    			/*
+    			** We silently ignore the error.
+    			** A failure in the monitor shouldn't stop query execution
+    			*/ 
+    			return;
+    		}
+        	
+        	/* Attach the new statement to IMA */
         	char buf[80];
-        	MOptrout(0, (PTR)old_stm, sizeof(buf), buf);
-        	MOdetach(scm_stm_index_class, buf);
-        	MEfree((PTR)old_stm);
+        	MOptrout(0, (PTR)statement, sizeof(buf), buf);
+        	MOattach(MO_INSTANCE_VAR, scm_stm_index_class, buf, (PTR)statement);
+        
+        	scm->statements[scm->cur_stm_idx] = statement;
         }
-       	
-       	/* And now attach the new statement to IMA */
-    	char buf[80];
-    	MOptrout(0, (PTR)statement, sizeof(buf), buf);
-    	MOattach(MO_INSTANCE_VAR, scm_stm_index_class, buf, (PTR)statement);
+
+        statement->query_key = hashkey;
+        STncpy(statement->database, db_name, DB_MAXNAME);
+        STncpy(statement->query_text, query_text, MAXQUERYLEN);
+        statement->database[DB_MAXNAME-1] = '\0';
+        statement->query_text[MAXQUERYLEN-1] = '\0';
+        statement->frequency = 0;
         
-        scm->statements[scm->cur_stm_idx] = statement;
-        
         /* Increment the current id */
         scm->cur_stm_idx++;
         
-	} else
-	{
-		/* We saw it before, so just increment the counter */
-		statement->frequency += 1;
 	}
+
+	/* Increment the counter */
+	statement->frequency += 1;
+	/* And update the time we saw the query */
+	SYSTIME now;
+	TMnow(&now);
+	statement->time = now.TM_secs; 
 	
 	return;
     
@@ -590,25 +592,7 @@
 	{
 		stm = scm_get_cur_stmt();
 	}
-
-	reference = (SCM_REFERENCE*)MEreqmem(0, sizeof(SCM_REFERENCE),TRUE,&status);
-    
-	if (status)
-	{
-		/*
-		** We silently ignore the error.
-		** A failure in the monitor shouldn't stop query execution
-		*/ 
-		return;
-	}
-    
-	reference->object_type = object_type;
-	reference->object_id = object_id;
-	reference->table_id = table_id;
-	reference->query_key = stm->query_key;
-	STncpy(reference->database, stm->database, DB_MAXNAME);
-	reference->database[DB_MAXNAME-1] = '\0';
-       
+           
 	/*
 	 ** Now let's attach it to the monitor
 	 ** But first let's see if we reached the boundary of the array
@@ -623,24 +607,41 @@
         	        	
 	}
         	
-	/* Second see if we need to remove an old reference from memory */
+	/* Second see if we need to overwrite an old reference */
 	SCM_REFERENCE *old_ref;
 	old_ref = scm->references[scm->cur_ref_idx];
 	if (old_ref != NULL) 
 	{
-        	char buf[80];
-        	MOptrout(0, (PTR)old_ref, sizeof(buf), buf);
-        	MOdetach(scm_ref_index_class, buf);
-        	MEfree((PTR)old_ref);
-	}
-       	
-	/* And now attach the new reference to IMA */
-	char buf[80];
-	MOptrout(0, (PTR)reference, sizeof(buf), buf);
-	MOattach(MO_INSTANCE_VAR, scm_ref_index_class, buf, (PTR)reference);
+		MEfill(sizeof(SCM_REFERENCE), 0, old_ref);
+        reference = old_ref;
+	} else {
+
+		reference = (SCM_REFERENCE*)MEreqmem(0, sizeof(SCM_REFERENCE),TRUE,&status);
+	    
+		if (status)
+		{
+			/*
+			** We silently ignore the error.
+			** A failure in the monitor shouldn't stop query execution
+			*/ 
+			return;
+		}
+
+		/* And now attach the new reference to IMA */
+		char buf[80];
+		MOptrout(0, (PTR)reference, sizeof(buf), buf);
+		MOattach(MO_INSTANCE_VAR, scm_ref_index_class, buf, (PTR)reference);
         
-	scm->references[scm->cur_ref_idx] = reference;
-        
+		scm->references[scm->cur_ref_idx] = reference;
+	}
+    
+	reference->object_type = object_type;
+	reference->object_id = object_id;
+	reference->table_id = table_id;
+	reference->query_key = stm->query_key;
+	STncpy(reference->database, stm->database, DB_MAXNAME);
+	reference->database[DB_MAXNAME-1] = '\0';
+	
 	/* Increment the current id */
 	scm->cur_ref_idx++;
         
@@ -716,26 +717,7 @@
 	}
 	
 	if (found == -1) 
-	{
-
-		table = (SCM_TABLE*)MEreqmem(0, sizeof(SCM_TABLE),TRUE,&status);
-    
-		if (status)
-		{
-			/*
-			** We silently ignore the error.
-			** A failure in the monitor shouldn't stop query execution
-			*/ 
-			return;
-		}
-    
-        table->table_id = table_id;
-        STncpy(table->database, db_name, DB_MAXNAME);
-        STncpy(table->name, name, DB_MAXNAME);
-        table->database[DB_MAXNAME-1] = '\0';
-        table->name[DB_MAXNAME-1] = '\0';
-        table->frequency = 0;
-        
+	{        
         /*
         ** Now let's attach it to the monitor
         ** But first let's see if we reached the boundary of the array
@@ -750,24 +732,41 @@
         	        	
         }
         	
-        /* Second see if we need to remove an old table from memory */
+        /* Second see if we need to overwrite an old table */
        	SCM_TABLE *old_tab;
        	old_tab = scm->tables[scm->cur_tab_idx];
        	if (old_tab != NULL) 
        	{
-        	char buf[80];
-        	MOptrout(0, (PTR)old_tab, sizeof(buf), buf);
-        	MOdetach(scm_tab_index_class, buf);
-        	MEfree((PTR)old_tab);
-        }
-       	
-       	/* And now attach the new table to IMA */
-    	char buf[80];
-    	MOptrout(0, (PTR)table, sizeof(buf), buf);
-    	MOattach(MO_INSTANCE_VAR, scm_tab_index_class, buf, (PTR)table);
+        	MEfill(sizeof(SCM_TABLE), 0, old_tab);
+        	table = old_tab;
+        } else {
+
+        	table = (SCM_TABLE*)MEreqmem(0, sizeof(SCM_TABLE),TRUE,&status);
         
-        scm->tables[scm->cur_tab_idx] = table;
+    		if (status)
+    		{
+    			/*
+    			** We silently ignore the error.
+    			** A failure in the monitor shouldn't stop query execution
+    			*/ 
+    			return;
+    		}
+
+    		/* And now attach the new table to IMA */
+    		char buf[80];
+    		MOptrout(0, (PTR)table, sizeof(buf), buf);
+    		MOattach(MO_INSTANCE_VAR, scm_tab_index_class, buf, (PTR)table);
         
+    		scm->tables[scm->cur_tab_idx] = table;
+        }
+
+        table->table_id = table_id;
+        STncpy(table->database, db_name, DB_MAXNAME);
+        STncpy(table->name, name, DB_MAXNAME);
+        table->database[DB_MAXNAME-1] = '\0';
+        table->name[DB_MAXNAME-1] = '\0';
+        table->frequency = 0;
+        
         /* Increment the current id */
         scm->cur_tab_idx++;
         
@@ -936,26 +935,7 @@
 	
 	if (found == -1) 
 	{
-
-		attribute = (SCM_ATTRIBUTE*)MEreqmem(0, sizeof(SCM_ATTRIBUTE),TRUE,&status);
-    
-		if (status)
-		{
-			/*
-			** We silently ignore the error.
-			** A failure in the monitor shouldn't stop query execution
-			*/ 
-			return;
-		}
-    
-        attribute->table_id = table_id;
-        attribute->attribute_id = attr_id;
-        STncpy(attribute->database, db_name, DB_MAXNAME);
-        STncpy(attribute->name, name, DB_MAXNAME);
-        attribute->database[DB_MAXNAME-1] = '\0';
-        attribute->name[DB_MAXNAME-1] = '\0';
-        attribute->frequency = 0;
-        
+		
         /*
         ** Now let's attach it to the monitor
         ** But first let's see if we reached the boundary of the array
@@ -970,24 +950,42 @@
         	        	
         }
         	
-        /* Second see if we need to remove an old attribute from memory */
+        /* Second see if we need to overwrite an old attribute */
        	SCM_ATTRIBUTE *old_atr;
        	old_atr = scm->attributes[scm->cur_atr_idx];
        	if (old_atr != NULL) 
        	{
-        	char buf[80];
-        	MOptrout(0, (PTR)old_atr, sizeof(buf), buf);
-        	MOdetach(scm_atr_index_class, buf);
-        	MEfree((PTR)old_atr);
-        }
-       	
-       	/* And now attach the new attribute to IMA */
-    	char buf[80];
-    	MOptrout(0, (PTR)attribute, sizeof(buf), buf);
-    	MOattach(MO_INSTANCE_VAR, scm_atr_index_class, buf, (PTR)attribute);
+        	MEfill(sizeof(SCM_ATTRIBUTE), 0, old_atr);
+        	attribute = old_atr;
+        } else {
+        	
+    		attribute = (SCM_ATTRIBUTE*)MEreqmem(0, sizeof(SCM_ATTRIBUTE),TRUE,&status);
         
-        scm->attributes[scm->cur_atr_idx] = attribute;
+    		if (status)
+    		{
+    			/*
+    			** We silently ignore the error.
+    			** A failure in the monitor shouldn't stop query execution
+    			*/ 
+    			return;
+    		}
         
+    		/* And now attach the new attribute to IMA */
+    		char buf[80];
+    		MOptrout(0, (PTR)attribute, sizeof(buf), buf);
+    		MOattach(MO_INSTANCE_VAR, scm_atr_index_class, buf, (PTR)attribute);
+        
+    		scm->attributes[scm->cur_atr_idx] = attribute;
+        }
+
+       	attribute->table_id = table_id;
+        attribute->attribute_id = attr_id;
+        STncpy(attribute->database, db_name, DB_MAXNAME);
+        STncpy(attribute->name, name, DB_MAXNAME);
+        attribute->database[DB_MAXNAME-1] = '\0';
+        attribute->name[DB_MAXNAME-1] = '\0';
+        attribute->frequency = 0;
+        
         /* Increment the current id */
         scm->cur_atr_idx++;
         
@@ -1079,32 +1077,7 @@
 		}
 	}
 	
-	index = (SCM_INDEX*)MEreqmem(0, sizeof(SCM_INDEX),TRUE,&status);
-    
-	if (status)
-	{
-		/*
-		** We silently ignore the error.
-		** A failure in the monitor shouldn't stop query execution
-		*/ 
-		return;
-	}
-    
-	index->index_id = index_id;
-	index->table_id = table_id;
-	index->attribute_id = attr_id;
-	STncpy(index->database, db_name, DB_MAXNAME);
-	STncpy(index->name, name, DB_MAXNAME);
-	index->database[DB_MAXNAME-1] = '\0';
-	index->name[DB_MAXNAME-1] = '\0';
 	/*
-	** If this index is never actually used
-	** this remains at 0 and we should remove 
-	** this unnecessary index
-	*/ 
-	index->frequency = 0;	
-        
-	/*
 	** Now let's attach it to the monitor
 	** But first let's see if we reached the boundary of the array
 	*/
@@ -1118,24 +1091,48 @@
         	        	
 	}
         	
-	/* Second see if we need to remove an old index from memory */
+	/* Second see if we need to overwrite an old index */
 	SCM_INDEX *old_idx;
 	old_idx = scm->indexes[scm->cur_idx_idx];
 	if (old_idx != NULL) 
 	{
+		MEfill(sizeof(SCM_INDEX), 0, old_idx);
+		index = old_idx;
+	} else {
+
+		index = (SCM_INDEX*)MEreqmem(0, sizeof(SCM_INDEX),TRUE,&status);
+	    
+		if (status)
+		{
+			/*
+			** We silently ignore the error.
+			** A failure in the monitor shouldn't stop query execution
+			*/ 
+			return;
+		}
+	    
+		/* And now attach the new index to IMA */
 		char buf[80];
-		MOptrout(0, (PTR)old_idx, sizeof(buf), buf);
-		MOdetach(scm_idx_index_class, buf);
-		MEfree((PTR)old_idx);
+		MOptrout(0, (PTR)index, sizeof(buf), buf);
+		MOattach(MO_INSTANCE_VAR, scm_idx_index_class, buf, (PTR)index);
+        
+		scm->indexes[scm->cur_idx_idx] = index;
 	}
-       	
-	/* And now attach the new index to IMA */
-	char buf[80];
-	MOptrout(0, (PTR)index, sizeof(buf), buf);
-	MOattach(MO_INSTANCE_VAR, scm_idx_index_class, buf, (PTR)index);
+	
+	index->index_id = index_id;
+	index->table_id = table_id;
+	index->attribute_id = attr_id;
+	STncpy(index->database, db_name, DB_MAXNAME);
+	STncpy(index->name, name, DB_MAXNAME);
+	index->database[DB_MAXNAME-1] = '\0';
+	index->name[DB_MAXNAME-1] = '\0';
+	/*
+	** If this index is never actually used
+	** this remains at 0 and we should remove 
+	** this unnecessary index
+	*/ 
+	index->frequency = 0;	
         
-	scm->indexes[scm->cur_idx_idx] = index;
-        
 	/* Increment the current id */
 	scm->cur_idx_idx++;
 

Modified: branches/advisor/src/back/scf/scm/scmonitor.sc
===================================================================
--- branches/advisor/src/back/scf/scm/scmonitor.sc	2008-07-03 15:22:01 UTC (rev 140)
+++ branches/advisor/src/back/scf/scm/scmonitor.sc	2008-07-04 15:42:43 UTC (rev 141)
@@ -78,96 +78,427 @@
 PROGRAM =	monitordb
 **/
 
+/* Global definitions */
+exec sql begin declare section;
+	char	db_name[DB_MAXNAME];
+	exec sql include '../hdr/scmonitor.h';
+	ESQL_SCM	*scm;
+exec sql end declare section;
+
+
 /*{
-** Name: scm_exit() -	exit handler for monitordb.
 **
-** Description:
-**        This is the exit handling routine for monitordb
+**  Name: get_statements() -   read statements from IMA
 **
-**	Inputs:
-**		status		the status with which we exit
+**  Description:
+**	Read statement data from IMA DB 
 **
-**	Outputs:
+**  Inputs:
 **		none
+**
+**  Outputs:
 **	Returns:
 **	    none
 **	Exceptions:
+**
+**  History:
+**      03-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+get_statements( VOID ) 
+{
+
+	exec sql begin declare section;
+		ESQL_SCM_STATEMENT statement;
+	exec sql end declare section;
+
+	/* Get all statements from IMADB for the given db_name */
+	exec sql declare stm cursor for
+		select * from ima_scm_statements
+			where database = :db_name;
+		
+	exec sql open stm for readonly;
+	
+    for (;;)
+    {
+        exec sql fetch stm into :statement;
+        if (sqlca.sqlcode == 100)
+        {
+            break;
+        }
+        else if (sqlca.sqlcode != 0)
+        {
+            SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+            PCexit(FAIL);
+        }
+        
+        /* See if we need to wrap around */
+        if (scm->cur_stm_idx > MAXMONITOR)
+        {
+        	scm->cur_stm_idx = 0;
+        }
+        
+        scm->statements[scm->cur_stm_idx] = statement;
+        scm->cur_stm_idx++;
+
+    }
+
+    exec sql close stm;
+
+	return;
+}
+
+/*{
+**
+**  Name: put_statements() -   put statements to workload db
+**
+**  Description:
+**	Put statement data to the workload db 
+**
+**  Inputs:
+**		none
+**
+**  Outputs:
+**	Returns:
 **	    none
+**	Exceptions:
 **
-** Side Effects:
+**  History:
+**      04-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+put_statements( VOID ) 
+{
+	i4		i;
+	exec sql begin declare section;
+		ESQL_SCM_STATEMENT	statement;
+		i4					time;
+	exec sql end declare section;
+
+    for (i = 0; i < MAXMONITOR; i++)
+    {
+    	/* 
+    	** We cannot check for statement == null here
+    	** as it is already allocated.
+    	** So use the server member instead
+    	*/
+        if (scm->statements[i].server[0] == '\0')
+        {
+        	return;
+        }
+        
+        statement = scm->statements[i];
+        
+        time = 0;
+        
+        exec sql select time
+        		into :time
+        		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
+        ** we need to update it or not
+        */
+        if (time > 0)
+        {
+        	if (statement.time > time)
+        	{
+        		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
+        			where database = :db_name
+        				and query_key = :statement.query_key;
+        	}
+        		        
+        } else
+        {
+        	exec sql insert into statements
+        		values (:statement);
+        }
+        	
+		if (sqlca.sqlcode != 0)
+        {
+            SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+            PCexit(FAIL);
+        }
+        
+    }
+
+	return;
+}
+
+/*{
+**
+**  Name: get_tables() -   read tables from IMA
+**
+**  Description:
+**	Read table data from IMA DB 
+**
+**  Inputs:
 **		none
-**	    
-** History:
-**	03-Jul-2008 (thial01)
-**	    Created.
+**
+**  Outputs:
+**	Returns:
+**	    none
+**	Exceptions:
+**
+**  History:
+**      04-Jul-2008 (thial01)
+**          Created
 */
+
 VOID
-scm_exit( STATUS status )
+get_tables( VOID ) 
 {
 
-	PCexit(status);
+	exec sql begin declare section;
+		ESQL_SCM_TABLE table;
+	exec sql end declare section;
 
+	/* Get all tables from IMADB for the given db_name */
+	exec sql declare tab cursor for
+		select * from ima_scm_tables
+			where database = :db_name;
+		
+	exec sql open tab for readonly;
+	
+    for (;;)
+    {
+        exec sql fetch tab into :table;
+        if (sqlca.sqlcode == 100)
+        {
+            break;
+        }
+        else if (sqlca.sqlcode != 0)
+        {
+            SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+            PCexit(FAIL);
+        }
+        
+        /* See if we need to wrap around */
+        if (scm->cur_tab_idx > MAXMONITOR)
+        {
+        	scm->cur_tab_idx = 0;
+        }
+        
+        scm->tables[scm->cur_tab_idx] = table;
+        scm->cur_tab_idx++;
+        
+    }
+
+    exec sql close tab;
+
+	return;
 }
 
 /*{
-** Name: scm_get_args()	-   parse the command line
 **
-** Description:
-**        This routine parses the command line 
+**  Name: get_attributes() -   read attributes from IMA
 **
-** Inputs:
-**	argc                Command line argument count.
-**	argv				Command line argument vector.
+**  Description:
+**	Read attribute data from IMA DB 
 **
-** Outputs:
+**  Inputs:
 **		none
 **
+**  Outputs:
 **	Returns:
-**	    OK			Completed successfully.
-**		FAIL		Error
+**	    none
+**	Exceptions:
 **
+**  History:
+**      04-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+get_attributes( VOID ) 
+{
+
+	exec sql begin declare section;
+		ESQL_SCM_ATTRIBUTE attribute;
+	exec sql end declare section;
+
+	/* Get all attributes from IMADB for the given db_name */
+	exec sql declare atr cursor for
+		select * from ima_scm_attributes
+			where database = :db_name;
+		
+	exec sql open atr for readonly;
+	
+    for (;;)
+    {
+        exec sql fetch atr into :attribute;
+        if (sqlca.sqlcode == 100)
+        {
+            break;
+        }
+        else if (sqlca.sqlcode != 0)
+        {
+            SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+            PCexit(FAIL);
+        }
+        
+        /* See if we need to wrap around */
+        if (scm->cur_atr_idx > MAXMONITOR)
+        {
+        	scm->cur_atr_idx = 0;
+        }
+        
+        scm->attributes[scm->cur_atr_idx] = attribute;
+        scm->cur_atr_idx++;
+
+    }
+
+    exec sql close atr;
+
+	return;
+}
+
+/*{
+**
+**  Name: get_indexes() -   read indexes from IMA
+**
+**  Description:
+**	Read index data from IMA DB 
+**
+**  Inputs:
+**		none
+**
+**  Outputs:
+**	Returns:
+**	    none
 **	Exceptions:
-**	    none
 **
-** Side Effects:
+**  History:
+**      04-Jul-2008 (thial01)
+**          Created
+*/
+
+VOID
+get_indexes( VOID ) 
+{
+
+	exec sql begin declare section;
+		ESQL_SCM_INDEX index;
+	exec sql end declare section;
+
+	/* Get all indexes from IMADB for the given db_name */
+	exec sql declare idx cursor for
+		select * from ima_scm_indexes
+			where database = :db_name;
+		
+	exec sql open idx for readonly;
+	
+    for (;;)
+    {
+        exec sql fetch idx into :index;
+        if (sqlca.sqlcode == 100)
+        {
+            break;
+        }
+        else if (sqlca.sqlcode != 0)
+        {
+            SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+            PCexit(FAIL);
+        }
+        
+        /* See if we need to wrap around */
+        if (scm->cur_idx_idx > MAXMONITOR)
+        {
+        	scm->cur_idx_idx = 0;
+        }
+        
+        scm->indexes[scm->cur_idx_idx] = index;
+        scm->cur_idx_idx++;
+
+    }
+
+    exec sql close idx;
+
+	return;
+}
+
+/*{
+**
+**  Name: get_references() -   read references from IMA
+**
+**  Description:
+**	Read reference data from IMA DB 
+**
+**  Inputs:
+**		none
+**
+**  Outputs:
+**	Returns:
 **	    none
+**	Exceptions:
 **
-** History:
-**	03-Jul-2008 (thial01)
-**	    Created.
+**  History:
+**      04-Jul-2008 (thial01)
+**          Created
 */
-STATUS
-scm_get_args( 
-		i4 		argc, 
-		char	*argv[] )
+
+VOID
+get_references( VOID ) 
 {
-	char		*p;
+
+	exec sql begin declare section;
+		ESQL_SCM_REFERENCE reference;
+	exec sql end declare section;
+
+	/* Get all references from IMADB for the given db_name */
+	exec sql declare ref cursor for
+		select * from ima_scm_references
+			where database = :db_name;
+		
+	exec sql open ref for readonly;
 	
-    while (--argc)
+    for (;;)
     {
-    	p   = *(++argv);
-    	switch (p[0])
-    	{
-    		case '-':
-    			switch (p[1])
-    			{
-    				case 's':
-    					break;
-    				case 'e':
-    					break;
-    			}
+        exec sql fetch ref into :reference;
+        if (sqlca.sqlcode == 100)
+        {
+            break;
+        }
+        else if (sqlca.sqlcode != 0)
+        {
+            SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+            PCexit(FAIL);
+        }
+        
+        /* See if we need to wrap around */
+        if (scm->cur_ref_idx > MAXMONITOR)
+        {
+        	scm->cur_ref_idx = 0;
+        }
+        
+        scm->references[scm->cur_ref_idx] = reference;
+        scm->cur_ref_idx++;
 
-    		default:
-    			/* Must be a database name parameter */
-    			
-    			break;
-    	}
+    }
 
-	}  
+    exec sql close ref;
 
-    return(OK);
+	return;
 }
 
+
 /*{
 **
 **  Name: main() -   main entry point to the tool.
@@ -203,68 +534,84 @@
 **          Created
 */
 
+i4
 main( 
 	i4 		argc, 
 	char	*argv[] )
 {
 
+	DB_STATUS status;
+
     (void)EXsetclient(EX_INGRES_TOOL);
 
     MEadvise(ME_INGRES_ALLOC); 
 
-	/* Process the command line to get all the necessary parameters */
-
-	if (scm_get_args(argc, argv) != OK)
+	/* Process the command line to get all the necessary parameters */	
+/*    if (argc != 2)
+    {
+    	SIprintf("Invalid number of parameters given\n");
+    	SIprintf("Usage:\n");
+    	SIprintf("  %s database_name\n", argv[0]);
+    	PCexit(FAIL);
+    }
+  			
+	STncpy(db_name, argv[1], DB_MAXNAME);*/
+	STprintf(db_name, "test");
+    db_name[DB_MAXNAME-1] = '\0';
+    
+    /* Let's see if the database is valid */
+    exec sql connect :db_name;
+	if (sqlca.sqlcode != 0)
 	{
-	    scm_exit(FAIL);
+		SIprintf("Error: %s\n", sqlca.sqlerrm.sqlerrmc);
+		PCexit(FAIL);
 	}
 
+	exec sql disconnect;
+
 	/* Let's fork as a daemon */
-	i4 pid;
-	DB_STATUS status;
+/*	i4 pid;
+	
 	switch (pid = PCfork(&status))
 	{
 		case -1:
 			status = errno;
 			SIprintf("Fork failed\n");
-			scm_exit(FAIL);
+			PCexit(FAIL);
 		case 0:
 			break;
 		default:
-			scm_exit(OK);
+			PCexit(OK);
 	}
+	*/
 	
-	exec sql begin declare section;
-	char	buf[1024];
-	exec sql end declare section;
+	/* Create the data container */
+	scm = (ESQL_SCM*)MEreqmem(0, sizeof(ESQL_SCM),TRUE,&status);
+
+	//PCsleep(1000);
 	
-	exec sql whenever sqlerror stop;
-	exec sql connect imadb;
+	exec sql whenever sqlerror stop;		
+	exec sql connect imadb session 1;	/* Session 1 is for IMADB */
+	exec sql set_sql(session = 1);
+	exec sql set autocommit on;
 	
-	exec sql declare cur1 cursor for
-		select value from ima_mib_objects;
-		
-	exec sql open cur1 for readonly;
+	/* 
+	** Get the data from IMA.
+	** Should have been one function but 
+	** the esql preprocessor is a bit tricky
+	*/
+	get_statements();
+	get_tables();
+	get_attributes();
+	get_indexes();
+	get_references();
 	
-    for (;;)
-    {
-        exec sql fetch cur1 into :buf;
-        if (sqlca.sqlcode == 100)
-        {
-            break;
-        }
-        else if (sqlca.sqlcode != 0)
-        {
-            scm_exit(FAIL);
-            break;
-        }
-        SIprintf("%s\n", buf);
-    }
-
-    exec sql close cur1;
-
-
+	exec sql connect workloaddb session 2;	/* Session 2 for the workload db */
+	exec sql set autocommit on;
 	
-    scm_exit(OK);
+	put_statements();
+	
+	
+    PCexit(OK);
 }
 




More information about the svn-commits mailing list