performance_timer 3.1.0 copy "performance_timer: ^3.1.0" to clipboard
performance_timer: ^3.1.0 copied to clipboard

A timer and utils to count time spent on methods and calculations

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();
  • 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();
  • Measure a callback
await timer.measure(
  'childTimer',
  () async {
    // Do some work
  },
);
  • 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');
  • 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');
  • Serialize the results
const stringSerializer = PerformanceTimerSerializerString();
print(await stringSerializer.serialize(timer));

const traceEventSerializer = PerformanceTimerSerializerTraceEvent();
print(jsonEncode(await traceEventSerializer.serialize(timer)));
7
likes
150
points
786
downloads

Publisher

verified publishernicobritos.com

Weekly Downloads

A timer and utils to count time spent on methods and calculations

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

duration, fixnum, http, meta, quiver

More

Packages that depend on performance_timer