Created
June 26, 2018 11:23
-
-
Save tarui/6e41c4b07ee000bd0fd5dabfa10459be to your computer and use it in GitHub Desktop.
mallocdetailinfo2graph
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
require 'rbplotly' | |
# monkey patch | |
class IRuby | |
def self.display(html) | |
html.render.sub(/style="height: 100%; width: 100%;"/,'style=""') | |
end | |
end | |
buffer=[""] | |
line = ARGF.gets | |
buffer[-1] << line | |
buffer[-1] << '<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>' | |
line = ARGF.gets | |
while line | |
unless line =~/^\* malloc_info gen statistics/ | |
buffer[-1] << line | |
line = ARGF.gets | |
next | |
end | |
show_graph = true | |
buffer << malloc_info = {} | |
buffer << "" | |
key = line.chomp | |
data = malloc_info[key] = [] | |
labels = [] | |
values = [] | |
values2 = [] | |
while (line = ARGF.gets) =~ /^(\S+)\s+(\d+)\s+(\d+)\s*$/ | |
data << [$1,$2,$3] | |
labels << $1 | |
values << $2.to_i | |
values2 << $3.to_i | |
end | |
(values.size-1).downto(0){|idx| | |
if values[idx]>0 | |
labels[idx+1..-1]=[] | |
values[idx+1..-1]=[] | |
values2[idx+1..-1]=[] | |
break | |
end | |
} | |
show_graph = false if labels.size < 3 | |
if show_graph | |
title= key + " malloc'ed count" | |
plot = Plotly::Plot.new(data: [{x: labels,y: values, type: :bar, sort: false }], | |
layout: {title: title,autosize: false,width: 1000,height: 300,xaxis:{type: :category}}) | |
buffer[-1] << plot.show | |
title= key + " malloc'ed total size" | |
plot = Plotly::Plot.new(data: [{x: labels,y: values2, type: :bar, sort: false }], | |
layout: {title: title,autosize: false,width: 1000,height: 300,xaxis:{type: :category}}) | |
buffer[-1] << plot.show | |
end | |
key = line.chomp | |
data = malloc_info[key] = [] | |
labels = [] | |
values = [] | |
values2 = [] | |
while (line = ARGF.gets) =~ /^(\S+)\s+(\d+)\s*$/ | |
data << [$1,$2.to_i] | |
labels << $1 | |
values << $2.to_i | |
end | |
if show_graph | |
title= key | |
plot = Plotly::Plot.new(data: [{x: labels,y: values, type: :bar, sort: false }], | |
layout: {title: title,autosize: false,width: 1000,height: 300,xaxis:{type: :category}}) | |
buffer[-1] << plot.show | |
end | |
key = line.chomp | |
data = malloc_info[key] = [] | |
labels = [] | |
values = [] | |
values2 = [] | |
while (line = ARGF.gets) =~ /^(\S+)\s+(\d+)\s+(\d+)\s*$/ | |
data << [$1,$2.to_i,$3.to_i] | |
labels << $1 | |
values << $2.to_i | |
values2 << $3.to_i | |
end | |
if show_graph | |
title= key + " malloc'ed count" | |
plot = Plotly::Plot.new(data: [{x: labels,y: values, type: :bar, sort: false }], | |
layout: {title: title,autosize: false,width: 1000,height: 300,xaxis:{type: :category}}) | |
buffer[-1] << plot.show | |
title= key + " malloc'ed total size" | |
plot = Plotly::Plot.new(data: [{x: labels,y: values2, type: :bar, sort: false }], | |
layout: {title: title,autosize: false,width: 1000,height: 300,xaxis:{type: :category}}) | |
buffer[-1] << plot.show | |
end | |
end | |
puts buffer | |
__END__ | |
* malloc_info size statistics | |
16 3 | |
32 0 | |
64 23031 | |
128 119486 | |
256 34751 | |
512 4708 | |
1024 40007 | |
2048 1704 | |
4096 4731 | |
8192 576 | |
more 1292 | |
* malloc_info file statistics | |
st.c 23017 139612160 | |
id_table.c 4436 652576 | |
class.c 147 8440 | |
string.c 53632 23486248 | |
iseq.c 9519 4216920 | |
iseq.h 6235 1154632 | |
compile.c 47082 21641968 | |
array.c 13795 2763064 | |
util.c 244 22848 | |
parse.y 36131 3007880 | |
node.c 2662 15641200 | |
io.c 1469 4909864 | |
vm_method.c 2 160 | |
gc.c 3389 483576 | |
re.c 26647 2371880 | |
vm.c 362 1090920 | |
vm_backtrace.c 12 4896 | |
variable.c 1476 169552 | |
error.c 4 224 | |
struct.c 11 968 | |
raddrinfo.c 7 456 | |
file.c 2 368 | |
(null) 3 0 | |
object.c 1 120 | |
zlib.c 2 40000 | |
stringio.c 1 72 | |
signal.c 1 16424 | |
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
sudo gem install ansi-to-html rbplotly | |
ansi-to-html rails-master-benchmark.log | ruby analyze_mallocdetail.rb > rails-master-benchmark.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment