Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #618 from chillu/pull/deprecate-profiler
API Deprecated Profiler class, removed related debug GET params
  • Loading branch information
chillu committed Jul 5, 2012
2 parents bc99382 + 0fe515e commit e00c875
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 69 deletions.
12 changes: 2 additions & 10 deletions control/Director.php
Expand Up @@ -134,15 +134,7 @@ static function direct($url, DataModel $model) {

$res = Injector::inst()->get('RequestProcessor')->postRequest($req, $response, $model);
if ($res !== false) {
// ?debug_memory=1 will output the number of bytes of memory used for this request
if(isset($_REQUEST['debug_memory']) && $_REQUEST['debug_memory']) {
Debug::message(sprintf(
"Peak memory usage in bytes: %s",
number_format(memory_get_peak_usage(),0)
));
} else {
$response->output();
}
$response->output();
} else {
// @TODO Proper response here.
throw new SS_HTTPResponse_Exception("Invalid response");
Expand Down Expand Up @@ -957,4 +949,4 @@ public static function get_template_global_variables() {
'BaseHref' => 'absoluteBaseURL', //@deprecated 3.0
);
}
}
}
3 changes: 3 additions & 0 deletions dev/Profiler.php
Expand Up @@ -9,6 +9,8 @@

/**
* Execution time profiler.
*
* @deprecated 3.1 The Profiler class is deprecated, use third party tools like XHProf instead
*
* @package framework
* @subpackage misc
Expand Down Expand Up @@ -51,6 +53,7 @@ function Profiler( $output_enabled=false, $trace_enabled=false)
// Public Methods

static function init() {
Deprecation::notice('3.1', 'The Profiler class is deprecated, use third party tools like XHProf instead');
if(!self::$inst) self::$inst = new Profiler(true,true);
}

Expand Down
9 changes: 9 additions & 0 deletions docs/en/changelogs/3.1.0.md
@@ -0,0 +1,9 @@
# 3.1.0 (unreleased)

## Overview ##

## Upgrading

* Deprecated `Profiler` class, use third-party solutions like [xhprof](https://github.com/facebook/xhprof/)
* Removed defunct or unnecessary debug GET parameters:
`debug_profile`, `debug_memory`, `profile_trace`, `debug_javascript`, `debug_behaviour`
9 changes: 0 additions & 9 deletions docs/en/reference/urlvariabletools.md
Expand Up @@ -45,15 +45,6 @@ Append the option and corresponding value to your URL in your browser's address
| showqueries | | 1 | | List all SQL queries executed |
| previewwrite | | 1 | | List all insert / update SQL queries, and **don't** execute them. Useful for previewing writes to the database. |

## Profiling

| URL Variable | | Values | | Description |
| ------------ | | ------ | | ----------- |
| debug_memory | | 1 | | Output the number of bytes of memory used for this
| debug_memory | | 1 | | Output the number of bytes of memory used for this request |
| debug_profile | | 1 | | Enable the [profiler](/topics/debugging) for the duration of the request |
| profile_trace | | 1 | | Includes full stack traces, must be used with **debug_profile** |

## Security Redirects

You can set an URL to redirect back to after a [Security](/topics/security) action. See the section on [URL
Expand Down
23 changes: 1 addition & 22 deletions main.php
Expand Up @@ -36,9 +36,6 @@
* After that, it calls {@link Director::direct()}, which is responsible for doing most of the
* real work.
*
* Finally, main.php will use {@link Profiler} to show a profile if the querystring variable
* "debug_profile" is set.
*
* CONFIGURING THE WEBSERVER
*
* To use SilverStripe, every request that doesn't point directly to a file should be rewritten to
Expand Down Expand Up @@ -89,12 +86,6 @@
// Remove base folders from the URL if webroot is hosted in a subfolder
if (substr(strtolower($url), 0, strlen(BASE_URL)) == strtolower(BASE_URL)) $url = substr($url, strlen(BASE_URL));

if (isset($_GET['debug_profile'])) {
Profiler::init();
Profiler::mark('all_execution');
Profiler::mark('main.php init');
}

// Connect to database
require_once('model/DB.php');

Expand All @@ -114,20 +105,8 @@
die();
}

if (isset($_GET['debug_profile'])) Profiler::mark('DB::connect');
DB::connect($databaseConfig);
if (isset($_GET['debug_profile'])) Profiler::unmark('DB::connect');

if (isset($_GET['debug_profile'])) Profiler::unmark('main.php init');


// Direct away - this is the "main" function, that hands control to the appropriate controller
DataModel::set_inst(new DataModel());
Director::direct($url, DataModel::inst());

if (isset($_GET['debug_profile'])) {
Profiler::unmark('all_execution');
if(!Director::isLive()) {
Profiler::show(isset($_GET['profile_trace']));
}
}
Director::direct($url, DataModel::inst());
8 changes: 0 additions & 8 deletions model/Database.php
Expand Up @@ -455,8 +455,6 @@ function requireField($table, $field, $spec) {
$fieldValue = null;
$newTable = false;

Profiler::mark('requireField');

// backwards compatibility patch for pre 2.4 requireField() calls
$spec_orig=$spec;

Expand Down Expand Up @@ -507,10 +505,7 @@ function requireField($table, $field, $spec) {
}

if($newTable || $fieldValue=='') {
Profiler::mark('createField');

$this->transCreateField($table, $field, $spec_orig);
Profiler::unmark('createField');
$this->alterationMessage("Field $table.$field: created as $spec_orig","created");
} else if($fieldValue != $specValue) {
// If enums/sets are being modified, then we need to fix existing data in the table.
Expand Down Expand Up @@ -545,12 +540,9 @@ function requireField($table, $field, $spec) {
}
}
}
Profiler::mark('alterField');
$this->transAlterField($table, $field, $spec_orig);
Profiler::unmark('alterField');
$this->alterationMessage("Field $table.$field: changed to $specValue <i style=\"color: #AAA\">(from {$fieldValue})</i>","changed");
}
Profiler::unmark('requireField');
}

/**
Expand Down
4 changes: 0 additions & 4 deletions view/Requirements.php
Expand Up @@ -646,8 +646,6 @@ function restore() {
* @return string HTML content thats augumented with the requirements before the closing <head> tag.
*/
function includeInHTML($templateFile, $content) {
if(isset($_GET['debug_profile'])) Profiler::mark("Requirements::includeInHTML");

if((strpos($content, '</head>') !== false || strpos($content, '</head ') !== false) && ($this->css || $this->javascript || $this->customCSS || $this->customScript || $this->customHeadTags)) {
$requirements = '';
$jsRequirements = '';
Expand Down Expand Up @@ -712,8 +710,6 @@ function includeInHTML($templateFile, $content) {
}
}

if(isset($_GET['debug_profile'])) Profiler::unmark("Requirements::includeInHTML");

return $content;
}

