mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
21c95391ca
Reviewed By: igorsugak Differential Revision: D25861960 fbshipit-source-id: e3c39c080429058a58cdc66d45350e5d1420f98c
86 lines
2.3 KiB
C++
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
|