D4856: keepalive: track request count and bytes sent

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Oct 3 20:07:40 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGdc82ad1b7f77: keepalive: track request count and bytes sent (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4856?vs=11634&id=11663

REVISION DETAIL
  https://phab.mercurial-scm.org/D4856

AFFECTED FILES
  mercurial/keepalive.py

CHANGE DETAILS

diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -174,6 +174,8 @@
 class KeepAliveHandler(object):
     def __init__(self):
         self._cm = ConnectionManager()
+        self.requestscount = 0
+        self.sentbytescount = 0
 
     #### Connection Management
     def open_connections(self):
@@ -312,6 +314,8 @@
         return r
 
     def _start_transaction(self, h, req):
+        oldbytescount = h.sentbytescount
+
         # What follows mostly reimplements HTTPConnection.request()
         # except it adds self.parent.addheaders in the mix and sends headers
         # in a deterministic order (to make testing easier).
@@ -346,6 +350,16 @@
         if urllibcompat.hasdata(req):
             h.send(data)
 
+        # This will fail to record events in case of I/O failure. That's OK.
+        self.requestscount += 1
+        self.sentbytescount += h.sentbytescount - oldbytescount
+
+        try:
+            self.parent.requestscount += 1
+            self.parent.sentbytescount += h.sentbytescount - oldbytescount
+        except AttributeError:
+            pass
+
 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
     pass
 
@@ -585,9 +599,11 @@
             data = read(blocksize)
             while data:
                 self.sock.sendall(data)
+                self.sentbytescount += len(data)
                 data = read(blocksize)
         else:
             self.sock.sendall(str)
+            self.sentbytescount += len(str)
     except socket.error as v:
         reraise = True
         if v[0] == errno.EPIPE:      # Broken pipe
@@ -624,6 +640,9 @@
     send = safesend
     getresponse = wrapgetresponse(httplib.HTTPConnection)
 
+    def __init__(self, *args, **kwargs):
+        httplib.HTTPConnection.__init__(self, *args, **kwargs)
+        self.sentbytescount = 0
 
 #########################################################################
 #####   TEST FUNCTIONS



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list