test v8 heap stats and aggregate all

This commit is contained in:
Sam 2017-07-20 13:23:48 -04:00
parent 1096dcd602
commit e7c170bb00
2 changed files with 18 additions and 0 deletions

View File

@ -14,6 +14,12 @@ class StatsSocket < SocketServer
when "gc_stat"
GC.stat.to_json
when "v8_stat"
stats = {}
ObjectSpace.each_object(MiniRacer::Context) do |context|
context.heap_stats.each do |k,v|
stats[k] = (stats[k] || 0) + v
end
end
PrettyText.v8.heap_stats.to_json
else
"[\"UNKNOWN COMMAND\"]"

View File

@ -40,6 +40,18 @@ describe StatsSocket do
parsed = JSON.parse(line)
expect(parsed.keys.sort).to eq(GC.stat.keys.map(&:to_s).sort)
# make sure we have libv8 going
PrettyText.cook("x")
socket = UNIXSocket.new(socket_path)
socket.send "v8_stat\n", 0
line = socket.readline
socket.close
parsed = JSON.parse(line)
expect(parsed['total_physical_size']).to be>(0)
end
end