Databases :: MySql :: cpu time mysql |
|||
| By: Nono |
Date: 14/06/2007 14:11:59 |
Points: 20 | Status: Answered Quality : Excellent |
| how to get the cpu time for a mysql query ? | |||
| By: VGR | Date: 14/06/2007 14:56:55 | Type : Answer |
|
| well, except in the "mysql console", mysqld does not return execution time. You probably won't have the real "CPU time" unless you can read twice the "task manager"/"ps" output before and after the query run, but you can get the "overall execution time" by just measuring the difference between system time before and after the query run. That's relatively easy. Here is sample code : (I use a session variable, but you can adapt) <?php // //VGR14042001 Creation //VGR24112002 ADDed sécurité pour mode globDisc // // // ----------------------------- FORUM ----------------------------------- // function myTime() { // en secondes $loc1=microtime(); $loc2 = (double)substr (strrchr ($loc1, ' '), 1); // secondes entières $loc3 = (double)substr ($loc1, 1,strpos($loc1,' ')); // fraction de seconde = 0.xxx $loc2 = (double)$loc2+$loc3; return $loc2; } function TimerStart() { GLOBAL $_SESSION; $_SESSION['TTime']=myTime(); } // TimerStart Procedure function TimerStop($parDisp=FALSE) { // and display GLOBAL $_SESSION; $locTime=myTime()-$_SESSION['TTime']; // en secondes //VGR14042001 BUGFIX // il y a un bug dans la fonction de base : la seconde n'est pas incrémentée correctement. if ($locTime<0) $locTime=1.0+$locTime; //EoFIX $locTime=round(1000.0*$locTime,5); // millisecondes arrondies à la 5ème décimale if ($parDisp) echo " <CENTER><font size=-2>page generated in $locTime milliseconds</font></CENTER>"; return($locTime); } // TimerStop Integer (ms) Function ?> usage : TimerStart(); mysql_query(etc etc etc); $timeused=TimerStop(TRUE); // will display a message // or $timeused=TimerStop(FALSE); echo "the query executed in $timeused milliseconds"; |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








