+def calibrateserialwrite(outfile, byteadjust):
+ # Build 4000 bytes of dummy data.
+ data = "0123456789" * 4 + "012345678" + "\n"
+ data = data * 80
+ while 1:
+ st = time.time()
+ outfile.write(data)
+ outfile.flush()
+ et = time.time()
+ sys.stdout.write(
+ "Wrote %d - %.1fus per char (theory states %.1fus)\n" % (
+ len(data), (et-st) / len(data) * 1000000, byteadjust * 1000000))
+ sys.stdout.flush()
+ time.sleep(3)
+
+def calibrateserialread(infile, byteadjust):
+ starttime = lasttime = 0
+ totalchars = 0
+ while 1:
+ select.select([infile], [], [])
+ d = infile.read(4096)
+ curtime = time.time()
+ if curtime - lasttime > 1.0:
+ if starttime and totalchars:
+ sys.stdout.write(
+ "Calibrating on %d bytes - %.1fus per char"
+ " (theory states %.1fus)\n" % (
+ totalchars,
+ float(lasttime - starttime) * 1000000 / totalchars,
+ byteadjust * 1000000))
+ totalchars = 0
+ starttime = curtime
+ else:
+ totalchars += len(d)
+ lasttime = curtime
+
+def readserial(infile, logfile, byteadjust):