Skip to content

Commit

Permalink
Move the watcher helper function out of the ddprof CLI's responsibility
Browse files Browse the repository at this point in the history
  • Loading branch information
r1viollet committed Jun 21, 2023
1 parent 33ced9b commit 4b7e337
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 43 deletions.
4 changes: 3 additions & 1 deletion include/perf_watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@ int sample_type_id_to_count_sample_type_id(int idx);

// Helper functions, mostly for tests
uint64_t perf_event_default_sample_type();
void log_watcher(const PerfWatcher *w, int idx);
void log_watcher(const PerfWatcher *w, int idx);

std::string_view watcher_help_text();
43 changes: 1 addition & 42 deletions src/ddprof_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,7 @@ std::string api_key_to_dbg_string(const std::string_view value) {
} // namespace

//clang-format off
void DDProfCLI::help_events() {
std::cout << "\nEvent Configuration Documentation\n";
std::cout << "===================================\n";
std::cout << "Events define " MYNAME "'s instrumentation settings.\n\n";
std::cout << "General Syntax for Event Configuration:\n";
std::cout << "---------------------------------------\n";
std::cout << "Events are defined by their type and various parameters. The configuration follows this basic syntax:\n\n";
std::cout << "<type Of event> <key1>:<value1>\n";
std::cout << "or alternatively you can use a comma as a separator:\n";
std::cout << "<type Of event>,<key1>:<value1>\n\n";

std::cout << "Common Examples:\n";
std::cout << "----------------\n";
std::cout << "1. CPU profiling with a custom sampling frequency: `-e \"sCPU,p=50\"`\n";
std::cout << "2. Allocation tracking to monitor what's active in the application: `-e sALLOC,mode=l`\n\n";

std::cout << "Event Types:\n";
std::cout << "------------\n";
std::cout << "Please consult the `perf_watcher.hpp` file for a comprehensive list of available events. \n";
std::cout << "Note: Some events may require hardware support and elevated permissions.\n\n";

std::cout << "Configuration Keys:\n";
std::cout << "-------------------\n";
std::cout << "- `s|value_scale|scale`: Scaling factor for the event.\n";
std::cout << "- `f|frequency|freq`: Frequency at which the event occurs.\n";
std::cout << "- `e|event|eventname|ev`: Name of the event.\n";
std::cout << "- `g|group|groupname|gr`: Name of the group to which the event belongs.\n";
std::cout << "- `i|id`: Identifier for the event.\n";
std::cout << "- `l|label`: Label for the event.\n";
std::cout << "- `m|mode`: Mode of the event.\n";
std::cout << "- `n|arg_num|argno`: Argument number of the event.\n";
std::cout << "- `o|raw_offset|rawoff`: Raw offset of the event.\n";
std::cout << "- `p|period|per`: Period of the event.\n";
std::cout << "- `r|register|regno`: Register number of the event.\n";
std::cout << "- `z|raw_size|rawsz`: Raw size of the event.\n\n";

std::cout << "Disclaimer:\n";
std::cout << "-----------\n";
std::cout << "Please note that this documentation is currently under construction. We recommend the use of presets.\n";
std::cout << "Not all options may be fully supported within the Datadog UI at present, and the described grammar is subject to change.\n";
std::cout << "Exercise caution and double-check your configurations before implementation.\n";
}
void DDProfCLI::help_events() { std::cout << watcher_help_text(); }
//clang-format on

int DDProfCLI::parse(int argc, const char *argv[]) {
Expand Down
48 changes: 48 additions & 0 deletions src/perf_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,51 @@ void log_watcher(const PerfWatcher *w, int idx) {
if (Any(EventConfMode::kLiveCallgraph & w->output_mode))
PRINT_NFO(" Outputting to live callgraph");
}

std::string_view watcher_help_text() {
static const std::string help_text =
// clang-format off
"\nEvent Configuration Documentation\n"
"===================================\n"
"Events define " + std::string(MYNAME) + "'s instrumentation settings.\n\n"
"General Syntax for Event Configuration:\n"
"---------------------------------------\n"
"Events are defined by their type and associated key value settings:\n\n"
"<type Of event> <key1>:<value1>\n"
"Or using comma as a separator: \n"
"<type Of event>,<key1>:<value1>\n"
"Events are repeatable\n\n"
"Common Examples:\n"
"----------------\n"
"1. CPU profiling with a custom sampling frequency: -e \"sCPU p=50\"\n"
"2. Live Allocation Tracking (leak detection):\n"
" -e sALLOC,mode=l\n\n"
"Event Types:\n"
"------------\n"
"The most common types are:\n"
"- sCPU for CPU Time \n"
"- sALLOC for allocations (only available in wrapper mode) \n"
"Please consult the `https://github.com/DataDog/ddprof/blob/main/include/perf_watcher.hpp#L117-L138` for an up to date list of available events. \n"
"Note: Some events may require hardware support and elevated permissions.\n\n"
"Configuration Keys:\n"
"-------------------\n"
"- `s|value_scale|scale`: Scaling factor for the event.\n"
"- `f|frequency|freq`: Frequency at which the event occurs.\n"
"- `e|event|eventname|ev`: Name of the event.\n"
"- `g|group|groupname|gr`: Name of the group to which the event belongs.\n"
"- `i|id`: Identifier for the event.\n"
"- `l|label`: Label for the event.\n"
"- `m|mode`: Mode of the event.\n"
"- `n|arg_num|argno`: Argument number to retrieve a value associated with this event.\n"
"- `p|period|per`: Period of the event.\n"
"- `r|register|regno`: Register to retrieve the value associated with this event.\n"
"- `o|raw_offset|rawoff`: Raw offset to retrieve the value associated with this event.\n"
"- `z|raw_size|rawsz`: Raw size associated to raw offset.\n\n"
"Disclaimer:\n"
"-----------\n"
"Please note that this documentation is currently under construction. We recommend the use of presets.\n"
"Not all options may be fully supported within the Datadog UI at present, and the described grammar is subject to change.\n"
"Exercise caution and double-check your configurations before implementation.\n";
// clang-format on
return help_text;
}

0 comments on commit 4b7e337

Please sign in to comment.