-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WebProfiler] Add a limit how many profiles should be saved #45831
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
Comments
Does anyone know how to implement it ? Is there native/efficient way to manage this ? (I'm very interested by this feature and can help to the PR) |
I think it should be part of Instead of a max number of profiles, I would remove the oldest ones, which could be done during a call to |
Can we use https://symfony.com/doc/current/reference/events.html#kernel-terminate ? Given such config: framework:
profiler:
max_retention_days: 3 # number of days to keep local profile files |
I think we can implements same logic of monolog RotatingFileHandler in Have a parameter in config is a good thing |
I would keep this as simple as possible, aka not configurable. |
@fabpot Is it a good approach ? And cpu/memory efficient implementation ? (seems good when no expired profile, tmp file in other case) public function removeOldestProfiles(string $indexFilename)
{
$minimalProfileTime = (new \DateTime())
->modify(sprintf('-%d days', self::MAX_RETENTION_DAYS))
->getTimestamp();
$handle = fopen($indexFilename, 'r');
$tmpIndexFileName = $indexFilename.'.tmp';
$beforeTime = true;
$atLeastOneProfileBeforeTime = false;
while ($beforeTime && $line = fgets($handle)) {
$csv = str_getcsv($line);
$profileTime = (int) $csv[4];
if ($profileTime > $minimalProfileTime) {
$beforeTime = false;
file_put_contents($tmpIndexFileName, $line);
} else {
$atLeastOneProfileBeforeTime = true;
}
}
if ($atLeastOneProfileBeforeTime) {
file_put_contents($tmpIndexFileName, stream_get_contents($handle), FILE_APPEND);
unlink($indexFilename);
rename($tmpIndexFileName, $indexFilename);
} else {
fclose($handle);
} I can open draft PR if it a better place for theses questions |
…es mechanism (alamirault) This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [HttpKernel] FileProfilerStorage remove expired profiles mechanism | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #45831 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> This is a first attempt for limit number of profiles saved (discussed in #45831). When we save new profile, all expired profiles are removed. Expiration is one day for the moment. Questions: - Not sure how to deal, profiles with time `0`, like an unexpired profile ? - I assume profiles are sorted and oldest profile is on firstline. -> avoid readind all index file if first profile is not expired - Is there a best way ? (cpu/memory, io efficient) (I'm not sure I have the necessary skills, changes are welcome :)) TODOS: - [x] Changelog - [x] Complete tests - [ ] Symfony docs PR Commits ------- 58d0662 [HttpKernel] FileProfilerStorage remove expired profiles mechanism
Description
I let run the profiler for a while and have now 80k profiles saved. It would be nice if we could set a limit of max profiles should be set and delete older ones to save disk
Example
The text was updated successfully, but these errors were encountered: