[ruby-core:95291] [Ruby master Feature#16245] Add interfaces to count and measure size all IMEMO objects

From: lourens@...
Date: 2019-10-09 11:00:42 UTC
List: ruby-core #95291
Issue #16245 has been updated by methodmissing (Lourens Naud薊.


I like this API more, however `RubyVM` has been under discussion in https://bugs.ruby-lang.org/issues/15752 regarding implementation specific exposure of experimental API and / or insights. These 2 issues are in a way strongly coupled.

sam.saffron (Sam Saffron) wrote:
> To be honest I think the best spot for this is `RubyVM.stat`
> 
> perhaps:
> 
> ```
> RubyVM.stat
> {
>    :global_method_state=>143, 
>    :global_constant_state=>1369, 
>    :class_serial=>8768,
>    :imemo_ment_count,
>    :imemo_iseq_count,
>    :imemo_env_count,
>    :imemo_tmpbuf_count,
>    :imemo_ast_count,
>    :imemo_ment_size,
>    :imemo_iseq_size,
>    :imemo_env_size,
>    :imemo_tmpbuf_size,
>    :imemo_ast_size
> }
> ```
> 
> Since `RubyVM.stat(:class_serial)` is already supported as an efficient way to grab a single metric this interface fits nicely. It does not expand the signature surface of Ruby and is something that would be very simple to add for 2.7. 
> 
> 
> Additionally for extra bonus points: 
> 
> 
> RubyVM.stat(:total_allocated_bytes): all the bytes Ruby xmalloc and family allocated since process start
> RubyVM.stat(:total_freed_bytes): all the bytes freed
> 
> 
> This comprehensive set of changes would make introspection of "why is my Ruby size XYZ?" really easy and provide some extremely powerful metrics for graphing.
> 
> Thoughts?



----------------------------------------
Feature #16245: Add interfaces to count and measure size all IMEMO objects
https://bugs.ruby-lang.org/issues/16245#change-81971

* Author: sam.saffron (Sam Saffron)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Koichi introduced an experimental gem: https://github.com/ko1/iseq_collector

It allows:

ObjectSpace.each_iseq{|iseq| ...}
ObjectSpace.count_iseq #=> Integer
ObjectSpace.memsize_of_all_iseq (should not generate RubyVM::InstructionSequence wrappers for IMEMOs)

Since the wrapper object  RubyVM::InstructionSequence is lazily allocated, ObjectSpace.each_object does not find these IMEMOs unless they have been wrapped. This design is good and conserves memory. 

`count_iseq` and `memsize_of_all_iseq` are very powerful metrics most large Ruby deployments can use to automatically detect method leaks introduced via meta programming. These issues are invisible now short of walking a heap dump. 

Can we add the new interface into 2.7?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next