Flight-history men usage cap.
Beyond a certain cap (currently 4MB), recycle buckets. With the default sample rate of 1Hz, this gives over 24 hours of history before recycling.
This commit is contained in:
parent
433af2b51a
commit
e88e821567
2 changed files with 25 additions and 3 deletions
|
@ -51,6 +51,7 @@ FGFlightHistory::~FGFlightHistory()
|
|||
|
||||
void FGFlightHistory::init()
|
||||
{
|
||||
m_enabled = fgGetNode("/sim/history/enabled", true);
|
||||
m_sampleInterval = fgGetDouble("/sim/history/sample-interval-sec", 1.0);
|
||||
if (m_sampleInterval <= 0.0) { // would be bad
|
||||
SG_LOG(SG_FLIGHT, SG_INFO, "invalid flight-history sample interval:" << m_sampleInterval
|
||||
|
@ -58,6 +59,8 @@ void FGFlightHistory::init()
|
|||
m_sampleInterval = 1.0;
|
||||
}
|
||||
|
||||
// cap memory use at 4MB
|
||||
m_maxMemoryUseBytes = fgGetInt("/sim/history/max-memory-use-bytes", 1024 * 1024 * 4);
|
||||
m_weightOnWheels = NULL;
|
||||
// reset the history when we detect a take-off
|
||||
if (fgGetBool("/sim/history/clear-on-takeoff", true)) {
|
||||
|
@ -82,7 +85,9 @@ void FGFlightHistory::reinit()
|
|||
|
||||
void FGFlightHistory::update(double dt)
|
||||
{
|
||||
SG_UNUSED(dt); // we care about sim-time, not frame-time
|
||||
if ((dt == 0.0) || !m_enabled->getBoolValue()) {
|
||||
return; // paused or disabled
|
||||
}
|
||||
|
||||
if (m_weightOnWheels) {
|
||||
|
||||
|
@ -100,7 +105,14 @@ void FGFlightHistory::update(double dt)
|
|||
|
||||
void FGFlightHistory::allocateNewBucket()
|
||||
{
|
||||
SampleBucket* bucket = new SampleBucket;
|
||||
SampleBucket* bucket = NULL;
|
||||
if (!m_buckets.empty() && (currentMemoryUseBytes() > m_maxMemoryUseBytes)) {
|
||||
bucket = m_buckets.front();
|
||||
m_buckets.erase(m_buckets.begin());
|
||||
} else {
|
||||
bucket = new SampleBucket;
|
||||
}
|
||||
|
||||
m_buckets.push_back(bucket);
|
||||
m_validSampleCount = 0;
|
||||
}
|
||||
|
@ -164,3 +176,8 @@ void FGFlightHistory::clear()
|
|||
m_validSampleCount = SAMPLE_BUCKET_WIDTH;
|
||||
}
|
||||
|
||||
size_t FGFlightHistory::currentMemoryUseBytes() const
|
||||
{
|
||||
return sizeof(SampleBucket) * m_buckets.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -94,12 +94,17 @@ private:
|
|||
unsigned int m_validSampleCount;
|
||||
|
||||
SGPropertyNode_ptr m_weightOnWheels;
|
||||
SGPropertyNode_ptr m_enabled;
|
||||
|
||||
bool m_lastWoW;
|
||||
|
||||
size_t m_maxMemoryUseBytes;
|
||||
|
||||
void allocateNewBucket();
|
||||
|
||||
void clear();
|
||||
void capture();
|
||||
|
||||
size_t currentMemoryUseBytes() const;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue