Skip to content

Commit d4da094

Browse files
committed
fix profiler clock
1 parent f5c16b8 commit d4da094

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

xmake/core/base/profiler.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ end
116116
-- profiling call
117117
function profiler:_profiling_call(funcinfo)
118118
local report = self:_func_report(funcinfo)
119-
report.calltime = os.clock()
119+
report.calltime = os.mclock()
120120
report.callcount = report.callcount + 1
121121
end
122122

123123
-- profiling return
124124
function profiler:_profiling_return(funcinfo)
125-
local stoptime = os.clock()
125+
local stoptime = os.mclock()
126126
local report = self:_func_report(funcinfo)
127127
if report.calltime and report.calltime > 0 then
128128
report.totaltime = report.totaltime + (stoptime - report.calltime)
@@ -160,7 +160,7 @@ function profiler:start()
160160
elseif self:is_perf("call") then
161161
self._REPORTS = self._REPORTS or {}
162162
self._REPORTS_BY_KEY = self._REPORTS_BY_KEY or {}
163-
self._STARTIME = self._STARTIME or os.clock()
163+
self._STARTIME = self._STARTIME or os.mclock()
164164
debug.sethook(profiler._profiling_handler, 'cr', 0)
165165
end
166166
end
@@ -170,7 +170,7 @@ function profiler:stop()
170170
if self:is_trace() then
171171
debug.sethook()
172172
elseif self:is_perf("call") then
173-
self._STOPTIME = os.clock()
173+
self._STOPTIME = os.mclock()
174174
debug.sethook()
175175

176176
-- calculate the total time
@@ -190,7 +190,7 @@ function profiler:stop()
190190
if percent < 1 then
191191
break
192192
end
193-
local report_line = string.format("%6.3f, %6.2f%%, %7d, %s", report.totaltime, percent, report.callcount, self:_func_title(report.funcinfo))
193+
local report_line = string.format("%6.3f, %6.2f%%, %7d, %s", report.totaltime / 1000.0, percent, report.callcount, self:_func_title(report.funcinfo))
194194
report_lines = report_lines .. report_line .. "\n"
195195
utils.print(report_line)
196196
end
@@ -214,7 +214,7 @@ function profiler:stop()
214214
local report_lines = ""
215215
while h:length() > 0 do
216216
local report = h:pop()
217-
local report_line = string.format("%6.3f, %7d, %s", report.totaltime, report.callcount, self:_tag_title(report.name, report.argv))
217+
local report_line = string.format("%6.3f, %7d, %s", report.totaltime / 1000.0, report.callcount, self:_tag_title(report.name, report.argv))
218218
report_lines = report_lines .. report_line .. "\n"
219219
count = count + 1
220220
end
@@ -241,7 +241,7 @@ function profiler:enter(name, ...)
241241
if is_perf_tag then
242242
local argv = table.pack(...)
243243
local report = self:_tag_report(name, argv)
244-
report.calltime = os.clock()
244+
report.calltime = os.mclock()
245245
report.callcount = report.callcount + 1
246246
end
247247
end
@@ -254,7 +254,7 @@ function profiler:leave(name, ...)
254254
self._IS_PERF_TAG = is_perf_tag
255255
end
256256
if is_perf_tag then
257-
local stoptime = os.clock()
257+
local stoptime = os.mclock()
258258
local argv = table.pack(...)
259259
local report = self:_tag_report(name, argv)
260260
if report.calltime and report.calltime > 0 then

0 commit comments

Comments
 (0)