Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the yappi profiler for multithread profiling #6695

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/dbt/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from pstats import Stats
from typing import Any, Generator

import yappi


@contextmanager
def profiler(enable: bool, outfile: str) -> Generator[Any, None, None]:
try:
if enable:
profiler = Profile()
profiler.enable()
yappi.start()

yield
finally:
Expand All @@ -18,3 +21,16 @@ def profiler(enable: bool, outfile: str) -> Generator[Any, None, None]:
stats = Stats(profiler)
stats.sort_stats("tottime")
stats.dump_stats(str(outfile))
yappi.stop()
threads = yappi.get_thread_stats()
all_stats = Stats()

for thread in threads:
stats = yappi.get_func_stats(ctx_id=thread.id)
filename = f"thread-{thread.id}.pstat"
stats.save(filename, "pstat")

pstats = yappi.convert2pstats(stats)
all_stats.add(pstats)

all_stats.dump_stats('threads-combined.pstat')
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ types-pytz
types-requests
types-setuptools
wheel
yappi