sapling/eden/fs/telemetry/FsEventLogger.h
Michael Cuevas 8cb3a150e9 refactor ServerState constructor
Summary:
Our aim is to construct as few things as possible in the ServerState constructor. Instead, we should preconstruct these objects, create shared pointers, and pass those into the ServerState constructor. This will allow us to pass in "null" pointers to ServerState for testing purposes in the future.

In this diff, we preconstruct a shared_ptr<ReloadableConfig> inside EdenServer so that we can pass it to the ServerState constructor.

Reviewed By: chadaustin

Differential Revision: D34541321

fbshipit-source-id: 99465fe08099ed95179e56b2e39a97ab68112733
2022-03-01 17:52:58 -08:00

59 lines
1.3 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and 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 <chrono>
#include <vector>
#include <folly/Synchronized.h>
#include "folly/Range.h"
namespace facebook::eden {
// `telemetry:request-sampling-group-denominators` should be
// maintained in ascending order so that the higher the sampling group
// the higher the sampling rate.
enum class SamplingGroup : uint32_t {
DropAll = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
};
class ReloadableConfig;
class IHiveLogger;
class FsEventLogger {
public:
struct Event {
std::chrono::nanoseconds durationNs;
SamplingGroup samplingGroup;
folly::StringPiece cause;
};
FsEventLogger(
std::shared_ptr<ReloadableConfig> edenConfig,
std::shared_ptr<IHiveLogger> logger);
void log(Event event);
private:
std::shared_ptr<ReloadableConfig> edenConfig_;
std::shared_ptr<IHiveLogger> logger_;
std::atomic<uint32_t> samplesCount_{0};
std::atomic<std::chrono::steady_clock::time_point> counterStartTime_;
folly::Synchronized<std::string> configsString_;
std::atomic<std::chrono::steady_clock::time_point> configsStringUpdateTime_;
};
} // namespace facebook::eden