Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: profiler.rb
module Profiler__
[0] Fix | Delete
# internal values
[1] Fix | Delete
@@start = @@stack = @@map = nil
[2] Fix | Delete
PROFILE_PROC = proc{|event, file, line, id, binding, klass|
[3] Fix | Delete
case event
[4] Fix | Delete
when "call", "c-call"
[5] Fix | Delete
now = Process.times[0]
[6] Fix | Delete
@@stack.push [now, 0.0]
[7] Fix | Delete
when "return", "c-return"
[8] Fix | Delete
now = Process.times[0]
[9] Fix | Delete
key = [klass, id]
[10] Fix | Delete
if tick = @@stack.pop
[11] Fix | Delete
data = (@@map[key] ||= [0, 0.0, 0.0, key])
[12] Fix | Delete
data[0] += 1
[13] Fix | Delete
cost = now - tick[0]
[14] Fix | Delete
data[1] += cost
[15] Fix | Delete
data[2] += cost - tick[1]
[16] Fix | Delete
@@stack[-1][1] += cost if @@stack[-1]
[17] Fix | Delete
end
[18] Fix | Delete
end
[19] Fix | Delete
}
[20] Fix | Delete
module_function
[21] Fix | Delete
def start_profile
[22] Fix | Delete
@@start = Process.times[0]
[23] Fix | Delete
@@stack = []
[24] Fix | Delete
@@map = {}
[25] Fix | Delete
set_trace_func PROFILE_PROC
[26] Fix | Delete
end
[27] Fix | Delete
def stop_profile
[28] Fix | Delete
set_trace_func nil
[29] Fix | Delete
end
[30] Fix | Delete
def print_profile(f)
[31] Fix | Delete
stop_profile
[32] Fix | Delete
total = Process.times[0] - @@start
[33] Fix | Delete
if total == 0 then total = 0.01 end
[34] Fix | Delete
data = @@map.values
[35] Fix | Delete
data.sort!{|a,b| b[2] <=> a[2]}
[36] Fix | Delete
sum = 0
[37] Fix | Delete
f.printf " %% cumulative self self total\n"
[38] Fix | Delete
f.printf " time seconds seconds calls ms/call ms/call name\n"
[39] Fix | Delete
for d in data
[40] Fix | Delete
sum += d[2]
[41] Fix | Delete
f.printf "%6.2f %8.2f %8.2f %8d ", d[2]/total*100, sum, d[2], d[0]
[42] Fix | Delete
f.printf "%8.2f %8.2f %s\n", d[2]*1000/d[0], d[1]*1000/d[0], get_name(*d[3])
[43] Fix | Delete
end
[44] Fix | Delete
f.printf "%6.2f %8.2f %8.2f %8d ", 0.0, total, 0.0, 1 # ???
[45] Fix | Delete
f.printf "%8.2f %8.2f %s\n", 0.0, total*1000, "#toplevel" # ???
[46] Fix | Delete
end
[47] Fix | Delete
def get_name(klass, id)
[48] Fix | Delete
name = klass.to_s || ""
[49] Fix | Delete
if klass.kind_of? Class
[50] Fix | Delete
name += "#"
[51] Fix | Delete
else
[52] Fix | Delete
name += "."
[53] Fix | Delete
end
[54] Fix | Delete
name + id.id2name
[55] Fix | Delete
end
[56] Fix | Delete
private :get_name
[57] Fix | Delete
end
[58] Fix | Delete
[59] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function