summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2023-03-17 22:39:48 +0800
committerruki <[email protected]>2023-03-17 22:39:48 +0800
commit0a0167ee3dcd059caa2ce09cc8bda13edb0d5d11 (patch)
tree00fdccce7316d5d145af0246ca7f2ff6dc5e0760 /xmake
parent7204348905ab1280f83a2b7d6f6a845988cb261e (diff)
use heap sort
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/profiler.lua15
1 files changed, 11 insertions, 4 deletions
diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua
index 3736398a3..34c5e4bd7 100644
--- a/xmake/core/base/profiler.lua
+++ b/xmake/core/base/profiler.lua
@@ -24,6 +24,7 @@ local profiler = {}
-- load modules
local os = require("base/os")
local path = require("base/path")
+local heap = require("base/heap")
local table = require("base/table")
local utils = require("base/utils")
local string = require("base/string")
@@ -191,15 +192,21 @@ function profiler:stop()
end
elseif self:is_perf("tag") then
- -- sort reports
+ -- sort reports, topN
local reports = self._REPORTS or {}
- table.sort(reports, function(a, b)
+ local h = heap.valueheap({cmp = function(a, b)
return a.totaltime > b.totaltime
- end)
+ end})
+ for _, report in ipairs(reports) do
+ h:push(report)
+ end
-- show reports
- for _, report in ipairs(reports) do
+ local count = 0
+ while count < 32 and h:length() > 0 do
+ local report = h:pop()
utils.print("%6.3f, %7d, %s", report.totaltime, report.callcount, self:_tag_title(report.name, report.argv))
+ count = count + 1
end
end
end