diff options
author | 2022-09-06 21:02:09 +0100 | |
---|---|---|
committer | 2022-09-16 20:14:46 +0000 | |
commit | 5494695148b63ab33e6e5e178dcef5fa6380116c (patch) | |
tree | 1d3b600c95254d6cf6f04126652ed7f6297a9e97 /runtime/exec_utils.h | |
parent | 6a73b2c1e2a5d007c7a34253c5586f995647de0e (diff) |
Add a function in ExecUtils to return wall time and CPU time.
Bug: 245380798
Test: m test-art-host-gtest-art_runtime_tests
Change-Id: I25d0d4c3dfaf24490c96ca650f076b2214597d2a
Merged-In: I25d0d4c3dfaf24490c96ca650f076b2214597d2a
(cherry picked from commit ebbd20c55adbdde7922c2ca402e1a04ed6ecee4c)
Diffstat (limited to 'runtime/exec_utils.h')
-rw-r--r-- | runtime/exec_utils.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/runtime/exec_utils.h b/runtime/exec_utils.h index 79a12d770a..751c64d9c8 100644 --- a/runtime/exec_utils.h +++ b/runtime/exec_utils.h @@ -26,6 +26,14 @@ namespace art { +struct ProcessStat { + // The total wall time, in milliseconds, that the process spent, or 0 if failed to get the value. + int wall_time_ms = 0; + // The total CPU time, in milliseconds, that the process and any waited-for children spent, or 0 + // if failed to get the value. + int cpu_time_ms = 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 @@ -49,8 +57,26 @@ class ExecUtils { /*out*/ bool* timed_out, /*out*/ std::string* error_msg) const; + // Same as above, but also collects stat of the process. 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, + /*out*/ bool* timed_out, + /*out*/ ProcessStat* stat, + /*out*/ std::string* error_msg) const; + protected: virtual android::base::unique_fd PidfdOpen(pid_t pid) const; + + // Returns the content of `/proc/<pid>/stat`, or an empty string if failed. + virtual std::string GetProcStat(pid_t pid) const; + + virtual int64_t GetUptimeMs() const; + + virtual int64_t GetTicksPerSec() const; + + private: + bool GetStat(pid_t pid, /*out*/ ProcessStat* stat, /*out*/ std::string* error_msg) const; }; inline bool Exec(const std::vector<std::string>& arg_vector, /*out*/ std::string* error_msg) { |