本文整理汇总了PHP中Symfony\Component\Stopwatch\Stopwatch::lap方法的典型用法代码示例。如果您正苦于以下问题:PHP Stopwatch::lap方法的具体用法?PHP Stopwatch::lap怎么用?PHP Stopwatch::lap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Stopwatch\Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::lap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rasterizeUrl
/**
* @param $url
* @param array $arguments
* @param string $uniqueId
*
* @throws \Exception
*
* @return string
*/
public function rasterizeUrl($url, $arguments = array(), $uniqueId = "")
{
if ($uniqueId === "") {
$uniqueId = uniqid("rasterize-");
}
if ($this->stopwatch instanceof Stopwatch) {
if ($this->stopwatch->isStarted($uniqueId)) {
$this->stopwatch->lap($uniqueId);
} else {
$this->stopwatch->start($uniqueId);
}
}
$process = $this->configHelper->buildProcess($url, $uniqueId, $arguments);
$exitCode = $process->run();
if ($exitCode != 0) {
throw new \Exception(sprintf("Rasterize script failed.\nCommandLine: %s\nExitCode: %d\nErrorOutput: %s", $process->getCommandLine(), $process->getExitCode(), $process->getErrorOutput()));
}
if ($this->stopwatch instanceof Stopwatch) {
$this->stopwatch->stop($uniqueId);
}
$output = $this->configHelper->getOutputFilePath($uniqueId);
$content = file_get_contents($output);
unlink($output);
return $content;
}
示例2: testLap
public function testLap()
{
$stopwatch = new Stopwatch();
$stopwatch->start('foo', 'cat');
usleep(100000);
$event = $stopwatch->lap('foo');
usleep(100000);
$stopwatch->stop('foo');
$this->assertInstanceof('Symfony\\Component\\Stopwatch\\StopwatchEvent', $event);
$this->assertEquals(200, $event->getDuration(), null, self::DELTA);
}
示例3: logAfterParsingAFile
/**
* Collects the time and duration of processing a file, logs it and returns the new amount of memory in use.
*
* @param integer $memory
*
* @return integer
*/
protected function logAfterParsingAFile($memory)
{
if (!$this->stopwatch) {
return $memory;
}
$lap = $this->stopwatch->lap('parser.parse');
$oldMemory = $memory;
$periods = $lap->getPeriods();
$memory = end($periods)->getMemory();
$this->log('>> Memory after processing of file: ' . number_format($memory / 1024 / 1024, 2) . ' megabytes (' . ($memory - $oldMemory >= 0 ? '+' : '-') . number_format(($memory - $oldMemory) / 1024) . ' kilobytes)', LogLevel::DEBUG);
return $memory;
}
示例4: run
/**
* @return Result
*/
public function run()
{
$stopwatch = new Stopwatch();
$result = '';
$stopwatch->start('parsing');
$this->driver->initialize();
$stopwatch->lap('parsing');
for ($i = 0; $i < $this->loopCount; $i++) {
$result = $this->driver->run($this->content);
}
$event = $stopwatch->stop('parsing');
return new Result($this->driver->getName(), $this->driver->getDialect(), $event, $result, memory_get_peak_usage(true));
}
示例5: run
public function run($collectionSize)
{
$testData = $this->prepareTestData($collectionSize);
/** @var Result[] $results */
$results = array();
foreach ($this->tasks as $task) {
if (!$task->isValid()) {
continue;
}
$stopwatch = new Stopwatch();
$stopwatch->start('mapping');
$task->prepare();
$stopwatch->lap('mapping');
$task->run($testData);
$event = $stopwatch->stop('mapping');
$results[] = new Result($task->getName(), $event, memory_get_peak_usage(true));
}
return $results;
}
示例6: Stopwatch
/**
* Stopwatch's example
*
* An example show you how to use Symfony Stopwatch
*
* @author nguyenvanduocit
*/
require_once 'vendor/autoload.php';
require_once 'functions.php';
use Symfony\Component\Stopwatch\Stopwatch;
$stopwatch = new Stopwatch();
$stopwatch->start('example_lap');
$totalLap = 10;
for ($count = 0; $count < $totalLap; $count++) {
doSomeFunction();
$stopwatch->lap('example_lap');
}
$event = $stopwatch->stop('example_lap');
$periods = $event->getPeriods();
?>
<ul>
<?php
foreach ($periods as $index => $period) {
echo '<li>#' . $index . ':' . $period->getDuration() . 'ms</li>';
}
?>
<li>Total time: <?php
echo $event->getDuration();
?>
ms</li>
<li>The fastest runner's time: <?php
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$logger = $this->getContainer()->get('logger');
$year = date("Y") - 1;
$interval = 20;
$stopwatch = new Stopwatch();
$stopwatch->start('syncing');
$id = $input->getArgument('id');
$capturedYear = $input->getArgument('year');
$orgunitid = $input->getArgument('orgunitid');
$entity = $em->getRepository('HrisIntergrationBundle:DHISDataConnection')->find($id);
if (!empty($orgunitid)) {
$orgunit = $em->getRepository('HrisOrganisationunitBundle:Organisationunit')->find($orgunitid);
} else {
$orgunit = $entity->getParentOrganisationunit();
}
if (!empty($capturedYear)) {
$year = $capturedYear;
}
if ($id) {
$this->dhisConnectionId = $id;
} else {
throw new NotFoundHttpException("Data connection not found!");
}
$this->xmlContents = "<?xml version='1.0' encoding='UTF-8'?>\n<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0\">";
$xmlFile = "/tmp/hrhis_data_" . str_replace(' ', '_', $orgunit) . ".xml";
file_put_contents($xmlFile, $this->xmlContents);
// Aggregate data for each orgunit in the current level.
$em = $this->getContainer()->get('doctrine')->getManager();
$entity = $em->getRepository('HrisIntergrationBundle:DHISDataConnection')->find($this->dhisConnectionId);
/*
* Initializing query for dhis dataset calculation
*/
// Get Standard Resource table name
$resourceTableName = str_replace(' ', '_', trim(strtolower(ResourceTable::getStandardResourceTableName())));
$resourceTableAlias = "ResourceTable";
/*
* Aggregate organisationunit for all the children
*/
$queryBuilder = $em->createQueryBuilder();
$allOrganisationunitsChildren = $queryBuilder->select('DISTINCT organisationunit')->from('HrisOrganisationunitBundle:Organisationunit', 'organisationunit')->join('organisationunit.organisationunitStructure', 'organisationunitStructure')->join('organisationunitStructure.level', 'level')->andWhere('
(
level.level >= :organisationunitLevel
AND organisationunitStructure.level' . $orgunit->getOrganisationunitStructure()->getLevel()->getLevel() . 'Organisationunit=:levelOrganisationunit
) AND organisationunit.dhisUid is not null
AND organisationunit.id IN ( SELECT DISTINCT(recordOrganisationunit.id) FROM HrisRecordsBundle:Record record INNER JOIN record.organisationunit recordOrganisationunit )')->setParameters(array('levelOrganisationunit' => $orgunit, 'organisationunitLevel' => $orgunit->getOrganisationunitStructure()->getLevel()->getLevel()))->getQuery()->getResult();
// Query for Options to exclude from reports
$fieldOptionsToSkip = $this->getContainer()->get('doctrine')->getManager()->getRepository('HrisFormBundle:FieldOption')->findBy(array('skipInReport' => True));
//filter the records with exclude report tag
foreach ($fieldOptionsToSkip as $key => $fieldOptionToSkip) {
if (empty($fieldOptionsToSkipQuery)) {
$fieldOptionsToSkipQuery = "{$resourceTableAlias}." . $fieldOptionToSkip->getField()->getName() . " !='" . $fieldOptionToSkip->getValue() . "'";
} else {
$fieldOptionsToSkipQuery .= " AND {$resourceTableAlias}." . $fieldOptionToSkip->getField()->getName() . " !='" . $fieldOptionToSkip->getValue() . "'";
}
}
$dataValueColumnName = NULL;
$selectQuery = NULL;
$organisationunitNames = NULL;
$incr = 0;
$totalIncr = 0;
$lastLap = $stopwatch->lap('syncing');
$lastLapDuration = round($lastLap->getDuration() / 1000, 2);
$previousTotalLapTime = round($lastLap->getDuration() / 1000, 2);
foreach ($allOrganisationunitsChildren as $organisationunitKey => $organisationunit) {
$organisationunitNames .= $organisationunit->getLongname() . ', ';
$incr++;
// Aggregate data for each orgunit in the current level.
$em = $this->getContainer()->get('doctrine')->getManager();
$entity = $em->getRepository('HrisIntergrationBundle:DHISDataConnection')->find($this->dhisConnectionId);
$fromClause = " FROM {$resourceTableName} {$resourceTableAlias} ";
$organisationunitLevelsWhereClause = " {$resourceTableAlias}.organisationunit_id=" . $organisationunit->getId() . " ";
// Dataelement field option relation
$dataelementFieldOptionRelation = $entity->getDataelementFieldOptionRelation();
foreach ($dataelementFieldOptionRelation as $dataelementFieldOptionKey => $dataelementFieldOptionValue) {
// Formulate Query for calculating field option
$columnFieldOptionGroup = $dataelementFieldOptionValue->getColumnFieldOptionGroup();
$rowFieldOptionGroup = $dataelementFieldOptionValue->getRowFieldOptionGroup();
$seriesFieldName = $rowFieldOptionGroup->getName();
//Column Query construction
$queryColumnNames[] = str_replace('-', '_', str_replace(' ', '', $columnFieldOptionGroup->getName()));
$categoryColumnFieldNames[] = $columnFieldOptionGroup->getField()->getName();
$categoryRowFieldName = $columnFieldOptionGroup->getField()->getName();
$columnWhereClause = NULL;
foreach ($columnFieldOptionGroup->getFieldOption() as $columnFieldOptionKey => $columnFieldOption) {
$operator = $columnFieldOptionGroup->getOperator();
if (empty($operator)) {
$operator = "OR";
}
$categoryColumnFieldOptionValue = str_replace('-', '_', $columnFieldOption->getValue());
$categoryColumnFieldName = $columnFieldOption->getField()->getName();
$categoryColumnResourceTableName = $resourceTableAlias;
if (!empty($columnWhereClause)) {
$columnWhereClause = $columnWhereClause . " " . strtoupper($operator) . " {$categoryColumnResourceTableName}.{$categoryColumnFieldName}='" . $categoryColumnFieldOptionValue . "'";
} else {
$columnWhereClause = "{$categoryColumnResourceTableName}.{$categoryColumnFieldName}='" . $categoryColumnFieldOptionValue . "'";
}
}
// Row Query construction
//.........这里部分代码省略.........
示例8: performanceAction
/**
* @ApiDoc(
* description="Check Public Api Status",
* statusCodes={200="Success"},
* section="Public Api"
* )
* @Route("/public-api/performance")
* @Template{}
* @Method({"GET"})
* @return mixed
*/
public function performanceAction()
{
$stopwatch = new Stopwatch();
$stopwatch->start('main');
$address = new Address();
$address->setCity('London');
$address->setCountry('GB');
$address->setLat('51.5286416');
$address->setLng('-0.1015987');
$geoname = $this->geonameRepository->getOneByAddress($address);
$stopwatch->lap('main');
$cuisines = $this->cuisineRepository->findAll();
$event = $stopwatch->stop('main');
$duration = $event->getDuration();
$endTime = $event->getEndTime();
$memory = $event->getMemory();
$periodsData = array();
foreach ($event->getPeriods() as $period) {
$periodsData[] = array('duration' => $period->getDuration(), 'memory' => $period->getMemory());
}
return $this->view(array('duration' => $duration, 'endTime' => $endTime, 'memory' => $memory, 'periods' => $periodsData, 'geoname' => $geoname, 'cuisines' => $cuisines));
}
示例9: lap
/**
* @param string $name
*/
public function lap($name)
{
if ($this->stopwatch) {
$this->stopwatch->lap($name);
}
}
示例10: getDuration
/**
* @param $batchElementName
* @param $eventName
* @return int
*/
public function getDuration($batchElementName, $eventName)
{
$event = $this->timer->lap($batchElementName . ":" . $eventName);
return $event->getDuration();
}
示例11: Stopwatch
<?php
require_once 'vendor/autoload.php';
require_once 'functions.php';
use Symfony\Component\Stopwatch\Stopwatch;
$stopwatch = new Stopwatch();
$stopwatch->openSection();
$stopwatch->start('do_phase_1');
doSomeFunction();
$stopwatch->stopSection('step1');
$stopwatch->openSection();
$stopwatch->start('do_phase_1');
$totalLap = 10;
for ($count = 0; $count < $totalLap; $count++) {
doSomeFunction();
$stopwatch->lap('do_phase_1');
}
$stopwatch->stopSection('step2');
echo '<p>Step 1 :</p>';
$events_1 = $stopwatch->getSectionEvents('step1');
echo '<ul>';
foreach ($events_1 as $id => $event) {
echo '<li> phase ' . $id . ':' . $event->getDuration() . '</li>';
}
echo '</ul>';
echo '<p>Step 2 :</p>';
$events_2 = $stopwatch->getSectionEvents('step2');
echo '<ul>';
foreach ($events_2 as $id => $event) {
echo '<li> phase ' . $id . ':' . $event->getDuration() . '</li>';
}
示例12: load
public function load(ObjectManager $manager)
{
$logger = $this->container->get('logger');
$stopwatch = new Stopwatch();
$stopwatch->start('dummyResourceTableGeneration');
// Populate dummy forms
$this->addDummyResourceTables();
// Seek dummy fields
$loadFieldData = new LoadFieldData();
$loadFieldData->addDummyFields();
$dummyFields = $loadFieldData->getFields();
foreach ($this->resourceTables as $resourceTableKey => $humanResourceResourceTable) {
$resourceTable = new ResourceTable();
$resourceTable->setName($humanResourceResourceTable['name']);
$resourceTable->setDescription($humanResourceResourceTable['description']);
$resourceTableRefernce = strtolower(str_replace(' ', '', $humanResourceResourceTable['name'])) . '-resourcetable';
$this->addReference($resourceTableRefernce, $resourceTable);
$manager->persist($resourceTable);
// Add Field Members for the resource table created
$sort = 1;
foreach ($dummyFields as $key => $dummyField) {
//Filter addition of fields not compliant to filter
if ($humanResourceResourceTable['filter'] == false || $humanResourceResourceTable['inputType'] == $dummyField['inputType'] || $humanResourceResourceTable['compulsory'] == $dummyField['compulsory']) {
$resourceTableMember = new ResourceTableFieldMember();
$resourceTableMember->setField($manager->merge($this->getReference(strtolower(str_replace(' ', '', $dummyField['name'])) . '-field')));
$resourceTableMember->setResourceTable($manager->merge($this->getReference($resourceTableRefernce)));
$resourceTableMember->setSort($sort++);
$referenceName = strtolower(str_replace(' ', '', $humanResourceResourceTable['name']) . str_replace(' ', '', $dummyField['name'])) . '-resourcetable-field-member';
$this->addReference($referenceName, $resourceTableMember);
$manager->persist($resourceTableMember);
$resourceTable->addResourceTableFieldMember($resourceTableMember);
unset($resourceTableMember);
}
}
$manager->persist($resourceTable);
unset($resourceTable);
}
$manager->flush();
$dummyResourceTableGenerationLap = $stopwatch->lap('dummyResourceTableGeneration');
$dummyResourceTableGenerationDuration = round($dummyResourceTableGenerationLap->getDuration() / 1000, 2);
if ($dummyResourceTableGenerationDuration < 60) {
$dummyResourceTableGenerationDurationMessage = round($dummyResourceTableGenerationDuration, 2) . ' sec.';
} elseif ($dummyResourceTableGenerationDuration >= 60 && $dummyResourceTableGenerationDuration < 3600) {
$dummyResourceTableGenerationDurationMessage = round($dummyResourceTableGenerationDuration / 60, 2) . ' min.';
} elseif ($dummyResourceTableGenerationDuration >= 3600 && $dummyResourceTableGenerationDuration < 216000) {
$dummyResourceTableGenerationDurationMessage = round($dummyResourceTableGenerationDuration / 3600, 2) . ' hrs';
} else {
$dummyResourceTableGenerationDurationMessage = round($dummyResourceTableGenerationDuration / 86400, 2) . ' days';
}
echo "\tDummy data schema generation complete in " . $dummyResourceTableGenerationDurationMessage . "\n";
// Generate resource tables
$resourceTables = $manager->getRepository('HrisFormBundle:ResourceTable')->findAll();
foreach ($resourceTables as $resourceTableKey => $resourceTable) {
// Ugly hack to generate resource table for "All Fields" only
if ($resourceTable->getName() == "All Fields") {
$success = $resourceTable->generateResourceTable($manager, $logger);
$messageLog = $resourceTable->getMessageLog();
if ($success) {
echo $messageLog;
} else {
echo "Failed with:" . $messageLog;
}
}
}
}
示例13: generateResourceTable
//.........这里部分代码省略.........
// Add History date field for fields with history
if ($field->getHashistory()) {
$resourceTable->addColumn($field->getName() . '_last_updated', "date", array('notnull' => false, 'precision' => 0, 'scale' => 0));
// Additional analysis columns
//$resourceTable->addColumn($field->getName().'_last_updated_day', "string",array('length'=>64, 'notnull'=>false));
//$resourceTable->addColumn($field->getName().'_last_updated_month_number', "integer",array('notnull'=>false,'precision'=>0, 'scale'=>0));
$resourceTable->addColumn($field->getName() . '_last_updated_month_text', "string", array('length' => 64, 'notnull' => false));
$resourceTable->addColumn($field->getName() . '_last_updated_year', "integer", array('notnull' => false, 'precision' => 0, 'scale' => 0));
//$resourceTable->addColumn($field->getName().'_last_updated_month_and_year', "string",array('length'=>64, 'notnull'=>false));
}
$totalResourceTableFields++;
unset($field);
}
// Make OrganisationunitLevels of orgunit
$organisationunitLevels = $entityManager->createQuery('SELECT DISTINCT organisationunitLevel FROM HrisOrganisationunitBundle:OrganisationunitLevel organisationunitLevel ORDER BY organisationunitLevel.level ')->getResult();
foreach ($organisationunitLevels as $organisationunitLevelKey => $organisationunitLevel) {
$organisationunitLevelName = "level" . $organisationunitLevel->getLevel() . "_" . str_replace(',', '_', str_replace('.', '_', str_replace('/', '_', str_replace(' ', '_', $organisationunitLevel->getName()))));
$resourceTable->addColumn($organisationunitLevelName, "string", array('length' => 64, 'notnull' => false));
}
// Make OrganisationunitGroupsets Column
$organisationunitGroupsets = $entityManager->getRepository('HrisOrganisationunitBundle:OrganisationunitGroupset')->findAll();
foreach ($organisationunitGroupsets as $organisationunitGroupsetKey => $organisationunitGroupset) {
$resourceTable->addColumn($organisationunitGroupset->getName(), "string", array('length' => 64, 'notnull' => false));
}
// Form and Organisationunit name
$resourceTable->addColumn("Organisationunit_name", "string", array('length' => 64, 'notnull' => false));
$resourceTable->addColumn("Form_name", "string", array('length' => 64, 'notnull' => false));
$resourceTable->addColumn('Organisationunit_id', "integer", array('notnull' => false, 'precision' => 0, 'scale' => 0));
$resourceTable->addColumn('Form_id', "integer", array('notnull' => false, 'precision' => 0, 'scale' => 0));
$resourceTable->addColumn("Lastupdated", "datetime", array('notnull' => false, 'precision' => 0, 'scale' => 0));
// Creating table
$schemaManager->createTable($resourceTable);
unset($resourceTable);
$schemaGenerationLap = $stopwatch->lap('resourceTableGeneration');
$schemaGenerationDuration = round($schemaGenerationLap->getDuration() / 1000, 2);
$this->messagelog .= 'Operation: Table named ' . $resourceTableName . ' with ' . $totalResourceTableFields . " Fields Generated in " . $schemaGenerationDuration . " seconds.\n";
// Populating data into created table
$queryBuilder = $entityManager->createQueryBuilder()->select('record')->from('HrisRecordsBundle:Record', 'record')->join('record.organisationunit', 'organisationunit')->join('record.form', 'form')->join('organisationunit.organisationunitStructure', 'organisationunitStructure')->getQuery();
try {
$records = $queryBuilder->getResult();
} catch (\Doctrine\Orm\NoResultException $e) {
echo 'Error in returning Data Values';
}
if (!empty($records)) {
/**
* Make sure organisationunitstructure is uptodate for good measure
*/
// Check and Notify if organisationunit structure doesn't exist
$queryBuilder = $entityManager->createQueryBuilder();
$organisationunitStructureCount = $queryBuilder->select('count( organisationunitStructure.id )')->from('HrisOrganisationunitBundle:OrganisationunitStructure', 'organisationunitStructure')->getQuery()->getSingleScalarResult();
$queryBuilder = $entityManager->createQueryBuilder();
$organisationunitCount = $queryBuilder->select('count( organisationunit.id )')->from('HrisOrganisationunitBundle:Organisationunit', 'organisationunit')->getQuery()->getSingleScalarResult();
// Regenerate Orgunit Stucture of Orgunit and OrgunitStructure Differs
if ($organisationunitCount != $organisationunitStructureCount) {
$logger->info('Regenerating organisationunit structure');
$this->returnMessage = '';
// Regenerate Orgunit Structure
$organisationunitStructure = new OrganisationunitStructureController();
$this->returnMessage = $organisationunitStructure->regenerateOrganisationunitStructure($entityManager);
} else {
$this->returnMessage = 'Organisationunit structure is complete!';
}
// Regenerate Levels if OrgunitLevel and DISTINCT OrgunitStructure.level differs
$organisationunitStructureLevels = $entityManager->createQuery('SELECT DISTINCT organisationunitLevel.level FROM HrisOrganisationunitBundle:OrganisationunitStructure organisationunitStructure INNER JOIN organisationunitStructure.level organisationunitLevel ORDER BY organisationunitLevel.level ')->getResult();
$organisationunitLevelInfos = $entityManager->createQuery('SELECT organisationunitLevel.level,organisationunitLevel.name,organisationunitLevel.description FROM HrisOrganisationunitBundle:OrganisationunitLevel organisationunitLevel ORDER BY organisationunitLevel.level ')->getResult();
$organisationunitStructureLevels = $this->array_value_recursive('level', $organisationunitStructureLevels);
示例14: _mp3Data
protected function _mp3Data()
{
if (empty($this->urls)) {
$this->getUrls();
}
$combined_data = [];
$stopwatch = new Stopwatch();
$stopwatch->start('download');
foreach ($this->urls as $url) {
set_time_limit(90);
list($filename, $data) = $this->_download($url);
if (!$filename) {
continue;
}
if (!empty($data)) {
sleep($this->sleep);
} else {
$data = file_get_contents($filename);
}
$combined_data[] = $data;
$stopwatch->lap('download');
}
$this->spent_time = $stopwatch->stop('download');
return $combined_data;
}