This question is covered here in great detail.
How do you measure the memory usage of an application or process in Linux?
From the blog articl
I would suggest that you use atop. You can find everything about it on this page. It is capable of providing all the necessary KPI for your processes and it can also capture to a file.