def rungames(vmlabels, games, gamelog, startgame): gamepids = [] for vmgroup in chunks(vmlabels, len(games)): for game in games: # Can't terminate threads in python, so we'll fork the # infinite loop in startgame and send/handle SIGINT. vm = vmgroup.pop(0) if game == 'none': continue pid = os.fork() if pid == 0: #sys.stdout = gamelog startgame(game, vm) sys.exit(0) gamepids.append(pid) return gamepids
def main(): """main function for standalone usage""" usage = "usage: %prog [options] deltas firstday" parser = OptionParser(usage=usage) parser.add_option( "-s", "--show", default=False, action="store_true", help="Show figure instead of save it to PNG [default: %default]", ) (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() return 2 # do stuff day = parse(args[1]) days = [] tomorrow = datetime.timedelta(1) resperday = list(chunks(file(args[0]).read().strip().split("\n"), 8)) # for dnsblack, dnsdecom, dnsincamp, dnsnever, ipblack, ipdecom, ipincamp, ipnever in resperday: for _ in resperday: days.append(day) day += tomorrow firstday = days[0] lastday = days[-1] dnsblack, dnsdecom, dnsincamp, dnsnever, ipblack, ipdecom, ipincamp, ipnever = zip(*resperday) fig = plt.figure() ax = fig.add_subplot(223) plt.ylabel("Frequency") ax.plot(days, map(extract, dnsblack), "-r+", label="Blacklisted") ax.plot(days, map(extract, dnsdecom), "-bx", label="Decommissioned") ax.plot(days, map(extract, dnsincamp), "-g*", label="In Campaign") ax = fig.add_subplot(221) plt.title("DNS Games") plt.ylabel("Frequency") ax.plot(days, map(extract, dnsblack), "-r+", label="Blacklisted") ax.plot(days, map(extract, dnsdecom), "-bx", label="Decommissioned") ax.plot(days, map(extract, dnsincamp), "-g*", label="In Campaign") ax.plot(days, map(extract, dnsnever), "-s", label="Never Blacklisted") plt.legend(loc=2) ax = fig.add_subplot(224) ax.plot(days, map(extract, ipblack), "-r+") ax.plot(days, map(extract, ipdecom), "-bx") ax.plot(days, map(extract, ipincamp), "-g*") ax = fig.add_subplot(222) plt.title("TCP Games") ax.plot(days, map(extract, ipblack), "-r+") ax.plot(days, map(extract, ipdecom), "-bx") ax.plot(days, map(extract, ipincamp), "-g*") ax.plot(days, map(extract, ipnever), "-s") fig.autofmt_xdate() plt.show()