summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-05-04 00:27:07 +0800
committerruki <[email protected]>2021-05-04 00:27:07 +0800
commit9016206b87381de0eb68f857a52bb910e9c077d0 (patch)
tree85dbc0df289ff1304ef04769ada2acf220dfcd0c
parent9fcc366603c2572eb2710b843d240b0368f32ad5 (diff)
improve profiler
-rw-r--r--xmake/core/base/profiler.lua23
-rw-r--r--xmake/core/main.lua10
2 files changed, 23 insertions, 10 deletions
diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua
index 9929e75e6..fd0e253c3 100644
--- a/xmake/core/base/profiler.lua
+++ b/xmake/core/base/profiler.lua
@@ -150,9 +150,10 @@ function profiler._tracing_handler(hooktype)
end
-- start profiling
-function profiler:start(mode)
+function profiler:start()
-- trace?
+ local mode = self:mode()
if mode and mode == "trace" then
debug.sethook(profiler._tracing_handler, 'cr', 0)
else
@@ -169,14 +170,13 @@ function profiler:start(mode)
end
-- stop profiling
-function profiler:stop(mode)
+function profiler:stop()
-- trace?
+ local mode = self:mode()
if mode and mode == "trace" then
-
-- stop to hook
debug.sethook()
-
else
-- save the stop time
@@ -208,5 +208,20 @@ function profiler:stop(mode)
end
end
+-- get profiler mode
+function profiler:mode()
+ local mode = self._MODE
+ if not mode then
+ mode = os.getenv("XMAKE_PROFILE")
+ self._MODE = mode
+ end
+ return mode
+end
+
+-- profiler is enabled?
+function profiler:enabled()
+ return self:mode() ~= nil
+end
+
-- return module
return profiler
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index a399ffccc..bdea1ab2e 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -38,6 +38,7 @@ local theme = require("theme/theme")
local config = require("project/config")
local project = require("project/project")
local localcache = require("cache/localcache")
+local profiler = require("base/profiler")
-- init the option menu
local menu =
@@ -240,11 +241,8 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
end
-- start profiling
- local profiler
- local profile_mode = os.getenv("XMAKE_PROFILE")
- if profile_mode then
- profiler = require("base/profiler")
- profiler:start(profile_mode)
+ if profiler:enabled() then
+ profiler:start()
end
-- show help?
@@ -285,7 +283,7 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
end
-- stop profiling
- if profiler then
+ if profiler:enabled() then
profiler:stop()
end