Skip to content

Instantly share code, notes, and snippets.

@supernifty
Created November 9, 2010 07:19

Revisions

  1. supernifty revised this gist Nov 9, 2010. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions profiler_usage.php
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    <?php
    $profile = true;
    require_once profile.php;
    require_once "profile.php";
    profile_start();
    $query = mysql_queryx( select status from table );
    profile_info( checkpoint );
    profile_end( page );
    // ...
    $query = mysql_queryx( "select status from table" );
    // ...
    profile_info( "checkpoint" );
    // ...
    profile_end( "page" );
    ?>
  2. supernifty created this gist Nov 9, 2010.
    47 changes: 47 additions & 0 deletions profile.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <?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 );
    }
    }
    ?>
    11 changes: 11 additions & 0 deletions profiler_usage.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <?php
    $profile = true;
    require_once ‘profile.php’;
    profile_start();
    $query = mysql_queryx( “select status from table” );
    profile_info( “checkpoint” );
    profile_end( “page” );
    ?>