def _stop_profiler(self, save=True):
        """Stops the profiler if currently active.

        Args:
          save: Whether to save the profiler results to TensorBoard.
        """
        if not self._profiler_started:
            return
        try:
            backend.tensorboard.stop_trace(save=save)
        except Exception as e:
            # Profiler errors should not be fatal.
            logging.error("Failed to stop profiler: %s", e)
        finally:
            self._profiler_started = False
Stops the profiler if currently active.

        Args:
          save: Whether to save the profiler results to TensorBoard.
        
keras/src/callbacks/tensorboard.py