Code Monkey home page Code Monkey logo

Comments (4)

joerick avatar joerick commented on June 2, 2024

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.

joerick avatar joerick commented on June 2, 2024

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.

if not frame.is_synthetic:

So why is it appearing here I wonder...

from pyinstrument.

joerick avatar joerick commented on June 2, 2024

Ah, that line should read if not child.is_synthetic:, it's testing the wrong thing.

from pyinstrument.

sbalian avatar sbalian commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.