diff options
author | Yabin Cui <yabinc@google.com> | 2015-06-01 11:21:37 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2015-06-04 15:26:32 -0700 |
commit | f79f07e13c56f7ca3be1435cea7f8861daf7efaa (patch) | |
tree | 8c76bac6fe4d9b52b69e57393f5deecb18febd97 /simpleperf/cmd_list.cpp | |
parent | d4637d6e7d17f48d9325fa133be82b06a408f523 (diff) | |
download | extras-f79f07e13c56f7ca3be1435cea7f8861daf7efaa.tar.gz |
Simpleperf: refactor command system.
Register a callback function to create a new command instance instead of
registering a command instance. Then we can release resources in the
command destructors, and don't need xxxCommandImpl classes any more.
Bug: 19483574
Change-Id: Ibb54892ec0655fd43909347afd72bb08bc8a716c
Diffstat (limited to 'simpleperf/cmd_list.cpp')
-rw-r--r-- | simpleperf/cmd_list.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/simpleperf/cmd_list.cpp b/simpleperf/cmd_list.cpp index 18c3972b..338ae266 100644 --- a/simpleperf/cmd_list.cpp +++ b/simpleperf/cmd_list.cpp @@ -56,16 +56,16 @@ bool ListCommand::Run(const std::vector<std::string>& args) { }; std::vector<std::string> names; - if (args.size() == 1) { + if (args.empty()) { for (auto& item : type_map) { names.push_back(item.first); } } else { - for (size_t i = 1; i < args.size(); ++i) { - if (type_map.find(args[i]) != type_map.end()) { - names.push_back(args[i]); + for (auto& arg : args) { + if (type_map.find(arg) != type_map.end()) { + names.push_back(arg); } else { - LOG(ERROR) << "unknown event type category: " << args[i] << ", try using \"help list\""; + LOG(ERROR) << "unknown event type category: " << arg << ", try using \"help list\""; return false; } } @@ -80,4 +80,6 @@ bool ListCommand::Run(const std::vector<std::string>& args) { return true; } -ListCommand list_command; +__attribute__((constructor)) static void RegisterListCommand() { + RegisterCommand("list", [] { return std::unique_ptr<Command>(new ListCommand); }); +} |