[PATCH 09/12] tests: Optimize process memory reading using join

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Benjamin Berg <benjamin.berg@xxxxxxxxx>

Appending to a bytes() object is rather inefficient. As such, avoid
doing so by first creating a list and then join'ing all buffers together
at the end only.

Signed-off-by: Benjamin Berg <benjamin.berg@xxxxxxxxx>
---
 tests/hwsim/test_ap_psk.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/hwsim/test_ap_psk.py b/tests/hwsim/test_ap_psk.py
index ab76372578..d175259b53 100644
--- a/tests/hwsim/test_ap_psk.py
+++ b/tests/hwsim/test_ap_psk.py
@@ -2625,7 +2625,7 @@ def find_wpas_process(dev):
     raise Exception("Could not find wpa_supplicant process")
 
 def read_process_memory(pid, key=None):
-    buf = bytes()
+    buf = []
     logger.info("Reading process memory (pid=%d)" % pid)
     with open('/proc/%d/maps' % pid, 'r') as maps, \
          open('/proc/%d/mem' % pid, 'rb') as mem:
@@ -2651,11 +2651,11 @@ def read_process_memory(pid, key=None):
             except OSError as e:
                 logger.info("Could not read mem: start=%d end=%d: %s" % (start, end, str(e)))
                 continue
-            buf += data
+            buf.append(data)
             if key and key in data:
                 logger.info("Key found in " + l)
     logger.info("Total process memory read: %d bytes" % len(buf))
-    return buf
+    return b''.join(buf)
 
 def verify_not_present(buf, key, fname, keyname):
     pos = buf.find(key)
-- 
2.43.0


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux