예제 #1
0
def dumpwriter(pipe, ns, ST=None):
    hphelper.set_affinity("parser")
    DEBUG("starting", __name__)

    stats = hphelper.stats_stats()

    # start progress bar thread
    hphelper.bar_init(options, stats)

    if not options.start_time:
        options.start_time = time.time()

    if not options.savefile:
        # default save name is destination + YYMMDD + HHMM
        options.savefile = options.DST + time.strftime("_%Y%m%d_%H%M", time.localtime(options.start_time))

    options.savefile += options.tag
    options.savefile += ".dump"

    print "saving RTTs to " + options.savefile + " ..."

    try:
        fs = open(options.savefile, mode="w")
        fs.write("% " + "options:" + " " + str(options) + "\n")  # save options
    except KeyboardInterrupt:
        print "canceled writing file."

    # block until sender + receiver say they are ready
    while not all([ns.RCV_READY, ns.SND_READY]):
        time.sleep(0.1)

    stats.run_start = time.time()
    try:
        while 1:
            (seq, slot, rtt) = pipe.recv()
            if seq == -2:
                break

            stats.update(seq, rtt=rtt, current_slot=slot)

            fs.write("%d %d %.9f\n" % (seq, slot, rtt))
    except (ValueError, KeyboardInterrupt) as e:
        print

    fs.close()
    DEBUG("done", __name__)

    stats.run_end = time.time()
    stats.pprint()
예제 #2
0
    def __init__(self, buf, slots):
            self.stats = hphelper.stats_stats()

            self.xc = XcovEst(options.L)
            self.L = self.xc.L            # max covariance lag

            self.buf = buf
            self.slots = slots

            self.min_win_seq = 1
            self.max_win_seq = self.L

            self.terminated = False

            self.mean_a = options.rate
            self.var_a = self.mean_a - self.mean_a**2

            # start progress bar thread 
            hphelper.bar_init(options, self.stats)

            threading.Thread.__init__(self)
예제 #3
0
    def __init__(self, buf, slots, M=None):

        
        self.buf = buf
        self.slots = slots
        if not M:
            #M = range(options.M[0], options.M[1], 300)
            M = 10**np.linspace(np.log10(options.M[0]),np.log10(options.M[1]),200)
            M = np.unique(np.floor(M)).astype(int)

        self.M = M            

        # sliding window to store arriving values
        self.win = np.zeros(np.max(M)).astype(bool)

        # avars stores an estimator for each aggregation level in M
        self.avars = dict.fromkeys(M,0)
        # ensure that we calculate the variance at the smallest
        # aggregate level, even when it was not specified by the user
        self.avars[1] = 0 
        for m in self.avars.iterkeys():
            self.avars[m] = var_est(m)


        self.probe_count = 0
        self.slot_count = 0


        self.stats = hphelper.stats_stats()
        self.mean_a = options.rate
        self.var_a = self.mean_a - self.mean_a**2
        self.va = self.var_a*np.ones(len(self.M))/self.M


        # start progress bar thread 
        hphelper.bar_init(options, self.stats)

        threading.Thread.__init__(self)
예제 #4
0
def statsparser(pipe, ns, slottimes=None):
    hphelper.set_affinity('parser')
    DEBUG('starting parser ', __name__)

    #block until sender + receiver say they are ready
    while not all([ns.RCV_READY,ns.SND_READY]):
        time.sleep(0.1)

    stats = hphelper.stats_stats()

    # init empty array to store RTTs for histogram
    rtts = -1.0*ones(options.pnum)

    # start progress bar thread
    hphelper.bar_init(options, stats,  ns.cnum)


    run_start = time.time()
    while 1:
        try:
            data = pipe.recv()
            if data == 'RCV_DONE':
                break

            (seq, currslot, rtt) = data
            if currslot == -1:
                 rtt = -1
                 stats.snd_err += 1
                 continue

            stats.update(seq, rtt, currslot)

            if rtt<stats.min_rtt:
                stats.min_rtt = rtt

            rtts[seq] = rtt


        except (KeyboardInterrupt) as e:
            print 'parser canceled'
        except (ValueError) as e:
            print e
            print 'done writing'
        except (IndexError) as e:
            print e, seq
            pass ### TODO last sequence number causes error

    # omit invalid rtts
    rtts = rtts[rtts!=-1]

    if not any(rtts):
        ns.FATAL_ERROR = True
        ERROR("could not calculate average delay")

    # store mean RTT for use in other modules
    ns.mean_rtt = mean(rtts)

    stats.append_stats(median=('RTT median','%.6f' % median(rtts)),
                       std=('RTT std. dev.','%.6f' % std(rtts)),
                       #min=('min RTT','%.6f' % min(rtts)),
                       max=('RTT maximum','%.6f' % max(rtts)),
                       )

    stats.pprint()

    if options.hist:
        plot_hist(rtts)

    return