class_docstr: A context manager that tracks call count and latency, and other stats.
  
  Usage:
      sw = stopwatch.Stopwatch()
      with sw("foo"):
        foo()
      with sw("bar"):
        bar()
      @sw.decorate
      def func():
        pass
      func()
      print(sw)
class_docstr_tok: ["A","context","manager","that","tracks","call","count","and","latency",",","and","other","stats",".","Usage",":","sw","=","stopwatch.Stopwatch","(",")","with","sw","(","``","foo","''",")",":","foo","(",")","with","sw","(","``","bar","''",")",":","bar","(",")","@","sw.decorate","def","func","(",")",":","pass","func","(",")","print","(","sw",")"]
docstr: Decorate a function/method to check its timings.
  
  To use the function's name:
    @sw.decorate
    def func():
      pass
  
  To name it explicitly:
    @sw.decorate("name")
    def random_func_name():
      pass
  
  Args:
    name_or_func: the name or the function to decorate.
  
  Returns:
    If a name is passed, returns this as a decorator, otherwise returns the
    decorated function.
docstr_tok: ["Decorate","a","function\/method","to","check","its","timings",".","To","use","the","function","'s","name",":","@","sw.decorate","def","func","(",")",":","pass","To","name","it","explicitly",":","@","sw.decorate","(","``","name","''",")","def","random_func_name","(",")",":","pass","Args",":","name_or_func",":","the","name","or","the","function","to","decorate",".","Returns",":","If","a","name","is","passed",",","returns","this","as","a","decorator",",","otherwise","returns","the","decorated","function","."]
code: def decorate(self, name_or_func):
      """Decorate a function/method to check its timings.
  
      To use the function's name:
        @sw.decorate
        def func():
          pass
  
      To name it explicitly:
        @sw.decorate("name")
        def random_func_name():
          pass
  
      Args:
        name_or_func: the name or the function to decorate.
  
      Returns:
        If a name is passed, returns this as a decorator, otherwise returns the
        decorated function.
      """
      if os.environ.get("SC2_NO_STOPWATCH"):
          return (
              name_or_func
              if callable(name_or_func)
              else lambda func: func
          )
  
      def decorator(name, func):
          @functools.wraps(func)
          def _stopwatch(*args, **kwargs):
              with self(name):
                  return func(*args, **kwargs)
  
          return _stopwatch
  
      if callable(name_or_func):
          return decorator(name_or_func.__name__, name_or_func)
      else:
          return lambda func: decorator(name_or_func, func)
  
imports: import collections
  import functools
  import math
  import os
  import sys
  import threading
  import time
label_desc: Use image node_id 7 for calling the StopWatch obj's underlying member method code with example usage: obj.decorate(name_or_func) and returns: unknown, _stopwatch, decorator, function, func