<div dir="ltr">Hi Jan,<div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 1, 2017 at 1:17 AM, Jan Vrany <span dir="ltr"><<a href="mailto:jan.vrany@fit.cvut.cz" target="_blank">jan.vrany@fit.cvut.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Hi folks,<br>
<br>
Having a Spur VM, I wonder how to measure heap allocations made <br>
by a process executing a particular block, from within the image. <br>
For example, let's have following block:<br>
<br>
[<br>
   | a |<br>
<br>
   100 timesRepeat: [<br>
      a := Array new: 100<br>
   ]<br>
].<br>
<br>
When run, this block allocates - if I'm correct - some 100 * (<object<br>
header size> + 4*100) bytes.<br>
<br>
Note that:<br>
 * Ideally, I'd like to exclude allocations made by other threads<br>
   but having allocations made by all threads would be OK too.<br>
 * Block can span multiple scavenges even oldspace collects.<br>
 * As shown in the example above, I need to take garbage into <br>
   an account.<br>
<br>
How to best measure this?<br></blockquote><div><br></div><div>I just committed the code for Spur, so as soon as the CI has built VMs you should be able to do</div><div><br></div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       initialAllocation := </span>Smalltalk vmParameterAt: 34.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>self doMyThing.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>bytesAllocated := (Smalltalk vmParameterAt: 34) - <span style="white-space:pre">initialAllocation</span></div></div><div><br></div><div>and/or</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>Smalltalk vmParameterAt: 34 put: 0.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>self doMyThing.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>bytesAllocated := Smalltalk vmParameterAt: 34</div><div><br></div><div>It needs testing.  Note that it measures bytes allocated at the lowest level I can manage so it should include everything, including hidden allocations in the GC's marked stack and remembered tables, and the class tables.  I *think* the code is not confused by heap growth and shrinkage.  I'd love for anyone interested to review the code (see the VMMaker.oscog-eem.2237 commit).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Thanks, Jan<br>
</blockquote></div><br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>