diff options
| author | ruki <[email protected]> | 2023-03-17 00:59:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-03-17 00:59:10 +0800 |
| commit | 193cef6e6c343fa613aa6bd245552c6b508e80d0 (patch) | |
| tree | 89a980711aca4be0b92842a87717816db41325b6 | |
| parent | f5fad07cfe262c5913df85bbedb6ec9087ad88c9 (diff) | |
profile compile and link
| -rw-r--r-- | xmake/core/base/profiler.lua | 8 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 6 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 6 |
3 files changed, 16 insertions, 4 deletions
diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua index 33fcf6bc7..8d314f214 100644 --- a/xmake/core/base/profiler.lua +++ b/xmake/core/base/profiler.lua @@ -91,6 +91,7 @@ end -- get the tag report function profiler:_tag_report(name, argv) + self._REPORTS_BY_KEY = self._REPORTS_BY_KEY or {} local key = self:_tag_key(name, argv) local report = self._REPORTS_BY_KEY[key] if not report then @@ -101,6 +102,7 @@ function profiler:_tag_report(name, argv) totaltime = 0 } self._REPORTS_BY_KEY[key] = report + self._REPORTS = self._REPORTS or {} table.insert(self._REPORTS, report) end return report @@ -199,8 +201,9 @@ function profiler:stop() end -- enter the given tag for perl:tag -function profiler:enter(name, argv) +function profiler:enter(name, ...) if self:is_perf("tag") then + local argv = table.pack(...) local report = self:_tag_report(name, argv) report.calltime = os.clock() report.callcount = report.callcount + 1 @@ -208,9 +211,10 @@ function profiler:enter(name, argv) end -- leave the given tag for perl:tag -function profiler:leave(name, argv) +function profiler:leave(name, ...) if self:is_perf("tag") then local stoptime = os.clock() + local argv = table.pack(...) local report = self:_tag_report(name, argv) if report.calltime and report.calltime > 0 then report.totaltime = report.totaltime + (stoptime - report.calltime) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index bf5dead36..8dc7bffd9 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -28,6 +28,7 @@ local utils = require("base/utils") local table = require("base/table") local string = require("base/string") local option = require("base/option") +local profiler = require("base/profiler") local tool = require("tool/tool") local builder = require("tool/builder") local config = require("project/config") @@ -269,7 +270,10 @@ function compiler:compile(sourcefiles, objectfile, opt) -- compile it opt = table.copy(opt) opt.target = self:target() - return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.dependinfo, compflags, opt) + profiler:enter(self:name(), "compile", sourcefiles) + local ok, errors = sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.dependinfo, compflags, opt) + profiler:leave(self:name(), "compile", sourcefiles) + return ok, errors end -- get the compile arguments list diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 09436aeee..88b6da6a9 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -28,6 +28,7 @@ local utils = require("base/utils") local table = require("base/table") local string = require("base/string") local option = require("base/option") +local profiler = require("base/profiler") local config = require("project/config") local sandbox = require("sandbox/sandbox") local language = require("language/language") @@ -217,7 +218,10 @@ function linker:link(objectfiles, targetfile, opt) local linkflags = opt.linkflags or self:linkflags(opt) opt = table.copy(opt) opt.target = self:target() - return sandbox.load(self:_tool().link, self:_tool(), table.wrap(objectfiles), self:_targetkind(), targetfile, linkflags, opt) + profiler:enter(self:name(), "link", targetfile) + local ok, errors = sandbox.load(self:_tool().link, self:_tool(), table.wrap(objectfiles), self:_targetkind(), targetfile, linkflags, opt) + profiler:leave(self:name(), "link", targetfile) + return ok, errors end -- get the link arguments list |
