-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/run_information' into develop
- Loading branch information
Showing
10 changed files
with
202 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* Require Performance | ||
*/ | ||
|
||
require_once('../vendor/autoload.php'); | ||
use Performance\Performance; | ||
use Performance\Config; | ||
|
||
/* | ||
* Set config item | ||
*/ | ||
Config::setConsoleLive(true); | ||
Config::setRunInformation(true); | ||
|
||
/* | ||
* One simply performance check | ||
*/ | ||
Performance::point(); | ||
|
||
// Run task A | ||
for($x = 0; $x < 100; $x++) | ||
{ | ||
echo "."; | ||
usleep(3000); | ||
} | ||
|
||
// Finish all tasks and show test results | ||
Performance::results(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php namespace Performance\Lib\Holders; | ||
|
||
|
||
use Performance\Lib\Handlers\ConfigHandler; | ||
|
||
class InformationHolder | ||
{ | ||
// Config | ||
private $config; | ||
|
||
// Run information holder | ||
private $currentUser; | ||
private $currentProcessId; | ||
|
||
public function __construct(ConfigHandler $config) | ||
{ | ||
$this->config = $config; | ||
|
||
// Set information | ||
$this->activateConfig(); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getCurrentUser() | ||
{ | ||
return $this->currentUser; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getCurrentProcessId() | ||
{ | ||
return $this->currentProcessId; | ||
} | ||
|
||
// | ||
// Private | ||
// | ||
|
||
private function activateConfig() | ||
{ | ||
if($this->config->isRunInformation()) | ||
$this->setRunInformation(); | ||
} | ||
|
||
private function setRunInformation() | ||
{ | ||
// Set unknown | ||
$this->currentUser = '?'; | ||
$this->currentProcessId = '?'; | ||
|
||
|
||
// Set current user | ||
try{ | ||
$this->currentUser = get_current_user(); | ||
}catch (\ErrorException $exception) {} | ||
|
||
// Set current user | ||
try{ | ||
$this->currentProcessId = getmypid(); | ||
}catch (\ErrorException $exception) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php namespace Tests\Unit; | ||
|
||
use Performance\Performance; | ||
use Performance\Config; | ||
|
||
class T10A_ConfigRunInformationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
protected function setTestUp() | ||
{ | ||
Performance::instanceReset(); | ||
} | ||
|
||
public function testConfigRunInformation() | ||
{ | ||
$this->setTestUp(); | ||
|
||
// Set config | ||
Config::setRunInformation(true); | ||
|
||
// Run test tasks | ||
$this->synchronizeTaskARun(); | ||
|
||
// Finish all tasks and show test results | ||
Performance::results(); | ||
} | ||
|
||
// Create task | ||
|
||
private function synchronizeTaskARun() | ||
{ | ||
// Set point Task A | ||
Performance::point(__FUNCTION__); | ||
|
||
// | ||
// Run code | ||
usleep(2000); | ||
// | ||
|
||
// Finish point Task C | ||
Performance::finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php namespace Tests\Unit; | ||
|
||
use Performance\Config; | ||
use Performance\Performance; | ||
|
||
class T10B_ConfigRunInformationTest extends T10A_ConfigRunInformationTest | ||
{ | ||
protected function setTestUp() | ||
{ | ||
Performance::instanceReset(); | ||
Config::setPresenter('web'); | ||
} | ||
} |