Expand Down
8 changes: 0 additions & 8 deletions view/SSViewer.php
Expand Up @@ -810,22 +810,16 @@ public function process($item, $arguments = null) {
$template = $this->chosenTemplates[$key];
}

if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process", " for $template");
$cacheFile = TEMP_FOLDER . "/.cache" . str_replace(array('\\','/',':'), '.', Director::makeRelative(realpath($template)));

$lastEdited = filemtime($template);

if(!file_exists($cacheFile) || filemtime($cacheFile) < $lastEdited || isset($_GET['flush'])) {
if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process - compile", " for $template");

$content = file_get_contents($template);
$content = SSViewer::parseTemplateContent($content, $template);

$fh = fopen($cacheFile,'w');
fwrite($fh, $content);
fclose($fh);

if(isset($_GET['debug_profile'])) Profiler::unmark("SSViewer::process - compile", " for $template");
}

$underlay = array('I18NNamespace' => basename($template));
Expand All @@ -846,8 +840,6 @@ public function process($item, $arguments = null) {

array_pop(SSViewer::$topLevel);

if(isset($_GET['debug_profile'])) Profiler::unmark("SSViewer::process", " for $template");

// If we have our crazy base tag, then fix # links referencing the current page.
if($this->rewriteHashlinks && self::$options['rewriteHashlinks']) {
if(strpos($output, '<base') !== false) {
Expand Down
8 changes: 0 additions & 8 deletions view/ViewableData.php
Expand Up @@ -351,10 +351,6 @@ public function renderWith($template, $customFields = null) {
* @param string $cacheName a custom cache name
*/
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
if(isset($_REQUEST['debug_profile'])) {
Profiler::mark("obj.$fieldName", "on a $this->class object");
}

if(!$cacheName) $cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName;

if(!isset($this->objCache[$cacheName])) {
Expand Down Expand Up @@ -384,10 +380,6 @@ public function obj($fieldName, $arguments = null, $forceReturnedObject = true,
$value = $this->objCache[$cacheName];
}

if(isset($_REQUEST['debug_profile'])) {
Profiler::unmark("obj.$fieldName", "on a $this->class object");
}

if(!is_object($value) && $forceReturnedObject) {
$default = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
$value = new $default($fieldName);
Expand Down

0 comments on commit e00c875

Please sign in to comment.