1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Perl 6Advent Calendar 2016

Day 18

Perl 6でのメモリーリークのチェック方法

Last updated at Posted at 2016-12-17

こんにちは、Perl 6アドベントカレンダーの18日目の投稿になります。

今回は簡単なTipsとして、Perl 6で書いたプログラムのメモリーリークのチェック方法を紹介しようと思います。
perl6のインストール時に同梱されているperl6-valgrind-mを使うと簡単にチェックできます。

-eオプションで実行

  • その場で一行のプログラムを書いて実行することができます
-eオプション
$ perl6-valgrind-m -e '"hello".say'
実行結果
================================================================================================
This is Rakudo Perl 6 running in valgrind, a tool for debugging and profiling programs.
Running a program in valgrind usually takes *a lot* more time than running it directly,
so please be patient.
This Rakudo version is 2016.11.182.gea.28845 built on MoarVM version 2016.11.41.gd.2139.b.5,
running on debian (8.jessie) / linux (3.16.0.4.amd.64)
------------------------------------------------------------------------------------------------
==7083== Memcheck, a memory error detector
==7083== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7083== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==7083== Command: /home/itoyota/.rakudobrew/moar-nom/install/bin/moar --full-cleanup --execname=/home/itoyota/.rakudobrew/bin/../moar-nom/install/bin/perl6-valgrind-m --libpath=/home/itoyota/.rakudobrew/moar-nom/install/share/nqp/lib --libpath=/home/itoyota/.rakudobrew/moar-nom/install/share/perl6/lib --libpath=/home/itoyota/.rakudobrew/moar-nom/install/share/perl6/runtime /home/itoyota/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6.moarvm -e "hello".say
==7083== 
hello
==7083== 
==7083== HEAP SUMMARY:
==7083==     in use at exit: 259,267 bytes in 39,001 blocks
==7083==   total heap usage: 244,187 allocs, 205,186 frees, 55,380,461 bytes allocated
==7083== 
==7083== LEAK SUMMARY:
==7083==    definitely lost: 8,766 bytes in 34,573 blocks
==7083==    indirectly lost: 22,260 bytes in 668 blocks
==7083==      possibly lost: 210,056 bytes in 3,751 blocks
==7083==    still reachable: 18,185 bytes in 9 blocks
==7083==         suppressed: 0 bytes in 0 blocks
==7083== Rerun with --leak-check=full to see details of leaked memory
==7083== 
==7083== For counts of detected and suppressed errors, rerun with: -v
==7083== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

テストに対して実行

  • テストプログラムに対して実行するのがよくあるユースケースかなと思います
実行
$ perl6-valgrind-m t/01-tagger.t
実行結果
================================================================================================
This is Rakudo Perl 6 running in valgrind, a tool for debugging and profiling programs.
Running a program in valgrind usually takes *a lot* more time than running it directly,
so please be patient.
This Rakudo version is 2016.11.182.gea.28845 built on MoarVM version 2016.11.41.gd.2139.b.5,
running on debian (8.jessie) / linux (3.16.0.4.amd.64)
------------------------------------------------------------------------------------------------
==7107== Memcheck, a memory error detector
==7107== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7107== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==7107== Command: /home/itoyota/.rakudobrew/moar-nom/install/bin/moar --full-cleanup --execname=/home/itoyota/.rakudobrew/bin/../moar-nom/install/bin/perl6-valgrind-m --libpath=/home/itoyota/.rakudobrew/moar-nom/install/share/nqp/lib --libpath=/home/itoyota/.rakudobrew/moar-nom/install/share/perl6/lib --libpath=/home/itoyota/.rakudobrew/moar-nom/install/share/perl6/runtime /home/itoyota/.rakudobrew/moar-nom/install/share/perl6/runtime/perl6.moarvm t/01-tagger.t
==7107== 
ok 1 - 
ok 2 - 
    ok 1 - 
    ok 2 - 
    1..2
ok 3 - MeCab::Tagger.parse-tonode should return a fulfilled MeCab::Node object.
1..3
==7107== 
==7107== HEAP SUMMARY:
==7107==     in use at exit: 704,650 bytes in 43,912 blocks
==7107==   total heap usage: 361,886 allocs, 317,974 frees, 110,964,543 bytes allocated
==7107== 
==7107== LEAK SUMMARY:
==7107==    definitely lost: 9,511 bytes in 39,336 blocks
==7107==    indirectly lost: 325,824 bytes in 794 blocks
==7107==      possibly lost: 341,152 bytes in 3,755 blocks
==7107==    still reachable: 28,163 bytes in 27 blocks
==7107==         suppressed: 0 bytes in 0 blocks
==7107== Rerun with --leak-check=full to see details of leaked memory
==7107== 
==7107== For counts of detected and suppressed errors, rerun with: -v
==7107== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

以上、Perl 6アドベントカレンダーの18日目の投稿でした。

P.S.
今回紹介したコマンドはMoarVMかコンパイラのメモリリークを検知するので、
なにかメモリーリークを実際に見つけてしまったら、既に報告がないか確認したうえでRTするとよいと思います。

参考(公式ドキュメントになかったのでISSUE立ててみました):https://github.com/perl6/doc/issues/1060

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?