Comments (4)
Hm, it does look like a bug in the pstats renderer. My recreation is like so:
$ pyinstrument examples/busy_wait.py
_ ._ __/__ _ _ _ _ _/_ Recorded: 15:37:52 Samples: 250
/_//_/// /_\ / //_// / //_'/ // Duration: 0.251 CPU time: 0.251
/ _/ v4.6.0
Program: /Users/joerick/Projects/pyinstrument/env/bin/pyinstrument examples/busy_wait.py
0.250 <module> busy_wait.py:1
└─ 0.250 main busy_wait.py:12
├─ 0.137 [self] busy_wait.py
├─ 0.042 function_2 busy_wait.py:8
├─ 0.036 time <built-in>
└─ 0.035 function_1 busy_wait.py:4
To view this report with different options, run:
pyinstrument --load-prev 2024-01-06T15-37-52 [options]
$ pyinstrument -o test.pstats -r pstats examples/busy_wait.py
$ python -c "import pstats; pstats.Stats('test.pstats').print_stats()"
Sat Jan 6 15:37:59 2024 test.pstats
-6 function calls in 0.391 seconds
Random listing order was used
ncalls tottime percall cumtime percall filename:lineno(function)
-1 0.000 -0.000 0.250 -0.250 examples/busy_wait.py:1(<module>)
-1 0.141 -0.141 0.250 -0.250 examples/busy_wait.py:12(main)
-1 0.141 -0.141 0.141 -0.141 :0([self])
-1 0.040 -0.040 0.040 -0.040 examples/busy_wait.py:4(function_1)
-1 0.037 -0.037 0.037 -0.037 <built-in>:0(time)
-1 0.032 -0.032 0.032 -0.032 examples/busy_wait.py:8(function_2)
$ python -c 'print(0.141 + 0.141 + 0.040 + 0.037 + 0.032)'
0.3909999999999999
That should be 0.250.
from pyinstrument.
I think the problem is probably the [self]
frame, which shouldn't be printed here, as it's an implementation detail of pyinstrument that doesn't exist in the pstats format. It should be simple to just exclude synthetic frames from the algorithm.
That's weird, it does that already.
So why is it appearing here I wonder...
from pyinstrument.
Ah, that line should read if not child.is_synthetic:
, it's testing the wrong thing.
from pyinstrument.
Thanks for looking into this! When do you think you'll make a new release that includes this fix? Happy to use it from the repo in the meantime.
from pyinstrument.
Related Issues (20)
- Add a renderer for pstats files HOT 3
- Reducing boilerplate HOT 2
- functions like time.sleep are reported as "sleep None" HOT 1
- Better support for sync routes in FastAPI HOT 3
- ValueError on ShowAll in Speedscope Renderer HOT 2
- Support `-c` input mode HOT 1
- Bug: Artificial characters in outfile when using pstats renderer HOT 7
- Significant performance overhead when timing requires a syscall on Linux HOT 18
- Question, missing Async-mode flag at running as module HOT 4
- Pyinstrument hiding useful frames HOT 8
- Automatic Web Deployment HOT 1
- Interpolation bug in jupyter magic HOT 3
- replace deprecated appdirs with platformdirs HOT 1
- HTML Renderer show-all HOT 2
- `pytinstrument` does not track the call stack of `__aenter__` and `__aexit__`
- Console renderer has much more detail than speedscope renderer HOT 1
- nevergrad import fails when profiler is active HOT 3
- Profiler().write_html() does not accept "show_all" argument, in contrast with API docs HOT 3
- Asyncio background tasks are added to total wall clock time
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyinstrument.