Timing.md
PuduLangLog.Timing
type: module path: "@root/src/PuduLangLog/Timing.pudu" fidelity: Active grammar: "[[grammar/pudu]]" depth_score: 0.6 depth_status: MEDIUM tags: [module] aliases: [PuduLangLog.Timing, operations]
Purpose
Measures a unit of work and writes one event when it ends: Charging 42 completed in 12.3 ms, or abandoned when it did not finish its job.
Interface
Signatures
export type Operation = {
logger: Logger.Logger,
template: Str,
arguments: Array[Log.Value],
started: Int,
completion: Log.Level,
abandonment: Log.Level,
warningAfter: Option[Int],
properties: Array[(Str, Log.Value)],
finished: Sync.Cell[Bool],
elapsed: fn() -> Int
}
export fn begin(logger: &Logger.Logger, template: Str, arguments: Array[Log.Value]) -> Operation
export fn beginWith(logger: &Logger.Logger, template: Str, arguments: Array[Log.Value], elapsed: fn() -> Int) -> Operation
export fn run[T](logger: &Logger.Logger, template: Str, arguments: Array[Log.Value], action: fn() -> T) -> T
export fn runResult[T, E](logger: &Logger.Logger, template: Str, arguments: Array[Log.Value], kind: Str, action: fn() -> Result[T, E]) -> Result[T, E]
export trait Measuring {
fn at(self: &Self, completion: Log.Level, abandonment: Log.Level) -> Self
fn warnAfter(self: &Self, millis: Int) -> Self
fn enrichWith(self: &Self, name: Str, held: Log.Value) -> Self
fn complete(self: &Self) -> ()
fn completeWith(self: &Self, name: Str, held: Log.Value) -> ()
fn abandon(self: &Self) -> ()
fn abandonWith(self: &Self, failure: Log.Failure) -> ()
fn cancel(self: &Self) -> ()
}Linkage
- Requires: [[src/PuduLangLog]], [[src/PuduLangLog/Domain/Levels]], [[src/PuduLangLog/Failure]], [[src/PuduLangLog/Logger]],
Std.Decimal,Std.Sync,Std.Time. - Consumed by: package users.
Algorithm
beginrecords the monotonic time;beginWithtakes the counter from the caller.- Ending writes the operation's template followed by
{Outcome:l} in {Elapsed:0.0} ms, binding the template's arguments, thenOutcome(completedorabandoned) andElapsedin milliseconds. - Completion writes at
Informationand abandonment atWarningunlessatchanges them; withwarnAfter, a completion slower than the limit is raised to at leastWarning. enrichWithandcompleteWithadd properties to the outcome event;abandonWithattaches a failure;cancelends the operation silently.runcompletes around an action;runResultcompletes onOkand abandons with the error onErr.
Negative Logic (Prohibited Paths)
- An operation writes at most one event, however many times it is ended.
Edge Cases
- An operation never ended writes nothing; there is no finalizer to abandon it.
Depth
DEPTH 0.6 (MEDIUM). Tested by test/PuduLangLog/TimingTest.
Grill Log
- Q: Why must the caller end an operation explicitly? A: Pudu has no scope-exit hook, so an operation cannot notice it was dropped.
runandrunResultend it for the common shapes. _Rejected:_ a background timeout that guesses.
Referenced by
[[src/PuduLangLog/_MOC]] · [[src/PuduLangLog/Clock]] · [[src/PuduLangLog/Failure]] · [[subsystems/Pipeline]]
