Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions meshroom/core/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,29 @@ class Statistics:
"""
fileVersion = 2.0

def __init__(self):
def __init__(self, maxPoints=100):
self.computer = ComputerStatistics()
self.process = ProcStatistics()
self.times = []
self.interval = 10 # refresh interval in seconds

self.interval = 1 # refresh interval in seconds
self.maxPoints = maxPoints # maximum number of points to keep
self.baseInterval = 10 # base interval in seconds

def _filterDataPoints(self, keepEveryN):
"""
Filter data points to keep every Nth point.
"""
# Filter times
self.times = self.times[::keepEveryN]

# Filter computer curves
for key in self.computer.curves:
self.computer.curves[key] = self.computer.curves[key][::keepEveryN]

# Filter process curves
for key in self.process.curves:
self.process.curves[key] = self.process.curves[key][::keepEveryN]

def update(self, proc):
'''
proc: psutil.Process object
Expand All @@ -249,6 +266,17 @@ def update(self, proc):
self.times.append(time.time())
self.computer.update()
self.process.update(proc)

# Check if we exceeded max points and need to adjust interval
if len(self.times) > self.maxPoints:
# Calculate new interval (double it)
newInterval = self.interval * 2
# Filter existing data to keep every other point
self._filterDataPoints(2)
# Update interval
self.interval = newInterval
logging.debug(f'Statistics: Increased interval to {self.interval}s to maintain max {self.maxPoints} points')

return True

def toDict(self):
Expand All @@ -257,7 +285,9 @@ def toDict(self):
'computer': self.computer.toDict(),
'process': self.process.toDict(),
'times': self.times,
'interval': self.interval
'interval': self.interval,
'maxPoints': self.maxPoints,
'baseInterval': self.baseInterval
}

def fromDict(self, d):
Expand All @@ -267,6 +297,9 @@ def fromDict(self, d):
self.computer = ComputerStatistics()
self.process = ProcStatistics()
self.times = []
self.interval = d.get('interval', 1)
self.maxPoints = d.get('maxPoints', 100)
self.baseInterval = d.get('baseInterval', 1)
try:
self.computer.fromDict(d.get('computer', {}))
except Exception as exc:
Expand Down
Loading