summaryrefslogtreecommitdiff
path: root/runtime/exec_utils.h
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2022-09-13 14:14:16 +0100
committer Treehugger Robot <treehugger-gerrit@google.com> 2022-09-16 20:14:46 +0000
commit1a8cc460546a3bf5f55acf46efb5073d5ed412d3 (patch)
tree24c2ffff1efae12e9f6f10c5a8df74b8ff7a2e0e /runtime/exec_utils.h
parent4c9498e8f1c8ef8c54cfd7462e24a505690cdc10 (diff)
odrefresh: Report dex2oat result for each stage.
This is the first step to improve odrefresh metrics collection. More CLs will follow. After the change, the metrics should tell: - whether dex2oat is invoked or not - whether dex2oat crashed or exited with a code Partially cherry-picked from commit fa152ba922a6301a10671d4684b75fe8cb2a2330 Bug: 246534524 Test: m test-art-host-gtest-art_runtime_tests Test: atest ArtGtestsTargetChroot:OdRefreshTest Merged-In: Id962a6e6a765371d290a836c51059d725c9250f3 Change-Id: I69ddf64552d4f2e51e111a40871890d41c88721d
Diffstat (limited to 'runtime/exec_utils.h')
-rw-r--r--runtime/exec_utils.h45
1 files changed, 33 insertions, 12 deletions
diff --git a/runtime/exec_utils.h b/runtime/exec_utils.h
index aa0d0fc932..c280e3e26f 100644
--- a/runtime/exec_utils.h
+++ b/runtime/exec_utils.h
@@ -43,6 +43,29 @@ struct ExecCallbacks {
std::function<void(pid_t pid)> on_end = [](pid_t) {};
};
+struct ExecResult {
+ enum Status {
+ // Unable to get the status.
+ kUnknown = 0,
+ // Process exited normally with an exit code.
+ kExited = 1,
+ // Process terminated by a signal.
+ kSignaled = 2,
+ // Process timed out and killed.
+ kTimedOut = 3,
+ // Failed to start the process.
+ kStartFailed = 4,
+ };
+
+ Status status = kUnknown;
+
+ // The process exit code, if `status` is `kExited`, or -1.
+ int exit_code = -1;
+
+ // The signal that terminated the process, if `status` is `kSignaled`, or 0.
+ int signal = 0;
+};
+
// Wrapper on fork/execv to run a command in a subprocess.
// These spawn child processes using the environment as it was set when the single instance
// of the runtime (Runtime::Current()) was started. If no instance of the runtime was started, it
@@ -59,21 +82,19 @@ class ExecUtils {
// Executes the command specified in `arg_vector` in a subprocess with a timeout.
// If `timeout_sec` is negative, blocks until the subprocess exits.
- // Returns the process exit code on success, -1 otherwise.
- // Sets `timed_out` to true if the process times out, or false otherwise.
- virtual int ExecAndReturnCode(const std::vector<std::string>& arg_vector,
- int timeout_sec,
- /*out*/ bool* timed_out,
- /*out*/ std::string* error_msg) const;
+ // Returns a structured result. If the status is not `kExited`, also returns a non-empty
+ // `error_msg`.
+ virtual ExecResult ExecAndReturnResult(const std::vector<std::string>& arg_vector,
+ int timeout_sec,
+ /*out*/ std::string* error_msg) const;
// Same as above, but also collects stat of the process and calls callbacks. The stat is collected
// no matter the child process succeeds or not.
- virtual int ExecAndReturnCode(const std::vector<std::string>& arg_vector,
- int timeout_sec,
- const ExecCallbacks& callbacks,
- /*out*/ bool* timed_out,
- /*out*/ ProcessStat* stat,
- /*out*/ std::string* error_msg) const;
+ virtual ExecResult ExecAndReturnResult(const std::vector<std::string>& arg_vector,
+ int timeout_sec,
+ const ExecCallbacks& callbacks,
+ /*out*/ ProcessStat* stat,
+ /*out*/ std::string* error_msg) const;
protected:
virtual android::base::unique_fd PidfdOpen(pid_t pid) const;