! fixed pepper fish to work with lua 5.3.4

This commit is contained in:
Mihai Sebea 2018-09-08 23:12:44 +02:00
parent 1abac192cb
commit 541958e4d2

View File

@ -206,8 +206,9 @@ function _profiler._internal_profile_by_call(self,action)
-- Retrieve the most recent activation record... -- Retrieve the most recent activation record...
local latest_ar = nil local latest_ar = nil
if table.getn(self.callstack) > 0 then local callstackLen = #self.callstack
latest_ar = self.callstack[table.getn(self.callstack)] if callstackLen > 0 then
latest_ar = self.callstack[callstackLen]
end end
-- Are we allowed to profile this function? -- Are we allowed to profile this function?
@ -280,7 +281,8 @@ function _profiler._internal_profile_by_call(self,action)
end end
-- Last thing to do on return is to drop the last activation record... -- Last thing to do on return is to drop the last activation record...
table.remove( self.callstack, table.getn( self.callstack ) ) local callstackLen = #self.callstack
table.remove( self.callstack, callstackLen )
end end
end end
@ -400,13 +402,15 @@ function _profiler.report( self, outfile, sort_by_total_time )
) )
end end
for i=1,table.getn(ordering) do local len = #ordering
for i=1,len do
local func = ordering[i] local func = ordering[i]
local record = self.rawstats[func] local record = self.rawstats[func]
local thisfuncname = " " .. self:_pretty_name(func) .. " " local thisfuncname = " " .. self:_pretty_name(func) .. " "
if string.len( thisfuncname ) < 42 then if string.len( thisfuncname ) < 42 then
local nameLen = math.ceil((42 - string.len(thisfuncname))/2)
thisfuncname = thisfuncname =
string.rep( "-", (42 - string.len(thisfuncname))/2 ) .. thisfuncname string.rep( "-", nameLen) .. thisfuncname
thisfuncname = thisfuncname =
thisfuncname .. string.rep( "-", 42 - string.len(thisfuncname) ) thisfuncname .. string.rep( "-", 42 - string.len(thisfuncname) )
end end
@ -476,20 +480,24 @@ function _profiler.lua_report(self,outfile)
local functonum = {} local functonum = {}
for func,record in pairs(self.rawstats) do for func,record in pairs(self.rawstats) do
table.insert(ordering, func) table.insert(ordering, func)
functonum[func] = table.getn(ordering) local len = #ordering
functonum[func] = len
end end
outfile:write( outfile:write(
"-- Profile generated by profiler.lua Copyright Pepperfish 2002+\n\n" ) "-- Profile generated by profiler.lua Copyright Pepperfish 2002+\n\n" )
outfile:write( "-- Function names\nfuncnames = {}\n" ) outfile:write( "-- Function names\nfuncnames = {}\n" )
for i=1,table.getn(ordering) do local len = #ordering
for i=1,len do
local thisfunc = ordering[i] local thisfunc = ordering[i]
outfile:write( "funcnames[" .. i .. "] = " .. outfile:write( "funcnames[" .. i .. "] = " ..
string.format("%q", self:_pretty_name(thisfunc)) .. "\n" ) string.format("%q", self:_pretty_name(thisfunc)) .. "\n" )
end end
outfile:write( "\n" ) outfile:write( "\n" )
outfile:write( "-- Function times\nfunctimes = {}\n" ) outfile:write( "-- Function times\nfunctimes = {}\n" )
for i=1,table.getn(ordering) do
local len = #ordering
for i=1,len do
local thisfunc = ordering[i] local thisfunc = ordering[i]
local record = self.rawstats[thisfunc] local record = self.rawstats[thisfunc]
outfile:write( "functimes[" .. i .. "] = { " ) outfile:write( "functimes[" .. i .. "] = { " )
@ -500,7 +508,9 @@ function _profiler.lua_report(self,outfile)
end end
outfile:write( "\n" ) outfile:write( "\n" )
outfile:write( "-- Child links\nchildren = {}\n" ) outfile:write( "-- Child links\nchildren = {}\n" )
for i=1,table.getn(ordering) do
local len = #ordering
for i=1,len do
local thisfunc = ordering[i] local thisfunc = ordering[i]
local record = self.rawstats[thisfunc] local record = self.rawstats[thisfunc]
outfile:write( "children[" .. i .. "] = { " ) outfile:write( "children[" .. i .. "] = { " )
@ -513,7 +523,9 @@ function _profiler.lua_report(self,outfile)
end end
outfile:write( "\n" ) outfile:write( "\n" )
outfile:write( "-- Child call counts\nchildcounts = {}\n" ) outfile:write( "-- Child call counts\nchildcounts = {}\n" )
for i=1,table.getn(ordering) do
local len = #ordering
for i=1,len do
local thisfunc = ordering[i] local thisfunc = ordering[i]
local record = self.rawstats[thisfunc] local record = self.rawstats[thisfunc]
outfile:write( "children[" .. i .. "] = { " ) outfile:write( "children[" .. i .. "] = { " )
@ -526,7 +538,8 @@ function _profiler.lua_report(self,outfile)
end end
outfile:write( "\n" ) outfile:write( "\n" )
outfile:write( "-- Child call time\nchildtimes = {}\n" ) outfile:write( "-- Child call time\nchildtimes = {}\n" )
for i=1,table.getn(ordering) do local len = #ordering
for i=1,len do
local thisfunc = ordering[i] local thisfunc = ordering[i]
local record = self.rawstats[thisfunc]; local record = self.rawstats[thisfunc];
outfile:write( "children[" .. i .. "] = { " ) outfile:write( "children[" .. i .. "] = { " )