EventCollector: tune the parameters and add a shrinking heuristic.

This commit is contained in:
Gustavo J. A. M. Carneiro committed 2007-07-30 14:48:56 +01:00
1 parent 98abf1d812
commit ea0a9ae7ab
2 files changed
+21 -4

No files matched your search

+19 -4
View File
@@ -19,10 +19,9 @@
* Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
*/
#include "event-collector.h"
#include <algorithm>
#define CLEANUP_CHUNK_MIN_SIZE 8
#define CLEANUP_CHUNK_MAX_SIZE 1024
#define CLEANUP_CHUNK_MAX_SIZE 128
namespace ns3 {
@@ -46,6 +45,21 @@ EventExpiredPredicate (const EventId &event)
return event.IsExpired ();
}
void
EventCollector::Grow ()
{
m_nextCleanupSize += (m_nextCleanupSize < CLEANUP_CHUNK_MAX_SIZE?
m_nextCleanupSize : CLEANUP_CHUNK_MAX_SIZE);
}
void
EventCollector::Shrink ()
{
while (m_nextCleanupSize > m_events.size ())
m_nextCleanupSize >>= 1;
Grow ();
}
// Called when a new event was added and the cleanup limit was exceeded in consequence.
void
EventCollector::Cleanup ()
@@ -54,8 +68,9 @@ EventCollector::Cleanup ()
// If after cleanup we are still over the limit, increase the limit.
if (m_events.size () >= m_nextCleanupSize)
m_nextCleanupSize = std::min (std::list<EventId>::size_type (CLEANUP_CHUNK_MAX_SIZE),
m_nextCleanupSize<<1);
Grow ();
else
Shrink ();
}
+2
View File
@@ -53,6 +53,8 @@ private:
std::list<EventId> m_events;
void Cleanup ();
void Grow ();
void Shrink ();
};
}; // namespace ns3