51 uint64_t count =
readLockCount.load(std::memory_order_relaxed);
52 if (count == 0)
return 0.0;
59 if (count == 0)
return 0.0;
103 std::vector<EntitySnapshotT>
truncate();
117 using ProviderSegmentBase::addEntity;
119 template <
class... Args>
123 Entity& added = ProviderSegmentBase::addEntity(
name, args...);
144 using CoreSegmentBase::addProviderSegment;
146 template <
class... Args>
152 if (maxHistorySize < 0)
154 ARMARX_INFO <<
"The maxHistorySize for this core segment is set to < 0. "
155 <<
"This means nothing will ever be forgotten in working memory. "
156 <<
"This may slow down the memory server. \n"
157 <<
"Core Segment Name: " << (this->
id()).
str();
159 added.setMaxHistorySize(maxHistorySize);
173 template <
class FunctionT>
177 auto startTime = std::chrono::steady_clock::now();
178 std::shared_lock lock(_mutex);
179 auto lockAcquiredTime = std::chrono::steady_clock::now();
182 uint64_t waitNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
183 lockAcquiredTime - startTime).count();
184 _lockStats.readLockCount.fetch_add(1, std::memory_order_relaxed);
185 _lockStats.totalReadLockWaitNs.fetch_add(waitNs, std::memory_order_relaxed);
188 uint64_t currentMax = _lockStats.maxReadLockWaitNs.load(std::memory_order_relaxed);
189 while (waitNs > currentMax)
191 if (_lockStats.maxReadLockWaitNs.compare_exchange_weak(currentMax, waitNs, std::memory_order_relaxed))
206 template <
class FunctionT>
210 auto startTime = std::chrono::steady_clock::now();
211 std::unique_lock lock(_mutex);
212 auto lockAcquiredTime = std::chrono::steady_clock::now();
215 uint64_t waitNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
216 lockAcquiredTime - startTime).count();
217 _lockStats.writeLockCount.fetch_add(1, std::memory_order_relaxed);
218 _lockStats.totalWriteLockWaitNs.fetch_add(waitNs, std::memory_order_relaxed);
221 uint64_t currentMax = _lockStats.maxWriteLockWaitNs.load(std::memory_order_relaxed);
222 while (waitNs > currentMax)
224 if (_lockStats.maxWriteLockWaitNs.compare_exchange_weak(currentMax, waitNs, std::memory_order_relaxed))
241 mutable std::shared_mutex _mutex;
271 using MemoryBase::addCoreSegment;
273 template <
class... Args>
Data of a core segment containing multiple provider segments.
ProviderSegment ProviderSegmentT
An entity over a period of time.
Data of a memory consisting of multiple core segments.
std::vector< UpdateResult > update(const Commit &commit, const bool addMissingCoreSegmentDuringUpdate=false, const bool checkMemoryName=true)
Data of a provider segment containing multiple entities.
const CoreSegmentLockStatistics & getLockStatistics() const
Get lock statistics for this core segment.
ProviderSegment & addProviderSegment(const std::string &name, Args... args)
auto doLocked(FunctionT &&function) const
Execute function under shared (read) lock.
void resetLockStatistics()
Reset lock statistics.
auto doLockedExclusive(FunctionT &&function)
Execute function under exclusive (write) lock.
void setMaxHistorySize(long maxSize)
Sets the maximum history size.
std::vector< EntitySnapshotT > truncate()
If maximum size is set, ensure history's is not higher.
UpdateResult update(const EntityUpdate &update)
std::vector< Base::UpdateResult > updateLocking(const Commit &commit)
Perform the commit, locking the core segments.
CoreSegment & addCoreSegment(const std::string &name, Args... args)
Entity & addEntity(const std::string &name, Args... args)
size_t getTruncateMaxBatchSize() const
void setTruncateMaxBatchSize(size_t batchSize)
Set the maximum number of snapshots to remove per truncate() call.
void setUnlimitedHistoryWarningThreshold(size_t threshold)
Set the threshold for warning about unlimited history growth.
size_t getUnlimitedHistoryWarningThreshold() const
long getMaxHistorySize() const
Can do predictions itself and has children it could delegate predictions to.
Can do predictions, but has no children it could delegate predictions to.
Client-side working entity instance.
Client-side working memory entity snapshot.
#define ARMARX_INFO
The normal logging level.
armem::wm::EntitySnapshot EntitySnapshot
base::EntityInstanceMetadata EntityInstanceMetadata
armem::wm::EntityInstance EntityInstance
armarx::aron::data::Dict EntityInstanceData
armarx::aron::data::DictPtr EntityInstanceDataPtr
std::shared_ptr< Dict > DictPtr
A bundle of updates to be sent to the memory.
An update of an entity for a specific point in time.
Statistics for CoreSegment lock operations.
double getMaxReadLockWaitMs() const
double getMaxWriteLockWaitMs() const
std::atomic< uint64_t > writeLockCount
std::atomic< uint64_t > totalWriteLockWaitNs
double getAvgWriteLockWaitMs() const
std::atomic< uint64_t > maxWriteLockWaitNs
std::atomic< uint64_t > readLockCount
std::atomic< uint64_t > maxReadLockWaitNs
std::atomic< uint64_t > totalReadLockWaitNs
double getAvgReadLockWaitMs() const