viff

changeset 1199:f640ea5f0920

Profiling outputs lifetime of every Share object.
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 10 Jul 2009 13:27:42 +0200
parents c15bc2925969
children 5da110d6e5b2
files viff/runtime.py
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Fri Jul 03 10:48:59 2009 +0200
     1.2 +++ b/viff/runtime.py	Fri Jul 10 13:27:42 2009 +0200
     1.3 @@ -37,9 +37,10 @@
     1.4  import struct
     1.5  from optparse import OptionParser, OptionGroup
     1.6  from collections import deque
     1.7 +import os
     1.8  
     1.9  from viff.field import GF256, FieldElement
    1.10 -from viff.util import wrapper, rand, deep_wait, track_memory_usage
    1.11 +from viff.util import wrapper, rand, deep_wait, track_memory_usage, begin, end
    1.12  import viff.reactor
    1.13  
    1.14  from twisted.internet import reactor
    1.15 @@ -87,6 +88,21 @@
    1.16          if value is not None:
    1.17              self.callback(value)
    1.18  
    1.19 +    if os.environ.get("VIFF_PROFILE"):
    1.20 +        old_init = __init__
    1.21 +
    1.22 +        def __init__(self, *a, **kw):
    1.23 +            self.old_init(*a, **kw)
    1.24 +            self.pc = self.runtime.program_counter[:]
    1.25 +            begin(None, self.label())
    1.26 +
    1.27 +        def __del__(self):
    1.28 +            end(None, self.label())
    1.29 +
    1.30 +        def label(self):
    1.31 +            return "share " + hex(id(self)) + " " + \
    1.32 +                   ".".join(map(str, self.pc))
    1.33 +
    1.34      def __add__(self, other):
    1.35          """Addition."""
    1.36          return self.runtime.add(self, other)