From: Francois Fleuret Date: Tue, 6 Dec 2016 09:58:15 +0000 (+0100) Subject: Now takes the total time estimated at the top if totalTime is not provided. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=a5f00c98459afa86205650ac4d4b474efe2d1949;p=profiler-torch.git Now takes the total time estimated at the top if totalTime is not provided. --- diff --git a/README.md b/README.md index 0e851f4..0e8bd5f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,6 @@ It also resets the accumulated timings to zero. ### profiler.print(model, [nbSamples], [totalTime]) ### -Prints the measured processing times. If nbSamples is provided, the time per samples will also be printed. If totalTime is provided, the percentages will also be printed. +Prints the measured processing times. If nbSamples is provided, the time per samples will also be printed. If totalTime is not provided, the total at the top is used. Non-Containers are hilighted with a '*' or in red. diff --git a/profiler.lua b/profiler.lua index 4420af7..4fec258 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 @@ -114,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 @@ -125,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() diff --git a/test-profiler.lua b/test-profiler.lua index aa6e800..71127a0 100755 --- a/test-profiler.lua +++ b/test-profiler.lua @@ -93,9 +93,8 @@ end -- Print the accumulated timings --- profiler.color = false -profiler.print(model, nbSamples, modelTime) --- profiler.print(model) +-- profiler.print(model, nbSamples) +profiler.print(model) print(string.format('Total model time %.02fs', modelTime)) print(string.format('Total data time %.02fs', dataTime))