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