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