mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
e97f1c7240
Summary: This adds logging for data fetches that come from the thrift checkout call to help debug the cause of unexpected data fetches. (See D22448048 for more motivation) Reviewed By: chadaustin Differential Revision: D22489504 fbshipit-source-id: 3b732a1e5627c2130f561ec0138a1df270e1925d
79 lines
1.8 KiB
C++
79 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 {
|
|
namespace 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 eden
|
|
} // namespace facebook
|