forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ruby implement memsize functions for native types
Fix: protocolbuffers#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.
- Loading branch information
Showing
4 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/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' | ||
|
||
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 | ||
assert_operator 40, :<, ObjectSpace.memsize_of(Google::Protobuf::Internal::Arena.new) | ||
end | ||
|
||
def test_objspace_memsize_of_message | ||
assert_operator 40, :<, ObjectSpace.memsize_of(FooBar::TestImportedMessage.new) | ||
end | ||
|
||
def test_objspace_memsize_of_map | ||
assert_operator 40, :<, ObjectSpace.memsize_of(Google::Protobuf::Map.new(:string, :int32)) | ||
end | ||
end |