55import os
66import platform
77import sys
8+ import time
89import warnings
910from threading import Lock
1011from typing import TYPE_CHECKING
@@ -78,7 +79,7 @@ def open(self) -> None:
7879 if not self ._open_lock .acquire (blocking = False ):
7980 raise RuntimeError ("Cannot open same pipe twice." )
8081
81- def write_json (self , obj : Mapping [str , Any ]) -> None :
82+ def write_json (self , obj : Mapping [str , Any ]) -> tuple [ float , float ] :
8283 """
8384 Send one json down the pipe.
8485
@@ -97,6 +98,7 @@ def write_json(self, obj: Mapping[str, Any]) -> None:
9798 f"size: { len (encoded_message )} ." ,
9899 )
99100 _logger .debug2 (f"Full Message: { encoded_message !r} " )
101+ start = time .perf_counter ()
100102 try :
101103 ret = os .write (self ._write_to_browser , encoded_message )
102104 _logger .debug (
@@ -109,12 +111,13 @@ def write_json(self, obj: Mapping[str, Any]) -> None:
109111 except OSError as e :
110112 self .close ()
111113 raise ChannelClosedError from e
114+ return (start , time .perf_counter ())
112115
113116 def read_jsons ( # noqa: PLR0912, PLR0915, C901 branches, complexity
114117 self ,
115118 * ,
116119 blocking : bool = True ,
117- ) -> Sequence [BrowserResponse ]:
120+ ) -> tuple [ Sequence [BrowserResponse ], float ]:
118121 """
119122 Read from the pipe and return one or more jsons in a list.
120123
@@ -168,7 +171,7 @@ def read_jsons( # noqa: PLR0912, PLR0915, C901 branches, complexity
168171 raw_buffer += os .read (self ._read_from_browser , 10000 )
169172 except BlockingIOError :
170173 _logger .debug ("BlockingIOError" )
171- return jsons
174+ return jsons , time . perf_counter ()
172175 except OSError as e :
173176 _logger .debug ("OSError" )
174177 self .close ()
@@ -182,7 +185,7 @@ def read_jsons( # noqa: PLR0912, PLR0915, C901 branches, complexity
182185 )
183186 _logger .debug2 (f"Whole buffer: { raw_buffer !r} " )
184187 if raw_buffer is None :
185- return jsons
188+ return jsons , time . perf_counter ()
186189 decoded_buffer = raw_buffer .decode ("utf-8" )
187190 raw_messages = decoded_buffer .split ("\0 " )
188191 _logger .debug (f"Received { len (raw_messages )} raw_messages." )
@@ -195,7 +198,7 @@ def read_jsons( # noqa: PLR0912, PLR0915, C901 branches, complexity
195198 except :
196199 _logger .exception ("Error in trying to decode JSON off our read." )
197200 raise
198- return jsons
201+ return jsons , time . perf_counter ()
199202
200203 def _unblock_fd (self , fd : int ) -> None :
201204 try :
0 commit comments