Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend decoupling #244

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
"slim/views": "^0.1.0",
"twig/twig": "~1.17",
"pimple/pimple": "^1.0.2",
"perftools/xhgui-collector": "^1.4.0"
"perftools/xhgui-collector": "^1.7.0"
},
"require-dev": {
"alcaeus/mongo-php-adapter": "^1.1",
"phpunit/phpunit": "^5.7.27 | ^6.5.13",
"ext-dom": "*"
"phpunit/phpunit": "^5.7.27 | ^6.5.13"
},
"scripts": {
"test": "phpunit",
Expand Down
9 changes: 8 additions & 1 deletion config/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
//
'save.handler' => 'mongodb',

'pdo' => array(
'dsn' => null,
'user' => null,
'pass' => null,
'table' => 'results'
),

// Database options for MongoDB.
//
// - db.host: Connection string in the form `mongodb://[ip or host]:[port]`.
Expand Down Expand Up @@ -68,7 +75,7 @@
// Default: Remove numeric values after `=`. For example,
// it turns "/foo?page=2" into "/foo?page".
'profiler.simple_url' => null,

// Enable to clean up the url saved to the DB
// in this way is possible to remove sensitive data or other kind of data
'profiler.replace_url' => null,
Expand Down
2 changes: 1 addition & 1 deletion external/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}

$container = Xhgui_ServiceContainer::instance();
$saver = $container['saverMongo'];
$saver = $container['saver.mongo'];


