sapling/eden/fs/inodes/RequestContext.cpp
Xavier Deguillard 0904c05535 win: plumb PrjfsRequestContext in the notification callback
Summary:
Now that all the pieces are in place, we can plumb the request context in. For
now, this adds it to only one callback as I figure out more about it and tweak
it until I have something satisfactory. There are some rough edges with it that
I'm not entirely happy about, but as I change the notification callback to be
more async, I'm hoping to make more convenient to use and less clanky.

Reviewed By: fanzeyi

Differential Revision: D23505508

fbshipit-source-id: d5f12e22a8f67dfa061b8ad82ea718582c323b45
2020-09-16 18:59:24 -07:00

65 lines
1.8 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 folly;
using namespace std::chrono;
namespace facebook::eden {
void RequestContext::startRequest(
EdenStats* stats,
ChannelThreadStats::HistogramPtr histogram,
std::shared_ptr<RequestMetricsScope::LockedRequestWatchList>&
requestWatches) {
startTime_ = steady_clock::now();
DCHECK(latencyHistogram_ == nullptr);
latencyHistogram_ = histogram;
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(
latencyHistogram_, diff_us);
latencyHistogram_ = nullptr;
stats_ = nullptr;
if (channelThreadLocalStats_) {
{
auto temp = std::move(requestMetricsScope_);
}
channelThreadLocalStats_.reset();
}
if (auto pid = getClientPid(); pid.has_value()) {
if (getEdenTopStats().didImportFromBackingStore()) {
auto type = ProcessAccessLog::AccessType::FsChannelBackingStoreImport;
pal_.recordAccess(*pid, type);
}
pal_.recordDuration(*pid, diff_ns);
}
}
} // namespace facebook::eden