public function testPrepare() { //$struct = pinba::get_packet_info(); //var_export($struct); //print_r($info); $testInfo = array('mem_peak_usage' => 3407872, 'req_time' => 0.023175954818725586, 'ru_utime' => 0.050366, 'ru_stime' => 0.012817, 'req_count' => 0, 'doc_size' => 0, 'server_name' => 'unknown', 'script_name' => '/private/var/folders/p5/fnl90gfx5_5f9599s3hpthfw0000gq/T/ide-phpunit.php', 'timers' => array(0 => array('value' => 0.0010178089141845703, 'tags' => array('tag1' => 'value1', 'tag2' => 'value2'), 'started' => false, 'data' => array(), 'count' => 1, 'tagids' => array(0 => 1, 2 => 3))), 'status' => 0, 'hostname' => 'phph.local', 'memory_peak' => 3407872, 'request_time' => 0.023175954818725586, 'request_count' => 0, 'document_size' => 0, 'timer_hit_count' => array(0 => 1), 'timer_value' => array(0 => 0.0010178089141845703), 'timer_tag_count' => array(0 => 2), 'timer_tag_name' => array(0 => 0, 1 => 2), 'timer_tag_value' => array(0 => 1, 1 => 3), 'dictionary' => array('tag1' => 0, 'value1' => 1, 'tag2' => 2, 'value2' => 3, 'tagrequest1' => 4, 'tagrequestvalue1' => 5, 'tagrequest2' => 6, 'tagrequestvalue2' => 7), 'tag_name' => array(4, 6), 'tag_value' => array(5, 7)); $expected = base64_decode('CgpwaHBoLmxvY2FsEgd1bmtub3duGkgvcHJpdmF0ZS92' . 'YXIvZm9sZGVycy9wNS9mbmw5MGdmeDVfNWY5NTk5czNocHRoZncwMDAwZ3EvVC9p' . 'ZGUtcGhwdW5pdC5waHAgASgAMICA0AE9gNu9PEWUTE49TWX+UTxQAV0AaIU6aABw' . 'AWgCcANgAnoEdGFnMXoGdmFsdWUxegR0YWcyegZ2YWx1ZTJ6C3RhZ3JlcXVlc3Qx' . 'ehB0YWdyZXF1ZXN0dmFsdWUxegt0YWdyZXF1ZXN0MnoQdGFncmVxdWVzdHZhbHVl' . 'MoABAA=='); // echo base64_encode(pinba::prepareMessage($testInfo)); $this->assertSame($expected, pinba::prepareMessage($testInfo)); }
<?php /** * A sample php file that uses the pinba php extension */ // start time measurement asap $starttime = microtime(true); include 'prtbfr.php'; include 'pinba.php'; include 'pinbafunctions.php'; // this is optional - if omitted time measurement will start when pinba.php file is included pinba::init($starttime); // do some stuff here ... // measure some operation $t = pinba_timer_start(array("group" => "mysql", "server" => "dbs2", "operation" => "select")); $result = mysql_query("SELECT ...", $connection); pinba_timer_stop($t); // that's all folks!
<?php require_once __DIR__ . '/vendor/autoload.php'; if (class_exists('pinba', false)) { pinba::ini_set_auto_flush(false); pinba::ini_set_enabled(1); pinba::ini_set_server('127.0.0.1:3300'); } $file = file_get_contents(__FILE__); //$timer = pinba_timer_start(array('action' => 'gzencode', 'tag2' => 'value2')); $start = microtime(1); gzencode($file); $elapsed = microtime(1) - $start; //$stop = pinba_timer_stop($timer); //$timer = pinba_timer_start(array('action' => 'md5', 'tag2' => 'value2')); $start = microtime(1); for ($i = 0; $i < 1000; ++$i) { md5($i); } $elapsed = microtime(1) - $start; //$stop = pinba_timer_stop($timer); //$timer = pinba_timer_start(array('action' => 'serialize', 'tag2' => 'value3')); $start = microtime(1); for ($i = 0; $i < 1000; ++$i) { serialize($_SERVER); } $elapsed = microtime(1) - $start; //$stop = pinba_timer_stop($timer); header("Content-Type: text/plain"); echo $file;
/** * A function not in the pinba extension api, needed to calculate total req. time */ static function init($time = null) { if (self::$start == null || $time != null) { if ($time == null) { $time = microtime(true); } self::$start = $time; } if (self::$hostname == null) { self::$hostname = isset($_SERVER['HOST_NAME']) ? $_SERVER['HOST_NAME'] : gethostname(); } if (self::$scriptName == null && isset($_SERVER['SCRIPT_NAME'])) { self::$scriptName = $_SERVER['SCRIPT_NAME']; } if (self::$serverName == null && isset($_SERVER['SERVER_NAME'])) { self::$serverName = $_SERVER['SERVER_NAME']; } if (!self::$shutdownRegistered) { self::$shutdownRegistered = true; register_shutdown_function('pinba::shutdownHandler'); } }
/** Useful when you need to send request data to the server immediately (for long running scripts). You can use optional argument script_name to set custom script name. @param string $script_name */ function pinba_flush($script_name = null) { return pinba::flush($script_name); }