MyDDAS: Enhanced the MyDDAS interface Statistics capabilities
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1501 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
8e15cd2bcf
commit
f62f62537b
@ -114,6 +114,12 @@ c_db_my_query(void) {
|
||||
int length=strlen(sql);
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
||||
|
||||
/* Count the number of querys made to the server */
|
||||
unsigned long number_querys = myddas_util_get_conn_number_querys_made(node);
|
||||
myddas_util_set_conn_number_querys_made(node,++number_querys);
|
||||
|
||||
/* Measure time spent by the MySQL Server
|
||||
processing the SQL Query */
|
||||
unsigned long start,end,total_time,last_time;
|
||||
@ -134,7 +140,6 @@ c_db_my_query(void) {
|
||||
processing the SQL Query */
|
||||
end = myddas_current_time();
|
||||
|
||||
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
||||
last_time = (end-start);
|
||||
total_time = last_time + myddas_util_get_conn_total_time_DBServer(node);
|
||||
|
||||
@ -143,7 +148,7 @@ c_db_my_query(void) {
|
||||
#endif
|
||||
|
||||
/* guardar os tuplos do lado do cliente */
|
||||
if (strcmp(mode,"store_result")!=0) //Verdadeiro
|
||||
if (strcmp(mode,"store_result")!=0) //True
|
||||
res_set = mysql_use_result(conn);
|
||||
else{
|
||||
|
||||
@ -178,6 +183,24 @@ c_db_my_query(void) {
|
||||
unsigned long numberRows = mysql_num_rows(res_set);
|
||||
numberRows = numberRows + myddas_util_get_conn_total_rows(node);
|
||||
myddas_util_set_conn_total_rows(node,numberRows);
|
||||
|
||||
/* Calculate the ammount of data sent by the server */
|
||||
unsigned long int total,number_fields = mysql_num_fields(res_set);
|
||||
MYSQL_ROW row;
|
||||
unsigned int i;
|
||||
total=0;
|
||||
while ((row = mysql_fetch_row(res_set)) != NULL){
|
||||
mysql_field_seek(res_set,0);
|
||||
|
||||
for(i=0;i<number_fields;i++){
|
||||
if (row[i] != NULL)
|
||||
total = total + strlen(row[i]);
|
||||
}
|
||||
}
|
||||
myddas_util_set_conn_last_bytes_transfering_from_DBserver(node,total);
|
||||
total = total + myddas_util_get_conn_total_bytes_transfering_from_DBserver(node);
|
||||
myddas_util_set_conn_total_bytes_transfering_from_DBserver(node,total);
|
||||
mysql_data_seek(res_set,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -229,9 +252,12 @@ c_db_my_number_of_fields(void) {
|
||||
/* guardar os tuplos do lado do cliente */
|
||||
if ((res_set = mysql_store_result(conn)) == NULL)
|
||||
{
|
||||
printf("Query vazia!\n");
|
||||
#ifdef DEBUG
|
||||
printf("Erro na query! %s\n",sql);
|
||||
#endif
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Yap_unify(arg_fields, MkIntegerTerm(mysql_num_rows(res_set)))){
|
||||
mysql_free_result(res_set);
|
||||
@ -419,6 +445,7 @@ c_db_my_row(void) {
|
||||
MYSQL_ROW row;
|
||||
MYSQL_FIELD *field;
|
||||
|
||||
|
||||
Term head, list, null_atom[1];
|
||||
int i, arity;
|
||||
|
||||
@ -517,7 +544,9 @@ c_db_my_number_of_fields_in_query(void) {
|
||||
/* guardar os tuplos do lado do cliente */
|
||||
if ((res_set = mysql_store_result(conn)) == NULL)
|
||||
{
|
||||
printf("Query vazia!\n");
|
||||
#ifdef DEBUG
|
||||
printf("Erro na query! %s\n",query);
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -192,10 +192,11 @@ c_db_stats(void) {
|
||||
Term arg_list = Deref(ARG2);
|
||||
|
||||
int *conn = (int *) (IntegerOfTerm(arg_conn));
|
||||
|
||||
//if (conn == 0) /* We want all the statistics */
|
||||
|
||||
|
||||
// TODO
|
||||
if (get_myddas_top() == 0 ){ /* We want all the statistics */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
MYDDAS_UTIL_CONNECTION
|
||||
node = myddas_util_search_connection(conn);
|
||||
@ -263,6 +264,35 @@ c_db_stats(void) {
|
||||
printf ("Time Spent by the db_row_function: %lu\n",db_row);
|
||||
#endif
|
||||
|
||||
//[Index 7] -> Total of Bytes Transfered by the
|
||||
// DB Server on all SQL Querys
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long totalBytes = myddas_util_get_conn_total_bytes_transfering_from_DBserver(node);
|
||||
Yap_unify(head, MkIntegerTerm(totalBytes));
|
||||
#ifdef DEBUG
|
||||
printf ("Bytes Transfered by the DB Server from all querys: %lu\n",totalBytes);
|
||||
#endif
|
||||
|
||||
//[Index 8] -> Total of Bytes Transfered by the
|
||||
// DB Server on the last SQL Query
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long lastBytes = myddas_util_get_conn_last_bytes_transfering_from_DBserver(node);
|
||||
Yap_unify(head, MkIntegerTerm(lastBytes));
|
||||
#ifdef DEBUG
|
||||
printf ("Bytes Transfered by the DB Server on the last query: %lu\n",lastBytes);
|
||||
#endif
|
||||
|
||||
//[Index 9] -> Number of querys made to the DBserver
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long number_querys = myddas_util_get_conn_number_querys_made(node);
|
||||
Yap_unify(head, MkIntegerTerm(number_querys));
|
||||
#ifdef DEBUG
|
||||
printf ("Number of Querys made to the server: %lu\n",number_querys);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,15 @@ struct list_connection {
|
||||
transfering the data of the last query */
|
||||
unsigned long lastFromDBServer;
|
||||
|
||||
/* Last bytes transfered from the server */
|
||||
unsigned long totalBytesTransfered;
|
||||
/* Total bytes transfered from the server */
|
||||
unsigned long lastBytesTransfered;
|
||||
|
||||
/* Total Time spent on the db_row function */
|
||||
unsigned long total_db_row;
|
||||
|
||||
unsigned long total_querys_made;
|
||||
#endif
|
||||
MYDDAS_UTIL_PREDICATE predicates;
|
||||
struct list_connection *next;
|
||||
|
@ -126,6 +126,33 @@ myddas_util_set_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node
|
||||
node->totalFromDBServer = totaltime;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node){
|
||||
return node->lastBytesTransfered;
|
||||
}
|
||||
void
|
||||
myddas_util_set_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node, unsigned long bytes){
|
||||
node->lastBytesTransfered = bytes;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node){
|
||||
return node->totalBytesTransfered;
|
||||
}
|
||||
void
|
||||
myddas_util_set_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node, unsigned long bytes){
|
||||
node->totalBytesTransfered = bytes;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION node){
|
||||
return node->total_querys_made;
|
||||
}
|
||||
void
|
||||
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION node, unsigned long number){
|
||||
node->total_querys_made = number;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_total_db_row_function(void){
|
||||
return MYDDAS_GLOBAL_STRUCT->myddas_statistics->total_db_row;
|
||||
@ -156,7 +183,7 @@ myddas_current_time(void) {
|
||||
microseconds -> s/1000000
|
||||
*/
|
||||
/* struct timeval tempo; */
|
||||
/* if (!gettimeofday(&tempo, NULL)) */
|
||||
/* if (!gettimeofday(&tempo, NULL)) */
|
||||
/* //returns time in microseconds */
|
||||
/* return (tempo.tv_sec %1000)*1000000+tempo.tv_usec; */
|
||||
/* //return (tempo.tv_sec %1000)*1000+tempo.tv_usec; */
|
||||
@ -512,6 +539,9 @@ myddas_util_initialize_connection(void *conn,void *enviromment,
|
||||
new->totalFromDBServer=0;
|
||||
new->lastFromDBServer=0;
|
||||
new->total_db_row=0;
|
||||
new->lastBytesTransfered=0;
|
||||
new->totalBytesTransfered=0;
|
||||
new->total_querys_made=0;
|
||||
#endif
|
||||
return new;
|
||||
}
|
||||
@ -569,6 +599,14 @@ myddas_util_delete_predicate_list(MYDDAS_UTIL_PREDICATE preds_list){
|
||||
}
|
||||
|
||||
|
||||
//DELETE THIS WHEN DB_STATS IS COMPLETED
|
||||
int
|
||||
get_myddas_top(){
|
||||
if (MYDDAS_GLOBAL_STRUCT == NULL)
|
||||
return 0;
|
||||
return (int)MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
|
||||
}
|
||||
|
||||
#endif /*defined MYDDAS_ODBC || defined MYDDAS_MYSQL*/
|
||||
#endif /*CUT_C*/
|
||||
|
||||
|
@ -92,6 +92,20 @@ myddas_util_get_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
|
||||
void
|
||||
myddas_util_set_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
|
||||
void
|
||||
myddas_util_set_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION,unsigned long);
|
||||
unsigned long
|
||||
myddas_util_get_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
|
||||
void
|
||||
myddas_util_set_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION,unsigned long);
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION);
|
||||
void
|
||||
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION, unsigned long);
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_total_db_row_function(void);
|
||||
void
|
||||
@ -110,4 +124,9 @@ myddas_current_time(void);
|
||||
void check_int(void);
|
||||
#endif
|
||||
|
||||
|
||||
//DELETE THIS WHEN DB_STATS IS COMPLETED
|
||||
int
|
||||
get_myddas_top(void);
|
||||
|
||||
#endif /*__MYDDAS_UTIL_H__*/
|
||||
|
Reference in New Issue
Block a user