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 wrap: on
line diff
--- a/viff/runtime.py	Fri Jul 03 10:48:59 2009 +0200
+++ b/viff/runtime.py	Fri Jul 10 13:27:42 2009 +0200
@@ -37,9 +37,10 @@
 import struct
 from optparse import OptionParser, OptionGroup
 from collections import deque
+import os
 
 from viff.field import GF256, FieldElement
-from viff.util import wrapper, rand, deep_wait, track_memory_usage
+from viff.util import wrapper, rand, deep_wait, track_memory_usage, begin, end
 import viff.reactor
 
 from twisted.internet import reactor
@@ -87,6 +88,21 @@
         if value is not None:
             self.callback(value)
 
+    if os.environ.get("VIFF_PROFILE"):
+        old_init = __init__
+
+        def __init__(self, *a, **kw):
+            self.old_init(*a, **kw)
+            self.pc = self.runtime.program_counter[:]
+            begin(None, self.label())
+
+        def __del__(self):
+            end(None, self.label())
+
+        def label(self):
+            return "share " + hex(id(self)) + " " + \
+                   ".".join(map(str, self.pc))
+
     def __add__(self, other):
         """Addition."""
         return self.runtime.add(self, other)