aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addons/eventstore.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-12-14 23:45:12 +0100
committerMaximilian Hils <git@maximilianhils.com>2017-12-14 23:45:12 +0100
commit96ee3d853be68ac7b2852aa8fdf4e0753125f5a7 (patch)
tree4329552f75fc460e388dd9bddbd31fc150413e02 /mitmproxy/addons/eventstore.py
parenta5fd4bdb82b0dcb8f49b023216978f2c032d722e (diff)
downloadmitmproxy-96ee3d853be68ac7b2852aa8fdf4e0753125f5a7.tar.gz
mitmproxy-96ee3d853be68ac7b2852aa8fdf4e0753125f5a7.tar.bz2
mitmproxy-96ee3d853be68ac7b2852aa8fdf4e0753125f5a7.zip
limit eventstore size
Diffstat (limited to 'mitmproxy/addons/eventstore.py')
-rw-r--r--mitmproxy/addons/eventstore.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/mitmproxy/addons/eventstore.py b/mitmproxy/addons/eventstore.py
index ff8429d7..415bd017 100644
--- a/mitmproxy/addons/eventstore.py
+++ b/mitmproxy/addons/eventstore.py
@@ -5,6 +5,8 @@ import blinker
from mitmproxy import command
from mitmproxy.log import LogEntry
+EVENTLOG_SIZE = 10000
+
class EventStore:
def __init__(self):
@@ -15,6 +17,15 @@ class EventStore:
def log(self, entry: LogEntry) -> None:
self.data.append(entry)
self.sig_add.send(self, entry=entry)
+ # Instead of removing one log row for every row > EVENTLOG_SIZE we add,
+ # we accept an overhead of 10% and only purge then to simplify the API.
+ if len(self.data) / EVENTLOG_SIZE >= 1.1:
+ self.purge()
+
+ def purge(self):
+ """Purge event store size to EVENTLOG_SIZE"""
+ self.data = self.data[len(self.data) - EVENTLOG_SIZE:]
+ self.sig_refresh.send(self)
@command.command("eventstore.clear")
def clear(self) -> None: