Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR does a bunch of changes to slow the coroutine detection mechanism:
function started 1.268 seconds ago
.@profile
decorator that logs statistics for the function and allows a developer to find the reason for its slowness and adds to the traceback a tip to use this decorator, which includes mentioning the function it should be applied to.This is how the current traceback looks after the PR changes:
You can see the duration in each line, a much shorter stack, and a tip at the end.
Internally, both main thread stack tracing and function profiler use the same mechanism for tracking the execution, so they are written in a compatible way. When the profiler decorator starts profiling the specific function, it temporarily turns off the main thread stack tracing and turns it on again after the profiling is done.
The statistics generated by the profiler go through important cosmetic updates before it is printed to the logs. First, some functions in Tribler are auto-generated, and their filenames actually contain the entire source code of the function, which destroys the profiler output. The cleanup fixes the names for such functions so they can be displayed in a table alongside other functions. Second, internal calls that a very fast are removed from the resulting statistics, so only functions that affect the execution time are shown in the statistics output; the function that makes the most slowdown is shown first.