class_docstr: Profiler for timing all aspects of a workflow. This includes using stack tracing to capture call times for
  all selected calls (by default calls to `Transform.__call__` methods), times within context blocks, times
  to generate items from iterables, and times to execute decorated functions.
  
  This profiler must be used only within its context because it uses an internal thread to read results from a
  multiprocessing queue. This allows the profiler to function across multiple threads and processes, though the
  multiprocess tracing is at times unreliable and not available in Windows at all.
  
  The profiler uses `sys.settrace` and `threading.settrace` to find all calls to profile, this will be set when
  the context enters and cleared when it exits so proper use of the context is essential to prevent excessive
  tracing. Note that tracing has a high overhead so times will not accurately reflect real world performance
  but give an idea of relative share of time spent.
  
  The tracing functionality uses a selector to choose which calls to trace, since tracing all calls induces
  infinite loops and would be terribly slow even if not. This selector is a callable accepting a `call` trace
  frame and returns True if the call should be traced. The default is `select_transform_call` which will return
  True for `Transform.__call__` calls only.
  
  Example showing use of all profiling functions:
  
  .. code-block:: python
  
      import monai.transform as mt
      from monai.utils import WorkflowProfiler
      import torch
  
      comp=mt.Compose([mt.ScaleIntensity(),mt.RandAxisFlip(0.5)])
  
      with WorkflowProfiler() as wp:
          for _ in wp.profile_iter("range",range(5)):
              with wp.profile_ctx("Loop"):
                  for i in range(10):
                      comp(torch.rand(1,16,16))
  
          @wp.profile_callable()
          def foo(): pass
  
          foo()
          foo()
  
      print(wp.get_times_summary_pd())  # print results
  
  Args:
      call_selector: selector to determine which calls to trace, use None to disable tracing
class_docstr_tok: ["Profiler","for","timing","all","aspects","of","a","workflow",".","This","includes","using","stack","tracing","to","capture","call","times","for","all","selected","calls","(","by","default","calls","to","`","Transform.__call__","`","methods",")",",","times","within","context","blocks",",","times","to","generate","items","from","iterables",",","and","times","to","execute","decorated","functions",".","This","profiler","must","be","used","only","within","its","context","because","it","uses","an","internal","thread","to","read","results","from","a","multiprocessing","queue",".","This","allows","the","profiler","to","function","across","multiple","threads","and","processes",",","though","the","multiprocess","tracing","is","at","times","unreliable","and","not","available","in","Windows","at","all",".","The","profiler","uses","`","sys.settrace","`","and","`","threading.settrace","`","to","find","all","calls","to","profile",",","this","will","be","set","when","the","context","enters","and","cleared","when","it","exits","so","proper","use","of","the","context","is","essential","to","prevent","excessive","tracing",".","Note","that","tracing","has","a","high","overhead","so","times","will","not","accurately","reflect","real","world","performance","but","give","an","idea","of","relative","share","of","time","spent",".","The","tracing","functionality","uses","a","selector","to","choose","which","calls","to","trace",",","since","tracing","all","calls","induces","infinite","loops","and","would","be","terribly","slow","even","if","not",".","This","selector","is","a","callable","accepting","a","`","call","`","trace","frame","and","returns","True","if","the","call","should","be","traced",".","The","default","is","`","select_transform_call","`","which","will","return","True","for","`","Transform.__call__","`","calls","only",".","Example","showing","use","of","all","profiling","functions",":","..","code-block",":",":","python","import","monai.transform","as","mt","from","monai.utils","import","WorkflowProfiler","import","torch","comp=mt.Compose","(","[","mt.ScaleIntensity","(",")",",","mt.RandAxisFlip","(","0.5",")","]",")","with","WorkflowProfiler","(",")","as","wp",":","for","_","in","wp.profile_iter","(","``","range","''",",","range","(","5",")",")",":","with","wp.profile_ctx","(","``","Loop","''",")",":","for","i","in","range","(","10",")",":","comp","(","torch.rand","(","1,16,16",")",")","@","wp.profile_callable","(",")","def","foo","(",")",":","pass","foo","(",")","foo","(",")","print","(","wp.get_times_summary_pd","(",")",")","#","print","results","Args",":","call_selector",":","selector","to","determine","which","calls","to","trace",",","use","None","to","disable","tracing"]
docstr: Save all results to a csv file.
docstr_tok: ["Save","all","results","to","a","csv","file","."]
code: def dump_csv(self, stream=sys.stdout):
      """Save all results to a csv file."""
      all_results = list(self.get_results().values())
      writer = csv.DictWriter(
          stream, fieldnames=all_results[0][0]._asdict().keys()
      )
      writer.writeheader()
  
      for rlist in all_results:
          for r in rlist:
              writer.writerow(r._asdict())
  
imports: from __future__ import annotations
  import csv
  import datetime
  import multiprocessing
  import os
  import sys
  import threading
  from collections import defaultdict, namedtuple
  from contextlib import contextmanager
  from functools import wraps
  from inspect import getframeinfo, stack
  from queue import Empty
  from time import perf_counter, perf_counter_ns
  from typing import TYPE_CHECKING, Any, cast
  import numpy
  import torch
  from monai.utils import optional_import
label_desc: Use image node_id 16 for calling the WorkflowProfiler obj's underlying member method code with example usage: obj.dump_csv(stream) without return types