aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addons/eventstore.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-12-15 01:36:41 +0100
committerMaximilian Hils <git@maximilianhils.com>2017-12-15 01:36:41 +0100
commit3ff380054c6627112fc6c0fe0d8e282877fddec9 (patch)
treeabf1b98518947c1eb8e1a75019044ad9ad6342cd /mitmproxy/addons/eventstore.py
parent96ee3d853be68ac7b2852aa8fdf4e0753125f5a7 (diff)
downloadmitmproxy-3ff380054c6627112fc6c0fe0d8e282877fddec9.tar.gz
mitmproxy-3ff380054c6627112fc6c0fe0d8e282877fddec9.tar.bz2
mitmproxy-3ff380054c6627112fc6c0fe0d8e282877fddec9.zip
improve eventstore truncation
Diffstat (limited to 'mitmproxy/addons/eventstore.py')
-rw-r--r--mitmproxy/addons/eventstore.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/mitmproxy/addons/eventstore.py b/mitmproxy/addons/eventstore.py
index 415bd017..73ffc70c 100644
--- a/mitmproxy/addons/eventstore.py
+++ b/mitmproxy/addons/eventstore.py
@@ -1,31 +1,25 @@
-from typing import List # noqa
+import collections
+import typing # noqa
import blinker
from mitmproxy import command
from mitmproxy.log import LogEntry
-EVENTLOG_SIZE = 10000
-
class EventStore:
- def __init__(self):
- self.data = [] # type: List[LogEntry]
+ def __init__(self, size=10000):
+ self.data = collections.deque(maxlen=size) # type: typing.Deque[LogEntry]
self.sig_add = blinker.Signal()
self.sig_refresh = blinker.Signal()
+ @property
+ def size(self) -> int:
+ return self.data.maxlen
+
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: