simpleperf: add --show-features option in list cmd.
It is used to show features supported on the device.
Bug: http://b/64147273
Test: run simpleperf_unit_test.
Change-Id: Idb7821e74d1a23f8988ef2207696114498713f47
diff --git a/simpleperf/cmd_list.cpp b/simpleperf/cmd_list.cpp
index 7aa0c96..7199814 100644
--- a/simpleperf/cmd_list.cpp
+++ b/simpleperf/cmd_list.cpp
@@ -26,6 +26,7 @@
#include "environment.h"
#include "event_attr.h"
#include "event_fd.h"
+#include "event_selection_set.h"
#include "event_type.h"
static bool IsEventTypeSupported(const EventType& event_type) {
@@ -92,11 +93,27 @@
public:
ListCommand()
: Command("list", "list available event types",
- "Usage: simpleperf list [hw|sw|cache|raw|tracepoint]\n"
- " List all available perf events on this machine.\n") {
+ // clang-format off
+"Usage: simpleperf list [options] [hw|sw|cache|raw|tracepoint]\n"
+" List all available event types.\n"
+" Filters can be used to show only event types belong to selected types:\n"
+" hw hardware events\n"
+" sw software events\n"
+" cache hardware cache events\n"
+" raw raw pmu events\n"
+" tracepoint tracepoint events\n"
+"Options:\n"
+"--show-features Show features supported on the device, including:\n"
+" dwarf-based-call-graph\n"
+" trace-offcpu\n"
+ // clang-format on
+ ) {
}
bool Run(const std::vector<std::string>& args) override;
+
+ private:
+ void ShowFeatures();
};
bool ListCommand::Run(const std::vector<std::string>& args) {
@@ -122,6 +139,9 @@
for (auto& arg : args) {
if (type_map.find(arg) != type_map.end()) {
names.push_back(arg);
+ } else if (arg == "--show-features") {
+ ShowFeatures();
+ return true;
} else {
LOG(ERROR) << "unknown event type category: " << arg << ", try using \"help list\"";
return false;
@@ -138,6 +158,15 @@
return true;
}
+void ListCommand::ShowFeatures() {
+ if (IsDwarfCallChainSamplingSupported()) {
+ printf("dwarf-based-call-graph\n");
+ }
+ if (IsDumpingRegsForTracepointEventsSupported()) {
+ printf("trace-offcpu\n");
+ }
+}
+
void RegisterListCommand() {
RegisterCommand("list", [] { return std::unique_ptr<Command>(new ListCommand); });
}
diff --git a/simpleperf/cmd_list_test.cpp b/simpleperf/cmd_list_test.cpp
index 2bc6421..3cc6712 100644
--- a/simpleperf/cmd_list_test.cpp
+++ b/simpleperf/cmd_list_test.cpp
@@ -39,3 +39,7 @@
TEST_F(ListCommandTest, multiple_options) {
ASSERT_TRUE(list_cmd->Run({"hw", "tracepoint"}));
}
+
+TEST_F(ListCommandTest, show_features_option) {
+ ASSERT_TRUE(list_cmd->Run({"--show-features"}));
+}