class_docstr: If you wish to write a custom profiler, you should inherit from this class.
code: def _prepare_streams(self) -> None:
      if self._write_stream is not None:
          return
      if self.filename and self.dirpath:
          filepath = os.path.join(
              self.dirpath, self._prepare_filename()
          )
          fs = get_filesystem(filepath)
          fs.mkdirs(self.dirpath, exist_ok=True)
          file = fs.open(filepath, "a")
          self._output_file = file
          self._write_stream = file.write
      else:
          self._write_stream = self._rank_zero_info
  
imports: import logging
  import os
  from abc import ABC, abstractmethod
  from contextlib import contextmanager
  from pathlib import Path
  from typing import Any, Callable, Dict, Generator, Optional, TextIO, Union
  from lightning.fabric.utilities.cloud_io import get_filesystem
label_desc: Use image node_id 8 for calling the Profiler obj's underlying member method code with example usage: obj._prepare_streams() without return types