View Single Post
  #58  
Old 2012-11-16, 17:32
reinob reinob is offline
 
Join Date: Feb 2011
Location: Germany
Posts: 1,808
Thanks!: 9,804
Thanked 4,272 Times in 1,292 Posts
Default Re: [ANNOUNCE]Alarm UI replacement

Quote:
Originally Posted by peterleinchen View Post
Yes, mee too.
My swap usage is increasing day by day. If I would not have extended size of swap on SD it would fill up completely (almost ).
Thanks for investigating!
Just coded this (perl) on the way home. It checks every $INTERVAL seconds and reports changes (positive or negative, above $THRESHOLD) in the memory use (VSZ output from ps) of a list of daemons (edit the file to add/delete some more).

Initial version, it works, but there's a lot we can do starting from this:

Code:
#!/usr/bin/perl

use strict;
use warnings;

my @watch = (
    "/sbin/dsme",
    "/sbin/dsme-server",
    "/usr/bin/pulseaudio",
    "/usr/bin/Xorg",
    "/usr/bin/dbus-daemon",
    "/usr/bin/systemui",
    "/usr/bin/hildon-status-menu",
    "/usr/bin/hildon-home",
    "/usr/bin/hildon-desktop",
    "/usr/sbin/browserd"
);

my %initial = ();

# percentage VSZ has to change to report
my $THRESHOLD = 0.0;

# will check once every $INTERVAL seconds
my $INTERVAL = 4;

while(1) {
    my %current = ();

    open(FH, "ps -eo vsz,command |");

    while(<FH>) {
	chomp;
	my @fields = split;
	my $vsz = $fields[0];
	my $cmd = $fields[1];
    
	# print "vsz($vsz) cmd($cmd)\n";

        foreach my $daemon (@watch) {
	    if($daemon eq $cmd) {
    		$current{$cmd} += $vsz;
    	    }
        }
    }

    if(%initial) {
	foreach my $daemon (keys %current) {
	    my $vsz0 = $initial{$daemon};
	    my $vsz1 = $current{$daemon};

	    my $mvar = (100.0 *($vsz1 - $vsz0)) / $vsz0;

	    if(abs($mvar) > $THRESHOLD) {
		    my $sign = "+";
		    
		    if($vsz1 < $vsz0) {
			$sign = "-";
		    }
		    
		    my $now = localtime;
		    print "[$now] $daemon, $vsz0 -> $vsz1 ($sign)\n";
	    }
	}
	
	# remove next line if absolute (from start) values are wanted
	%initial = %current;
    } else {
	print "Initializing..\n";
	%initial = %current;
    }

    close(FH);
    sleep($INTERVAL);
}
Reply With Quote
The Following 8 Users Say Thank You to reinob For This Useful Post: