Skip to content

Instantly share code, notes, and snippets.

@ashikawa
Last active December 19, 2015 11:19
Show Gist options
  • Save ashikawa/5946569 to your computer and use it in GitHub Desktop.
Save ashikawa/5946569 to your computer and use it in GitHub Desktop.
Copy on Write メモリを調べるコマンド @see http://d.hatena.ne.jp/naoya/20080212/1202830671
cpan local::lib
cpan Linux::Smaps
shared_memory_size.pl `pgrep httpd`
#!/usr/bin/env perl
# @usage udo ./shared_memory.pl `pgrep httpd`
use strict;
use warnings;
use Linux::Smaps;
@ARGV or die "usage: %0 [pid ...]";
printf "PID\tRSS\tSHARED\n";
for my $pid (@ARGV) {
my $map = Linux::Smaps->new($pid);
unless ($map) {
warn $!;
next;
}
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment