measurements of time spent in SQL statements.
authorAleš Křenek <ljocha@ics.muni.cz>
Thu, 13 Apr 2006 09:00:02 +0000 (09:00 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Thu, 13 Apr 2006 09:00:02 +0000 (09:00 +0000)
covered by #ifdef LBS_DB_PROFILE, not compiled in by default

org.glite.lb.server/src/lbs_db.c

index 515d596..41a3c06 100644 (file)
@@ -78,6 +78,8 @@ int edg_wll_ExecStmt(edg_wll_Context ctx,char *txt,edg_wll_Stmt *stmt)
        int     err;
        int     retry_nr = 0;
        int     do_reconnect = 0;
+       struct timeval  start,end;
+       int     pid;
 
        edg_wll_ResetError(ctx);
 
@@ -85,6 +87,10 @@ int edg_wll_ExecStmt(edg_wll_Context ctx,char *txt,edg_wll_Stmt *stmt)
                *stmt = NULL;
        }
 
+#ifdef LBS_DB_PROFILE
+       gettimeofday(&start,NULL);
+#endif
+
        while (retry_nr == 0 || do_reconnect) {
                do_reconnect = 0;
                if (mysql_query((MYSQL *) ctx->mysql,txt)) {
@@ -128,6 +134,15 @@ int edg_wll_ExecStmt(edg_wll_Context ctx,char *txt,edg_wll_Stmt *stmt)
                MYSQL_RES       *r = mysql_store_result((MYSQL *) ctx->mysql);
                mysql_free_result(r);
        }
+#ifdef LBS_DB_PROFILE
+       gettimeofday(&end,NULL);
+       end.tv_usec -= start.tv_usec;
+       end.tv_sec -= start.tv_sec;
+       if (end.tv_usec < 0) { end.tv_sec--; end.tv_usec += 1000000; }
+
+       pid = getpid();
+       fprintf(stderr,"[%d] %s\n[%d] %3ld.%06ld\n",pid,txt,pid,end.tv_sec,end.tv_usec);
+#endif
        
        return mysql_affected_rows((MYSQL *) ctx->mysql);
 }