Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: third_party/gsutil/third_party/boto/boto/requestlog.py

Issue 1377933002: [catapult] - Copy Telemetry's gsutilz over to third_party. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Rename to gsutil. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/gsutil/third_party/boto/boto/requestlog.py
diff --git a/third_party/gsutil/third_party/boto/boto/requestlog.py b/third_party/gsutil/third_party/boto/boto/requestlog.py
new file mode 100644
index 0000000000000000000000000000000000000000..d8009fe76f6662373b7653c2b872c0a8cf67e1bc
--- /dev/null
+++ b/third_party/gsutil/third_party/boto/boto/requestlog.py
@@ -0,0 +1,39 @@
+import sys
+from datetime import datetime
+from threading import Thread
+import Queue
+
+from boto.utils import RequestHook
+from boto.compat import long_type
+
+
+class RequestLogger(RequestHook):
+ """
+ This class implements a request logger that uses a single thread to
+ write to a log file.
+ """
+ def __init__(self, filename='/tmp/request_log.csv'):
+ self.request_log_file = open(filename, 'w')
+ self.request_log_queue = Queue.Queue(100)
+ Thread(target=self._request_log_worker).start()
+
+ def handle_request_data(self, request, response, error=False):
+ len = 0 if error else response.getheader('Content-Length')
+ now = datetime.now()
+ time = now.strftime('%Y-%m-%d %H:%M:%S')
+ td = (now - request.start_time)
+ duration = (td.microseconds + long_type(td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
+
+ # write output including timestamp, status code, response time, response size, request action
+ self.request_log_queue.put("'%s', '%s', '%s', '%s', '%s'\n" % (time, response.status, duration, len, request.params['Action']))
+
+ def _request_log_worker(self):
+ while True:
+ try:
+ item = self.request_log_queue.get(True)
+ self.request_log_file.write(item)
+ self.request_log_file.flush()
+ self.request_log_queue.task_done()
+ except:
+ import traceback
+ traceback.print_exc(file=sys.stdout)
« no previous file with comments | « third_party/gsutil/third_party/boto/boto/regioninfo.py ('k') | third_party/gsutil/third_party/boto/boto/resultset.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698