limit eventstore size

This commit is contained in:
Maximilian Hils 2017-12-14 23:45:12 +01:00
parent a5fd4bdb82
commit 96ee3d853b
2 changed files with 11 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import blinker
from mitmproxy import command from mitmproxy import command
from mitmproxy.log import LogEntry from mitmproxy.log import LogEntry
EVENTLOG_SIZE = 10000
class EventStore: class EventStore:
def __init__(self): def __init__(self):
@ -15,6 +17,15 @@ class EventStore:
def log(self, entry: LogEntry) -> None: def log(self, entry: LogEntry) -> None:
self.data.append(entry) self.data.append(entry)
self.sig_add.send(self, entry=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") @command.command("eventstore.clear")
def clear(self) -> None: def clear(self) -> None:

View File

@ -2,8 +2,6 @@ import urwid
from mitmproxy.tools.console import layoutwidget from mitmproxy.tools.console import layoutwidget
from mitmproxy import log from mitmproxy import log
EVENTLOG_SIZE = 10000
class LogBufferWalker(urwid.SimpleListWalker): class LogBufferWalker(urwid.SimpleListWalker):
pass pass
@ -47,8 +45,6 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget):
else: else:
e = urwid.Text(txt) e = urwid.Text(txt)
self.walker.append(e) self.walker.append(e)
if len(self.walker) > EVENTLOG_SIZE:
self.walker.pop(0)
if self.master.options.console_focus_follow: if self.master.options.console_focus_follow:
self.walker.set_focus(len(self.walker) - 1) self.walker.set_focus(len(self.walker) - 1)