Created
November 9, 2010 07:19
-
-
Save supernifty/668809 to your computer and use it in GitHub Desktop.
Ultra Simple PHP Profiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$_start = 0; | |
$_subdata = ''; | |
function profile_start() { | |
global $profile; | |
if ( $profile ) { | |
global $_start, $_subdata; | |
$_start = microtime(true); | |
$_subdata = ''; | |
} | |
} | |
function profile_end( $data ) { | |
global $profile, $_subdata; | |
if ( $profile ) { | |
global $_start; | |
// open file | |
$fd = fopen("/tmp/profile.csv", "a"); | |
// write string | |
fwrite($fd, ( microtime(true) - $_start ) . "," . $data . "\n"); | |
fwrite($fd, $_subdata ); | |
// close file | |
fclose($fd); | |
} | |
} | |
function profile_info( $q ) { | |
global $profile, $_subdata, $_start; | |
if ( $profile ) { | |
$_subdata .= (microtime(true) - $_start) . ",\"- " . $q . "\"\n"; | |
} | |
} | |
function mysql_queryx( $q ) { | |
global $profile, $_subdata; | |
if ( $profile ) { | |
$pre = microtime(true); | |
$result = mysql_query( $q ); | |
$_subdata .= (microtime(true) - $pre) . ",\"- " . $q . "\"\n"; | |
return $result; | |
} | |
else { | |
return mysql_query( $q ); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$profile = true; | |
require_once "profile.php"; | |
profile_start(); | |
// ... | |
$query = mysql_queryx( "select status from table" ); | |
// ... | |
profile_info( "checkpoint" ); | |
// ... | |
profile_end( "page" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment