# from Donn # on Thursday 29 March 2007 03:21 am:
It might be useful to use the script that I mentioned earlier with the
Eric, how do I capture the output from that script into a log file? I gave it the name : ericlogger and tried: ./ericlogger >> logfile but that don't work. I don't know perl at all so my hacking is not getting me anywhere.
Just paste to a shell. What I wrote was a command and script. Where did I lose you? The script is between the pair of single quotes. The required argument is the pid. The "$(pid of inkscape)" bit is just bash backticks (but the $() form nests, so that's my habit.)
perl -e 'my $pid = shift; while(1) { open(my $fh, "<", "/proc/$pid/statm") or die; my $data = <$fh>; chomp($data); print join(" ", time,map({$_ * 4} split(/ /, $data))), "\n"; sleep(1); }' $(pidof inkscape) > logfile
Or, if you want to put it in a file:
#!/usr/bin/perl # track_memory.pl my $pid = shift(@ARGV); while(1) { # read the proc data open(my $fh, "<", "/proc/$pid/statm") or die; my $data = readline($fh); chomp($data); # prepend the time and multiply blocks by 4KB print join(" ", time(), map({$_ * 4} split(/ /, $data) ) ), "\n"; sleep(1); }
That version has comments and uses some clearer constructs, but is otherwise equivalent.
Then you chmod +x and run:
./track_memory.pl $(pidof inkscape) > logfile
--Eric