Last active
December 15, 2015 18:29
-
-
Save denisdefreyne/5303756 to your computer and use it in GitHub Desktop.
This is a DTrace script for Ruby 2.0 that profiles object allocations.
This file contains hidden or 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
#pragma D option dynvarsize=100m | |
dtrace:::BEGIN | |
{ | |
self->depth = 0; | |
} | |
ruby*:::method-entry | |
{ | |
self->depth++; | |
self->classes[self->depth] = copyinstr(arg0); | |
self->methods[self->depth] = copyinstr(arg1); | |
} | |
ruby*:::method-return | |
{ | |
self->depth--; | |
} | |
ruby*:::object-create | |
{ | |
@allocations[self->classes[self->depth], self->methods[self->depth], copyinstr(arg0)] = count(); | |
} | |
dtrace:::END | |
{ | |
printf("\n\n"); | |
printf("---------------------------------------- ---------------------------------------- ---------------------------------------- -------\n"); | |
printf("%-40s %-40s %-40s %s\n", "CALLER CLASS", "CALLER METHOD", "ALLOCATED CLASS", "COUNT"); | |
printf("---------------------------------------- ---------------------------------------- ---------------------------------------- -------\n"); | |
printa("%-40s %-40s %-40s %@d\n", @allocations); | |
printf("---------------------------------------- ---------------------------------------- ---------------------------------------- -------\n"); | |
} |
This file contains hidden or 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
------------------------------ ------------------------------ ------------------------------ ------- | |
CALLER CLASS CALLER METHOD ALLOCATED CLASS COUNT | |
------------------------------ ------------------------------ ------------------------------ ------- | |
#<Class:0x007f89e18e0720> 1 | |
ARGF.class 1 | |
Foo 1 | |
Gem::Version 1 | |
IOError 1 | |
Mutex 1 | |
NoMemoryError 1 | |
SystemStackError 1 | |
ThreadGroup 1 | |
Time 1 | |
Gem::Requirement parse Gem::Version 1 | |
Gem::Specification unresolved_deps Hash 1 | |
Hash 2 | |
LoadError 2 | |
Object 2 | |
Gem::Requirement default Gem::Requirement 2 | |
Gem::Specification initialize Hash 8 | |
Gem::Specification load Gem::Specification 8 | |
Gem::Specification load String 8 | |
Gem::Version create Gem::Version 8 | |
Gem::Version initialize String 10 | |
Gem::Specification initialize Gem::Requirement 21 | |
Gem::Specification initialize String 24 | |
Gem::Specification initialize Array 96 | |
Foo initialize Bob 100 | |
Foo initialize String 100 | |
String 218 | |
------------------------------ ------------------------------ ------------------------------ ------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment