fix(logger): skip profiling when the level is off, bound the profiler state - #10677
fix(logger): skip profiling when the level is off, bound the profiler state#10677davidfirst wants to merge 3 commits into
Conversation
PR Summary by QodoSkip disabled profiling and bound retained profiler state
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
|
Code review by qodo was updated up to the latest commit 09b41e0 |
|
Code review by qodo was updated up to the latest commit 98c3232 |
The logger profiler has two problems.
The log level controls only the printing.
profile()always records the time and builds the message. Therefore a disabled level does not prevent the work. The method now returns before it records the time, if the level is off. The--log=profileflag and theconsoleargument continue to work. The default level isdebug. Therefore allprofileTrace()calls are now free.profile()is a paired API. The daemon changes the level between CLI requests, therefore a measurement can stay open. A later call with the same id would then close it and report an incorrect time. The disabled call now discards the measurement of its own id. It does not touch the other ids, because requests can run in parallel.The profiler state increases without a limit. The profiler keeps one entry for each id, and it removes no entry. An id that changes for each call (for example
getMany-${callId}) makes the state increase for the life of the process. Thebit clidaemon does not stop, which makes this worse.The profiler now keeps the running measurements apart from the completed ones. Each group holds a maximum of 10000 entries. Each group removes its oldest entry to make space. Therefore a new measurement never removes a measurement that still runs. The limit is sufficient for real use: 300 components with 5 profile points on each need 1500 entries.
profiler.spec.tsadds 9 unit tests.