Skip to content

Commit

Permalink
Fixed tests (8)
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikPrinsZA committed Sep 20, 2023
1 parent d1d7f97 commit e6c3db1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .env.circleci
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ DB_HOST_OVERRIDE=127.0.0.1
LK_PROGRESS_BAR_DISABLED=true
LK_DD_MAX_USERS=1000
LK_DD_MAX_USER_BLOGS=10
XDEBUG_MODE=profile
XDEBUG_MODE=profile,trace
SAIL_XDEBUG_MODE=profile,trace
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LOG_LEVEL=debug
# LK_RUN_MODE=debug

# Xdebug
SAIL_XDEBUG_MODE=profile
SAIL_XDEBUG_MODE=profile,trace
SAIL_XDEBUG_CONFIG="client_host=host.docker.internal output_dir=/var/www/html/storage/logs/xdebug"

# Database / Main
Expand Down
22 changes: 14 additions & 8 deletions app/Utilities/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Exceptions\BenchmarkProfileException;
use Closure;
use ErrorException;
use Illuminate\Support\Benchmark as SupportBenchmark;

class Benchmark extends SupportBenchmark
Expand Down Expand Up @@ -34,8 +35,6 @@ protected static function getTraceLineValue(array $lineParts, string $key): mixe

public static function profileGetStats(string $filepath): array
{
$filepath = trim($filepath, '.xt').'.xt';

if (! file_exists($filepath)) {
throw new BenchmarkProfileException(sprintf(
'Expected profile stats file not found at: %s',
Expand Down Expand Up @@ -78,6 +77,8 @@ public static function profileGetStats(string $filepath): array

}

fclose($handle);

if (is_null($start)) {
throw new BenchmarkProfileException('No start found');
}
Expand Down Expand Up @@ -117,24 +118,29 @@ public static function profile(
}

// Might want to save the static file for debugging...
$tempFilePath = sys_get_temp_dir().'/'.uniqid('xdt-', true);
// copy($tempFilePath.'.xt', sprintf('/var/www/html/sample-memory-%s.xt', now()->format('ymd_His')));

try {
$tempFile = tmpfile();
$tempFilePath = stream_get_meta_data($tempFile)['uri'];
xdebug_start_trace($tempFilePath, XDEBUG_TRACE_COMPUTERIZED);
xdebug_start_trace($tempFilePath, XDEBUG_TRACE_COMPUTERIZED | XDEBUG_TRACE_NAKED_FILENAME);
$benchmarkable();
xdebug_stop_trace();

return [
...self::profileGetStats($tempFilePath),
'max_iterations' => $maxIterations,
];
} catch (BenchmarkProfileException $_) {
} catch (BenchmarkProfileException $exception) {
return self::profile($benchmarkable, $maxIterations, $maxTries - 1);
} catch (ErrorException $exception) {
if ($exception->getMessage() === 'Functionality is not enabled') {
return [];
}

throw new BenchmarkProfileException($exception->getMessage());
} finally {
if (file_exists($tempFilePath.'.xt')) {
@unlink($tempFilePath.'.xt');
if (file_exists($tempFilePath)) {
@unlink($tempFilePath);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions docker/8.2/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
memory_limit = 4G

xdebug.mode=profile,trace
xdebug.start_with_request=trigger

0 comments on commit e6c3db1

Please sign in to comment.