sapling/eden/fs/store/BackingStoreLogger.cpp
Andres Suarez 21c95391ca Apply clang-format update fixes
Reviewed By: igorsugak

Differential Revision: D25861960

fbshipit-source-id: e3c39c080429058a58cdc66d45350e5d1420f98c
2021-01-10 10:06:29 -08:00

86 lines
2.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.
*/
#include "eden/fs/store/BackingStoreLogger.h"
#include <folly/Conv.h>
#include "eden/fs/store/ObjectFetchContext.h"
#include "eden/fs/telemetry/LogEvent.h"
#include "eden/fs/telemetry/StructuredLogger.h"
#include "eden/fs/utils/ProcessNameCache.h"
#include "eden/fs/utils/UnboundedQueueExecutor.h"
namespace facebook {
namespace eden {
BackingStoreLogger::BackingStoreLogger(
std::shared_ptr<StructuredLogger> logger,
std::shared_ptr<ProcessNameCache> processNameCache)
: logger_{std::move(logger)},
processNameCache_{std::move(processNameCache)},
loggingAvailable_{true} {}
void BackingStoreLogger::logImport(
ObjectFetchContext& context,
RelativePathPiece importPath,
ObjectFetchContext::ObjectType fetchedType) {
if (!loggingAvailable_) {
return;
}
auto pid = context.getClientPid();
auto cause = context.getCause();
auto importPathString = importPath.stringPiece().str();
std::optional<std::string> cmdline;
if (pid) {
cmdline = processNameCache_->getSpacedProcessName(pid.value());
}
std::string cause_string = "<invalid>";
switch (cause) {
case ObjectFetchContext::Cause::Channel:
cause_string = "Channel";
break;
case ObjectFetchContext::Cause::Thrift:
cause_string = "Thrift";
break;
case ObjectFetchContext::Unknown:
cause_string = "Unknown";
}
if (auto causeDetail = context.getCauseDetail()) {
cause_string =
folly::to<std::string>(cause_string, " - ", causeDetail.value());
}
std::string typeString = "<invalid>";
switch (fetchedType) {
case ObjectFetchContext::ObjectType::Blob:
typeString = "Blob";
break;
case ObjectFetchContext::ObjectType::BlobMetadata:
typeString = "Blob Metadata";
break;
case ObjectFetchContext::ObjectType::Tree:
typeString = "Tree";
break;
case ObjectFetchContext::ObjectType::kObjectTypeEnumMax:
// invalid string prolly good here
break;
}
logger_->logEvent(ServerDataFetch{
std::move(cause_string),
pid,
std::move(cmdline),
std::move(importPathString),
std::move(typeString)});
}
} // namespace eden
} // namespace facebook