diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-12-14 23:45:12 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-12-14 23:45:12 +0100 |
commit | 96ee3d853be68ac7b2852aa8fdf4e0753125f5a7 (patch) | |
tree | 4329552f75fc460e388dd9bddbd31fc150413e02 /mitmproxy/addons/eventstore.py | |
parent | a5fd4bdb82b0dcb8f49b023216978f2c032d722e (diff) | |
download | mitmproxy-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.py | 11 |
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: |