Skip to content

Commit

Permalink
help: improve feature descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHillion committed Jul 3, 2023
1 parent 6aead62 commit edefa55
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
47 changes: 47 additions & 0 deletions oi/Features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions oi/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

#include <array>
#include <ostream>
#include <string_view>

#include "oi/EnumBitset.h"
Expand All @@ -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,
Expand Down
23 changes: 8 additions & 15 deletions oi/OID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 6 additions & 13 deletions tools/OITB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit edefa55

Please sign in to comment.