Skip to content

Commit

Permalink
Add accessors for deletion stats
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Oct 8, 2024
1 parent aa81cbd commit 924b000
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CesiumGltf/include/CesiumGltf/SharedAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class CESIUMGLTF_API SharedAsset : public CesiumUtility::ExtensibleObject {
*/
virtual int64_t getSizeBytes() const = 0;

private:
const std::string& getUniqueAssetId() const { return this->_uniqueAssetId; }

private:
mutable std::atomic<std::int32_t> _referenceCount{0};
CesiumUtility::IntrusivePointer<SharedAssetDepot<T>> _pDepot;
std::string _uniqueAssetId;
Expand Down
25 changes: 6 additions & 19 deletions CesiumGltf/include/CesiumGltf/SharedAssetDepot.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,13 @@ class SharedAssetDepot : public CesiumUtility::ReferenceCountedThreadSafe<
return count;
}

/**
* @brief Obtains statistics on the number of assets currently listed as
* candidates for deletion, along with the average number of seconds that
* they've been pending deletion.
* @param outAverageAge The average time in seconds that the current deletion
* candidates have spent pending deletion.
* @param outCount The number of current deletion candidates.
*/
void getDeletionStats(float& outAverageAge, size_t& outCount) const {
size_t count = 0;
float total = 0;

size_t getDeletionCandidateCount() const {
std::lock_guard lock(this->deletionCandidatesMutex);
for (auto& [asset, age] : this->deletionCandidates) {
total += age;
count++;
}
return this->deletionCandidates.size();
}

outAverageAge = count > 0 ? total / count : 0;
outCount = count;
int64_t getDeletionCandidateTotalSizeBytes() const {
return this->totalDeletionCandidateMemoryUsage;
}

private:
Expand Down Expand Up @@ -250,7 +237,7 @@ class SharedAssetDepot : public CesiumUtility::ReferenceCountedThreadSafe<
std::list<CesiumUtility::IntrusivePointer<AssetType>> deletionCandidates;
// The total amount of memory used by all assets in the deletionCandidates
// list.
int64_t totalDeletionCandidateMemoryUsage;
std::atomic<int64_t> totalDeletionCandidateMemoryUsage;
// Mutex for modifying the deletionCandidates list.
mutable std::mutex deletionCandidatesMutex;

Expand Down

0 comments on commit 924b000

Please sign in to comment.