summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-05-04 00:34:10 +0800
committerruki <[email protected]>2021-05-04 00:34:10 +0800
commitcfb8bf67018d7df4bd76c768025b476e7582b24d (patch)
tree72790853c6908c66acb6fc709dab3b79c6fcb389
parent77b05dde3e72e0b3b02bb31091ea176b18680742 (diff)
improve style
-rw-r--r--xmake/core/base/profiler.lua42
1 files changed, 1 insertions, 41 deletions
diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua
index 51f3a9172..a53452113 100644
--- a/xmake/core/base/profiler.lua
+++ b/xmake/core/base/profiler.lua
@@ -30,79 +30,43 @@ local string = require("base/string")
-- get the function title
function profiler:_func_title(funcinfo)
-
- -- check
- assert(funcinfo)
-
- -- the function name
local name = funcinfo.name or 'anonymous'
-
- -- the function line
local line = string.format("%d", funcinfo.linedefined or 0)
-
- -- the function source
local source = funcinfo.short_src or 'C_FUNC'
if os.isfile(source) then
source = path.relative(source, xmake._PROGRAM_DIR)
end
-
- -- make title
return string.format("%-30s: %s: %s", name, source, line)
end
-- get the function report
function profiler:_func_report(funcinfo)
-
- -- get the function title
local title = self:_func_title(funcinfo)
-
- -- get the function report
local report = self._REPORTS_BY_TITLE[title]
if not report then
-
- -- init report
report =
{
title = self:_func_title(funcinfo)
, callcount = 0
, totaltime = 0
}
-
- -- save it
self._REPORTS_BY_TITLE[title] = report
table.insert(self._REPORTS, report)
end
-
- -- ok?
return report
end
-- profiling call
function profiler:_profiling_call(funcinfo)
-
- -- get the function report
local report = self:_func_report(funcinfo)
- assert(report)
-
- -- save the call time
report.calltime = os.clock()
-
- -- update the call count
report.callcount = report.callcount + 1
-
end
-- profiling return
function profiler:_profiling_return(funcinfo)
-
- -- get the stoptime
local stoptime = os.clock()
-
- -- get the function report
local report = self:_func_report(funcinfo)
- assert(report)
-
- -- update the total time
if report.calltime and report.calltime > 0 then
report.totaltime = report.totaltime + (stoptime - report.calltime)
report.calltime = 0
@@ -111,11 +75,7 @@ end
-- the profiling handler
function profiler._profiling_handler(hooktype)
-
- -- the function info
local funcinfo = debug.getinfo(2, 'nS')
-
- -- dispatch it
if hooktype == "call" then
profiler:_profiling_call(funcinfo)
elseif hooktype == "return" then
@@ -125,8 +85,8 @@ end
-- the tracing handler
function profiler._tracing_handler(hooktype)
+ local funcinfo = debug.getinfo(2, 'nS')
if hooktype == "call" then
- local funcinfo = debug.getinfo(2, 'nS')
local name = funcinfo.name
local source = funcinfo.short_src or 'C_FUNC'
if name and os.isfile(source) then