| 482 | } |
| 483 | |
| 484 | CacheComponentStats RAMCacheComponent::getStats() const noexcept { |
| 485 | CacheComponentStats stats(*stats_); |
| 486 | |
| 487 | // Populate numItems from pool stats |
| 488 | stats.numItems = cache_->getPoolStats(defaultPool_).numItems(); |
| 489 | |
| 490 | // Populate removeByKey throughput from CacheAllocator's counters |
| 491 | auto& allocatorStats = cache_->stats(); |
| 492 | stats.removeByKey_.throughput_.calls_ = allocatorStats.numCacheRemoves.get(); |
| 493 | stats.removeByKey_.throughput_.hits_ = |
| 494 | allocatorStats.numCacheRemoveRamHits.get(); |
| 495 | stats.removeByKey_.throughput_.misses_ = |
| 496 | stats.removeByKey_.throughput_.calls_ - |
| 497 | stats.removeByKey_.throughput_.hits_; |
| 498 | |
| 499 | // Populate allocate latency from CacheAllocator's counter |
| 500 | stats.allocate_.latency_ = allocatorStats.allocateLatency_.estimate(); |
| 501 | |
| 502 | auto now = std::chrono::steady_clock::now(); |
| 503 | auto prev = std::exchange(lastStatsCollectionTime_, now); |
| 504 | cache_->exportStats( |
| 505 | /* statPrefix */ "", |
| 506 | std::chrono::duration_cast<std::chrono::seconds>(now - prev), |
| 507 | [&stats](folly::StringPiece name, uint64_t value) { |
| 508 | stats.extraStats_.insertCount(name.toString(), value); |
| 509 | }); |
| 510 | |
| 511 | return stats; |
| 512 | } |
| 513 | |
| 514 | } // namespace facebook::cachelib::interface |