r14207 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14206‎ | r14207 | r14208 >
Date:22:47, 13 May 2006
Author:brion
Status:old
Tags:
Comment:
include runtime and input and output data rates with -v
Modified paths:
  • /trunk/tools/dbzip2/dbzip2 (modified) (history)

Diff [purge]

Index: trunk/tools/dbzip2/dbzip2
@@ -37,13 +37,18 @@
3838 self.inputStream = sys.stdin
3939 self.outputStream = sys.stdout
4040 self.blockSize = 900000 # 900k default blocksize
41 - self.queue = []
42 - self.done = False
4341 self.threads = 1
 42+ self.verbosity = 0
 43+
4444 self.readCount = 0
4545 self.writeCount = 0
46 - self.verbosity = 0
 46+ self.bytesRead = 0L
 47+ self.bytesWritten = 0L
 48+
 49+ self.queue = []
 50+ self.done = False
4751 self.threadLock = thread.allocate_lock()
 52+
4853 self.processArgs(args)
4954
5055 def processArgs(self, args):
@@ -75,7 +80,7 @@
7681
7782 def readerThread(self):
7883 """Producer thread: run through the file handing out blocks."""
79 - self.debug(1, "readerThread: starting!")
 84+ self.debug(2, "readerThread: starting!")
8085 block = self.nextBlock()
8186 while block:
8287 while not self.ready():
@@ -84,17 +89,17 @@
8590
8691 self.lock()
8792 self.readCount += 1
88 - self.debug(1, "readerThread: dispatching block %d" % self.readCount)
 93+ self.debug(2, "readerThread: dispatching block %d" % self.readCount)
8994 self.dispatch(block)
9095 self.unlock()
9196
9297 block = self.nextBlock()
9398 self.done = True
94 - self.debug(1, "readerThread: done; read %d blocks" % self.readCount)
95 - # FIXME: we're not _totally_ done until it's processed.
 99+ self.debug(2, "readerThread: done; read %d blocks" % self.readCount)
96100
97101 def nextBlock(self):
98102 buffer = self.inputStream.read(self.blockSize)
 103+ self.bytesRead += len(buffer)
99104 self.debug(3, "nextBlock: %d" % len(buffer))
100105 return buffer
101106
@@ -114,7 +119,8 @@
115120 """Consumer thread: as we receive compressed blocks from the
116121 distributed compressors, write them to the output file.
117122 Currently only writes blocks in order."""
118 - self.debug(1, "writerThread: starting")
 123+ self.debug(2, "writerThread: starting")
 124+ startTime = time.time()
119125 while not (self.done and self.writeCount == self.readCount):
120126 self.lock()
121127 buffer = self.dequeue()
@@ -122,12 +128,17 @@
123129
124130 if buffer:
125131 self.writeCount += 1
126 - self.debug(1, "writerThread: writing block %d" % self.writeCount)
 132+ self.debug(2, "writerThread: writing block %d" % self.writeCount)
127133 self.writeBuffer(buffer)
128134 else:
129 - self.debug(3, "writerThread: sleeping")
 135+ self.debug(4, "writerThread: sleeping")
130136 self.sleep()
131 - self.debug(1, "writerThread: done; wrote %d blocks" % self.writeCount)
 137+ delta = time.time() - startTime
 138+ megabyte = 1024.0 * 1024.0
 139+ rateIn = (float(self.bytesRead) / megabyte) / delta
 140+ rateOut = (float(self.bytesWritten) / megabyte) / delta
 141+ self.debug(1, "Wrote %d blocks in %0.1f seconds (%0.3f MB/s in, %0.3f MB/s out)" % (
 142+ self.writeCount, delta, rateIn, rateOut))
132143
133144 def dequeue(self):
134145 """Fetch the next completed block for writing."""
@@ -140,9 +151,10 @@
141152 def writeBuffer(self, buffer):
142153 """Write a buffer to the file. Currently requires that buffers
143154 be processed in streaming order."""
144 - self.debug(1, "writeBuffer: writing block %d" % buffer.index)
 155+ self.debug(3, "writeBuffer: writing block %d" % buffer.index)
145156 assert buffer.contents is not None
146157 assert buffer.index == self.writeCount
 158+ self.bytesWritten += len(buffer.contents)
147159 self.outputStream.write(buffer.contents)
148160
149161

Status & tagging log