1.1 --- a/rsvp.py Tue Sep 21 00:11:34 2010 +0200
1.2 +++ b/rsvp.py Mon Sep 27 23:30:55 2010 +0200
1.3 @@ -100,6 +100,7 @@
1.4
1.5 # Profiling.
1.6
1.7 + self.coverage = [0] * len(self.memory)
1.8 self.counter = 0
1.9 self.cost = 0
1.10
1.11 @@ -169,16 +170,17 @@
1.12 print "Exception", self.exception
1.13
1.14 def show(self):
1.15 - self.show_memory(self.memory, 0)
1.16 + self.show_memory(self.memory, self.coverage, 0)
1.17
1.18 def show_pc(self, run_in=10):
1.19 start = max(0, self.pc - run_in)
1.20 end = self.pc + run_in
1.21 memory = self.memory[start:end]
1.22 - self.show_memory(memory, start)
1.23 + coverage = self.coverage[start:end]
1.24 + self.show_memory(memory, coverage, start)
1.25
1.26 - def show_memory(self, memory, start):
1.27 - for i, x in enumerate(memory):
1.28 + def show_memory(self, memory, coverage, start):
1.29 + for i, (c, x) in enumerate(map(None, coverage, memory)):
1.30 location = start + i
1.31 if location == self.pc:
1.32 print "->",
1.33 @@ -186,7 +188,7 @@
1.34 print "..",
1.35 else:
1.36 print " ",
1.37 - print "%5d %r" % (location, x)
1.38 + print "%-5s %5d %r" % (c or "", location, x)
1.39
1.40 def step(self, dump=0):
1.41 self.execute()
1.42 @@ -325,6 +327,10 @@
1.43
1.44 next_pc = self.perform(self.instruction)
1.45
1.46 + # Update the coverage.
1.47 +
1.48 + self.coverage[self.pc] += 1
1.49 +
1.50 # Update the program counter.
1.51
1.52 if next_pc is None: