Untangle.Time (Bonfire v0.9.12-social-beta.68)
View SourceProvides timing utilities for measuring function execution time.
This module offers decorators for measuring and logging the execution time of functions:
time()
: Basic measurement of single function callstime_process()
: Tracks count and total time across multiple callstime_tree()
: Captures timing across process trees
Summary
Functions
Decorator that measures and logs execution time of functions.
Decorator that aggregates execution counts and times across multiple calls.
Decorator that measures execution time across a process tree.
Functions
Decorator that measures and logs execution time of functions.
When applied to a function, this decorator will:
- Measure the function's execution time if the logger level is set to
:debug
- Log the execution time if it exceeds a configured threshold (default: 10,000 microseconds)
- Return the function's result unchanged
Configuration
The minimum time threshold for logging can be configured in your application:
config :untangle, :time_slow_min, 10_000 # microseconds
Examples
defmodule Demo do
use Untangle.Time
@decorate time()
def slow_function(ms) do
Process.sleep(ms)
:ok
end
end
Decorator that aggregates execution counts and times across multiple calls.
When applied to a function, this decorator will:
- Track each call in the process dictionary
- Count the number of executions
- Sum total execution time
- Log detailed statistics when execution time exceeds threshold
- Return the function's result unchanged
Examples
defmodule Demo do
use Untangle.Time
@decorate time_process()
def repeated_function(ms) do
Process.sleep(ms)
:ok
end
end
After multiple calls, logs will include call count and total time.
Decorator that measures execution time across a process tree.
When applied to a function, this decorator will:
- Track execution time of the function in the current process and all processes it spawns
- Log detailed timing statistics when execution completes
- Return the function's result unchanged
Requires the ProcessTree library to be added to your app's dependencies.
Examples
defmodule Demo do
use Untangle.Time
@decorate time_tree()
def spawn_function(depth \ 1) do
Process.sleep(50)
if depth < 3 do
Task.async(fn ->
Demo.spawn_function(depth + 1)
end)
|> Task.await()
end
:ok
end
end