-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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 (#10291)
Fix: #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=#10291 from casperisfine:ruby-sizes 9150795 PiperOrigin-RevId: 606718632
- Loading branch information
1 parent
0c715b5
commit 87cbddd
Showing
6 changed files
with
57 additions
and
5 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,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 |
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