Comments (8)
Thanks for the report, that's indeed a nasty bug.
from memory_profiler.
Thank you for your answer!
Offtopic:
Excuse me for an offtopic question. I'm a student. Deadline for passing laboratory work in data structures and algorithms (binary search trees, balanced (AVL) trees, hash) is tomorrow evening and I finished this work completely excluding memory usage measuring.
Are there dirty way to fix this? Or do you know another way to profile methods (I've tried heapy
, but it really complicated, I gave up)? I just need maximum memory usage, i.e.:
memory_list = memory_usage((func, (), {}))
memory = max(memory_list) - min(memory_list)
I thought about measuring memory with console API and decorators, parsing output, ... But that is silly.
Excuse me once again for inappropriate question.
from memory_profiler.
@rominf A quick and probably dirty way to do what you want.
First install psutil.
This assumes that your function does not return anything (as in your example). Adjust as necessary. The function below takes a callable (the fn
argument), and any args and keyword args to pass to it, and will return the change in resident set size, and change in virtual memory size, in bytes.
def call_with_memory(fn, *args, **kwargs):
process = psutil.Process(os.getpid())
start_rss, start_vms = process.get_memory_info()
fn(*args, **kwargs)
end_rss, end_vms = process.get_memory_info()
return (end_rss - start_rss), (end_vms - start_vms)
from memory_profiler.
@sjagoe Thank you for suggestion. Unfortunately it doesn't work as I want: it returns (0, 0)
all the time :(
For example if I have:
def f():
s = 'a'*10000
it returns (0, 0), not something like (in C style) sizeof(char)*10000 = 10000 bytes
I've tried to disable garbage collector, use global var with global
keyword, measure end_rss
, end_vms
inside of fn
, it doesn't work either. It worked only when I created lists inside fn
, but that's not enough.
from memory_profiler.
@rominf This discussion no longer belongs here. You can contact me by email (see my profile).
from memory_profiler.
@fabianp Apologies for allowing this issue-hijacking for going on so long. I have moved my information to the SO thread.
I would suggest deleting the off topic comments here given that the same content is in the linked SO thread.
from memory_profiler.
@sjagoe no problem, I'm just sorry I don't have time to look into this at the moment.
from memory_profiler.
This is missing a SSCCE.
from memory_profiler.
Related Issues (20)
- How to test memory usage for a time-loop function?
- Inconsistent result between line profiler and plot
- The @profile decorator will profile another decorator when chaining multiple decorators into a function. HOT 1
- include-children in decorator
- do not work in python 3.11 HOT 3
- Is maintained or not? HOT 4
- [BUG] invalid non-printable character U+FEFF HOT 6
- After delete the snapshot file, the function cannot be used when the memory profiler is opened again
- mprof: error: unrecognized arguments: --backend
- AttributeError: module 'pylab' has no attribute 'ioff' (Python 3.9) HOT 2
- Adding "--" to argment list may change the argument of the program started by `mprof run`. HOT 2
- non-ascii source characters misprocessed (maybe through 8859?) HOT 3
- mem usage and increment print is missing HOT 2
- I'm a beginner in the world of developing, I just finished learning python and html and css what's the next step please?I need a help with that. HOT 1
- Is it possible to compare two plots? HOT 1
- negative memory increment
- Is there a specific reason memory_usage return None when stream=True ? HOT 1
- Inconsistent documentation of units
- not sure how to interpret these results
- `tracemalloc` `backend` broken for `memory_usage`
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 memory_profiler.