code: def test_pytorch_profiler_trainer_ddp(tmpdir, pytorch_profiler):
      """Ensure that the profiler can be given to the training and default step are properly recorded."""
      model = BoringModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_train_batches=5,
          limit_val_batches=5,
          profiler=pytorch_profiler,
          strategy="ddp",
          accelerator="gpu",
          devices=2,
          enable_progress_bar=False,
          enable_model_summary=False,
      )
      trainer.fit(model)
      expected = {"[pl][profile][Strategy]DDPStrategy.validation_step"}
      if not _KINETO_AVAILABLE:
          expected |= {
              "[pl][profile][Strategy]DDPStrategy.training_step",
              "[pl][profile][Strategy]DDPStrategy.backward",
          }
      for name in expected:
          assert sum(
              e.name == name for e in pytorch_profiler.function_events
          ), name
  
      files = set(os.listdir(pytorch_profiler.dirpath))
      expected = f"fit-profiler-{trainer.local_rank}.txt"
      assert expected in files
  
      path = pytorch_profiler.dirpath / expected
      assert path.read_text("utf-8")
  
      if _KINETO_AVAILABLE:
          files = os.listdir(pytorch_profiler.dirpath)
          files = [file for file in files if file.endswith(".json")]
          assert len(files) == 2, files
          local_rank = trainer.local_rank
          assert any(
              f"{local_rank}-[Strategy]DDPStrategy.training_step" in f
              for f in files
          )
          assert any(
              f"{local_rank}-[Strategy]DDPStrategy.validation_step" in f
              for f in files
          )
  
imports: import logging
  import os
  import platform
  import time
  from copy import deepcopy
  from unittest.mock import patch
  import numpy
  import pytest
  import torch
  from lightning.pytorch import Callback, Trainer
  from lightning.pytorch.callbacks import EarlyStopping, StochasticWeightAveraging
  from lightning.pytorch.demos.boring_classes import BoringModel, ManualOptimBoringModel
  from lightning.pytorch.loggers import CSVLogger, TensorBoardLogger
  from lightning.pytorch.profilers import AdvancedProfiler, PassThroughProfiler, PyTorchProfiler, SimpleProfiler
  from lightning.pytorch.profilers.pytorch import _KINETO_AVAILABLE, RegisterRecordFunction, warning_cache
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 23 for calling a global function with example usage: test_pytorch_profiler_trainer_ddp(tmpdir, pytorch_profiler) without return types