scalene icon indicating copy to clipboard operation
scalene copied to clipboard

Profiled submodule shows only CPU usage -- no values in Memory column

Open alecstein opened this issue 2 years ago • 7 comments

Describe the bug I have a script main.py that imports another module, utils.py.

main.py

from utils import func1
...

I want to profile all of the functions (not just func1) in utils.py after calling main. But I don't see any output in the Memory column.

Expected behavior I expect the rows profiled in utils.py to show values in the Memory column. I tried --profile-only 'utils', but I still don't see values in that column.

Screenshots image

Desktop (please complete the following information):

  • macOS Monterey
  • Firefox 108.0.1
  • Scalene version 1.5.16 (2022.12.08)

alecstein avatar Jan 02 '23 14:01 alecstein

Unless code increases or decreases memory consumption by at least 10MB, it won't show up in a profile. It might be useful to try to run the code with memray, for example (a memory-only profiler that reports memory usage at peak point of consumption) to see what it shows. If the consumption is more than 10MB, this is a possible bug, and we'd love more info.

PS Though I doubt this makes a difference, you can always try again with the latest release (1.5.17).

emeryberger avatar Jan 02 '23 16:01 emeryberger

@emeryberger If I run scalene on a test script which contains all the functions in utils.py, they get profiled correctly.

image

It seems to me that if I import a function func1 from some module, and that function calls other functions (subfunc1 and subfunc2) within the same module, then scalene does not report the memory usage of subfunc1 and subfunc2, but only the combined usage of func1 from the script I ran scalene on.

On the other hand this seems like something you would have caught so I'm wondering if I'm just using Scalene incorrectly.

alecstein avatar Jan 02 '23 16:01 alecstein

I tried to make a MWE but couldn't repro:

main.py

from utils import forloop

forloop()

utils.py

def forloop():
	vals = []
	for i in range(100_000_000):
		vals.append(i)

def expensive_fun(n):
	return n**50

This returns what you'd expect:

image

alecstein avatar Jan 02 '23 18:01 alecstein

Let me know if you'd like me to give you the actual script to run.

alecstein avatar Jan 03 '23 16:01 alecstein

Definitely. If you don't want to post it here, you can send it to my e-mail account ([email protected]). Thanks in advance.

emeryberger avatar Jan 03 '23 17:01 emeryberger

@emeryberger If I run scalene on a test script which contains all the functions in utils.py, they get profiled correctly.

image

It seems to me that if I import a function func1 from some module, and that function calls other functions (subfunc1 and subfunc2) within the same module, then scalene does not report the memory usage of subfunc1 and subfunc2, but only the combined usage of func1 from the script I ran scalene on.

On the other hand this seems like something you would have caught so I'm wondering if I'm just using Scalene incorrectly.

For what it's worth, I also experience this. Am I also using scalene wrong, or is this an issue? Apologies for bumping an old-ish thread.

chrisstuartparry avatar Mar 31 '23 19:03 chrisstuartparry

Hi @chrisstuartparry - can you try this again on the latest version of Scalene?

emeryberger avatar Dec 29 '23 21:12 emeryberger