diff options
author | Yabin Cui <yabinc@google.com> | 2017-07-14 15:59:56 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2017-07-14 17:58:51 -0700 |
commit | 616b3a020bf708f364e0608107ded083930ac6b4 (patch) | |
tree | cf7de582ecda3ec87fe4a9f35b71f55aa996fe56 /simpleperf/command.cpp | |
parent | 9aa1dc2f3039db9faee9d581360a5d65caddb8f4 (diff) | |
download | extras-616b3a020bf708f364e0608107ded083930ac6b4.tar.gz |
simpleperf: change the way running cts tests.
Before this CL, CtsSimpleperfTestCases copies itself to the app's
directory, then run it using run-as.
With this CL, CtsSimpleperfTestCases keeps itself in /data/local/tmp,
but forces stat/record cmd to run with --app option. This gives
more freedom to tests:
1. They can stay in shell's context with --in-app option.
2. The stat/record cmds are started in the shell's context, so
they can collect information no available in app's context (like
data in /sys/kernel/debug/tracing/events).
This is a preparation to add tests for recording tracepoint events.
It also matches the way we want users to use simpleperf (with --app option).
Bug: http://b/29520177
Test: run CtsSimpleperfTestCases.
Change-Id: I1709adfb1ff7169df87560226c197e473fdf8516
Diffstat (limited to 'simpleperf/command.cpp')
-rw-r--r-- | simpleperf/command.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/simpleperf/command.cpp b/simpleperf/command.cpp index f5d4e8bd..034163f9 100644 --- a/simpleperf/command.cpp +++ b/simpleperf/command.cpp @@ -23,6 +23,8 @@ #include <android-base/logging.h> +#include "utils.h" + bool Command::NextArgumentOrError(const std::vector<std::string>& args, size_t* pi) { if (*pi + 1 == args.size()) { LOG(ERROR) << "No argument following " << args[*pi] << " option. Try `simpleperf help " << name_ @@ -95,3 +97,49 @@ class CommandRegister { }; CommandRegister command_register; + +bool RunSimpleperfCmd(int argc, char** argv) { + android::base::InitLogging(argv, android::base::StderrLogger); + std::vector<std::string> args; + android::base::LogSeverity log_severity = android::base::INFO; + + for (int i = 1; i < argc; ++i) { + if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { + args.insert(args.begin(), "help"); + } else if (strcmp(argv[i], "--log") == 0) { + if (i + 1 < argc) { + ++i; + if (!GetLogSeverity(argv[i], &log_severity)) { + LOG(ERROR) << "Unknown log severity: " << argv[i]; + return false; + } + } else { + LOG(ERROR) << "Missing argument for --log option.\n"; + return false; + } + } else if (strcmp(argv[i], "--version") == 0) { + LOG(INFO) << "Simpleperf version " << GetSimpleperfVersion(); + return true; + } else { + args.push_back(argv[i]); + } + } + android::base::ScopedLogSeverity severity(log_severity); + + if (args.empty()) { + args.push_back("help"); + } + std::unique_ptr<Command> command = CreateCommandInstance(args[0]); + if (command == nullptr) { + LOG(ERROR) << "malformed command line: unknown command " << args[0]; + return false; + } + std::string command_name = args[0]; + args.erase(args.begin()); + + LOG(DEBUG) << "command '" << command_name << "' starts running"; + bool result = command->Run(args); + LOG(DEBUG) << "command '" << command_name << "' " + << (result ? "finished successfully" : "failed"); + return result; +} |