projects
/
profiler-torch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update.
[profiler-torch.git]
/
profiler.lua
diff --git
a/profiler.lua
b/profiler.lua
index
4420af7
..
9d493c0
100644
(file)
--- a/
profiler.lua
+++ b/
profiler.lua
@@
-64,15
+64,20
@@
function profiler.decorate(model, functionsToDecorate)
-- save models anymore.
if rawget(model, name) then
-- save models anymore.
if rawget(model, name) then
- error('We decorate the class, not the objects, and there is a `'
+ error('We decorate the class
es
, not the objects, and there is a `'
.. name
.. '\' function in '
.. tostring(model))
end
.. name
.. '\' function in '
.. tostring(model))
end
- local toDecorate =
getmetatable(model)
+ local toDecorate =
model
- if toDecorate[name] and not toDecorate[nameOrig] then
+ while not rawget(toDecorate, name) do
+ toDecorate = getmetatable(toDecorate)
+ end
+
+ if not toDecorate[nameOrig] then
+ -- print('Decorating ' .. toDecorate.__typename .. '.' .. name)
toDecorate[nameOrig] = toDecorate[name]
toDecorate[name] = function(self, ...)
local startTime = sys.clock()
toDecorate[nameOrig] = toDecorate[name]
toDecorate[name] = function(self, ...)
local startTime = sys.clock()
@@
-94,14
+99,20
@@
function profiler.decorate(model, functionsToDecorate)
end
function profiler.timing(l, t, nbSamples, totalTime)
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
if nbSamples then
s = s .. string.format(profiler.colors('green') .. ' (%.01fmus/sample)', 1e6 * t / nbSamples)
end
+
s = s .. profiler.colors('black')
s = s .. profiler.colors('black')
+
return s
end
return s
end
@@
-109,11
+120,17
@@
function profiler.print(model, nbSamples, totalTime, indent)
local indent = indent or ''
local hint
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
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
if torch.isTypeOf(model, nn.Container) then
hint = ' '
else
@@
-125,10
+142,11
@@
function profiler.print(model, nbSamples, totalTime, indent)
hint = hint .. profiler.colors('red')
end
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
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()
end
print()