Last active
October 2, 2015 14:16
-
-
Save gazay/6bd7f9057108479c5f23 to your computer and use it in GitHub Desktop.
JQ scripts for analyzing heap dumps
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
# Sort by memsize from first 50 lines of dump (can be just with `cat` command) | |
head -50 input.json | jq --slurp '[.[] | {address: .address, type: .type, file: .file, line: .line, method: .method, memsize: .memsize }] | sort_by(.memsize) | map([.address, .type, .file, "\(.line)", .method, "\(.memsize)"] | join(" ")) | reverse' | head -20 | |
# Group objects by type-class-struct-name, count them, count sum of their memsize and sort them by count | |
# Useful when you didn't trace allocations | |
cat input_file | jq --slurp '[.[] | {type: "\(.type) \(.class) \(.struct) \(.name)", memsize: .memsize}] | group_by(.type) | map(reduce .[] as $item ({type: .[0].type, memsize: .[0].memsize, count: 0}; {type: .type, memsize: (.memsize + $item.memsize), count: (.count + 1)})) | sort_by(.count) | map(["\(.count)", "\(.memsize)", .type] | join(" : ")) | reverse' > output_file | |
# Group objects by allocation file-line, count them and their sum of memsize and sort by memsize | |
cat input_file | jq --slurp '[.[] | {address: .address, type: .type, file: "\(.file)\(.line)", value: .value, method: .method, memsize: .memsize }] | group_by(.file) | map(reduce .[] as $item ({file: .[0].file, type: .[0].type, count: 0, memsize: 0}; {file: .file, type: .type, count: (.count + 1), memsize: (.memsize + $item.memsize)})) | sort_by(.memsize) | map(["\(.count)", "\(.memsize)", .type, .file] | join(" ")) | reverse' > output_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment