sapling/eden/fs/inodes/RequestContext.cpp
Zhengchao Liu 067abe2d55 collect memory and disk fetch counts
Summary: This adds counters for memory and disk counts in addition to import count so that we can understand cache hit rates during local investigation or output this in ActivityRecorder.

Reviewed By: genevievehelsel

Differential Revision: D29805637

fbshipit-source-id: 34261f91c33d6bd4bcb4b85b17d2e68360410896
2021-07-21 21:37:20 -07:00

74 lines
2.0 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "eden/fs/inodes/RequestContext.h"
#include <folly/logging/xlog.h>
#include "eden/fs/notifications/Notifications.h"
#include "eden/fs/telemetry/RequestMetricsScope.h"
#include "eden/fs/utils/SystemError.h"
using namespace std::chrono;
namespace facebook::eden {
void RequestContext::startRequest(
EdenStats* stats,
ChannelThreadStats::StatPtr stat,
std::shared_ptr<RequestMetricsScope::LockedRequestWatchList>&
requestWatches) {
startTime_ = steady_clock::now();
XDCHECK(latencyStat_ == nullptr);
latencyStat_ = stat;
stats_ = stats;
channelThreadLocalStats_ = requestWatches;
if (channelThreadLocalStats_) {
requestMetricsScope_ = RequestMetricsScope(channelThreadLocalStats_.get());
}
}
void RequestContext::finishRequest() {
const auto now = steady_clock::now();
const auto diff = now - startTime_;
const auto diff_us = duration_cast<microseconds>(diff);
const auto diff_ns = duration_cast<nanoseconds>(diff);
stats_->getChannelStatsForCurrentThread().recordLatency(
latencyStat_, diff_us);
latencyStat_ = nullptr;
stats_ = nullptr;
if (channelThreadLocalStats_) {
{ auto temp = std::move(requestMetricsScope_); }
channelThreadLocalStats_.reset();
}
if (auto pid = getClientPid(); pid.has_value()) {
switch (getEdenTopStats().getFetchOrigin()) {
case Origin::FromMemoryCache:
pal_.recordAccess(
*pid, ProcessAccessLog::AccessType::FsChannelMemoryCacheImport);
break;
case Origin::FromDiskCache:
pal_.recordAccess(
*pid, ProcessAccessLog::AccessType::FsChannelDiskCacheImport);
break;
case Origin::FromBackingStore:
pal_.recordAccess(
*pid, ProcessAccessLog::AccessType::FsChannelBackingStoreImport);
break;
default:
break;
}
pal_.recordDuration(*pid, diff_ns);
}
}
} // namespace facebook::eden