MCPcopy Create free account
hub / github.com/facebook/CacheLib / recordEvent

Method recordEvent

cachelib/navy/block_cache/BlockCache.cpp:1065–1116  ·  view source on GitHub ↗

* Record event, key, result, size and info from nvmItem. * * @param key The key associated with the event. * @param event The event of type AllocatorApiEvent. * @param result The result of type AllocatorApiResult. * @param size The size of the item in NVM. * @param params Optional struct of type EventRecordParams. * * @return

Source from the content-addressed store, hash-verified

1063 * @return void
1064 */
1065void BlockCache::recordEvent(folly::StringPiece key,
1066 AllocatorApiEvent event,
1067 AllocatorApiResult result,
1068 uint32_t size,
1069 const NvmItem* nvmItem) {
1070 auto eventTracker = getEventTracker();
1071 if (eventTracker) {
1072 if (!eventTracker->sampleKey(key)) {
1073 return;
1074 }
1075 EventInfo eventInfo;
1076 eventInfo.event = event;
1077 eventInfo.result = result;
1078 eventInfo.size = size;
1079 eventInfo.key = key;
1080
1081 // Extract additional information from NvmItem if available
1082 if (nvmItem) {
1083 eventInfo.poolId = nvmItem->poolId();
1084 const auto expiryTime = nvmItem->getExpiryTime();
1085 const auto creationTime = nvmItem->getCreationTime();
1086
1087 // expiryTime == 0 means no TTL was set for this item
1088 if (expiryTime != 0) {
1089 eventInfo.expiryTime = expiryTime;
1090
1091 // Calculate configured TTL from expiryTime and creationTime
1092 // TTL = expiryTime - creationTime
1093 if (expiryTime > creationTime) {
1094 eventInfo.ttlSecs = expiryTime - creationTime;
1095 }
1096
1097 // Calculate time to expire from current time
1098 const auto currentTime = util::getCurrentTimeSec();
1099 if (expiryTime > currentTime) {
1100 eventInfo.timeToExpire =
1101 static_cast<uint32_t>(expiryTime - currentTime);
1102 }
1103 }
1104
1105 // Access the allocation size of the item being stored
1106 if (nvmItem->getNumBlobs() > 0) {
1107 const auto blob = nvmItem->getBlob(0);
1108 eventInfo.allocSize = blob.origAllocSize;
1109 }
1110 }
1111
1112 eventTracker->recordWithoutSampling(std::move(eventInfo));
1113 } else if (legacyEventTracker_.has_value()) {
1114 legacyEventTracker_->get().record(event, key, result, size);
1115 }
1116}
1117
1118/**
1119 * Reinsert or remove an item during region reclaim.

Callers

nothing calls this directly

Calls 9

getCurrentTimeSecFunction · 0.85
sampleKeyMethod · 0.80
poolIdMethod · 0.80
getBlobMethod · 0.80
recordWithoutSamplingMethod · 0.80
getExpiryTimeMethod · 0.45
getCreationTimeMethod · 0.45
recordMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected