logml.stopwatch
Simple stopwatch module to track execution performance.
Classes
|
Default time tracker. |
|
Simple time tracker to check execution time. |
|
Context manager that tracks time. |
- class logml.stopwatch.TimeTracker(parent_sw, name: str)
Bases:
object
Context manager that tracks time.
- class logml.stopwatch.NullTracker(*args, **kwargs)
Bases:
object
Default time tracker.
- class logml.stopwatch.Stopwatch(enabled: bool = True, name: Optional[str] = None, summary_file=None)
Bases:
object
Simple time tracker to check execution time.
Usage: .. code-block:
sw = Stopwatch() @sw.decorate('init') # name optional def fn1(): pass # track execution without a function: with sw.track("render_loop"): while(not stop): render()
- enable()
Enable tracking.
- disable()
Disable tracking.
- reset_state(profile, log_file: str)
Resets state of SW.
- property enabled: bool
Checks whether SW was enabled.
- track(name)
Returns context manager to be used with tracked block:
with sw.track("save_to_db"): hibernate.save()
- on_start(name: str)
Invoke on entering a function.
- on_finish(name: str, duration: float)
Invoke when exiting from the function.
- decorate(name_or_func)
Decorator for functions being tracked. Can be used as is, or with name as parameter.
- get_summary_df(max_threshold: Optional[float] = None) Optional[pandas.core.frame.DataFrame]
Wraps result of get_summary into pandas dataframe
- Parameters
max_threshold – when provided, datafarme is filtered to contain max time >= this value
- Returns
pd.DataFrame
- get_summary()
Fetch summary for time tracks (sum, count, statistics). :rtype: list or dictionaries, one per name.
- dump_summary()
Creates a file with a summary of seen runs.