Skip to content

Instantly share code, notes, and snippets.

@supernifty
Created November 9, 2010 07:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save supernifty/668809 to your computer and use it in GitHub Desktop.
Save supernifty/668809 to your computer and use it in GitHub Desktop.
Ultra Simple PHP Profiler
<?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 );
}
}
?>
<?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