X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=profiler.lua;h=f57c9d885f5aa7681e4efbc60ac5ee1442ee00e1;hb=b758f38fa8142256d754a5ba18d6a7932d6e203c;hp=4420af79b203464c276bc573bfb95459ddc461e9;hpb=f59950ed20a2d471c59e2c23bc41b50111a54cd6;p=profiler-torch.git diff --git a/profiler.lua b/profiler.lua index 4420af7..f57c9d8 100644 --- a/profiler.lua +++ b/profiler.lua @@ -94,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 @@ -109,11 +115,17 @@ function profiler.print(model, nbSamples, totalTime, indent) local indent = indent or '' local hint + if not model.accTime then + error('The model does not seem decorated for profiling.') + end + local localTotal = 0 for _, t in pairs(model.accTime) do localTotal = localTotal + t end + totalTime = totalTime or localTotal + if torch.isTypeOf(model, nn.Container) then hint = ' ' else @@ -125,10 +137,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()