summaryrefslogtreecommitdiff
path: root/xmake/core/base/profiler.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/core/base/profiler.lua')
-rw-r--r--xmake/core/base/profiler.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua
index ae0ced4fc..1cd1a1d2d 100644
--- a/xmake/core/base/profiler.lua
+++ b/xmake/core/base/profiler.lua
@@ -182,14 +182,20 @@ function profiler:stop()
return a.totaltime > b.totaltime
end)
- -- show reports
+ -- show and save reports
+ local report_lines = ""
+ local outfile = path.join(os.tmpdir(), "perf-call-" .. os.date("%d-%m-%y-%S-%M-%H") .. ".log")
for _, report in ipairs(reports) do
local percent = (report.totaltime / totaltime) * 100
if percent < 1 then
break
end
- utils.print("%6.3f, %6.2f%%, %7d, %s", report.totaltime, percent, report.callcount, self:_func_title(report.funcinfo))
+ local report_line = string.format("%6.3f, %6.2f%%, %7d, %s", report.totaltime, percent, report.callcount, self:_func_title(report.funcinfo))
+ report_lines = report_lines .. report_line .. "\n"
+ utils.print(report_line)
end
+ utils.print("full log written to %s", outfile)
+ io.writefile(outfile, report_lines)
elseif self:is_perf("tag") then
-- sort reports, topN
@@ -201,16 +207,27 @@ function profiler:stop()
h:push(report)
end
- -- show reports
+ -- show and save reports
local count = 0
- while count < 64 and h:length() > 0 do
+ local max_count = 64
+ local outfile = path.join(os.tmpdir(), "perf-tag-" .. os.date("%d-%m-%y-%S-%M-%H") .. ".log")
+ local report_lines = ""
+ while 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))
+ local report_line = string.format("%6.3f, %7d, %s", report.totaltime, report.callcount, self:_tag_title(report.name, report.argv))
+ report_lines = report_lines .. report_line .. "\n"
count = count + 1
end
- if h:length() > 0 then
+ if count <= max_count then
+ utils.print(report_lines)
+ elseif count > max_count then
+ local max_count_lines = {table.unpack(report_lines:split("\n"), 1, max_count)}
+ utils.print(table.concat(max_count_lines, "\n"))
utils.print("...")
+ count = count + 1
end
+ utils.print("full log written to %s", outfile)
+ io.writefile(outfile, report_lines)
end
end