help: improve feature descriptions

This commit is contained in:
Jake Hillion 2023-07-03 08:02:51 -07:00 committed by Jake Hillion
parent db243d9845
commit 3da628b852
4 changed files with 63 additions and 28 deletions

View File

@ -16,8 +16,39 @@
#include "Features.h"
#include <map>
#include <numeric>
#include <stdexcept>
namespace ObjectIntrospection {
namespace {
std::string_view featureHelp(Feature f) {
switch (f) {
case Feature::ChaseRawPointers:
return "Chase raw pointers in the probed object.";
case Feature::PackStructs:
return "Pack structs.";
case Feature::GenPaddingStats:
return "Generate statistics on padding of structures.";
case Feature::CaptureThriftIsset:
return "Capture isset data for Thrift object.";
case Feature::TypeGraph:
return "Use Type Graph for code generation (CodeGen V2).";
case Feature::TypedDataSegment:
return "Use Typed Data Segment in generated code.";
case Feature::GenJitDebug:
return "Generate debug information for the JIT object.";
case Feature::JitLogging:
return "Log information from the JIT code for debugging.";
case Feature::PolymorphicInheritance:
return "Follow polymorphic inheritance hierarchies in the probed object.";
case Feature::UnknownFeature:
throw std::runtime_error("should not ask for help for UnknownFeature!");
}
}
} // namespace
Feature featureFromStr(std::string_view str) {
static const std::map<std::string_view, Feature> nameMap = {
@ -45,4 +76,20 @@ const char* featureToStr(Feature f) {
}
}
void featuresHelp(std::ostream& out) {
out << "FEATURES SUMMARY" << std::endl;
size_t longestName = std::accumulate(
allFeatures.begin(), allFeatures.end(), 0, [](size_t acc, Feature f) {
return std::max(acc, std::string_view(featureToStr(f)).size());
});
for (Feature f : allFeatures) {
std::string_view name(featureToStr(f));
out << " " << name << std::string(longestName - name.size() + 2, ' ')
<< featureHelp(f) << std::endl;
}
}
} // namespace ObjectIntrospection

View File

@ -16,6 +16,7 @@
#pragma once
#include <array>
#include <ostream>
#include <string_view>
#include "oi/EnumBitset.h"
@ -42,6 +43,7 @@ enum class Feature {
Feature featureFromStr(std::string_view);
const char* featureToStr(Feature);
void featuresHelp(std::ostream& out);
constexpr std::array allFeatures = {
#define X(name, _) Feature::name,

View File

@ -145,25 +145,18 @@ constexpr static OIOpts opts{
OIOpt{'a', "log-all-structs", no_argument, nullptr, "Log all structures"},
OIOpt{'m', "mode", required_argument, "[prod]",
"Allows to specify a mode of operation/group of settings"},
OIOpt{'f', "enable-feature", required_argument, nullptr,
"Enable a specific feature: ["
#define X(name, str) str ","
OI_FEATURE_LIST
#undef X
"]"},
OIOpt{'F', "disable-feature", required_argument, nullptr,
"Disable a specific feature: ["
#define X(name, str) str ","
OI_FEATURE_LIST
#undef X
"]"},
OIOpt{'f', "enable-feature", required_argument, "FEATURE",
"Enable feature"},
OIOpt{'F', "disable-feature", required_argument, "FEATURE",
"Disable feature"},
};
void usage() {
std::cout << "usage: oid ...\n";
std::cout << opts;
std::cerr << "usage: oid ...\n";
std::cerr << opts << std::endl;
featuresHelp(std::cerr);
std::cout << "\n\tFor problem reporting, questions and general comments "
std::cerr << "\n\tFor problem reporting, questions and general comments "
"please pop along"
"\n\tto the Object Introspection Workplace group at "
"https://fburl.com/oid.\n"

View File

@ -42,18 +42,10 @@ constexpr static OIOpts opts{
OIOpt{'J', "dump-json", optional_argument, "[oid_out.json]",
"File to dump the results to, as JSON\n"
"(in addition to the default RocksDB output)"},
OIOpt{'f', "enable-feature", required_argument, nullptr,
"Enable a specific feature: ["
#define X(name, str) str ","
OI_FEATURE_LIST
#undef X
"]"},
OIOpt{'F', "disable-feature", required_argument, nullptr,
"Disable a specific feature: ["
#define X(name, str) str ","
OI_FEATURE_LIST
#undef X
"]"},
OIOpt{'f', "enable-feature", required_argument, "FEATURE",
"Enable feature"},
OIOpt{'F', "disable-feature", required_argument, "FEATURE",
"Disable feature"},
};
static void usage(std::ostream& out) {
@ -65,7 +57,8 @@ static void usage(std::ostream& out) {
out << "\nusage: oitb [opts...] [--] <path-th> <path-pd> "
"<path-dataseg-dump>\n";
out << opts;
out << opts << std::endl;
featuresHelp(out);
out << std::endl;
}