2017-04-25 11:12:39 -05:00
|
|
|
require 'socket_server'
|
2017-04-21 09:24:43 -05:00
|
|
|
|
2017-04-25 11:12:39 -05:00
|
|
|
class StatsSocket < SocketServer
|
2017-04-21 09:24:43 -05:00
|
|
|
|
|
|
|
def initialize(socket_path)
|
2017-04-25 11:12:39 -05:00
|
|
|
super(socket_path)
|
2017-04-21 09:24:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def get_response(command)
|
|
|
|
result =
|
|
|
|
case command
|
|
|
|
when "gc_stat"
|
|
|
|
GC.stat.to_json
|
2017-07-19 23:07:22 -05:00
|
|
|
when "v8_stat"
|
2017-07-20 12:23:48 -05:00
|
|
|
stats = {}
|
|
|
|
ObjectSpace.each_object(MiniRacer::Context) do |context|
|
2017-07-27 20:20:09 -05:00
|
|
|
context.heap_stats.each do |k, v|
|
2017-07-20 12:23:48 -05:00
|
|
|
stats[k] = (stats[k] || 0) + v
|
|
|
|
end
|
|
|
|
end
|
2017-07-21 15:37:05 -05:00
|
|
|
stats.to_json
|
2017-04-21 09:24:43 -05:00
|
|
|
else
|
|
|
|
"[\"UNKNOWN COMMAND\"]"
|
|
|
|
end
|
|
|
|
|
|
|
|
result << "\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|