You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this has already been asked, but was curious if there's a best way to only profile part of process - I'd also be willing to make code modifications if need be.
Motivation is two-fold:
I would like to ignore import times for certain things.
I am using Bazel w/ additional wrappers. Even using --subprocesses, I found it hard to see the timings I expected (multiple hops with execv, maybe?).
I found this works 'aight, albeit somewhat sloppy:
fromcontextlibimportcontextmanagerimportosimportsignalimportsubprocess@contextmanagerdefuse_py_spy(output_file, *, sudo=False):
"""Use py-spy in specific context."""args= ["py-spy", "record", "-o", output_file, "--pid", str(os.getpid())]
ifsudo:
args= ["sudo"] +argsp=subprocess.Popen(args)
# TODO(eric.cousineau): Startup time of py-spy may lag behind other# instructions. However, maybe can assume this isn't critical for profiling# purposes?yieldp.send_signal(signal.SIGINT)
p.wait()
defmain():
withuse_py_spy("/tmp/crazy_stuff.svg"):
do_crazy_stuff()
...
Not sure if this has already been asked, but was curious if there's a best way to only profile part of process - I'd also be willing to make code modifications if need be.
Motivation is two-fold:
--subprocesses
, I found it hard to see the timings I expected (multiple hops withexecv
, maybe?).I found this works 'aight, albeit somewhat sloppy:
See usecase for CPython API extension stuff:
Thanks for the awesome tool!
The text was updated successfully, but these errors were encountered: