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: Return a string representation of the timings.
docstr_tok: ["Return","a","string","representation","of","the","timings","."]
code: def str(self, threshold=0.1):
      """Return a string representation of the timings."""
      if not self._times:
          return ""
      total = sum(s.sum for k, s in self._times.items() if "." not in k)
      table = [
          ["", "% total", "sum", "avg", "dev", "min", "max", "num"]
      ]
      for k, v in sorted(self._times.items()):
          percent = 100 * v.sum / (total or 1)
          if percent > threshold:  # ignore anything below the threshold
              table.append(
                  [
                      k,
                      "%.2f%%" % percent,
                      "%.4f" % v.sum,
                      "%.4f" % v.avg,
                      "%.4f" % v.dev,
                      "%.4f" % v.min,
                      "%.4f" % v.max,
                      "%d" % v.num,
                  ]
              )
      col_widths = [
          max(len(row[i]) for row in table)
          for i in range(len(table[0]))
      ]
  
      out = ""
      for row in table:
          out += "  " + row[0].ljust(col_widths[0]) + "  "
          out += "  ".join(
              val.rjust(width)
              for val, width in zip(row[1:], col_widths[1:])
          )
          out += "\n"
      return out
  
imports: import collections
  import functools
  import math
  import os
  import sys
  import threading
  import time
label_desc: Use image node_id 17 for calling the StopWatch obj's underlying member method code with example usage: obj.str(threshold) and returns: out, str