note 72534 added to function.debug-backtrace

From: Date: Tue, 23 Jan 2007 18:24:35 +0000
Subject: note 72534 added to function.debug-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-122075@lists.php.net to get a copy of this message
<? // useful and comfortable debug function // it's show memory usage and time flow between calls, so we can quickly find a block of code that need optimisation... // example result: /* debug example.php> initialize debug example.php> code-lines: 39-41 time: 2.0002 mem: 19 KB debug example.php> code-lines: 41-44 time: 0.0000 mem: 19 KB debug example.php> code-lines: 44-51 time: 0.6343 mem: 9117 KB debug example.php> code-lines: 51-53 time: 0.1003 mem: 9117 KB debug example.php> code-lines: 53-55 time: 0.0595 mem: 49 KB */ function debug() { static $start_time = NULL; static $start_code_line = 0; $call_info = array_shift( debug_backtrace() ); $code_line = $call_info['line']; $file = array_pop( explode('/', $call_info['file'])); if( $start_time === NULL ) { print "debug ".$file."> initialize\n"; $start_time = time() + microtime(); $start_code_line = $code_line; return 0; } printf("debug %s> code-lines: %d-%d time: %.4f mem: %d KB\n", $file, $start_code_line, $code_line, (time() + microtime() - $start_time), ceil( memory_get_usage()/1024)); $start_time = time() + microtime(); $start_code_line = $code_line; } //////////////////////////////////////////////// // example: debug(); sleep(2); debug(); // soft-code... $a = 3 + 5; debug(); // hard-code for( $i=0; $i<100000; $i++) { $dummy['alamakota'.$i] = 'alamakota'.$i; } debug(); usleep(100000); debug(); unset($dummy); debug(); ?> ---- Server IP: 195.136.184.34 Probable Submitter: 83.9.242.73 ---- Manual Page -- http://www.php.net/manual/en/function.debug-backtrace.php Edit -- https://master.php.net/note/edit/72534 Del: integrated -- https://master.php.net/note/delete/72534/integrated Del: useless -- https://master.php.net/note/delete/72534/useless Del: bad code -- https://master.php.net/note/delete/72534/bad+code Del: spam -- https://master.php.net/note/delete/72534/spam Del: non-english -- https://master.php.net/note/delete/72534/non-english Del: in docs -- https://master.php.net/note/delete/72534/in+docs Del: other reasons-- https://master.php.net/note/delete/72534 Reject -- https://master.php.net/note/reject/72534 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122075) next »