summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-17 00:50:47 +0800
committerruki <[email protected]>2023-03-17 00:50:47 +0800
commitb48a0dce1c10f24c045aab889ea4ec72f9db1b7f (patch)
treed0d3ff1febe43ed20d1639bbe28af856b4821179
parent879f532bca3c8b56c7a2979c0246ca9ae2a909c2 (diff)
improve profiler
-rw-r--r--xmake/core/base/profiler.lua39
-rw-r--r--xmake/plugins/show/lists/envs.lua2
2 files changed, 21 insertions, 20 deletions
diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua
index 429715eae..2d5037a02 100644
--- a/xmake/core/base/profiler.lua
+++ b/xmake/core/base/profiler.lua
@@ -107,9 +107,9 @@ end
-- start profiling
function profiler:start()
local mode = self:mode()
- if mode and mode == "trace" then
+ if self:is_trace() then
debug.sethook(profiler._tracing_handler, 'cr', 0)
- else
+ elseif self:is_perf("call") then
self._REPORTS = self._REPORTS or {}
self._REPORTS_BY_KEY = self._REPORTS_BY_KEY or {}
self._STARTIME = self._STARTIME or os.clock()
@@ -119,18 +119,10 @@ end
-- stop profiling
function profiler:stop()
-
- -- trace?
- local mode = self:mode()
- if mode and mode == "trace" then
- -- stop to hook
+ if self:is_trace() then
debug.sethook()
- else
-
- -- save the stop time
+ elseif self:is_perf("call") then
self._STOPTIME = os.clock()
-
- -- stop to hook
debug.sethook()
-- calculate the total time
@@ -143,20 +135,16 @@ function profiler:stop()
-- show reports
for _, report in ipairs(self._REPORTS) do
-
- -- calculate percent
local percent = (report.totaltime / totaltime) * 100
if percent < 1 then
break
end
-
- -- trace
utils.print("%6.3f, %6.2f%%, %7d, %s", report.totaltime, percent, report.callcount, self:_func_title(report.funcinfo))
end
end
end
--- get profiler mode, e.g. perf, trace
+-- get profiler mode, e.g. perf:call, perf:tag, trace
function profiler:mode()
local mode = self._MODE
if mode == nil then
@@ -166,10 +154,23 @@ function profiler:mode()
return mode or nil
end
+-- is trace?
+function profiler:is_trace()
+ local mode = self:mode()
+ return mode and mode == "trace"
+end
+
+-- is perf?
+function profiler:is_perf(name)
+ local mode = self:mode()
+ if mode and name then
+ return mode == "perf:" .. name
+ end
+end
+
-- profiler is enabled?
function profiler:enabled()
- local mode = self:mode()
- return mode ~= nil and (mode == "trace" or mode == "perf")
+ return self:is_perf("call") or self:is_perf("tag") or self:is_trace()
end
-- return module
diff --git a/xmake/plugins/show/lists/envs.lua b/xmake/plugins/show/lists/envs.lua
index 753efd997..11d3ffc59 100644
--- a/xmake/plugins/show/lists/envs.lua
+++ b/xmake/plugins/show/lists/envs.lua
@@ -36,7 +36,7 @@ function main()
XMAKE_RAMDIR = {"Set the ramdisk directory.", os.getenv("XMAKE_RAMDIR")},
XMAKE_RCFILES = {"Set the runtime configuration files.", path.joinenv(project.rcfiles())},
XMAKE_TMPDIR = {"Set the temporary directory.", os.tmpdir()},
- XMAKE_PROFILE = {"Start profiler, e.g. perf, trace, stuck.", os.getenv("XMAKE_PROFILE")},
+ XMAKE_PROFILE = {"Start profiler, e.g. perf:call, perf:tag, trace, stuck.", os.getenv("XMAKE_PROFILE")},
XMAKE_PKG_CACHEDIR = {"Set the cache directory of packages.", os.getenv("XMAKE_PKG_CACHEDIR")},
XMAKE_PKG_INSTALLDIR = {"Set the install directory of packages.", os.getenv("XMAKE_PKG_INSTALLDIR")}}
local width = 24