def benchmark(func):
  '''
  Decorator method to help gather metrics.
  '''

  global _metrics

  def wrapper(*__args, **__kwargs):
    name = func.__name__

    start_time = time.time()
    result = func.__call__(*__args, **__kwargs)
    delta_t = time.time() - start_time

    try:
      _metrics_lock.acquire()

      if not _metrics.has_key(name):
        _metrics[name] = [ 1, delta_t ]
      else:
        _metrics[name][0] += 1
        _metrics[name][1] += delta_t

    finally:
      _metrics_lock.release()

    return result
  return wrapper