def METHOD_NAME(profile_dir: pathlib.Path):
    counter = 0
    try:
        while True:
            f = io.StringIO()
            st = pstats.Stats(str(profile_dir / ("slot-%05d.profile" % counter)), stream=f)
            st.strip_dirs()
            st.sort_stats(pstats.SortKey.CUMULATIVE)
            st.print_stats()
            f.seek(0)
            total = 0.0
            sleep = 0.0
            # output looks like this:
            # ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            # 1    0.000    0.000    0.000    0.000 <function>
            for line in f:
                if " function calls " in line and " in " in line and " seconds":
                    # 304307 function calls (291692 primitive calls) in 1.031 seconds
                    assert total == 0
                    total = float(line.split()[-2])
                    continue
                columns = line.split(None, 5)
                if len(columns) < 6 or columns[0] == "ncalls":
                    continue
                # TODO: to support windows and MacOS, extend this to a list of function known to sleep the process
                # e.g. WaitForMultipleObjects or kqueue
                if (
                    "{method 'poll' of 'select.epoll' objects}" in columns[5]
                    or "method 'control' of 'select.kqueue' objects" in columns[5]
                    or "method _overlapped.GetQueuedCompletionStatus" in columns[5]
                ):
                    # cumulative time
                    sleep += float(columns[3])
            if sleep < 0.000001:
                percent = 100.0
            else:
                percent = 100.0 * (total - sleep) / total
            if percent > 90:
                color = Fore.RED + Style.BRIGHT
            elif percent > 80:
                color = Fore.MAGENTA + Style.BRIGHT
            elif percent > 70:
                color = Fore.YELLOW + Style.BRIGHT
            elif percent > 60:
                color = Style.BRIGHT
            elif percent < 10:
                color = Fore.GREEN
            else:
                color = ""
            quantized = int(percent // 2)
            print(
                ("%05d: " + color + "%3.0f%% CPU " + Back.WHITE + "%s" + Style.RESET_ALL + "%s|")
                % (counter, percent, " " * quantized, " " * (50 - quantized))
            )
            counter += 1
    except Exception as e:
        print(e)