Ask Ubuntu Asked by GeneralCode on August 6, 2020
I want to compare the RAM consumption for a Python versus C++ implementation of a code I have written. Essentially I am looking for a command like:
<record ram> python3 main.py
and
<record this runtime ram> g++ main.cpp
Is is possible to record RAM for a specific task like this in Linux Ubuntu?
Thank you for your time.
You can read the text file /prof/self/stat
after all the memory allocation takes place. Its fields are described here. In linux we refer to two kinds of memory:
From the stat
file read vsize
and rss
. After reading this you can find the size in kb
using the following in C++.
#include <unistd.h>
...
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
vm_usage = vsize / 1024.0;
resident_set = rss * page_size_kb;
In Python you can use os.sysconf("SC_PAGE_SIZE")
to get the PAGE_SIZE
and do the equivalent calculation.
You can also explore Valgrind for this purpose.
Answered by turbulence on August 6, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP