@@ -21,29 +21,32 @@ function M.raw(typ, fmt, ...)
2121 end
2222end
2323
24+ --- @class Profile
25+ --- @field start number nanos
26+ --- @field tag string
27+
2428--- Write profile start to log file
2529--- START is prefixed
2630--- @param fmt string for string.format
2731--- @vararg any arguments for string.format
28- --- @return number nanos to pass to profile_end
32+ --- @return Profile to pass to profile_end
2933function M .profile_start (fmt , ...)
34+ local profile = {}
3035 if M .enabled " profile" then
31- M .line (" profile" , " START " .. (fmt or " ???" ), ... )
32- return vim .loop .hrtime ()
33- else
34- return 0
36+ profile .start = vim .loop .hrtime ()
37+ profile .tag = string.format ((fmt or " ???" ), ... )
38+ M .line (" profile" , " START %s" , profile .tag )
3539 end
40+ return profile
3641end
3742
3843--- Write profile end to log file
3944--- END is prefixed and duration in seconds is suffixed
40- --- @param start number nanos returned from profile_start
41- --- @param fmt string for string.format
42- --- @vararg any arguments for string.format
43- function M .profile_end (start , fmt , ...)
44- if M .enabled " profile" then
45- local millis = start and math.modf ((vim .loop .hrtime () - start ) / 1000000 ) or - 1
46- M .line (" profile" , " END " .. (fmt or " ???" ) .. " " .. millis .. " ms" , ... )
45+ --- @param profile Profile returned from profile_start
46+ function M .profile_end (profile )
47+ if M .enabled " profile" and type (profile ) == " table" then
48+ local millis = profile .start and math.modf ((vim .loop .hrtime () - profile .start ) / 1000000 ) or - 1
49+ M .line (" profile" , " END %s %dms" , profile .tag or " " , millis )
4750 end
4851end
4952
5457--- @vararg any arguments for string.format
5558function M .line (typ , fmt , ...)
5659 if M .enabled (typ ) then
57- M .raw (typ , string.format (" [%s] [%s] %s\n " , os.date " %Y-%m-%d %H:%M:%S" , typ , fmt ), ... )
60+ M .raw (typ , string.format (" [%s] [%s] %s\n " , os.date " %Y-%m-%d %H:%M:%S" , typ , ( fmt or " ??? " ) ), ... )
5861 end
5962end
6063
0 commit comments