mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
340866508b
Summary: In the code base, "channel" is used to denote the OS mechanism that sends EdenFS notifications. In macOS and Linux, that's Fuse, on Windows, that's ProjectedFS. To avoid platform specific naming in ObjectedFetchContext, let's rename the fetch cause enum. Reviewed By: kmancini Differential Revision: D23462460 fbshipit-source-id: 3ac68cdf4999e6a3b4ff4ee266f94e1f9736df39
87 lines
2.5 KiB
C++
87 lines
2.5 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) {
|
|
#ifndef _WIN32
|
|
cmdline = processNameCache_->getSpacedProcessName(pid.value());
|
|
#endif
|
|
}
|
|
|
|
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
|