How can I obtain information of the memory usage with Rust?

Just like infomation below:

~$ cat /proc/meminfo
MemTotal:        6051304 kB
MemFree:          452540 kB
...

Is there any std modules?

1 Like

Do you want to know the memory usage of a single Rust program, or the total memory usage of the system?

1 Like

The whole system.

You can get this info using the sys-info crate.

2 Likes

Many thanks,:evergreen_tree:

What if I want to know the (peak) memory usage of a single Rust program?

The simplest answer is /usr/bin/time command which prints the RSS. For anything more complex, can't recommend GitHub - koute/bytehound: A memory profiler for Linux. strongly enough, it is really a top-notch bit of engineering.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.