def measure(stride): fileutil.rm_dir("build") fileutil.rm_dir("instdir") fileutil.remove_if_possible(os.path.join("zfec", "_fec.so")) fileutil.make_dirs("instdir") fname = os.path.join("benchresults", "comp_0-stride_%d"%stride) os.system("PYTHONPATH=instdir ./setup.py develop --install-dir=instdir --stride=%d >/dev/null" % stride) os.system("PYTHONPATH=instdir python -OO ./bench/bench_zfec.py >> %s" % fname) inf = open(fname, "rU") for l in inf: m = R.search(l) if m: result = int(m.group(1)) if results.has_key(stride): print "stride: %d, results: %d (dup %d)" % (stride, result, results[stride]) else: print "stride: %d, results: %d" % (stride, result) results[stride] = result break
def measure(stride): fileutil.rm_dir("build") fileutil.rm_dir("instdir") fileutil.remove_if_possible(os.path.join("zfec", "_fec.so")) fileutil.make_dirs("instdir") fname = os.path.join("benchresults", "comp_0-stride_%d" % stride) os.system( "PYTHONPATH=instdir ./setup.py develop --install-dir=instdir --stride=%d >/dev/null" % stride) os.system("PYTHONPATH=instdir python -OO ./bench/bench_zfec.py >> %s" % fname) inf = open(fname, "rU") for l in inf: m = R.search(l) if m: result = int(m.group(1)) if results.has_key(stride): print "stride: %d, results: %d (dup %d)" % (stride, result, results[stride]) else: print "stride: %d, results: %d" % (stride, result) results[stride] = result break
def encode_to_files(inf, fsize, dirname, prefix, k, m, suffix=".fec", overwrite=False, verbose=False): """ Encode inf, writing the shares to specially named, newly created files. @param fsize: calling read() on inf must yield fsize bytes of data and then raise an EOFError @param dirname: the name of the directory into which the sharefiles will be written """ mlen = len(str(m)) format = FORMAT_FORMAT % (mlen, mlen,) padbytes = pad_size(fsize, k) fns = [] fs = [] try: for shnum in range(m): hdr = _build_header(m, k, padbytes, shnum) fn = os.path.join(dirname, format % (prefix, shnum, m, suffix,)) if verbose: print "Creating share file %r..." % (fn,) if overwrite: f = open(fn, "wb") else: flags = os.O_WRONLY|os.O_CREAT|os.O_EXCL | (hasattr(os, 'O_BINARY') and os.O_BINARY) fd = os.open(fn, flags) f = os.fdopen(fd, "wb") f.write(hdr) fs.append(f) fns.append(fn) sumlen = [0] def cb(blocks, length): assert len(blocks) == len(fs) oldsumlen = sumlen[0] sumlen[0] += length if verbose: if int((float(oldsumlen) / fsize) * 10) != int((float(sumlen[0]) / fsize) * 10): print str(int((float(sumlen[0]) / fsize) * 10) * 10) + "% ...", if sumlen[0] > fsize: raise IOError("Wrong file size -- possibly the size of the file changed during encoding. Original size: %d, observed size at least: %s" % (fsize, sumlen[0],)) for i in range(len(blocks)): data = blocks[i] fs[i].write(data) length -= len(data) encode_file_stringy_easyfec(inf, cb, k, m, chunksize=4096) except EnvironmentError, le: print "Cannot complete because of exception: " print le print "Cleaning up..." # clean up while fs: f = fs.pop() f.close() ; del f fn = fns.pop() if verbose: print "Cleaning up: trying to remove %r..." % (fn,) fileutil.remove_if_possible(fn) return 1
def encode_to_files(inf, fsize, dirname, prefix, k, m, suffix=".fec", overwrite=False, verbose=False): """ Encode inf, writing the shares to specially named, newly created files. @param fsize: calling read() on inf must yield fsize bytes of data and then raise an EOFError @param dirname: the name of the directory into which the sharefiles will be written """ mlen = len(str(m)) format = FORMAT_FORMAT % (mlen, mlen,) padbytes = pad_size(fsize, k) fns = [] fs = [] got_error = False try: for shnum in range(m): hdr = _build_header(m, k, padbytes, shnum) fn = os.path.join(dirname, format % (prefix, shnum, m, suffix,)) if verbose: print("Creating share file %r..." % (fn,)) if overwrite: f = open(fn, "wb") else: flags = os.O_WRONLY|os.O_CREAT|os.O_EXCL | (hasattr(os, 'O_BINARY') and os.O_BINARY) fd = os.open(fn, flags) f = os.fdopen(fd, "wb") fs.append(f) fns.append(fn) f.write(hdr) sumlen = [0] def cb(blocks, length): assert len(blocks) == len(fs) oldsumlen = sumlen[0] sumlen[0] += length if verbose: if int((float(oldsumlen) / fsize) * 10) != int((float(sumlen[0]) / fsize) * 10): print(str(int((float(sumlen[0]) / fsize) * 10) * 10) + "% ...", end=" ") if sumlen[0] > fsize: raise IOError("Wrong file size -- possibly the size of the file changed during encoding. Original size: %d, observed size at least: %s" % (fsize, sumlen[0],)) for i in range(len(blocks)): data = blocks[i] fs[i].write(data) length -= len(data) encode_file_stringy_easyfec(inf, cb, k, m, chunksize=4096) except EnvironmentError as le: print("Cannot complete because of exception: ") print(le) got_error = True finally: for f in fs: f.close() if got_error: print("Cleaning up...") # clean up for fn in fns: if verbose: print("Cleaning up: trying to remove %r..." % (fn,)) fileutil.remove_if_possible(fn) return 1 if verbose: print() print("Done!") return 0
def setUp(self): trialcoverage.cov.stop() fileutil.remove_if_possible(trialcoverage.COVERAGE_FNAME)