sapling/eden/fs/telemetry/FsEventLogger.h
Zhengchao Liu 8fe7e16f7c log FS trace events with HiveLogger
Summary: This diff lets `FsEventLogger` send the sample through `HiveLogger`

Reviewed By: genevievehelsel

Differential Revision: D30305695

fbshipit-source-id: 88613dc6c74710cc0f33c44ce4e36c35c58e6406
2021-09-02 10:32:03 -07:00

59 lines
1.3 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 <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(
ReloadableConfig& edenConfig,
std::shared_ptr<IHiveLogger> logger);
void log(Event event);
private:
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