Add timing stats to verbose download output.

When using the swift command-line tool to evaluate a Swift cluster, it
can be very handy to get some insight into the download timing.  This
patch adds timing data to verbose output for the download command.  For
each downloaded file, the printed line will also contain:
 - The time it took to send the request and receive the header
 - The total time the request took (including writing the file out
   locally)
 - The average throughput of the download

Change-Id: Ib4a995623af973bb1eed4fb52c8c0e5da935964d
This commit is contained in:
Darrell Bishop 2012-08-16 21:30:54 -07:00
parent 99b8253450
commit 9a3aa066c3

@ -24,7 +24,7 @@ from os.path import basename, dirname, getmtime, getsize, isdir, join
from Queue import Empty, Queue
from sys import argv, exc_info, exit, stderr, stdout
from threading import current_thread, enumerate as threading_enumerate, Thread
from time import sleep
from time import sleep, time
from traceback import format_exception
from urllib import quote, unquote
@ -350,8 +350,10 @@ def st_download(parser, args, print_queue, error_queue):
else:
raise Exception("Invalid queue_arg length of %s" % len(queue_arg))
try:
start_time = time()
headers, body = \
conn.get_object(container, obj, resp_chunk_size=65536)
header_receipt = time()
content_type = headers.get('content-type')
if 'content-length' in headers:
content_length = int(headers.get('content-length'))
@ -402,11 +404,15 @@ def st_download(parser, args, print_queue, error_queue):
mtime = float(headers['x-object-meta-mtime'])
utime(path, (mtime, mtime))
if options.verbose:
finish_time = time()
time_str = 'headers %.3fs, total %.3fs, %.3fs MB/s' % (
header_receipt - start_time, finish_time - start_time,
float(read_length) / (finish_time - start_time) / 1000000)
if conn.attempts > 1:
print_queue.put('%s [after %d attempts' %
(path, conn.attempts))
print_queue.put('%s [%s after %d attempts]' %
(path, time_str, conn.attempts))
else:
print_queue.put(path)
print_queue.put('%s [%s]' % (path, time_str))
except ClientException, err:
if err.http_status != 404:
raise