Ruby implement memsize functions for native types (#10291)
Fix: https://github.com/protocolbuffers/protobuf/issues/10280
This allows Ruby to report a more correct estimation of the memory used by these objects.
It's useful when running memory profilers against applications.
cc @zhangskz @haberman
Closes #10291
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/10291 from casperisfine:ruby-sizes 9150795328
PiperOrigin-RevId: 606718632
pull/15811/head
parent
0c715b5e9e
commit
87cbdddbf0
6 changed files with 57 additions and 5 deletions
@ -0,0 +1,33 @@ |
||||
#!/usr/bin/ruby |
||||
# |
||||
# generated_code.rb is in the same directory as this test. |
||||
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) |
||||
|
||||
require 'test/unit' |
||||
require 'objspace' |
||||
require 'test_import_pb' |
||||
|
||||
$is_64bit = Google::Protobuf::Internal::SIZEOF_LONG == 8 |
||||
|
||||
class MemoryTest < Test::Unit::TestCase |
||||
# 40 byte is the default object size. But the real size is dependent on many things |
||||
# such as arch etc, so there's no point trying to assert the exact return value here. |
||||
# We merely assert that we return something other than the default. |
||||
def test_objspace_memsize_of_arena |
||||
if $is_64bit |
||||
assert_operator 40, :<, ObjectSpace.memsize_of(Google::Protobuf::Internal::Arena.new) |
||||
end |
||||
end |
||||
|
||||
def test_objspace_memsize_of_message |
||||
if $is_64bit |
||||
assert_operator 40, :<, ObjectSpace.memsize_of(FooBar::TestImportedMessage.new) |
||||
end |
||||
end |
||||
|
||||
def test_objspace_memsize_of_map |
||||
if $is_64bit |
||||
assert_operator 40, :<, ObjectSpace.memsize_of(Google::Protobuf::Map.new(:string, :int32)) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue