sapling/eden/fs/store/BackingStoreLogger.cpp
Xavier Deguillard d8d841ae80 prjfs: add partial support for debug processfetch on Windows
Summary:
This will enable to gather a bit more debugging regarding what processes are
fetching data. The one missing bit on Windows is to collect the process name,
for now, a "NOT IMPLEMENTED" placeholder is put in place.

Reviewed By: wez

Differential Revision: D23946258

fbshipit-source-id: 9f7642c7b9207c5b48ffff0f4eb0333af00bc7d5
2020-10-05 15:46:02 -07:00

85 lines
2.4 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