Tracking *maximum* memory usage by a Python function

前端 未结 8 1676
轻奢々
轻奢々 2020-12-02 09:07

I want to find out what the maximum amount of RAM allocated during the call to a function is (in Python). There are other questions on SO related to tracking RAM usage:

8条回答
  •  死守一世寂寞
    2020-12-02 09:42

    Improvement of the answer of @Vader B (as it did not work for me out of box):

    $ /usr/bin/time --verbose  ./myscript.py
            Command being timed: "./myscript.py"
            User time (seconds): 16.78
            System time (seconds): 2.74
            Percent of CPU this job got: 117%
            Elapsed (wall clock) time (h:mm:ss or m:ss): 0:16.58
            Average shared text size (kbytes): 0
            Average unshared data size (kbytes): 0
            Average stack size (kbytes): 0
            Average total size (kbytes): 0
            Maximum resident set size (kbytes): 616092   # WE NEED THIS!!!
            Average resident set size (kbytes): 0
            Major (requiring I/O) page faults: 0
            Minor (reclaiming a frame) page faults: 432750
            Voluntary context switches: 1075
            Involuntary context switches: 118503
            Swaps: 0
            File system inputs: 0
            File system outputs: 800
            Socket messages sent: 0
            Socket messages received: 0
            Signals delivered: 0
            Page size (bytes): 4096
            Exit status: 0
    

提交回复
热议问题