sapling/eden/fs/inodes/TreePrefetchLease.h
Stanislau Hlebik ea4e64864c fix one case of logging of null ClientPid
Summary:
Scuba logging that tracks undesired file fetches has some blind spots i.e. a
lot of fetches have null pid and null cmd line. This diff fixes at least part
of the problem.

TreePrefetchContext which is used from TreePrefetchLease didn't logged client
pid at all (in fact, it logged almost nothing). This diff fixes at least one blind spot, however it doesn't look like this is the only one.

Reviewed By: kmancini

Differential Revision: D23417451

fbshipit-source-id: 107884e94c6b40de999328ec2ef78fe22174c1ca
2020-08-31 10:05:02 -07:00

91 lines
2.5 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.
*/
#pragma once
#include "eden/fs/inodes/TreeInode.h"
#include "eden/fs/store/ImportPriority.h"
#include "eden/fs/store/ObjectFetchContext.h"
namespace facebook {
namespace eden {
/**
* TreePrefetchLease is a small helper class to track the total number of
* concurrent tree prefetch operations running in an EdenMount.
*
* When TreeInode wants to perform a prefetch it should call
* EdenMount::tryStartTreePrefetch() to obtain a prefetch lease. If it obtains
* a lease it can perform the prefetch, and should hold the TreePrefetchLease
* object around until the prefetch completes. When the TreePrefetchLease is
* destroyed this will inform the EdenMount that the prefetch is complete.
*/
class TreePrefetchLease {
class TreePrefetchContext : public ObjectFetchContext {
public:
TreePrefetchContext(
std::optional<pid_t> clientPid,
ObjectFetchContext::Cause cause)
: clientPid_(clientPid), cause_(cause) {}
ImportPriority getPriority() const override {
return ImportPriority::kLow();
}
std::optional<pid_t> getClientPid() const override {
return clientPid_;
}
ObjectFetchContext::Cause getCause() const override {
return cause_;
}
private:
std::optional<pid_t> clientPid_ = std::nullopt;
ObjectFetchContext::Cause cause_;
};
public:
explicit TreePrefetchLease(TreeInodePtr inode, ObjectFetchContext& context)
: inode_{std::move(inode)},
context_(std::make_unique<TreePrefetchContext>(
context.getClientPid(),
context.getCause())) {}
~TreePrefetchLease() {
release();
}
TreePrefetchLease(TreePrefetchLease&& lease) noexcept
: inode_{std::move(lease.inode_)}, context_(std::move(lease.context_)) {}
TreePrefetchLease& operator=(TreePrefetchLease&& lease) noexcept {
if (&lease != this) {
release();
inode_ = std::move(lease.inode_);
context_ = std::move(lease.context_);
}
return *this;
}
const TreeInodePtr& getTreeInode() const {
return inode_;
}
ObjectFetchContext& getContext() const {
return *context_;
}
private:
TreePrefetchLease(const TreePrefetchLease& lease) = delete;
TreePrefetchLease& operator=(const TreePrefetchLease& lease) = delete;
void release() noexcept;
TreeInodePtr inode_;
std::unique_ptr<ObjectFetchContext> context_;
};
} // namespace eden
} // namespace facebook