Skip to content

Commit 3da628b

Browse files
committed
help: improve feature descriptions
1 parent db243d9 commit 3da628b

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed

oi/Features.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,39 @@
1616
#include "Features.h"
1717

1818
#include <map>
19+
#include <numeric>
20+
#include <stdexcept>
1921

2022
namespace ObjectIntrospection {
23+
namespace {
24+
25+
std::string_view featureHelp(Feature f) {
26+
switch (f) {
27+
case Feature::ChaseRawPointers:
28+
return "Chase raw pointers in the probed object.";
29+
case Feature::PackStructs:
30+
return "Pack structs.";
31+
case Feature::GenPaddingStats:
32+
return "Generate statistics on padding of structures.";
33+
case Feature::CaptureThriftIsset:
34+
return "Capture isset data for Thrift object.";
35+
case Feature::TypeGraph:
36+
return "Use Type Graph for code generation (CodeGen V2).";
37+
case Feature::TypedDataSegment:
38+
return "Use Typed Data Segment in generated code.";
39+
case Feature::GenJitDebug:
40+
return "Generate debug information for the JIT object.";
41+
case Feature::JitLogging:
42+
return "Log information from the JIT code for debugging.";
43+
case Feature::PolymorphicInheritance:
44+
return "Follow polymorphic inheritance hierarchies in the probed object.";
45+
46+
case Feature::UnknownFeature:
47+
throw std::runtime_error("should not ask for help for UnknownFeature!");
48+
}
49+
}
50+
51+
} // namespace
2152

2253
Feature featureFromStr(std::string_view str) {
2354
static const std::map<std::string_view, Feature> nameMap = {
@@ -45,4 +76,20 @@ const char* featureToStr(Feature f) {
4576
}
4677
}
4778

79+
void featuresHelp(std::ostream& out) {
80+
out << "FEATURES SUMMARY" << std::endl;
81+
82+
size_t longestName = std::accumulate(
83+
allFeatures.begin(), allFeatures.end(), 0, [](size_t acc, Feature f) {
84+
return std::max(acc, std::string_view(featureToStr(f)).size());
85+
});
86+
87+
for (Feature f : allFeatures) {
88+
std::string_view name(featureToStr(f));
89+
90+
out << " " << name << std::string(longestName - name.size() + 2, ' ')
91+
<< featureHelp(f) << std::endl;
92+
}
93+
}
94+
4895
} // namespace ObjectIntrospection

oi/Features.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma once
1717

1818
#include <array>
19+
#include <ostream>
1920
#include <string_view>
2021

2122
#include "oi/EnumBitset.h"
@@ -42,6 +43,7 @@ enum class Feature {
4243

4344
Feature featureFromStr(std::string_view);
4445
const char* featureToStr(Feature);
46+
void featuresHelp(std::ostream& out);
4547

4648
constexpr std::array allFeatures = {
4749
#define X(name, _) Feature::name,

oi/OID.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,18 @@ constexpr static OIOpts opts{
145145
OIOpt{'a', "log-all-structs", no_argument, nullptr, "Log all structures"},
146146
OIOpt{'m', "mode", required_argument, "[prod]",
147147
"Allows to specify a mode of operation/group of settings"},
148-
OIOpt{'f', "enable-feature", required_argument, nullptr,
149-
"Enable a specific feature: ["
150-
#define X(name, str) str ","
151-
OI_FEATURE_LIST
152-
#undef X
153-
"]"},
154-
OIOpt{'F', "disable-feature", required_argument, nullptr,
155-
"Disable a specific feature: ["
156-
#define X(name, str) str ","
157-
OI_FEATURE_LIST
158-
#undef X
159-
"]"},
148+
OIOpt{'f', "enable-feature", required_argument, "FEATURE",
149+
"Enable feature"},
150+
OIOpt{'F', "disable-feature", required_argument, "FEATURE",
151+
"Disable feature"},
160152
};
161153

162154
void usage() {
163-
std::cout << "usage: oid ...\n";
164-
std::cout << opts;
155+
std::cerr << "usage: oid ...\n";
156+
std::cerr << opts << std::endl;
157+
featuresHelp(std::cerr);
165158

166-
std::cout << "\n\tFor problem reporting, questions and general comments "
159+
std::cerr << "\n\tFor problem reporting, questions and general comments "
167160
"please pop along"
168161
"\n\tto the Object Introspection Workplace group at "
169162
"https://fburl.com/oid.\n"

tools/OITB.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,10 @@ constexpr static OIOpts opts{
4242
OIOpt{'J', "dump-json", optional_argument, "[oid_out.json]",
4343
"File to dump the results to, as JSON\n"
4444
"(in addition to the default RocksDB output)"},
45-
OIOpt{'f', "enable-feature", required_argument, nullptr,
46-
"Enable a specific feature: ["
47-
#define X(name, str) str ","
48-
OI_FEATURE_LIST
49-
#undef X
50-
"]"},
51-
OIOpt{'F', "disable-feature", required_argument, nullptr,
52-
"Disable a specific feature: ["
53-
#define X(name, str) str ","
54-
OI_FEATURE_LIST
55-
#undef X
56-
"]"},
45+
OIOpt{'f', "enable-feature", required_argument, "FEATURE",
46+
"Enable feature"},
47+
OIOpt{'F', "disable-feature", required_argument, "FEATURE",
48+
"Disable feature"},
5749
};
5850

5951
static void usage(std::ostream& out) {
@@ -65,7 +57,8 @@ static void usage(std::ostream& out) {
6557

6658
out << "\nusage: oitb [opts...] [--] <path-th> <path-pd> "
6759
"<path-dataseg-dump>\n";
68-
out << opts;
60+
out << opts << std::endl;
61+
featuresHelp(out);
6962

7063
out << std::endl;
7164
}

0 commit comments

Comments
 (0)