while (!feof($fp)) {
Expand Down
14 changes: 13 additions & 1 deletion src/Xhgui/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@

use Slim\Slim;

class Xhgui_Controller
abstract class Xhgui_Controller
glensc marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* @var array
*/
protected $_templateVars = array();

/**
* @var string|null
*/
protected $_template = null;

/**
* @var Slim
*/
protected $app;

public function __construct(Slim $app)
{
$this->app = $app;
}

public function set($vars)
{
$this->_templateVars = array_merge($this->_templateVars, $vars);
Expand Down
25 changes: 12 additions & 13 deletions src/Xhgui/Controller/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class Xhgui_Controller_Custom extends Xhgui_Controller
{
/**
* @var Xhgui_Profiles
* @var Xhgui_Searcher_Interface
*/
protected $profiles;
protected $searcher;

public function __construct(Slim $app, Xhgui_Profiles $profiles)
public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
{
$this->app = $app;
$this->profiles = $profiles;
parent::__construct($app);
$this->searcher = $searcher;
}

public function get()
Expand All @@ -24,9 +24,9 @@ public function help()
{
$request = $this->app->request();
if ($request->get('id')) {
$res = $this->profiles->get($request->get('id'));
$res = $this->searcher->get($request->get('id'));
} else {
$res = $this->profiles->latest();
$res = $this->searcher->latest();
}
$this->_template = 'custom/help.twig';
$this->set(array(
Expand All @@ -42,12 +42,12 @@ public function query()

$query = json_decode($request->post('query'), true);
$error = array();
if (is_null($query)) {
if (null === $query) {
$error['query'] = json_last_error();
}

$retrieve = json_decode($request->post('retrieve'), true);
if (is_null($retrieve)) {
if (null === $retrieve) {
$error['retrieve'] = json_last_error();
}

Expand All @@ -58,9 +58,8 @@ public function query()

$perPage = $this->app->config('page.limit');

$res = $this->profiles->query($query, $retrieve)
->limit($perPage);
$r = iterator_to_array($res);
return $response->body(json_encode($r));
$res = $this->searcher->query($query, $perPage, $retrieve);

return $response->body(json_encode($res));
}
}
6 changes: 3 additions & 3 deletions src/Xhgui/Controller/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
class Xhgui_Controller_Import extends Xhgui_Controller
{
/**
* @var Xhgui_Saver_Mongo
* @var Xhgui_Saver_Interface
*/
private $saver;

public function __construct(Slim $app, Xhgui_Saver_Mongo $saver)
public function __construct(Slim $app, Xhgui_Saver_Interface $saver)
{
$this->app = $app;
parent::__construct($app);
$this->saver = $saver;
}

Expand Down
59 changes: 27 additions & 32 deletions src/Xhgui/Controller/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class Xhgui_Controller_Run extends Xhgui_Controller
* HTTP GET attribute name for comma separated filters
*/
const FILTER_ARGUMENT_NAME = 'filter';

/**
* @var Xhgui_Profiles
*/
private $profiles;

/**
* @var Xhgui_WatchFunctions
* @var Xhgui_Searcher_Interface
*/
private $watches;
private $searcher;

public function __construct(Slim $app, Xhgui_Profiles $profiles, Xhgui_WatchFunctions $watches)
public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
{
$this->app = $app;
$this->profiles = $profiles;
$this->watches = $watches;
parent::__construct($app);
$this->searcher = $searcher;
}

public function index()
Expand All @@ -39,7 +33,7 @@ public function index()
}
$sort = $request->get('sort');

$result = $this->profiles->getAll(array(
$result = $this->searcher->getAll(array(
'sort' => $sort,
'page' => $request->get('page'),
'direction' => $request->get('direction'),
Expand Down Expand Up @@ -81,7 +75,7 @@ public function view()
{
$request = $this->app->request();
$detailCount = $this->app->config('detail.count');
$result = $this->profiles->get($request->get('id'));
$result = $this->searcher->get($request->get('id'));

$result->calculateSelf();

Expand All @@ -93,7 +87,7 @@ public function view()

// Watched Functions Block
$watchedFunctions = array();
foreach ($this->watches->getAll() as $watch) {
foreach ($this->searcher->getAllWatches() as $watch) {
$matches = $result->getWatched($watch['name']);
if ($matches) {
$watchedFunctions = array_merge($watchedFunctions, $matches);
Expand All @@ -116,7 +110,7 @@ public function view()
'date_format' => $this->app->config('date.format'),
));
}

/**
* @return array
*/
Expand All @@ -129,7 +123,7 @@ protected function getFilters()
} else {
$filters = $this->app->config('run.view.filter.names');
}

return $filters;
}

Expand All @@ -142,7 +136,7 @@ public function deleteForm()
}

// Get details
$result = $this->profiles->get($id);
$result = $this->searcher->get($id);

$this->_template = 'runs/delete-form.twig';
$this->set(array(
Expand All @@ -164,7 +158,7 @@ public function deleteSubmit()
}

// Delete the profile run.
$delete = $this->profiles->delete($id);
$this->searcher->delete($id);

$this->app->flash('success', 'Deleted profile ' . $id);

Expand All @@ -178,10 +172,8 @@ public function deleteAllForm()

public function deleteAllSubmit()
{
$request = $this->app->request();

// Delete all profile runs.
$delete = $this->profiles->truncate();
$this->searcher->truncate();

$this->app->flash('success', 'Deleted all profiles');

Expand All @@ -204,17 +196,20 @@ public function url()
$search[$key] = $request->get($key);
}

$runs = $this->profiles->getForUrl(
$runs = $this->searcher->getForUrl(
$request->get('url'),
$pagination,
$search
);

if (isset($search['limit_custom']) && strlen($search['limit_custom']) > 0 && $search['limit_custom'][0] == 'P') {
if (isset($search['limit_custom']) &&
strlen($search['limit_custom']) > 0 &&
$search['limit_custom'][0] === 'P'
) {
$search['limit'] = $search['limit_custom'];
}

$chartData = $this->profiles->getPercentileForUrl(
$chartData = $this->searcher->getPercentileForUrl(
90,
$request->get('url'),
$search
Expand Down Expand Up @@ -247,7 +242,7 @@ public function compare()
$paging = array();

if ($request->get('base')) {
$baseRun = $this->profiles->get($request->get('base'));
$baseRun = $this->searcher->get($request->get('base'));
}

if ($baseRun && !$request->get('head')) {
Expand All @@ -257,7 +252,7 @@ public function compare()
'page' => $request->get('page'),
'perPage' => $this->app->config('page.limit'),
);
$candidates = $this->profiles->getForUrl(
$candidates = $this->searcher->getForUrl(
$baseRun->getMeta('simple_url'),
$pagination
);
Expand All @@ -271,7 +266,7 @@ public function compare()
}

if ($request->get('head')) {
$headRun = $this->profiles->get($request->get('head'));
$headRun = $this->searcher->get($request->get('head'));
}

if ($baseRun && $headRun) {
Expand Down Expand Up @@ -301,7 +296,7 @@ public function symbol()
$id = $request->get('id');
$symbol = $request->get('symbol');

$profile = $this->profiles->get($id);
$profile = $this->searcher->get($id);
$profile->calculateSelf();
list($parents, $current, $children) = $profile->getRelatives($symbol);

Expand All @@ -324,7 +319,7 @@ public function symbolShort()
$symbol = $request->get('symbol');
$metric = $request->get('metric');

$profile = $this->profiles->get($id);
$profile = $this->searcher->get($id);
$profile->calculateSelf();
list($parents, $current, $children) = $profile->getRelatives($symbol, $metric, $threshold);

Expand All @@ -342,7 +337,7 @@ public function symbolShort()
public function callgraph()
{
$request = $this->app->request();
$profile = $this->profiles->get($request->get('id'));
$profile = $this->searcher->get($request->get('id'));

$this->_template = 'runs/callgraph.twig';
$this->set(array(
Expand All @@ -355,7 +350,7 @@ public function callgraphData()
{
$request = $this->app->request();
$response = $this->app->response();
$profile = $this->profiles->get($request->get('id'));
$profile = $this->searcher->get($request->get('id'));
$metric = $request->get('metric') ?: 'wt';
$threshold = (float)$request->get('threshold') ?: 0.01;
$callgraph = $profile->getCallgraph($metric, $threshold);
Expand All @@ -368,7 +363,7 @@ public function callgraphDataDot()
{
$request = $this->app->request();
$response = $this->app->response();
$profile = $this->profiles->get($request->get('id'));
$profile = $this->searcher->get($request->get('id'));
$metric = $request->get('metric') ?: 'wt';
$threshold = (float)$request->get('threshold') ?: 0.01;
$callgraph = $profile->getCallgraphNodes($metric, $threshold);
Expand Down
Loading