diff --git a/oi/Features.cpp b/oi/Features.cpp index 644e7ce..f3bab9f 100644 --- a/oi/Features.cpp +++ b/oi/Features.cpp @@ -16,8 +16,39 @@ #include "Features.h" #include +#include +#include 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 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 diff --git a/oi/Features.h b/oi/Features.h index 391b4c8..56b25b6 100644 --- a/oi/Features.h +++ b/oi/Features.h @@ -16,6 +16,7 @@ #pragma once #include +#include #include #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, diff --git a/oi/OID.cpp b/oi/OID.cpp index b9cba6f..ed02305 100644 --- a/oi/OID.cpp +++ b/oi/OID.cpp @@ -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" diff --git a/tools/OITB.cpp b/tools/OITB.cpp index ba6adf1..0adeddd 100644 --- a/tools/OITB.cpp +++ b/tools/OITB.cpp @@ -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...] [--] " "\n"; - out << opts; + out << opts << std::endl; + featuresHelp(out); out << std::endl; }