stopTimer static method

void stopTimer(
  1. String timerId, {
  2. Map<String, String>? tags,
})

Stops a timer and records the duration.

Implementation

static void stopTimer(String timerId, {Map<String, String>? tags}) {
  if (!_enabled) return;

  final startTime = _timers.remove(timerId);
  if (startTime == null) return;

  final duration = DateTime.now().difference(startTime);
  final name = timerId.split('|').first;

  record(
    Metric(
      name: '$name.duration',
      type: MetricType.timer,
      value: duration.inMicroseconds,
      tags: {...?tags, 'unit': 'microseconds'},
    ),
  );
}