Commit 954a7241 authored by Michael Büsch's avatar Michael Büsch

Add environment variable to configure garbage collector

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 97aa208c
......@@ -189,6 +189,21 @@ The following environment variables control Awlsim's basic behavior:
* `AWLSIM_COVERAGE`<br />
`=DATAFILE` Enable code coverage tracing.<br />
* `AWLSIM_GCMODE`<br />
`=realtime` Enable manual garbage collection, if realtime scheduling is enabled. (default)<br />
`=auto` Always use automatic garbage collection.<br />
`=manual` Always use manual garbage collection.<br />
* `AWLSIM_GCTHRES`<br />
`=700,1,1`<br />
A comma separated string with up to 3 integers.<br />
Each integer corresponding to the Python garbage collector generation 0 to 2 thresholds for manual garbage collection.<br />
A threshold value of 0 disables garbage collection. (not recommended)<br />
* `AWLSIM_GCCYCLE`<br />
`=64`<br />
The number of OB1 cycles it takes to trigger a manual garbage collection.<br />
## Building Awlsim
......
......@@ -2,7 +2,7 @@
#
# AWL simulator - Environment variables
#
# Copyright 2017-2018 Michael Buesch <m@bues.ch>
# Copyright 2017-2019 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -27,6 +27,7 @@ from awlsim.common.util import *
from awlsim.common.exceptions import *
import os
import gc
__all__ = [
......@@ -141,3 +142,55 @@ class AwlSimEnv(object):
except ValueError as e:
pass
return None
GCMODE_RT = "realtime" # Manual GC, if realtime scheduling
GCMODE_AUTO = "auto" # Automatic GC
GCMODE_MANUAL = "manual" # Manual GC
@classmethod
def getGcMode(cls):
"""Get AWLSIM_GCMODE.
Returns one of the GCMODE_... constants.
"""
gcModeStr = cls.__getVar("GCMODE", "").lower().strip()
if gcModeStr == cls.GCMODE_RT:
return cls.GCMODE_RT
if gcModeStr == cls.GCMODE_AUTO:
return cls.GCMODE_AUTO
if gcModeStr == cls.GCMODE_MANUAL:
return cls.GCMODE_MANUAL
return cls.GCMODE_RT
@classmethod
def getGcThreshold(cls, generation):
"""Get AWLSIM_GCTHRES.
AWLSIM_GCTHRES is a comma separated string with up to 3 integers.
Each integer corresponding to the generation 0 to 2 thresholds.
Returns the garbage collector threshold for the selected generation.
"""
thresStr = cls.__getVar("GCTHRES", "")
thres = thresStr.split(",")
assert(generation in (0, 1, 2))
try:
return clamp(int(thres[generation]),
0, 0x7FFFFFFF)
except (ValueError, IndexError) as e:
if generation == 0:
gc_get_threshold = getattr(gc, "get_threshold", None)
if gc_get_threshold:
return gc_get_threshold()[0]
return 700
return 1
@classmethod
def getGcCycle(cls):
"""Get AWLSIM_GCCYCLE.
AWLSIM_GCCYCLE is the number of OB1 cycles it takes to trigger
a manual garbage collection.
Returns an integer.
"""
cycStr = cls.__getVar("GCCYCLE", "")
try:
return clamp(int(cycStr), 1, 0xFFFF)
except ValueError as e:
return 64
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment