sapling/eden/fs/telemetry/StructuredLoggerFactory.cpp
Chad Austin e419dd2799 remove the reference-counting overhead from DurationScope
Summary:
DurationScope has a pair of atomic reference count operations at the
beginning and end of every recorded duration. To avoid that overhead,
reference EdenStats with RefPtr and, in production EdenFS, store a
global, unowned EdenStats object.

This gives us the benefits of explicit dependencies and no global
state in tests, while avoiding atomic RMWs in the release build.

Reviewed By: xavierd

Differential Revision: D44323723

fbshipit-source-id: 1b3384d2e6a0a2959fd79774a8ba46afc4c176ca
2023-03-24 13:50:40 -07:00

54 lines
1.7 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.
*/
#include "eden/fs/telemetry/StructuredLoggerFactory.h"
#include <fb303/ServiceData.h>
#include <folly/logging/xlog.h>
#include "eden/fs/config/EdenConfig.h"
#include "eden/fs/telemetry/EdenStats.h"
#include "eden/fs/telemetry/NullStructuredLogger.h"
#include "eden/fs/telemetry/ScubaStructuredLogger.h"
#include "eden/fs/telemetry/SubprocessScribeLogger.h"
namespace facebook::eden {
std::shared_ptr<StructuredLogger> makeDefaultStructuredLogger(
const EdenConfig& config,
SessionInfo sessionInfo,
EdenStatsPtr edenStats) {
const auto& binary = config.scribeLogger.getValue();
const auto& category = config.scribeCategory.getValue();
if (binary.empty()) {
return std::make_shared<NullStructuredLogger>();
}
if (category.empty()) {
XLOGF(
WARN,
"Scribe binary '{}' specified, but no category specified. Structured logging is disabled.",
binary);
return std::make_shared<NullStructuredLogger>();
}
try {
auto logger =
std::make_unique<SubprocessScribeLogger>(binary.c_str(), category);
return std::make_shared<ScubaStructuredLogger>(
std::move(logger), std::move(sessionInfo));
} catch (const std::exception& ex) {
edenStats->increment(&TelemetryStats::subprocessLoggerFailure, 1);
XLOGF(
ERR,
"Failed to create SubprocessScribeLogger: {}. Structured logging is disabled.",
folly::exceptionStr(ex));
return std::make_shared<NullStructuredLogger>();
}
}
} // namespace facebook::eden