diff --git a/composer.json b/composer.json index aaa59925b..4f1212faf 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,9 @@ "description": "A web based interface for viewing profile data collected by XHProf.", "license": "MIT", "autoload": { + "psr-4": { + "Tideways\\Xhprof\\": "src/" + }, "psr-0": { "Xhgui_": "src/" } diff --git a/src/Xhgui/Controller/Export.php b/src/Xhgui/Controller/Export.php new file mode 100644 index 000000000..8cc93d288 --- /dev/null +++ b/src/Xhgui/Controller/Export.php @@ -0,0 +1,35 @@ +searcher = $searcher; + $this->converter = new CachegrindConverter(); + } + + public function cachegrind() + { + $request = $this->app->request(); + $id = $request->get('id'); + + $profile = $this->searcher->get($id); + $output = $this->converter->convertToCachegrind($profile->toArray()['profile']); + + $response = $this->app->response(); + $response['Content-Type'] = 'application/octet-stream'; + $response['Cache-Control'] = 'public, max-age=60, must-revalidate'; + $response['Content-Disposition'] = sprintf('attachment; filename=cachegrind-%s.out', $id); + $response->body($output); + } +} diff --git a/src/Xhgui/ServiceContainer.php b/src/Xhgui/ServiceContainer.php index e20b0ede1..813774ae1 100644 --- a/src/Xhgui/ServiceContainer.php +++ b/src/Xhgui/ServiceContainer.php @@ -154,6 +154,9 @@ protected function _controllers() $this['importController'] = function ($c) { return new Xhgui_Controller_Import($c['app'], $c['saver'], $c['config']['upload.token']); }; - } + $this['exportController'] = function ($c) { + return new Xhgui_Controller_Export($c['app'], $c['searcher']); + }; + } } diff --git a/src/routes.php b/src/routes.php index 1e47d9cb7..65cf8b237 100644 --- a/src/routes.php +++ b/src/routes.php @@ -88,6 +88,13 @@ $controller->import(); })->name('run.import'); +// Export +$app->get('/export/cachegrind', function () use ($di) { + /** @var Xhgui_Controller_Export $controller */ + $controller = $di['exportController']; + $controller->cachegrind(); +})->name('export.cachegrind'); + // Watch function routes. $app->get('/watch', function () use ($di, $app) { $app->controller = $di['watchController']; diff --git a/src/templates/runs/view.twig b/src/templates/runs/view.twig index cc3d7449c..f51344d58 100644 --- a/src/templates/runs/view.twig +++ b/src/templates/runs/view.twig @@ -21,6 +21,7 @@