ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hello everybody,
I need to count reads and writes to the memory allocated by mmap().
I tried Valgrind, but it counts only the heap accesses and mmap() doesn't allocate in the heap !!
Please, could someone help me to achieve my purpose (counting reads and writes in mmap()'d area)?
Thank you
I searched online for variations of the term mmap monitoring and did not find anything that appeared to directly answer your question. I see no obvious facility for monitoring accesses to mmaped memory as you describe.
probably impossible, because you can pass mmapped address to external functions (libc ...) and also mmapped memory can be accessed from several processes.
I would try to create some wrapper functions to be able to log access.
I don't think it would be possible without a specific CPU instruction, say START/STOP_VIRTUAL_MEMORY_USAGE_STATISTICS MINADDR=addr MAXADDR=addr INTO=addr
What's the real problem ?. Simple things can be strace'd - libc:read and write can be dynamically probed. The kernel functions likewise. Not many would describe that as "simple", although it is getting easier.
Hello everybody,
I need to count reads and writes to the memory allocated by mmap().
I tried Valgrind, but it counts only the heap accesses and mmap() doesn't allocate in the heap !!
Please, could someone help me to achieve my purpose (counting reads and writes in mmap()'d area)?
Thank you
Resolved.
I have used this command line:
valgrind --tool=lackey --trace-mem=yes --log-file=outputlackey.txt <command>
This will trace all the memory space of the process <command> that has been monitored and logs a file.
First of all, I got the address returned by mmap() function. Then, I read the log file, and I counted the number of the Loads and Stores. You can look at the details of the output. https://github.com/mozilla-b2g/valgr...ckey/lk_main.c
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.