Last updated:
0 purchases
performance timer
Performance Timer #
Performance Timer is a package that allows you to time function and method
calls, allowing for nesting/children timers, tracking real and own time spent
inside each timer.
Also allows for printing the results or dumping them to Trace Event Format,
which can then be parsed and analyzed by a lot of Trace analyzers, like
Google Perfetto (https://ui.perfetto.dev/)
Features #
Track time spent inside a method with timer.ownDuration and timer.child
Track all time spent since timer creation with timer.realDuration
Store additional data linked to each (root) timer with timer.setTag
Print results with PerformanceTimerSerializerString
Export results to TraceEventFormat with PerformanceTimerSerializerTraceEvent
Usage #
Create a timer
final timer = PerformanceTimer(name: 'rootTimer', category: 'category', tags: {'key': 'value'});
// Do some work
timer.finish();
copied to clipboard
Create a nested/child timer
// Create a child event, which pause `timer.ownDuration`.
final child = timer.child('childTimer');
// Do some work
// ...
// Stop timer and signal parent to resume `timer.ownDuration`.
child.finish();
copied to clipboard
Measure a callback
await timer.measure(
'childTimer',
() async {
// Do some work
},
);
copied to clipboard
Add a tag
timer.setTag('result', '3');
// If setting a tag inside a child, then it
// sets it on the root timer (in this case, `timer`)
child.setTag('result', '3');
copied to clipboard
Remove a tag
timer.setTag('result');
// If removing a tag inside a child, then it
// removes it on the root timer (in this case, `timer`)
child.setTag('result');
copied to clipboard
Serialize the results
const stringSerializer = PerformanceTimerSerializerString();
print(await stringSerializer.serialize(timer));
const traceEventSerializer = PerformanceTimerSerializerTraceEvent();
print(jsonEncode(await traceEventSerializer.serialize(timer)));
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.