Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log the memory consumption on Linux?

Is there any ready-to-use solution to log the memory consumption from the start of the system? I'd like to log the data to simple text file or some database so I can analyze it later.

I'm working on Linux 2.4-based embedded system. I need to debug the problem related to memory consumption. My application automatically start on every system start. I need the way to get the data with timestamps from regular intervals (as often as possible), so I can track down problem.

The symptoms of my problem: when system starts it launched my main application and GUI to visualize the main parameters of the system. GUI based on GTK+ (X server). If I disable GUI and X server then my application works OK. If I enable GUI and X server it does not work when I have 256 MiB or 512 MiB of physical memory installed on the motherboard. If I have 1 GiB of memory installed then everything is OK.

like image 819
bialix Avatar asked Dec 08 '09 16:12

bialix


People also ask

How do I log my memory usage?

Check Detailed Memory Usage with Performance MonitorTo open up Performance Monitor type: perfmon into the Run window (Windows Key + R). In the window that comes up, click the Performance Monitor under Monitoring Tools in the left pane. The right pane turns into a live graph/chart that looks like the screenshot below.


2 Answers

The following script prints time stamps and a header.

#!/bin/bash -e  echo "      date     time $(free -m | grep total | sed -E 's/^    (.*)/\1/g')" while true; do     echo "$(date '+%Y-%m-%d %H:%M:%S') $(free -m | grep Mem: | sed 's/Mem://g')"     sleep 1 done 

The output looks like this (tested on Ubuntu 15.04, 64-bit).

      date     time          total       used       free     shared    buffers     cached 2015-08-01 13:57:27          24002      13283      10718        522        693       2308 2015-08-01 13:57:28          24002      13321      10680        522        693       2308 2015-08-01 13:57:29          24002      13355      10646        522        693       2308 2015-08-01 13:57:30          24002      13353      10648        522        693       2308 
like image 60
klaus se Avatar answered Oct 21 '22 00:10

klaus se


A small script like

rm memory.log while true; do free >> memory.log; sleep 1; done 
like image 28
Gunther Piez Avatar answered Oct 21 '22 02:10

Gunther Piez