def python_profiler(event: PodEvent, action_params: StartProfilingParams):
    """
    Attach a python profiler to a running pod, and run a profiling session for the specified duration.

    No need to change the profiled application code, or to restart it.

    This is powered by PySpy
    """
    # This should use ephemeral containers, but they aren't in GA yet. To enable them on GCP for example,
    # you need to create a brand new cluster. Therefore we're sticking with regular containers for now
    pod = event.get_pod()
    if "debug-toolkit:v6.0" not in PYTHON_DEBUGGER_IMAGE:
        logging.error(f"The python_profiler action is deprecated "
                      f"to run set the PYTHON_DEBUGGER_IMAGE environment variable to debug-toolkit:v6.0.")
        return
    logging.warning(f"The python_profiler action is deprecated and might not work on all platforms.")
    if not pod:
        logging.info(f"python_profiler - pod not found for event: {event}")
        return
    processes = pod.get_processes(custom_annotations=action_params.custom_annotations)
    debugger = RobustaPod.create_debugger_pod(
        pod.metadata.name, pod.spec.nodeName, custom_annotations=action_params.custom_annotations
    )

    try:
        finding = Finding(
            title=f"Profile results for {pod.metadata.name} in namespace {pod.metadata.namespace}:",
            source=FindingSource.MANUAL,
            aggregation_key="PythonProfiler",
            subject=PodFindingSubject(pod),
            finding_type=FindingType.REPORT,
            failure=False,
        )

        for target_proc in processes:
            target_cmd = " ".join(target_proc.cmdline)
            if action_params.process_name not in target_cmd:
                logging.info(f"skipping process because it doesn't match process_name. {target_cmd}")
                continue
            elif "python" not in target_proc.exe:
                logging.info(f"skipping process because it doesn't look like a python process. {target_cmd}")
                continue

            filename = "/profile.svg"
            pyspy_cmd = f"py-spy record --duration={action_params.seconds} --pid={target_proc.pid} --rate 30 --nonblocking -o {filename} {'--idle' if action_params.include_idle else ''}"
            logging.info(f"starting to run profiler on {target_cmd} with pyspy command: {pyspy_cmd}")
            pyspy_output = debugger.exec(pyspy_cmd)
            if "Error:" in pyspy_output:
                logging.info(f"error profiler on {target_cmd}. error={pyspy_output}")
                continue

            logging.info(f"done running profiler on {target_cmd}")
            svg = debugger.exec(f"cat {filename}")
            finding.add_enrichment([FileBlock(f"{target_cmd}.svg", svg)])
        event.add_finding(finding)

    finally:
        debugger.deleteNamespacedPod(debugger.metadata.name, debugger.metadata.namespace)

    Attach a python profiler to a running pod, and run a profiling session for the specified duration.

    No need to change the profiled application code, or to restart it.

    This is powered by PySpy
    
playbooks/robusta_playbooks/pod_troubleshooting.py