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","."]
code: def _preprocess(self):
      if self.xp is numpy:
          start = _get_time()
          self._running_stack.append(start)
      else:
          assert self.xp is cuda.cupy
          start = cuda.Event()
          stop = cuda.Event()
          start.record()
          self._running_stack.append((start, stop))
      self._depth += 1
  
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 2 for calling the TimerHook obj's underlying member method code with example usage: obj._preprocess() without return types