MCPcopy Create free account
hub / github.com/alibaba/loongcollector / ClearExpiredCache

Method ClearExpiredCache

core/ebpf/plugin/ProcessCache.cpp:102–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void ProcessCache::ClearExpiredCache() {
103 {
104 std::lock_guard<std::mutex> lock(mCacheExpireQueueMutex);
105 mCacheExpireQueueProcessing.swap(mCacheExpireQueue);
106 }
107 if (mCacheExpireQueueProcessing.empty()) {
108 return;
109 }
110 size_t nextQueueSize = 0;
111 for (auto& entry : mCacheExpireQueueProcessing) {
112 if (entry.value->LifeStage() == ProcessCacheValue::LifeStage::kDeleted) {
113 LOG_WARNING(sLogger, ("clear expired cache twice pid", entry.key.pid)("ktime", entry.key.time));
114 continue;
115 }
116 if (entry.value->RefCount() > 0) {
117 entry.value->SetLifeStage(ProcessCacheValue::LifeStage::kInUse);
118 continue;
119 }
120 if (entry.value->LifeStage() == ProcessCacheValue::LifeStage::kDeletePending) {
121 entry.value->SetLifeStage(ProcessCacheValue::LifeStage::kDeleteReady);
122 mCacheExpireQueueProcessing[nextQueueSize++] = entry;
123 continue;
124 }
125 if (entry.value->LifeStage() == ProcessCacheValue::LifeStage::kDeleteReady) {
126 entry.value->SetLifeStage(ProcessCacheValue::LifeStage::kDeleted);
127 LOG_DEBUG(sLogger, ("clear expired cache pid", entry.key.pid)("ktime", entry.key.time));
128 removeCache(entry.key);
129 }
130 }
131 if (nextQueueSize > 0) {
132 mCacheExpireQueueProcessing.resize(nextQueueSize);
133 mCacheExpireQueue.insert(mCacheExpireQueue.end(),
134 std::make_move_iterator(mCacheExpireQueueProcessing.begin()),
135 std::make_move_iterator(mCacheExpireQueueProcessing.end()));
136 }
137 mCacheExpireQueueProcessing.clear();
138}
139
140void ProcessCache::ForceShrink() {
141 if (mLastForceShrinkTimeSec != 0 && mLastForceShrinkTimeSec > TimeKeeper::GetInstance()->NowSec() - 120) {

Calls 9

LifeStageMethod · 0.80
RefCountMethod · 0.80
SetLifeStageMethod · 0.80
insertMethod · 0.80
swapMethod · 0.45
emptyMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
clearMethod · 0.45