sumerc / yappi

Yet Another Python Profiler, but this time multithreading, asyncio and gevent aware.
MIT License
1.45k stars 73 forks source link

3.10 compatability -- changes to frame object #65

Closed isidentical closed 3 years ago

isidentical commented 3 years ago

Due to the changes in python/cpython#20803 (made the code a lot simpler), yappi isn't compiling on 3.10;

 $ python -m pip install yappi         
Collecting yappi
  Downloading yappi-1.3.0.tar.gz (58 kB)
     |████████████████████████████████| 58 kB 407 kB/s 
Building wheels for collected packages: yappi
  Building wheel for yappi (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/isidentical/.venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nwzsms_w/yappi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nwzsms_w/yappi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-77oifsdj
       cwd: /tmp/pip-install-nwzsms_w/yappi/
  Complete output (23 lines):
  /tmp/timer_create17izrlg5.c: In function ‘main’:
  /tmp/timer_create17izrlg5.c:2:5: warning: implicit declaration of function ‘timer_create’ [-Wimplicit-function-declaration]
      2 |     timer_create();
        |     ^~~~~~~~~~~~
  running bdist_wheel
  running build
  running build_py
  /home/isidentical/.venv/lib/python3.10/site-packages/setuptools/lib2to3_ex.py:13: PendingDeprecationWarning: lib2to3 package is deprecated and may not be able to parse Python 3.10+
    from lib2to3.refactor import RefactoringTool, get_fixers_from_package
  creating build
  creating build/lib.linux-x86_64-3.10-pydebug
  copying yappi/yappi.py -> build/lib.linux-x86_64-3.10-pydebug
  running build_ext
  building '_yappi' extension
  creating build/temp.linux-x86_64-3.10-pydebug
  creating build/temp.linux-x86_64-3.10-pydebug/yappi
  gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -fPIC -DLIB_RT_AVAILABLE=1 -I/home/isidentical/.venv/include -I/usr/local/include/python3.10d -c yappi/_yappi.c -o build/temp.linux-x86_64-3.10-pydebug/yappi/_yappi.o
  yappi/_yappi.c: In function ‘_call_leave’:
  yappi/_yappi.c:1008:20: error: ‘PyFrameObject’ {aka ‘struct _frame’} has no member named ‘f_stacktop’; did you mean ‘f_stackdepth’?
   1008 |         if (frame->f_stacktop) {
        |                    ^~~~~~~~~~
        |                    f_stackdepth
  error: command '/usr/lib/ccache/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for yappi
sumerc commented 3 years ago

Thanks for the heads up! Working on it.

sumerc commented 3 years ago

I have a probable fix for this. @isidentical , I was using f_stacktop being non-NULL to detect a coroutine yield now I use frame->state == FRAME_SUSPENDED. All tests pass on my side. Can you spot any issue with that?

See the possible fix: https://github.com/sumerc/yappi/pull/66

isidentical commented 3 years ago

Yeah, looks right!