# HG changeset patch # User Paul Boddie # Date 1285623055 -7200 # Node ID 078c71c2a581c816a556d728e9af674d602d3f88 # Parent dd7487acd048190400a4a6ba7aa970be8a169a87 Added instruction coverage reporting. diff -r dd7487acd048 -r 078c71c2a581 rsvp.py --- a/rsvp.py Tue Sep 21 00:11:34 2010 +0200 +++ b/rsvp.py Mon Sep 27 23:30:55 2010 +0200 @@ -100,6 +100,7 @@ # Profiling. + self.coverage = [0] * len(self.memory) self.counter = 0 self.cost = 0 @@ -169,16 +170,17 @@ print "Exception", self.exception def show(self): - self.show_memory(self.memory, 0) + self.show_memory(self.memory, self.coverage, 0) def show_pc(self, run_in=10): start = max(0, self.pc - run_in) end = self.pc + run_in memory = self.memory[start:end] - self.show_memory(memory, start) + coverage = self.coverage[start:end] + self.show_memory(memory, coverage, start) - def show_memory(self, memory, start): - for i, x in enumerate(memory): + def show_memory(self, memory, coverage, start): + for i, (c, x) in enumerate(map(None, coverage, memory)): location = start + i if location == self.pc: print "->", @@ -186,7 +188,7 @@ print "..", else: print " ", - print "%5d %r" % (location, x) + print "%-5s %5d %r" % (c or "", location, x) def step(self, dump=0): self.execute() @@ -325,6 +327,10 @@ next_pc = self.perform(self.instruction) + # Update the coverage. + + self.coverage[self.pc] += 1 + # Update the program counter. if next_pc is None: