X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=profiler.lua;h=b95d7507575da856f5f4919e825a05a82b2eafb6;hb=4ed0c97b543f69caac452b7775a5ca57d017637a;hp=6f63861ea87df8d7d38501d83510bd3cf3e497ea;hpb=c4b8d97c31f5e7dc948bf51ad6564d24e377801b;p=profiler-torch.git diff --git a/profiler.lua b/profiler.lua index 6f63861..b95d750 100644 --- a/profiler.lua +++ b/profiler.lua @@ -48,22 +48,11 @@ function profiler.decor(model, functionsToDecorate) for _, name in pairs(functionsToDecorate) do model.accTime = {} - local functionTable = model - - -- We decorate the function where it is defined in the class - -- hierarchy, so we have to go up the metatables until we find - -- it with rawget - - while functionTable and not rawget(functionTable, name) do - functionTable = getmetatable(functionTable) - end - local nameOrig = name .. '__orig' - if functionTable[name] and not functionTable[nameOrig] then - print('Profiler decoring ' .. functionTable.__typename .. '.' .. name) - functionTable[nameOrig] = functionTable[name] - functionTable[name] = function(self, ...) + if model[name] and not model[nameOrig] then + model[nameOrig] = model[name] + model[name] = function(self, ...) local startTime = sys.clock() local result = { self[nameOrig](self, unpack({...})) } local endTime = sys.clock()