One way of finding out more exact CPU utilization and other stats for
one or more Erlang processes from the Linux point of view could be to
bind them to a specific Erlang scheduler [1] which requires you to first
bind each Erlang scheduler to a CPU thread [2] (logical processor)
rather than have the OS migrate them at its will between the available
threads.<br>
<br>After this you can find the thread id of the Linux thread executing that Erlang scheduler [3].<br><br>Then
you can look at interesting statistics such as CPU utilization for the
thread corresponding to that Erlang scheduler using for example the %cpu
format specifier to ps. There is also a bunch of interesting things
under stat in proc for each tid such as page faults stats and time
scheduled in kernel mode [4] which could be useful.<br>
<br>Things to consider is that the Erlang scheduler could have executed
other Erlang processes than the ones specificity bound to it. Also, if
you bound several Erlang processes to a Erlang scheduler, the Linux
thread stats would be for all of them. Also, binding Erlang processes to
a scheduler is not generally recommended and you might only want todo
something like this in a testing environment for benchmarking.<br>
<br>[1] Use the {scheduler, N} option (undocumented) to
erlang:spawn_opt/2,3,4,5. The number of schedulers can be found with
erlang:system_info(schedulers)<div id=":1lt">, and the scheduler for the calling process with erlang:system_info(scheduler_id).<br>
<br>[2] Look at the +sbt options at <a href="http://www.erlang.org/doc/man/erl.html#emu_flags" target="_blank">http://www.erlang.org/doc/man/erl.html#emu_flags</a><br><br>[3]
You can find out the tids with ps -Leo pid,tid,comm | grep beam.
Finding the exact thread might be tricky, but if you bind all the
processes doing heavy stuff to one thread, that one should stand out if
you add other stats like %cpu and %mem to the format specifiers. A more
explicit way would be to call pid_t tid = syscall(SYS_gettid) in a NIF
from the bound Erlang processes you want to look at.<br>
<br>[4] man 5 proc, look under the stat and statm sections, you can read
it directly at /proc/<tid>/stat or use ps to list them.<br><br>Cheers,<br>Gustav Simonsson<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 2, 2012 at 4:39 AM, József Bérces <span dir="ltr"><<a href="mailto:jozsef.berces@ericsson.com" target="_blank">jozsef.berces@ericsson.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div>
<div><font face="Arial"><span>Hi,</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>I am writing an application that runs in the background crunching some data and writing result files to the disk. It has a web interface to configure what data and how to process. And I was thinking
about that it would be good to be able to present some stats on the web interface about which Erlang processes how much CPU resources used during the last second/minute/day/week etc.</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>Is there any way to get this kind of info somehow without wasting too much resources on the stat collection itself? I do not want it for all Erlang processes, only for a well defined subset of
them.</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>eprof/fprof seem to be too heavy: they would take too much system resources and they would produce too detailed data for me.
</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>erlang:system_profile seems to be promising (I have not started playing with it) but it has that note in the doc that it is experimental so I am a bit afraid of it.</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>I was also thinking about tracing my processes with the flag 'running' so I would get 'in' and 'out' message tags in a profiling process. I am not sure how much resources this would take.</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>Any suggestions are welcome!</span></font></div>
<div><font face="Arial"><span></span></font> </div>
<div><font face="Arial"><span>Thanks,</span></font></div>
<div><font face="Arial"><span>Jozsef</span></font></div>
</div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>