sapling/eden/fs/store/StatsFetchContext.h
Chad Austin 49385c8a07 store: namespace facebook::eden
Summary: C++17

Reviewed By: fanzeyi

Differential Revision: D28966939

fbshipit-source-id: c8c9d49bc02557263a6acf9357c90b50e04fbdb9
2021-06-08 19:29:37 -07:00

77 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.
*/
#pragma once
#include <atomic>
#include <optional>
#include "eden/fs/store/ObjectFetchContext.h"
namespace facebook::eden {
struct FetchStatistics {
struct Access {
/**
* Total number of object accesses, including cache hits.
*/
uint64_t accessCount = 0;
/**
* Number of object fetches from the backing store.
*/
uint64_t fetchCount = 0;
/**
* In range [0, 100]. unsigned char is big enough, but prints as a
* character.
*/
unsigned short cacheHitRate = 0;
};
Access tree;
Access blob;
Access metadata;
};
class StatsFetchContext : public ObjectFetchContext {
public:
StatsFetchContext() = default;
StatsFetchContext(
std::optional<pid_t> pid,
Cause cause,
folly::StringPiece causeDetail);
StatsFetchContext(const StatsFetchContext& other);
void didFetch(ObjectType type, const Hash& id, Origin origin) override;
std::optional<pid_t> getClientPid() const override;
Cause getCause() const override;
std::optional<folly::StringPiece> getCauseDetail() const override;
uint64_t countFetchesOfType(ObjectType type) const;
uint64_t countFetchesOfTypeAndOrigin(ObjectType type, Origin origin) const;
FetchStatistics computeStatistics() const;
/**
* Sums the counts from another fetch context into this one.
*/
void merge(const StatsFetchContext& other);
private:
std::atomic<uint64_t> counts_[ObjectFetchContext::kObjectTypeEnumMax]
[ObjectFetchContext::kOriginEnumMax] = {};
std::optional<pid_t> clientPid_ = std::nullopt;
Cause cause_ = Cause::Unknown;
folly::StringPiece causeDetail_;
};
} // namespace facebook::eden