perl 5 まとめウィキ

Linux OSのプロセスのcopy-on-writeのメモリ量を調べたりとか。



(例) modperlのメモリ使用量を調べる


#!/usr/bin/perl

use strict;
use warnings;
use Linux::Smaps;

my @pids = `pgrep modperl`;

printf "PID\tRSS\tSHARED\n";

my $total = {
        rss    => 0,
        shared => 0,
};

my $cnt = 0;
for my $pid (@pids) {
    chomp $pid ;
    my $map = Linux::Smaps->new($pid);
    unless ($map) {
        warn $!;
        next;
    }
    $cnt++;
    $total->{rss} += $map->rss;
    $total->{shared} += $map->shared_dirty + $map->shared_clean;

    printf
        "%d\t%d\t%d (%d%%)\n",
        $pid,
        $map->rss,
        $map->shared_dirty + $map->shared_clean,
        int(
        ( ( $map->shared_dirty + $map->shared_clean ) / $map->rss ) * 100 );
}
    printf
        "TOTAL\t%d\t%d (%d%%)\n",
        $total->{rss},
        $total->{shared},
        $total->{shared} / $total->{rss} * 100 ;

my $avg = {
    rss => 0,
    sahred => 0
};


    printf
        "ARG\t%d\t%d (%d processes)\n",
        $total->{rss} / $cnt,
        $total->{shared} / $cnt ,
        $cnt;

__END__
タグ

このページへのコメント

1raA0h Really appreciate you sharing this blog article.Much thanks again. Really Cool.

0
Posted by check this out 2013年12月19日(木) 13:47:54 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

Menu

ここは自由に編集できるエリアです。

フリーエリア

どなたでも編集できます