plasma-umass / scalene

Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals
Apache License 2.0
12.23k stars 399 forks source link

scalene doesn't see code loaded via exec? #824

Open tsvibt opened 6 months ago

tsvibt commented 6 months ago

(I don't know if this is intended behavior, so I don't know if it's a bug.)

It seems scalene doesn't see the code for functions loaded by exec. If I have a file like this:

def function():
   [x+x for x in range(100000)]
   [x*x for x in range(100000)]

function()
function()

and run scalene scalene_test1.py, I get:

Screenshot 2024-05-09 at 19 15 17

But if the file has this:

code = '''
def function():
   [x+x for x in range(100000)]
   [x*x for x in range(100000)]
'''
exec(code)

function()
function()

I get this:

Screenshot 2024-05-09 at 19 16 09

What's up with that? Is this intended behavior?