##// END OF EJS Templates
util: don't log low-level I/O calls for HTTP peer...
Gregory Szorc -
r37062:d3a9036d default
parent child Browse files
Show More
@@ -2839,9 +2839,13 b' def debugwireproto(ui, repo, path=None, '
2839 r'loggingname': b's',
2839 r'loggingname': b's',
2840 r'loggingopts': {
2840 r'loggingopts': {
2841 r'logdata': True,
2841 r'logdata': True,
2842 r'logdataapis': False,
2842 },
2843 },
2843 }
2844 }
2844
2845
2846 if ui.debugflag:
2847 openerargs[r'loggingopts'][r'logdataapis'] = True
2848
2845 opener = urlmod.opener(ui, authinfo, **openerargs)
2849 opener = urlmod.opener(ui, authinfo, **openerargs)
2846
2850
2847 if opts['peer'] == 'raw':
2851 if opts['peer'] == 'raw':
@@ -762,7 +762,8 b' class socketproxy(object):'
762 return makeloggingfileobject(observer.fh, res, observer.name,
762 return makeloggingfileobject(observer.fh, res, observer.name,
763 reads=observer.reads,
763 reads=observer.reads,
764 writes=observer.writes,
764 writes=observer.writes,
765 logdata=observer.logdata)
765 logdata=observer.logdata,
766 logdataapis=observer.logdataapis)
766
767
767 def recv(self, *args, **kwargs):
768 def recv(self, *args, **kwargs):
768 return object.__getattribute__(self, r'_observedcall')(
769 return object.__getattribute__(self, r'_observedcall')(
@@ -825,18 +826,24 b' def escapedata(s):'
825 class baseproxyobserver(object):
826 class baseproxyobserver(object):
826 def _writedata(self, data):
827 def _writedata(self, data):
827 if not self.logdata:
828 if not self.logdata:
829 if self.logdataapis:
828 self.fh.write('\n')
830 self.fh.write('\n')
829 self.fh.flush()
831 self.fh.flush()
830 return
832 return
831
833
832 # Simple case writes all data on a single line.
834 # Simple case writes all data on a single line.
833 if b'\n' not in data:
835 if b'\n' not in data:
836 if self.logdataapis:
834 self.fh.write(': %s\n' % escapedata(data))
837 self.fh.write(': %s\n' % escapedata(data))
838 else:
839 self.fh.write('%s> %s\n' % (self.name, escapedata(data)))
835 self.fh.flush()
840 self.fh.flush()
836 return
841 return
837
842
838 # Data with newlines is written to multiple lines.
843 # Data with newlines is written to multiple lines.
844 if self.logdataapis:
839 self.fh.write(':\n')
845 self.fh.write(':\n')
846
840 lines = data.splitlines(True)
847 lines = data.splitlines(True)
841 for line in lines:
848 for line in lines:
842 self.fh.write('%s> %s\n' % (self.name, escapedata(line)))
849 self.fh.write('%s> %s\n' % (self.name, escapedata(line)))
@@ -844,10 +851,12 b' class baseproxyobserver(object):'
844
851
845 class fileobjectobserver(baseproxyobserver):
852 class fileobjectobserver(baseproxyobserver):
846 """Logs file object activity."""
853 """Logs file object activity."""
847 def __init__(self, fh, name, reads=True, writes=True, logdata=False):
854 def __init__(self, fh, name, reads=True, writes=True, logdata=False,
855 logdataapis=True):
848 self.fh = fh
856 self.fh = fh
849 self.name = name
857 self.name = name
850 self.logdata = logdata
858 self.logdata = logdata
859 self.logdataapis = logdataapis
851 self.reads = reads
860 self.reads = reads
852 self.writes = writes
861 self.writes = writes
853
862
@@ -858,22 +867,28 b' class fileobjectobserver(baseproxyobserv'
858 if res is None:
867 if res is None:
859 res = ''
868 res = ''
860
869
870 if self.logdataapis:
861 self.fh.write('%s> read(%d) -> %d' % (self.name, size, len(res)))
871 self.fh.write('%s> read(%d) -> %d' % (self.name, size, len(res)))
872
862 self._writedata(res)
873 self._writedata(res)
863
874
864 def readline(self, res, limit=-1):
875 def readline(self, res, limit=-1):
865 if not self.reads:
876 if not self.reads:
866 return
877 return
867
878
879 if self.logdataapis:
868 self.fh.write('%s> readline() -> %d' % (self.name, len(res)))
880 self.fh.write('%s> readline() -> %d' % (self.name, len(res)))
881
869 self._writedata(res)
882 self._writedata(res)
870
883
871 def readinto(self, res, dest):
884 def readinto(self, res, dest):
872 if not self.reads:
885 if not self.reads:
873 return
886 return
874
887
888 if self.logdataapis:
875 self.fh.write('%s> readinto(%d) -> %r' % (self.name, len(dest),
889 self.fh.write('%s> readinto(%d) -> %r' % (self.name, len(dest),
876 res))
890 res))
891
877 data = dest[0:res] if res is not None else b''
892 data = dest[0:res] if res is not None else b''
878 self._writedata(data)
893 self._writedata(data)
879
894
@@ -886,7 +901,9 b' class fileobjectobserver(baseproxyobserv'
886 if res is None and data:
901 if res is None and data:
887 res = len(data)
902 res = len(data)
888
903
904 if self.logdataapis:
889 self.fh.write('%s> write(%d) -> %r' % (self.name, len(data), res))
905 self.fh.write('%s> write(%d) -> %r' % (self.name, len(data), res))
906
890 self._writedata(data)
907 self._writedata(data)
891
908
892 def flush(self, res):
909 def flush(self, res):
@@ -897,32 +914,44 b' class fileobjectobserver(baseproxyobserv'
897
914
898 # For observedbufferedinputpipe.
915 # For observedbufferedinputpipe.
899 def bufferedread(self, res, size):
916 def bufferedread(self, res, size):
917 if not self.reads:
918 return
919
920 if self.logdataapis:
900 self.fh.write('%s> bufferedread(%d) -> %d' % (
921 self.fh.write('%s> bufferedread(%d) -> %d' % (
901 self.name, size, len(res)))
922 self.name, size, len(res)))
923
902 self._writedata(res)
924 self._writedata(res)
903
925
904 def bufferedreadline(self, res):
926 def bufferedreadline(self, res):
905 self.fh.write('%s> bufferedreadline() -> %d' % (self.name, len(res)))
927 if not self.reads:
928 return
929
930 if self.logdataapis:
931 self.fh.write('%s> bufferedreadline() -> %d' % (
932 self.name, len(res)))
933
906 self._writedata(res)
934 self._writedata(res)
907
935
908 def makeloggingfileobject(logh, fh, name, reads=True, writes=True,
936 def makeloggingfileobject(logh, fh, name, reads=True, writes=True,
909 logdata=False):
937 logdata=False, logdataapis=True):
910 """Turn a file object into a logging file object."""
938 """Turn a file object into a logging file object."""
911
939
912 observer = fileobjectobserver(logh, name, reads=reads, writes=writes,
940 observer = fileobjectobserver(logh, name, reads=reads, writes=writes,
913 logdata=logdata)
941 logdata=logdata, logdataapis=logdataapis)
914 return fileobjectproxy(fh, observer)
942 return fileobjectproxy(fh, observer)
915
943
916 class socketobserver(baseproxyobserver):
944 class socketobserver(baseproxyobserver):
917 """Logs socket activity."""
945 """Logs socket activity."""
918 def __init__(self, fh, name, reads=True, writes=True, states=True,
946 def __init__(self, fh, name, reads=True, writes=True, states=True,
919 logdata=False):
947 logdata=False, logdataapis=True):
920 self.fh = fh
948 self.fh = fh
921 self.name = name
949 self.name = name
922 self.reads = reads
950 self.reads = reads
923 self.writes = writes
951 self.writes = writes
924 self.states = states
952 self.states = states
925 self.logdata = logdata
953 self.logdata = logdata
954 self.logdataapis = logdataapis
926
955
927 def makefile(self, res, mode=None, bufsize=None):
956 def makefile(self, res, mode=None, bufsize=None):
928 if not self.states:
957 if not self.states:
@@ -935,6 +964,7 b' class socketobserver(baseproxyobserver):'
935 if not self.reads:
964 if not self.reads:
936 return
965 return
937
966
967 if self.logdataapis:
938 self.fh.write('%s> recv(%d, %d) -> %d' % (
968 self.fh.write('%s> recv(%d, %d) -> %d' % (
939 self.name, size, flags, len(res)))
969 self.name, size, flags, len(res)))
940 self._writedata(res)
970 self._writedata(res)
@@ -943,24 +973,30 b' class socketobserver(baseproxyobserver):'
943 if not self.reads:
973 if not self.reads:
944 return
974 return
945
975
976 if self.logdataapis:
946 self.fh.write('%s> recvfrom(%d, %d) -> %d' % (
977 self.fh.write('%s> recvfrom(%d, %d) -> %d' % (
947 self.name, size, flags, len(res[0])))
978 self.name, size, flags, len(res[0])))
979
948 self._writedata(res[0])
980 self._writedata(res[0])
949
981
950 def recvfrom_into(self, res, buf, size, flags=0):
982 def recvfrom_into(self, res, buf, size, flags=0):
951 if not self.reads:
983 if not self.reads:
952 return
984 return
953
985
986 if self.logdataapis:
954 self.fh.write('%s> recvfrom_into(%d, %d) -> %d' % (
987 self.fh.write('%s> recvfrom_into(%d, %d) -> %d' % (
955 self.name, size, flags, res[0]))
988 self.name, size, flags, res[0]))
989
956 self._writedata(buf[0:res[0]])
990 self._writedata(buf[0:res[0]])
957
991
958 def recv_into(self, res, buf, size=0, flags=0):
992 def recv_into(self, res, buf, size=0, flags=0):
959 if not self.reads:
993 if not self.reads:
960 return
994 return
961
995
996 if self.logdataapis:
962 self.fh.write('%s> recv_into(%d, %d) -> %d' % (
997 self.fh.write('%s> recv_into(%d, %d) -> %d' % (
963 self.name, size, flags, res))
998 self.name, size, flags, res))
999
964 self._writedata(buf[0:res])
1000 self._writedata(buf[0:res])
965
1001
966 def send(self, res, data, flags=0):
1002 def send(self, res, data, flags=0):
@@ -975,9 +1011,11 b' class socketobserver(baseproxyobserver):'
975 if not self.writes:
1011 if not self.writes:
976 return
1012 return
977
1013
1014 if self.logdataapis:
978 # Returns None on success. So don't bother reporting return value.
1015 # Returns None on success. So don't bother reporting return value.
979 self.fh.write('%s> sendall(%d, %d)' % (
1016 self.fh.write('%s> sendall(%d, %d)' % (
980 self.name, len(data), flags))
1017 self.name, len(data), flags))
1018
981 self._writedata(data)
1019 self._writedata(data)
982
1020
983 def sendto(self, res, data, flagsoraddress, address=None):
1021 def sendto(self, res, data, flagsoraddress, address=None):
@@ -989,8 +1027,10 b' class socketobserver(baseproxyobserver):'
989 else:
1027 else:
990 flags = 0
1028 flags = 0
991
1029
1030 if self.logdataapis:
992 self.fh.write('%s> sendto(%d, %d, %r) -> %d' % (
1031 self.fh.write('%s> sendto(%d, %d, %r) -> %d' % (
993 self.name, len(data), flags, address, res))
1032 self.name, len(data), flags, address, res))
1033
994 self._writedata(data)
1034 self._writedata(data)
995
1035
996 def setblocking(self, res, flag):
1036 def setblocking(self, res, flag):
@@ -1019,11 +1059,12 b' class socketobserver(baseproxyobserver):'
1019 self.name, level, optname, value))
1059 self.name, level, optname, value))
1020
1060
1021 def makeloggingsocket(logh, fh, name, reads=True, writes=True, states=True,
1061 def makeloggingsocket(logh, fh, name, reads=True, writes=True, states=True,
1022 logdata=False):
1062 logdata=False, logdataapis=True):
1023 """Turn a socket into a logging socket."""
1063 """Turn a socket into a logging socket."""
1024
1064
1025 observer = socketobserver(logh, name, reads=reads, writes=writes,
1065 observer = socketobserver(logh, name, reads=reads, writes=writes,
1026 states=states, logdata=logdata)
1066 states=states, logdata=logdata,
1067 logdataapis=logdataapis)
1027 return socketproxy(fh, observer)
1068 return socketproxy(fh, observer)
1028
1069
1029 def version():
1070 def version():
@@ -175,7 +175,6 b' Test listkeys for listing namespaces'
175 > command listkeys
175 > command listkeys
176 > namespace namespaces
176 > namespace namespaces
177 > EOF
177 > EOF
178 s> sendall(*, 0): (glob)
179 s> GET /?cmd=capabilities HTTP/1.1\r\n
178 s> GET /?cmd=capabilities HTTP/1.1\r\n
180 s> Accept-Encoding: identity\r\n
179 s> Accept-Encoding: identity\r\n
181 s> accept: application/mercurial-0.1\r\n
180 s> accept: application/mercurial-0.1\r\n
@@ -183,21 +182,14 b' Test listkeys for listing namespaces'
183 s> user-agent: mercurial/proto-1.0 (Mercurial *)\r\n (glob)
182 s> user-agent: mercurial/proto-1.0 (Mercurial *)\r\n (glob)
184 s> \r\n
183 s> \r\n
185 s> makefile('rb', None)
184 s> makefile('rb', None)
186 s> readline() -> 36:
187 s> HTTP/1.1 200 Script output follows\r\n
185 s> HTTP/1.1 200 Script output follows\r\n
188 s> readline() -> 28:
189 s> Server: testing stub value\r\n
186 s> Server: testing stub value\r\n
190 s> readline() -> *: (glob)
191 s> Date: $HTTP_DATE$\r\n
187 s> Date: $HTTP_DATE$\r\n
192 s> readline() -> 41:
193 s> Content-Type: application/mercurial-0.1\r\n
188 s> Content-Type: application/mercurial-0.1\r\n
194 s> readline() -> 21:
195 s> Content-Length: *\r\n (glob)
189 s> Content-Length: *\r\n (glob)
196 s> readline() -> 2:
197 s> \r\n
190 s> \r\n
198 s> read(*) -> *: lookup branchmap pushkey known getbundle unbundlehash batch changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx compression=$BUNDLE2_COMPRESSIONS$ (glob)
191 s> lookup branchmap pushkey known getbundle unbundlehash batch changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024 httpmediatype=0.1rx,0.1tx,0.2tx compression=$BUNDLE2_COMPRESSIONS$
199 sending listkeys command
192 sending listkeys command
200 s> sendall(*, 0): (glob)
201 s> GET /?cmd=listkeys HTTP/1.1\r\n
193 s> GET /?cmd=listkeys HTTP/1.1\r\n
202 s> Accept-Encoding: identity\r\n
194 s> Accept-Encoding: identity\r\n
203 s> vary: X-HgArg-1,X-HgProto-1\r\n
195 s> vary: X-HgArg-1,X-HgProto-1\r\n
@@ -208,19 +200,12 b' Test listkeys for listing namespaces'
208 s> user-agent: mercurial/proto-1.0 (Mercurial *)\r\n (glob)
200 s> user-agent: mercurial/proto-1.0 (Mercurial *)\r\n (glob)
209 s> \r\n
201 s> \r\n
210 s> makefile('rb', None)
202 s> makefile('rb', None)
211 s> readline() -> 36:
212 s> HTTP/1.1 200 Script output follows\r\n
203 s> HTTP/1.1 200 Script output follows\r\n
213 s> readline() -> 28:
214 s> Server: testing stub value\r\n
204 s> Server: testing stub value\r\n
215 s> readline() -> *: (glob)
216 s> Date: $HTTP_DATE$\r\n
205 s> Date: $HTTP_DATE$\r\n
217 s> readline() -> 41:
218 s> Content-Type: application/mercurial-0.1\r\n
206 s> Content-Type: application/mercurial-0.1\r\n
219 s> readline() -> 20:
220 s> Content-Length: 30\r\n
207 s> Content-Length: 30\r\n
221 s> readline() -> 2:
222 s> \r\n
208 s> \r\n
223 s> read(30) -> 30:
224 s> bookmarks \n
209 s> bookmarks \n
225 s> namespaces \n
210 s> namespaces \n
226 s> phases
211 s> phases
@@ -235,7 +220,6 b' Same thing, but with "httprequest" comma'
235 > x-hgarg-1: namespace=namespaces
220 > x-hgarg-1: namespace=namespaces
236 > EOF
221 > EOF
237 using raw connection to peer
222 using raw connection to peer
238 s> sendall(*, 0): (glob)
239 s> GET /?cmd=listkeys HTTP/1.1\r\n
223 s> GET /?cmd=listkeys HTTP/1.1\r\n
240 s> Accept-Encoding: identity\r\n
224 s> Accept-Encoding: identity\r\n
241 s> accept: application/mercurial-0.1\r\n
225 s> accept: application/mercurial-0.1\r\n
@@ -244,19 +228,12 b' Same thing, but with "httprequest" comma'
244 s> host: $LOCALIP:$HGPORT\r\n (glob)
228 s> host: $LOCALIP:$HGPORT\r\n (glob)
245 s> \r\n
229 s> \r\n
246 s> makefile('rb', None)
230 s> makefile('rb', None)
247 s> readline() -> 36:
248 s> HTTP/1.1 200 Script output follows\r\n
231 s> HTTP/1.1 200 Script output follows\r\n
249 s> readline() -> 28:
250 s> Server: testing stub value\r\n
232 s> Server: testing stub value\r\n
251 s> readline() -> *: (glob)
252 s> Date: $HTTP_DATE$\r\n
233 s> Date: $HTTP_DATE$\r\n
253 s> readline() -> 41:
254 s> Content-Type: application/mercurial-0.1\r\n
234 s> Content-Type: application/mercurial-0.1\r\n
255 s> readline() -> 20:
256 s> Content-Length: 30\r\n
235 s> Content-Length: 30\r\n
257 s> readline() -> 2:
258 s> \r\n
236 s> \r\n
259 s> read(30) -> 30:
260 s> bookmarks \n
237 s> bookmarks \n
261 s> namespaces \n
238 s> namespaces \n
262 s> phases
239 s> phases
General Comments 0
You need to be logged in to leave comments. Login now