bee.util
Profiling
A thread-safe profiler for measuring the self-time execution of named code blocks,
designed to work with nested scopes and parallel execution environments, potentially
leveraging InheritableThreadLocal
for parent scope tracking across threads
(especially effective with virtual threads).
Use this profiler with a try-with-resources statement:
try (Profiling ignored = Profiling.of("Your Scope Name")) { ... }
Results are collected globally and can be displayed using #show(UserInterface)
.
The reported time represents the "self-time" – time spent directly within a scope,
excluding time spent in nested child scopes started on the same logical thread
(as tracked by InheritableThreadLocal
).
close
()
void
Stops the timer, records the profiling data (if named), restores the parent scope for the current thread, and resumes the parent's timer. Automatically called by the try-with-resources statement.
measureJVMStartup
()
void
Records the approximate JVM startup time as a special profiling entry.
of
(String
name
)
Profiling
String
name
)String name |
The descriptive name for this profiling scope (e.g., "Compile", "Network IO"). Must not be null. |
Profiling |
An |
Starts a new profiling scope with the given name for the current thread.
This method MUST be used within a try-with-resources statement:
try (Profiling p = Profiling.of("Scope Name")) { ... }
show
(UserInterface
ui
)
void
UserInterface
ui
)UserInterface ui |
The |
Aggregates profiling results from all threads, formats them, and displays a summary.
Shows the top 10 scopes ranked by total self-time (minimum 1ms displayed), sorted descendingly. Percentages indicate contribution relative to the total time of the *displayed* top scopes. Includes JVM input arguments for context. Cleans up the current thread's profiler state.