Coder Social home page Coder Social logo

Comments (8)

fabianp avatar fabianp commented on August 29, 2024

Thanks for the report, that's indeed a nasty bug.

from memory_profiler.

rominf avatar rominf commented on August 29, 2024

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.

sjagoe avatar sjagoe commented on August 29, 2024

@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.

rominf avatar rominf commented on August 29, 2024

@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.

sjagoe avatar sjagoe commented on August 29, 2024

@rominf This discussion no longer belongs here. You can contact me by email (see my profile).

from memory_profiler.

sjagoe avatar sjagoe commented on August 29, 2024

@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.

fabianp avatar fabianp commented on August 29, 2024

@sjagoe no problem, I'm just sorry I don't have time to look into this at the moment.

from memory_profiler.

astrojuanlu avatar astrojuanlu commented on August 29, 2024

This is missing a SSCCE.

from memory_profiler.

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.