From 3253a97ca88c8478ac048332ddd13e31be100bad Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Tue, 13 May 2025 23:06:53 +0200 Subject: (profiler) save full report into a file --- xmake/core/base/profiler.lua | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'xmake/core/base/profiler.lua') diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua index ae0ced4fc..a5e51f836 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 = os.tmpfile() .. os.date() .. ".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 = os.tmpfile() .. os.date() .. ".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 -- cgit v1.3.1 From c99e8d0bc160c308fc5766e5735f84a00f52c9ec Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Tue, 13 May 2025 23:30:26 +0200 Subject: (profiler) change profiler perf log file name --- xmake/core/base/profiler.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xmake/core/base/profiler.lua') diff --git a/xmake/core/base/profiler.lua b/xmake/core/base/profiler.lua index a5e51f836..1cd1a1d2d 100644 --- a/xmake/core/base/profiler.lua +++ b/xmake/core/base/profiler.lua @@ -184,7 +184,7 @@ function profiler:stop() -- show and save reports local report_lines = "" - local outfile = os.tmpfile() .. os.date() .. ".log" + 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 @@ -210,7 +210,7 @@ function profiler:stop() -- show and save reports local count = 0 local max_count = 64 - local outfile = os.tmpfile() .. os.date() .. ".log" + 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() -- cgit v1.3.1