本文整理汇总了PHP中Tracy\Debugger::timer方法的典型用法代码示例。如果您正苦于以下问题:PHP Debugger::timer方法的具体用法?PHP Debugger::timer怎么用?PHP Debugger::timer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tracy\Debugger
的用法示例。
在下文中一共展示了Debugger::timer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stopQuery
public function stopQuery()
{
if ($this->explainRunning) {
return;
}
$keys = array_keys($this->queries);
$key = end($keys);
$this->queries[$key][self::TIME] = Debugger::timer('doctrine');
$this->totalTime += $this->queries[$key][self::TIME];
// get EXPLAIN for SELECT queries
if ($this->doExplains) {
if ($this->connection === NULL) {
throw new InvalidStateException('You must set a Doctrine\\DBAL\\Connection to get EXPLAIN.');
}
$query = $this->queries[$key][self::SQL];
if (!Strings::startsWith($query, 'SELECT')) {
// only SELECTs are supported
return;
}
// prevent logging explains & infinite recursion
$this->explainRunning = TRUE;
$params = $this->queries[$key][self::PARAMS];
$types = $this->queries[$key][self::TYPES];
$stmt = $this->connection->executeQuery('EXPLAIN ' . $query, $params, $types);
$this->queries[$key][self::EXPLAIN] = $stmt->fetchAll();
$this->explainRunning = FALSE;
}
}
示例2: startup
public function startup()
{
parent::startup();
\Tracy\Debugger::timer('global');
// Log visits
// todo: replace by mongoDB log_visit
/*
$httpRequest = $this->getHttpRequest();
$requestHeaders = apache_request_headers();
$ipAddress = (empty($requestHeaders['X-Forwarded-For']) ? $httpRequest->getRemoteAddress() : $requestHeaders['X-Forwarded-For']);
// ip address can be more values divided by comma (it's path to remote server), take only the last (most accurate IP of visitor)
$ipAddressParts = explode(',', $ipAddress);
$ipAddress = array_pop($ipAddressParts);
if ($httpRequest->getUrl()->path != '/healthy-check') {
$this->lastLogItem = $this->logger->logVisit(
$httpRequest->getUrl()->path, // URL
$ipAddress, // IP
$httpRequest->getHeader('User-Agent'), // USER_AGENT
$httpRequest->getReferer() // REFERRER
);
}*/
}
示例3: importTable
/**
* @param $tempTableName
* @param $columns
* @param CsvFile $csvFile
* @param array $options
* - isManifest
* - copyOptions
* @throws Exception
* @throws \Exception
*/
protected function importTable($tempTableName, $columns, CsvFile $csvFile, array $options)
{
if ($csvFile->getEnclosure() && $csvFile->getEscapedBy()) {
throw new Exception('Invalid CSV params. Either enclosure or escapedBy must be specified for Redshift backend but not both.', Exception::INVALID_CSV_PARAMS, null);
}
try {
Debugger::timer('copyToStaging');
$copyOptions = ['isManifest' => $options['isManifest'], 'copyOptions' => isset($options['copyOptions']) ? $options['copyOptions'] : []];
if ($options['isManifest']) {
$manifest = $this->downloadManifest($csvFile->getPathname());
// empty manifest handling - do nothing
if (!count($manifest['entries'])) {
$this->addTimer('copyToStaging', Debugger::timer('copyToStaging'));
return;
}
$copyOptions['isGzipped'] = $this->isGzipped(reset($manifest['entries'])['url']);
} else {
$copyOptions['isGzipped'] = $this->isGzipped($csvFile->getPathname());
}
$this->query($this->generateCopyCommand($tempTableName, $columns, $csvFile, $copyOptions));
$this->addTimer('copyToStaging', Debugger::timer('copyToStaging'));
} catch (\Exception $e) {
$result = $this->connection->query("SELECT * FROM stl_load_errors WHERE query = pg_last_query_id();")->fetchAll();
if (!count($result)) {
throw $e;
}
$messages = [];
foreach ($result as $row) {
$messages[] = "Line {$row['line_number']} - {$row['err_reason']}";
}
$message = "Load error: " . implode("\n", $messages);
throw new Exception($message, Exception::INVALID_SOURCE_DATA, $e);
}
}
示例4: importDataToStagingTable
protected function importDataToStagingTable($stagingTableName, $columns, $sourceData)
{
if (!isset($sourceData['schemaName'])) {
throw new Exception('Invalid source data. schemaName must be set', Exception::INVALID_SOURCE_DATA);
}
if (!isset($sourceData['tableName'])) {
throw new Exception('Invalid source data. schemaName must be set', Exception::INVALID_SOURCE_DATA);
}
$sql = "INSERT INTO " . $this->nameWithSchemaEscaped($stagingTableName) . " (" . implode(', ', array_map(function ($column) {
return $this->quoteIdentifier($column);
}, $columns)) . ") ";
$sql .= "SELECT " . implode(',', array_map(function ($column) {
return $this->quoteIdentifier($column);
}, $columns)) . " FROM " . $this->nameWithSchemaEscaped($sourceData['tableName'], $sourceData['schemaName']);
try {
Debugger::timer('copyToStaging');
$this->connection->query($sql);
$rows = $this->connection->fetchAll(sprintf('SELECT COUNT(*) as "count" from %s.%s', $this->connection->quoteIdentifier($this->schemaName), $this->connection->quoteIdentifier($stagingTableName)));
$this->importedRowsCount += (int) $rows[0]['count'];
$this->addTimer('copyToStaging', Debugger::timer('copyToStaging'));
} catch (\Exception $e) {
// everything is user error
throw new Exception($e->getMessage(), Exception::UNKNOWN_ERROR, $e);
}
}
示例5: createGuzzleClient
/**
* @param $tempDir
* @param array $guzzleConfig
* @return \GuzzleHttp\Client
* @throws \Matyx\Guzzlette\GuzzletteException
*/
public static function createGuzzleClient($tempDir, $guzzleConfig = [])
{
if (isset(static::$client)) {
return static::$client;
}
if (Tracy\Debugger::isEnabled()) {
$handler = NULL;
if (isset($guzzleConfig['handler'])) {
$handler = $guzzleConfig['handler'];
if (!$handler instanceof GuzzleHttp\HandlerStack) {
throw new GuzzletteException("Handler must be instance of " . GuzzleHttp\HandlerStack::class);
}
} else {
$handler = GuzzleHttp\HandlerStack::create();
}
$requestStack = new RequestStack();
Tracy\Debugger::getBar()->addPanel(new TracyPanel($tempDir, $requestStack));
$handler->push(function (callable $handler) use($requestStack) {
return function ($request, array $options) use($handler, $requestStack) {
Tracy\Debugger::timer();
$guzzletteRequest = new Request();
$guzzletteRequest->request = $request;
return $handler($request, $options)->then(function ($response) use($requestStack, $guzzletteRequest) {
$guzzletteRequest->time = Tracy\Debugger::timer();
$guzzletteRequest->response = $response;
$requestStack->addRequest($guzzletteRequest);
return $response;
});
};
});
$guzzleConfig['handler'] = $handler;
}
static::$client = new GuzzleHttp\Client($guzzleConfig);
return static::$client;
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
Debugger::timer();
$output->writeln('Running tests...');
$runner = new Runner();
$path = realpath($input->getArgument('path'));
if ($path) {
if (is_dir($path)) {
$runner->setTestsRoot($path . '/');
foreach (Finder::findFiles('*.php')->exclude('tester.php')->from($path) as $path => $fileInfo) {
$basePath = Helpers::stripExtension($path);
$runner->addTest($basePath);
}
} else {
$basePath = Helpers::stripExtension($path);
$runner->addTest($basePath);
}
} else {
if ($path = realpath($input->getArgument('path') . '.php')) {
$basePath = Helpers::stripExtension($path);
$runner->addTest($basePath);
} else {
$output->writeln("<error>The given path isn't valid</error>");
return 1;
}
}
$runner->setOutput($output);
$runner->runTests();
$output->writeln('Completed in ' . round(Debugger::timer(), 2) . ' seconds');
if ($runner->failed()) {
return 1;
} else {
return 0;
}
}
示例7: importDataToStagingTable
protected function importDataToStagingTable($stagingTempTableName, $columns, $sourceData, array $options = [])
{
if (!isset($sourceData['schemaName'])) {
throw new Exception('Invalid source data. schemaName must be set', Exception::INVALID_SOURCE_DATA);
}
if (!isset($sourceData['tableName'])) {
throw new Exception('Invalid source data. schemaName must be set', Exception::INVALID_SOURCE_DATA);
}
$sourceColumnTypes = $this->describeTable(strtolower($sourceData['tableName']), strtolower($sourceData['schemaName']));
$sql = "INSERT INTO " . $this->tableNameEscaped($stagingTempTableName) . " (" . implode(', ', array_map(function ($column) {
return $this->quoteIdentifier($column);
}, $columns)) . ") ";
$sql .= "SELECT " . implode(',', array_map(function ($column) use($sourceColumnTypes) {
if ($sourceColumnTypes[$column]['DATA_TYPE'] === 'bool') {
return sprintf('DECODE(%s, true, 1, 0) ', $this->quoteIdentifier($column));
} else {
return "COALESCE(CAST({$this->quoteIdentifier($column)} as varchar), '') ";
}
}, $columns)) . " FROM " . $this->nameWithSchemaEscaped($sourceData['tableName'], $sourceData['schemaName']);
try {
Debugger::timer('copyToStaging');
$this->query($sql);
$this->addTimer('copyToStaging', Debugger::timer('copyToStaging'));
} catch (\Exception $e) {
if (strpos($e->getMessage(), 'Datatype mismatch') !== false) {
throw new Exception($e->getMessage(), Exception::DATA_TYPE_MISMATCH, $e);
}
// everything is user error
throw new Exception($e->getMessage(), Exception::UNKNOWN_ERROR, $e);
}
}
示例8: stopQuery
public function stopQuery()
{
if (Debugger::$productionMode) {
return;
}
$keys = array_keys($this->queries);
$key = end($keys);
$this->queries[$key][2] = Debugger::timer('doctrine');
$this->totalTime += $this->queries[$key][2];
}
示例9: subscribe
/**
* subscribe.
*
* @method subscribe
*/
public function subscribe()
{
$key = get_class($this);
$timer = Debugger::timer($key);
$this->laravel['events']->listen('*', function ($params) use($key) {
$execTime = Debugger::timer($key);
$firing = $this->laravel['events']->firing();
$editorLink = self::editorLink(self::findSource());
$this->totalTime += $execTime;
$this->events[] = compact('execTime', 'firing', 'params', 'editorLink');
});
}
示例10: actionDefault
public function actionDefault()
{
$this->cronner->onTaskBegin[] = function (Cronner $cronner, Task $task) {
echo '<h3>' . $task->getName() . '</h3>';
Debugger::timer($task->getName());
};
$this->cronner->onTaskFinished[] = function (Cronner $cronner, Task $task) {
echo '<p>Total time: ' . Debugger::timer($task->getName()) . ' s</p>';
};
$this->cronner->run();
$this->terminate();
}
示例11: call
public function call($type, $service, $params = [])
{
$url = $this->protocol . $this->host . "/?presenter={$type}&action={$service}";
if (count($params) > 0) {
foreach ($params as $name => $value) {
$url .= "&{$name}={$value}";
}
}
Debugger::timer();
$data = $this->sendGet($url);
$time = Debugger::timer();
return ['data' => $data, 'url' => $url, 'time' => $time];
}
示例12: subscribe
public function subscribe(Dispatcher $event)
{
$key = get_class($this);
$timer = Debugger::timer($key);
$event->listen('*', function ($params) use($key, $event) {
$execTime = Debugger::timer($key);
// $dispatcher = static::findDispatcher();
// $firing = array_get($dispatcher, 'dispatcher.args.0');
$firing = $event->firing();
$editorLink = Helper::getEditorLink(Helper::findSource());
$this->attributes['totalTime'] += $execTime;
$this->attributes['events'][] = compact('execTime', 'firing', 'params', 'editorLink');
});
}
示例13: execute
protected function execute($command)
{
$time = $timerName = '';
if (class_exists('\\Tracy\\Debugger')) {
\Tracy\Debugger::timer($timerName = md5($command));
}
$this->logCmd($command, 'Executing');
$output = shell_exec($command);
if (class_exists('\\Tracy\\Debugger')) {
$time = \Tracy\Debugger::timer($timerName);
}
$this->logCmd($output, 'Result', $time);
return $output;
}
示例14: subscribe
public function subscribe()
{
$key = get_class($this);
$timer = Debugger::timer($key);
$event = $this->app['events'];
$event->listen('*', function ($params) use($key, $event) {
$execTime = Debugger::timer($key);
$firing = $event->firing();
$editorLink = Helper::getEditorLink(Helper::findSource());
$this->attributes['count']++;
$this->attributes['totalTime'] += $execTime;
$this->attributes['logs'][] = compact('execTime', 'firing', 'params', 'editorLink');
});
}
示例15: stop
/**
* Stops the timer and logs event to syslog.
*
* @param string $name The timer name.
* @return float The current timer value.
*/
public static function stop($name, $data = [])
{
$point = Debugger::timer($name);
$measure = self::add($point, $name);
if (self::$profile) {
$tags = [];
if (isset($data['tags'])) {
$tags = $data['tags'];
unset($data['tags']);
}
if (function_exists('syslog')) {
syslog(LOG_INFO, json_encode(['type' => self::$indexName, 'tags' => explode(' ', $name) + $tags, 'host' => gethostname(), 'dur' => round($measure * 1000, 1), 'mem' => memory_get_peak_usage(), 'php' => PHP_VERSION, 'timestamp' => (string) time(), 'data' => array_merge(self::$defaults, $data)]));
}
}
return $measure;
}