def main(): """Main script Acts as a terminal towards the DHT""" emu = Emulator(int(sys.argv[1])) emu.print_help('') for i in range(2, 10): emu.execute(['join', str(i)]) emu.execute(['insert', 'Imagine', '2']) emu.execute(['insert', 'Ameranhs', '3']) emu.execute(['insert', 'Valkanos', '4']) emu.execute(['query', '*']) while True: command = raw_input('Action: ').split(', ') emu.execute(command) if command[0] == 'exit': break time.sleep(1) logging.debug('END')
def main(): """Emulator Creates the DHT Adds another 9 nodes Uses the 'insert.txt' file to insert data and measures its throughput Uses the 'query.txt' file to find data and measures its throughput Uses the 'request.txt' file to perform requests and measures its throughput Closes the DHT""" # Create the DHT emu = Emulator(int(sys.argv[1])) for i in range(2, 10): emu.execute(['join', str(i)]) # Measure throughputs and report them to the user write_throughput = measure_throughput(emu, 'insert.txt') print 'Write throughput:', write_throughput read_throughput = measure_throughput(emu, 'query.txt') print 'Read throughput:', read_throughput request_throughput = measure_throughput(emu, 'requests.txt') print 'Request throughput:', request_throughput emu.execute(['exit'])
import struct import sys import optparse from cpu import CPU from emulator import Emulator optparser = optparse.OptionParser() optparser.add_option("-f", "--file", dest="file", help="Program file") optparser.add_option("-l", "--limit", dest="limit", help="Max number of instructions to execute") (options, args) = optparser.parse_args(sys.argv) if not options.file: optparser.print_help() exit(1) cpu = CPU() limit = None if options.limit: limit = int(options.limit, 0) # Guess base f = open(options.file) data = f.read() words = struct.unpack(">%dH" % (len(data) / 2), data) for word, idx in zip(words, range(len(words))): cpu.ram[idx] = word emulator = Emulator(cpu) emulator.execute(0, limit)