/** * Creates and starts new timer. * * @param array $tags an array of tags and their values in the form of "tag" => "value". Cannot contain numeric indexes for obvious reasons. * @param array $data optional array with user data, not sent to the server. "hit_count" - optional hit_count parameter, set to 1 be default. * @return resource new timer resource. */ public static function start(array $tags, array $data = []) { if (!self::isEnabled()) { return; } return pinba_timer_start($tags, $data); }
public function __call($method, $args) { $tags = array('group' => 'redis', 'op' => $method); $timer = pinba_timer_start($tags); $result = call_user_func_array(array($this->Redis, $method), $args); pinba_timer_stop($timer); return $result; }
/** * Запускает таймер и возвращает ресурс * https://github.com/tony2001/pinba_engine/wiki/PHP-extension#pinba_timer_start * * @param array $data Любые произвольные данные * * @return resource|null */ public function start(array $data = []) { if (!$this->isEnabled() || !$this->isConfigured()) { return null; } /** @noinspection PhpUndefinedFunctionInspection */ return pinba_timer_start(['type' => $this->config['type'], 'target' => $this->config['target']], $data); }
/** * Запускает таймер и возвращает ресурс * https://github.com/tony2001/pinba_engine/wiki/PHP-extension#pinba_timer_start * @param string $type * @param string $target * @param array $more * @return resource|null */ public static function start($type, $target, array $more = []) { if (!self::isEnabled()) { return null; } /** @noinspection PhpUndefinedFunctionInspection */ return pinba_timer_start(array_merge(['type' => $type, 'target' => $target], $more)); }
/** * Creates and starts new timer. * * @param array $tags An array of tags and their values in the form of "tag" => "value". Cannot contain numeric indexes for obvious reasons. * @return StopwatchEvent Always returns new timer resource object. */ public function start(array $tags) { if ($this->_enabled) { $tags = array_merge($this->_initTags, $tags); if (isset($tags['group']) && !isset($tags['category']) && strpos($tags['group'], '::') !== false) { $v = explode('::', $tags['group']); if (count($v) > 0) { $tags['category'] = $v[0]; } } } return new StopwatchEvent($this->_enabled ? pinba_timer_start($tags) : null); }
public function testTwo() { $timer = pinba_timer_start(array('tag1' => 'value1', 'tag2' => 'value2')); $start = microtime(1); for ($i = 0; $i < 1000; ++$i) { md5($i); } $elapsed = microtime(1) - $start; $stop = pinba_timer_stop($timer); $this->assertTrue($stop); $info = pinba_timer_get_info($timer); $this->assertLessThan(0.1, abs($elapsed - $info['value'])); }
/** * @param $options array * @return bool */ public static function timerStart($options) { if (!is_array($options)) { return false; } if (self::init()) { $options = self::noramlizeOptions($options); $name = self::getTimerName($options); //TLog::write('start: '.$name. 'dedug:'.json_encode(debug_backtrace()), 'TProfile.log'); self::$timer[$name][] = pinba_timer_start($options); return true; } return false; }
public function timerStart($name, array $tags, array $data = []) { if (array_key_exists($name, $this->timers)) { throw new WrongArgumentException('a timer with the same name allready exists'); } if ($this->isTreeLogEnabled()) { $id = uniqid(); $tags['treeId'] = $id; if (!empty($this->queue)) { $tags['treeParentId'] = end($this->queue); } else { $tags['treeParentId'] = 'root'; } $this->queue[] = $id; } $this->timers[$name] = count($data) ? pinba_timer_start($tags, $data) : pinba_timer_start($tags); return $this; }
<?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!
require_once __DIR__ . '/../vendor/autoload.php'; if (class_exists('pinba', false)) { pinba::ini_set_auto_flush(true); pinba::ini_set_enabled(1); pinba::ini_set_server('127.0.0.1:3300'); } var_dump(ini_set('pinba.enabled', 1)); var_dump(ini_set('pinba.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;
/** * Starts the timer * * @param string $token * @param array $tags * * @return bool Operation success */ public function startTimer($token, $tags = []) { if ($this->worksWithoutPinba && $this->getClientUsed() === self::CLIENT_NONE) { return true; } if (isset($this->runningTimers[$token])) { return false; } $actualTags = array_merge($tags, ['timerToken' => $token]); $this->runningTimers[$token] = pinba_timer_start($this->formatTags($actualTags)); return true; }