class_docstr: Link hook for measuring elapsed time of :meth:`Link.forward() <chainer.Link.forward>`.
  
  Example:
      Code example::
  
          from chainer.link_hooks import TimerHook
          hook = TimerHook()
          with hook:
              trainer.run()
          hook.print_report()
  
      Output example::
  
            LinkName  ElapsedTime  Occurrence
              Linear     41.42sec        2100
                 MLP     42.09sec         700
          Classifier     42.39sec         700
  
      where *LinkName* is the name of link that calls the hook,
      and *ElapsedTime* is the elapsed time the link consumed,
      and *Occurrence* is the number of calls.
  Warning:
      Call graph of links are hierarchical. That means reported elapsed times
      may be overlapping with each other and the sum may exceed the total
      time.
  Attributes:
      call_history: List of measurement results. It consists of pairs of
          the name of the link that calls this hook and the elapsed time
          the :meth:`forward` method of link consumes.
class_docstr_tok: ["Link","hook","for","measuring","elapsed","time","of",":","meth",":","`","Link.forward","(",")","<","chainer.Link.forward",">","`",".","Example",":","Code","example",":",":","from","chainer.link_hooks","import","TimerHook","hook","=","TimerHook","(",")","with","hook",":","trainer.run","(",")","hook.print_report","(",")","Output","example",":",":","LinkName","ElapsedTime","Occurrence","Linear","41.42sec","2100","MLP","42.09sec","700","Classifier","42.39sec","700","where","*","LinkName","*","is","the","name","of","link","that","calls","the","hook",",","and","*","ElapsedTime","*","is","the","elapsed","time","the","link","consumed",",","and","*","Occurrence","*","is","the","number","of","calls",".","Warning",":","Call","graph","of","links","are","hierarchical",".","That","means","reported","elapsed","times","may","be","overlapping","with","each","other","and","the","sum","may","exceed","the","total","time",".","Attributes",":","call_history",":","List","of","measurement","results",".","It","consists","of","pairs","of","the","name","of","the","link","that","calls","this","hook","and","the","elapsed","time","the",":","meth",":","`","forward","`","method","of","link","consumes","."]
docstr: Prints a summary report of time profiling in links.
  
  Args:
      unit (str): Supplementary units used for computational times.
          `sec`, `ms`, `us`, `ns`, `auto`(default) and `auto_foreach`
          are supported. If `auto`, units of times are aligned to the
          largest, and if `auto_foreach`, units of times are adjusted for
          each element.
docstr_tok: ["Prints","a","summary","report","of","time","profiling","in","links",".","Args",":","unit","(","str",")",":","Supplementary","units","used","for","computational","times",".","`","sec","`",",","`","ms","`",",","`","us","`",",","`","ns","`",",","`","auto","`","(","default",")","and","`","auto_foreach","`","are","supported",".","If","`","auto","`",",","units","of","times","are","aligned","to","the","largest",",","and","if","`","auto_foreach","`",",","units","of","times","are","adjusted","for","each","element","."]
code: def print_report(self, unit="auto", file=sys.stdout):
      """Prints a summary report of time profiling in links.
  
      Args:
          unit (str): Supplementary units used for computational times.
              `sec`, `ms`, `us`, `ns`, `auto`(default) and `auto_foreach`
              are supported. If `auto`, units of times are aligned to the
              largest, and if `auto_foreach`, units of times are adjusted for
              each element.
      """
      entries = [["LinkName", "ElapsedTime", "Occurrence"]]
      auto_foreach = unit == "auto_foreach"
      if unit == "auto":
          max_time = max(
              record["elapsed_time"]
              for record in self.summary().values()
          )
          factor, unit = self._choose_unit(max_time)
      elif not auto_foreach:
          factor = self.table[unit]
      for link_name, record in self.summary().items():
          second = record["elapsed_time"]
          if auto_foreach:
              factor, unit = self._choose_unit(second)
          elapsed_time = "%3.2f%s" % (second * factor, unit)
          occurrence = str(record["occurrence"])
          entries.append([link_name, elapsed_time, occurrence])
      entry_widths = []
      entry_widths.append(max(len(f) for f, _, _ in entries))
      entry_widths.append(max(len(e) for _, e, _ in entries))
      entry_widths.append(max(len(o) for _, _, o in entries))
      template = "  ".join("{:>%d}" % w for w in entry_widths)
      for link_name, elapsed_time, occurrence in entries:
          line = template.format(link_name, elapsed_time, occurrence)
          file.write(line)
          file.write("\n")
      file.flush()
  
file_path: chainer/chainer/link_hooks/timer.py
imports: import collections
  import os
  import sys
  import time
  import numpy
  from chainer.backends import cuda
  from chainer import link_hook
label_desc: Use image node_id 9 for calling the TimerHook obj's underlying member method code with example usage: obj.print_report(unit, file) without return types