From: Robert Klemme Date: 2013-06-25T02:44:07+09:00 Subject: Re: A working memory profiling solution? --047d7bb03e6a77352104dfe9f5ac Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 24, 2013 at 6:59 PM, Andras Horvath wrote: > Dear All, > > I've spent the last 2 days by trying to find a working memory profiling > solution for either 1.9.x or 2.0 that can show the memory usage by > methods. How exactly do you imagine "memory usage by methods" to be measured? Are you just interested in learning how much memory is allocated (temporarily) from withing a method or do you have a memory leak? > Similar to the process time output. > I usually found "ruby -r profile" helpful. You can also use module Benchmark for measuring timing of specific parts of code. You can even use Benchmark.measure { ... } around a specific piece and you'll get CPU, system and wall clock time in an instance of class Benchmark::Tms, > # code to profile > 10000.times { "hello".chars.to_a.shuffle.join } > This will allocate objects just temporarily and drop them pretty soon again => no leak. CPU wise on my box: irb(main):007:0> Benchmark.measure { 10000.times { "hello".chars.to_a.shuffle.join } } => 0.063000 0.000000 0.063000 ( 0.066000) For memory leak detection I once created a small tool with ObjectSpace which just counts instances per class and outputs deltas. You might find it in the archives of this forum. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --047d7bb03e6a77352104dfe9f5ac Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Jun 24, 2013 at 6:59 PM, Andras Horvath &= lt;lists@ruby-for= um.com> wrote:
Dear All,

I've spent the last 2 days by trying to find a working memory profiling=
solution for either 1.9.x or 2.0 that can show the memory usage by
methods.

How exactly do you imagine "= memory usage by methods" to be measured? =A0Are you just interested in= learning how much memory is allocated (temporarily) from withing a method = or do you have a memory leak?
=A0
Similar to the process time output.

I usually found "ruby -r profile" helpful. = =A0You can also use module Benchmark for measuring timing of specific parts= of code. =A0You can even use Benchmark.measure { ... } around a specific p= iece and you'll get CPU, system and wall clock time in an instance of c= lass Benchmark::Tms,
=A0
=A0 =A0 =A0 =A0 # code to profile
=A0 =A0 =A0 =A0 10000.times { "hello".chars.to_a.shuffle.join }

This will allocate objects just temporar= ily and drop them pretty soon again =3D> no leak. =A0CPU wise on my box:=

irb(main):007:0> Benchmark.measure { 10000.times { &= quot;hello".chars.to_a.shuffle.join } }
=3D> =A0 0.063000= =A0 0.000000 =A0 0.063000 ( =A00.066000)

Fo= r memory leak detection I once created a small tool with ObjectSpace which = just counts instances per class and outputs deltas. =A0You might find it in= the archives of this forum.

Kind regards

robert


--
remember.guy do |as, often| as.you= _can - without end
http:/= /blog.rubybestpractices.com/
--047d7bb03e6a77352104dfe9f5ac--