Created
August 8, 2009 23:54
-
-
Save methodmissing/164550 to your computer and use it in GitHub Desktop.
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
| #!/usr/sbin/dtrace -Zs | |
| /* | |
| Memory allocation / deallocation instrumentation with the PID provider | |
| (c) 2009 Lourens Naudé (methodmissing) */ | |
| #pragma D option quiet | |
| #pragma D option switchrate=10 | |
| #pragma D option dynvarsize=128m | |
| #pragma D option bufsize=128m | |
| #pragma D option aggsize=64m | |
| struct meminfo{ | |
| uint64_t cpu; | |
| uint64_t timestamp; | |
| uint64_t elapsed; | |
| uintptr_t addr; | |
| uint64_t elements; | |
| size_t size; | |
| }; | |
| struct meminfo m[string]; | |
| pid$target::malloc:entry | |
| { | |
| m[probefunc].cpu = cpu; | |
| m[probefunc].timestamp = timestamp; | |
| m[probefunc].size = arg0; | |
| } | |
| pid$target::malloc:return | |
| /m[probefunc].cpu/ | |
| { | |
| m[probefunc].elapsed = timestamp - m[probefunc].timestamp; | |
| @num[probefunc] = count(); | |
| @eavg[probefunc] = avg(m[probefunc].elapsed); | |
| @esum[probefunc] = sum(m[probefunc].elapsed); | |
| @edist[probefunc] = quantize(m[probefunc].elapsed); | |
| } | |
| pid$target::calloc:entry | |
| { | |
| m[probefunc].cpu = cpu; | |
| m[probefunc].timestamp = timestamp; | |
| m[probefunc].elements = arg0; | |
| m[probefunc].size = arg1; | |
| } | |
| pid$target::calloc:return | |
| /m[probefunc].cpu/ | |
| { | |
| m[probefunc].elapsed = timestamp - m[probefunc].timestamp; | |
| @num[probefunc] = count(); | |
| @eavg[probefunc] = avg(m[probefunc].elapsed); | |
| @esum[probefunc] = sum(m[probefunc].elapsed); | |
| @edist[probefunc] = quantize(m[probefunc].elapsed); | |
| } | |
| pid$target::realloc:entry | |
| { | |
| m[probefunc].cpu = cpu; | |
| m[probefunc].timestamp = timestamp; | |
| m[probefunc].addr = arg0; | |
| m[probefunc].size = arg1; | |
| } | |
| pid$target::realloc:return | |
| /m[probefunc].cpu/ | |
| { | |
| m[probefunc].elapsed = timestamp - m[probefunc].timestamp; | |
| @num[probefunc] = count(); | |
| @eavg[probefunc] = avg(m[probefunc].elapsed); | |
| @esum[probefunc] = sum(m[probefunc].elapsed); | |
| @edist[probefunc] = quantize(m[probefunc].elapsed); | |
| } | |
| pid$target::free:entry | |
| { | |
| m[probefunc].cpu = cpu; | |
| m[probefunc].timestamp = timestamp; | |
| m[probefunc].addr = arg0; | |
| } | |
| pid$target::free:return | |
| /m[probefunc].cpu/ | |
| { | |
| m[probefunc].elapsed = timestamp - m[probefunc].timestamp; | |
| @num[probefunc] = count(); | |
| @eavg[probefunc] = avg(m[probefunc].elapsed); | |
| @esum[probefunc] = sum(m[probefunc].elapsed); | |
| @edist[probefunc] = quantize(m[probefunc].elapsed); | |
| } | |
| dtrace:::END | |
| { | |
| normalize(@eavg, 1000); | |
| normalize(@esum, 1000); | |
| printf("ELAPSED TIME DISTRIBUTION, %s\n", execname); | |
| printa(@edist); | |
| setopt("aggsortpos", "2"); | |
| printf("%-24s %6s %10s %12s\n", "FUNC", "COUNT", "AVG(us)", "SUM(us)"); | |
| printa("%-24.24s %@6d %@10d %@12d\n", @num, @eavg, @esum); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment