Skip to content

Commit

Permalink
[#272] Switch to new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragonite committed Sep 5, 2023
1 parent 02961ba commit 588a52d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 39 additions & 1 deletion classes/script_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,44 @@ public static function get_request(): string {
return $request;
}

/**
* Gets the name of the script.
* Parameters are share the names of globals as a hint to the caller.
* @param string $ME
* @param string $SCRIPT
* @return string the request path for this profile.
*/
public static function get_normalised_relative_script_path(?string $ME, ?string $SCRIPT): string {
if (isset($ME)) {
$scriptpath = $ME;
} else if (isset($SCRIPT)) {
$scriptpath = $SCRIPT;
} else {
return self::REQUEST_UNKNOWN;
}

// Remove consecutive slashes.
$scriptpath = preg_replace('/\/+/', '/', $scriptpath);

// Strip pathinfo.
$scriptpath = preg_replace('/\.php.*$/', '.php', $scriptpath, 1);

// Strip off the query string ($ME includes this).
$scriptpath = preg_replace('/\?.*$/', '', $scriptpath);

// Remove 'index.php' from the end ($SCRIPT includes this).
$scriptpath = preg_replace('/\/index\.php$/', '', $scriptpath, 1);

// Remove leading and trailing slashes.
$scriptpath = trim($scriptpath, '/');

if ($scriptpath === '') {
return '/';
}

return $scriptpath;
}

/**
* Checks the current response headers and tries to resolve the content type
* e.g. to store as part of the profile.
Expand Down Expand Up @@ -401,7 +439,7 @@ public static function get_timer_interval(): float {
public static function get_sampling_period(): float {
$period = get_config('tool_excimer', 'sample_ms') / 1000;
$insensiblerange = $period >= self::SAMPLING_PERIOD_MIN && $period <= self::SAMPLING_PERIOD_MAX;
if (! $insensiblerange) {
if (!$insensiblerange) {
set_config('sample_ms', self::SAMPLING_PERIOD_DEFAULT * 1000, 'tool_excimer');
$period = self::SAMPLING_PERIOD_DEFAULT;
}
Expand Down
4 changes: 3 additions & 1 deletion classes/web_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function init(manager $manager) {
// Record and set initial memory usage at this point.
$memoryusage = memory_get_usage();

$request = script_metadata::get_request();
global $ME, $SCRIPT;

$request = script_metadata::get_normalised_relative_script_path($ME, $SCRIPT);
$starttime = (int) $manager->get_starttime();
$this->sampleset = new sample_set($request, $starttime);

Expand Down

0 comments on commit 588a52d

Please sign in to comment.