X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=profiler.lua;h=4fec2582ceb8635f34a69ab24f651b240ee67e83;hb=a5f00c98459afa86205650ac4d4b474efe2d1949;hp=77398a01e3b1c21abcd2a17ef000c55f042a24a3;hpb=78ce9a217ef066c8f01b1531c27c6ef38c45ece1;p=profiler-torch.git diff --git a/profiler.lua b/profiler.lua index 77398a0..4fec258 100644 --- a/profiler.lua +++ b/profiler.lua @@ -64,7 +64,10 @@ function profiler.decorate(model, functionsToDecorate) -- save models anymore. if rawget(model, name) then - error('We decorate the class, not the objects, and there is a ' .. name .. ' in ' .. model) + error('We decorate the class, not the objects, and there is a `' + .. name + .. '\' function in ' + .. tostring(model)) end local toDecorate = getmetatable(model) @@ -91,14 +94,20 @@ function profiler.decorate(model, functionsToDecorate) end function profiler.timing(l, t, nbSamples, totalTime) - local s = string.format('%s %.02fs', l, t) - if totalTime then - s = s .. string.format(profiler.colors('blue') .. ' [%.02f%%]', 100 * t / totalTime) - end + local s + + s = string.format('%s %.02fs %s[%.02f%%]', + l, t, + profiler.colors('blue'), + 100 * t / totalTime + ) + if nbSamples then s = s .. string.format(profiler.colors('green') .. ' (%.01fmus/sample)', 1e6 * t / nbSamples) end + s = s .. profiler.colors('black') + return s end @@ -111,6 +120,8 @@ function profiler.print(model, nbSamples, totalTime, indent) localTotal = localTotal + t end + totalTime = totalTime or localTotal + if torch.isTypeOf(model, nn.Container) then hint = ' ' else @@ -122,10 +133,11 @@ function profiler.print(model, nbSamples, totalTime, indent) hint = hint .. profiler.colors('red') end - print(profiler.timing(indent .. hint .. ' ' .. model.__typename, localTotal, nbSamples, totalTime)) + print(profiler.timing(indent .. hint .. ' ' .. model.__typename, + localTotal, nbSamples, totalTime)) for l, t in pairs(model.accTime) do - print(profiler.timing(indent .. ' ' .. l, t, nbSamples, totalTime)) + print(profiler.timing(indent .. ' :' .. l, t, nbSamples, totalTime)) end print()