ArchThis Forum is for the discussion of Arch Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I wasn't sure which subforum to go to but I am using Artix linux, and I installed the latest updates today. My problem is related to profiling my Python code using the "memory_profiler" module. I'd place some @profile decorators around the functions that I'm interested in and whenever I run
Code:
python -m memory_profiler <my program>.py
I get this error:
Code:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/numpy/core/getlimits.py", line 516, in __init__
self.dtype = numeric.dtype(int_type)
TypeError: 'numpy.dtype[bool_]' object is not callable
The error disappears when I remove the @profile and execute it normally. But I want to use it (or something like it) so I can get some information on what line in my code is consuming a lot of memory. I've looked around to see what are some good memory profilers and I found these that seem to match what I'm looking for:
I've tried the guppy module and it seems nice (especially after going through the tutorial in the above link) but my head spins when I use it on my code and I don't know what I'm looking at (pointers to memory, for example, instead of a specific function). Then again, I am a noob when it comes to using it.
Anyway, I'm hoping anyone can help me figure out why I'm getting that error or maybe even offer some other ways in profiling my code for finding memory consumption.
The only other thing that I can think of is first copy memory_profiler.py and mprof.py to the test directory and create a script:
Code:
#!/bin/bash
for f in *.py; do
if [ -f $f ]; then
if [[ $f != memory_profiler.py && $f != mprof.py ]]; then
echo $f;
if ! python -m memory_profiler $f; then
echo failed
echo
else
echo success
echo
fi
fi
fi
done
which seems to work ok, except that it may have missed a couple tests (some of the outputs were "Ran 0 tests in 0.000s"). I tee'd the output to a logfile (see attachment).
Looks like Gentoo devs seem to have done something similar (minus the loops and patches): https://gitweb.gentoo.org/repo/gento...er-0.60.ebuild. So, I tried something like that while still copying memory_profiler.py and mprof.py to the test directory (just in case):
Now I'm a little confused by these results. Why the dependency in line number and memory usage? I'd understand maybe one is more precise than the other but difference in line numbers?
I still got the same error in my first post using either scalene or memory_profiler so I investigated a little further into the full traceback (below is a snippet):
Code:
...
File "mycode.py", line 662, in myfunc
C = diags(C).toarray()
File "/usr/lib/python3.10/site-packages/scipy/sparse/construct.py", line 186, in diags
return dia_matrix((data_arr, offsets), shape=(m, n)).asformat(format)
File "/usr/lib/python3.10/site-packages/scipy/sparse/dia.py", line 125, in __init__
dtype=get_index_dtype(maxval=max(shape)),
File "/usr/lib/python3.10/site-packages/scipy/sparse/sputils.py", line 153, in get_index_dtype
int32min = np.iinfo(np.int32).min
File "/usr/lib/python3.10/site-packages/numpy/core/getlimits.py", line 518, in __init__
self.dtype = numeric.dtype(type(int_type))
TypeError: 'numpy.dtype[bool_]' object is not callable
I replaced
Code:
C = diags(C).toarray()
with
Code:
C = np.diagflat(C)
and it seem to have fixed that problem that I was having earlier. As a bonus, the amount of time to complete is cut in half! However, the memory consumed is still about the same so I would need to figure out what's going on there.
In either case, I'll mark this thread as "SOLVED". Thanks everyone for the suggestions!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.