アプリの使ってるモジュール郡のメモリ測定
Devel::FindNamespacesと組み合わせてみたら面白いんじゃないかと思ってやってみた。
#!/usr/bin/env perl use strict; use warnings; use Devel::MemUsed; use Devel::FindNamespaces; foreach my $module ( Devel::FindNamespaces->find(shift) ) { my $pid = fork(); if ($pid) { # parent wait(); } elsif ( defined $pid ) { my $memused = Devel::MemUsed->new; eval "use $module"; print "$module -> $memused \n"; exit(); } else { die "fork error : $!"; } }
./profile_memory.pl Mouse
Algorithm::C3 -> 31080 Class::C3 -> 1056 Class::C3::XS -> 1200 Class::Method -> 1120 Class::Method::Modifiers -> 25040 MRO::Compat -> 1200 Mouse::Meta::Attribute -> 1024 Mouse::Meta::Class -> 1024 Mouse::Meta::Method -> 1144 Mouse::Meta::Method::Constructor -> 1056 Mouse::Meta::Method::Destructor -> 1040 Mouse::Object -> 1008 Mouse::TypeRegistry -> 2472 Mouse::Util -> 1008 f845a9c1ac41be33 -> 1144 maybe::next -> 1120 mro -> 1024 next -> 1096
binあたりにこういうスクリプトを用意しておいて、定期的にモジュールのメモリ使用量をチェックしておくと、大体のメモリー使用量の感覚がつかめて、どこ削るべきかを判断しやすくなるかも。
ただ、この粒度だと細かいかなぁ。Makefile.PLの中からrequires探してきて、モジュール単位でメモリだしたほうが現実的かもなぁと。