summaryrefslogtreecommitdiff
path: root/runtime/exec_utils.h
AgeCommit message (Collapse)Author
2024-09-20Report dex2oat metrics to StatsD when dexopting Stefano Cianciulli
Bug: 327134025 Test: atest art_standalone_artd_tests && atest ArtServicesTest Change-Id: I4212899e78c23d8ff8c0307f9699f6b772c50000
2024-08-12Fix big negative dex2oatWallTimeMillis. Jiakai Zhang
We calculate dex2oatWallTimeMillis by (uptime - starttime). To get a reasonable result, both times need to be from the same clock. However, it's unclear which clock the kernel uses for the latter. proc_pid_stat(5) does not have anything helpful on this matter: (22) starttime %llu The time the process started after system boot. Before Linux 2.6, this value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock ticks (divide by sysconf(_SC_CLK_TCK)). The format for this field was %lu before Linux 2.6. To make sure we use the same clock, we obtain the uptime on process start as the start time. Bug: 315061143 Test: Presubmit Change-Id: I5f344e953a945656474b3f625368c1ccb5aa52d8
2024-06-11Use process groups to manage artd's subprocesses. Jiakai Zhang
This change adds a new option `new_process_group` to ExecUtils, and this option is only used by artd to manage its subprocesses. artd creates a process group for each child process and its descendants, and it uses `kill(-pid, SIGKILL)` to kill the whole process group upon job cancellation. Before this change, ExecUtils always creates a new process group for a child process. This behavior can be dated back to https://android.googlesource.com/platform/art/+/5643b786dd48df1f4b89a39e6024a22d032c79d4%5E%21/. A comment on the `setpgid` call says: "change process groups, so we don't get reaped by ProcessManager". We cannot find out why changing the process group was needed or how process reaping was related to process groups at that time because there isn't such a thing called "ProcessManager" in Android anymore. However, we don't need this behavior today because the usage of the code that does fork and exec has completely changed. At the time where the original CL was submitted, the code was for the runtime to generate a persistent boot image on /data. Today, the runtime never generates a persistent boot image because it's considered insecure. Today, ExecUtils is mostly used in tests. Other than tests, it's only used in four places: Zygote, odrefresh, artd, and dexopt_chroot_setup. - Zygote uses it to call dex2oat to create an in-memory boot image. It doesn't make sense to keep dex2oat running when Zygote (the memfd owner) is killed. - odrefresh uses it to call dex2oat to create persistent boot images. We do want to kill dex2oat when killing odrefresh. - artd uses it to call dex2oat, profman, derive_classpath, and odrefresh. It sets `new_process_group` to true, so it's behavior regarding process groups is unchanged. It's a service managed by the service manager. The service manager uses cgroups, not process grups, to manage and kill processes, so creating new process groups for artd's children is fine. - dexopt_chroot_setup uses it to call apexd and linkerconfig. We do want to kill apexd and linkerconfig when dexopt_chroot_setup is killed. Therefore, changing this behavior is fine. After this change, ExecUtils no longer creates a new process group for a child process unless `new_process_group` is set to true. Bug: 345723405 Bug: 311377497 Test: m test-art-host-gtest-art_runtime_tests Test: m test-art-host-gtest-art_artd_tests Test: - 1. adb shell pm compile -m speed -f -v com.android.settings 2. adb shell pm art cancel <job-id> 3. No change to the existing behavior: dex2oat is still killed. Test: - 1. adb shell pm art pr-dexopt-job --run 2. Press Ctrl+C. 3. Both odrefresh and dex2oat are killed. Change-Id: I3058fc68a6bd5f98617422c1eb0861648b144a51
2024-01-18Add visibility attributes in runtime/e* Dmitrii Ishcheikin
Bug: 260881207 Test: presubmit Test: abtd app_compat_drm Test: abtd app_compat_top_100 Test: abtd app_compat_banking Change-Id: I0eca5c4fd64ec61388eded9b9e066091581e0c7e
2023-12-07Make ProcessStat collection more robust. Jiakai Zhang
- Handle the case where start time is 0. - Handle the case where getting uptime failed. - Use 64bit int. (32bit is enough to record a time less than 24 days, but just in case.) Bug: 315061143 Test: m test-art-host-gtest-art_runtime_tests Change-Id: I3ac546f6921b8d6add2491170b5d8f50cc7169c1
2023-04-26Report Odrefresh BCP compilation type to StatsD Stefano Cianciulli
Bug: 279004055 Test: atest art_standalone_odrefresh_tests Change-Id: If563943ddbce706dc81fda7a11c78ac4c067fa9a
2022-10-18Report Odrefresh compilation status, exit code and signal to statsd Stefano Cianciulli
As part of the changes done in aosp/2223024, we are now collecting some additional information about the compilation for primary/secondary architecture and system_server in dex2oat: - result status - exit code (if status is Exited) - signal (if status is Signaled) This CL reports this new data points to statsd as part of the already existing OdrefreshReported atom, so that this new information can be extracted and analysed. Bug: 246534524 Test: atest ArtGtestsTargetChroot (in particular art_standalone_odrefresh_tests) Change-Id: I9705845a6bae0716d091400adde6415c20eda3de
2022-09-16odrefresh: Report dex2oat result for each stage. Jiakai Zhang
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
2022-09-16Change ExecUtils to support callbacks. Jiakai Zhang
artd needs the callbacks to get the pid in order to kill the subprocess. Partially cherry-picked from commit 659f49bdb1263ceb26f666052f3ef7e4732b4eb2 Bug: 244412198 Test: m test-art-host-gtest-art_runtime_tests Merged-In: I8c40949b5ed88ff85ddedad9d86f0b9bbfddb98d Change-Id: Ia28410bdf6314178756ee5e3a94000dc6f3ecc97
2022-09-16Add a function in ExecUtils to return wall time and CPU time. Jiakai Zhang
Bug: 245380798 Test: m test-art-host-gtest-art_runtime_tests Change-Id: I25d0d4c3dfaf24490c96ca650f076b2214597d2a Merged-In: I25d0d4c3dfaf24490c96ca650f076b2214597d2a (cherry picked from commit ebbd20c55adbdde7922c2ca402e1a04ed6ecee4c)
2022-07-11Fix ExecUtils.WaitChildWithTimeoutFallback by adding a fallback. Jiakai Zhang
`WaitChildWithTimeout` didn't work with old Linux kernels because it uses a syscall `pidfd_open`, which was added in Linux 5.4. This change adds a fallback implementation of `WaitChildWithTimeout` that creates a thread to wait instead of relying on `pidfd_open`. Also: - Use android::base::unique_fd to hold pidfd so that the fd is guaranteed to be closed. - Allow timeout_sec to be negative, in which case it blocks until the subprocess exits. Bug: 229268202 Test: m test-art-host-gtest-art_runtime_tests Change-Id: Iec3f21db135d9a8a3a915372253f1ff3e285e5cf Merged-In: Iec3f21db135d9a8a3a915372253f1ff3e285e5cf (cherry picked from commit 99bd8dd2bf8eac1a60bf65e442462753ed7f2147)
2022-07-11Revert^2 "Update ExecUtils to support artd use cases." Jiakai Zhang
This reverts commit ff95ad517297384d4a2ea589490019f90d637e17. Reason for revert: Fix available (aosp/2148047) Test: Presubmit Change-Id: I952960949267a7b6e63cd7966a347cb1f3374b85 Merged-In: I375034162cded6fdf09ee4d4cd783a0d3987af49
2022-07-05Revert "Update ExecUtils to support artd use cases." Jiakai Zhang
This reverts commit f0061f62fbd5e4766220c154d914e7b9d07a86eb. Reason for revert: Broke LUCI. Change-Id: Iec793a667545a8469f2a712135353e816c623262
2022-07-04Update ExecUtils to support artd use cases. Jiakai Zhang
- Use pidfd_open/poll instaed of sigprocmask/sigtimedwait to implement executing a command with a timeout because sigprocmask/sigtimedwait does not support multithreaded program, while artd is multithreaded. The same approach is used in installd in https://r.android.com/1993670. - Add "const" to the `std::vector<std::string>& arg_vector` parameter. - Use "int" instead of "time_t" for the "timeout_sec" parameter because "time_t" represents the time since epoch rather than a duration. - Set an error message with the signal number when the subprocess is terminated by a signal. - Crash the subprocess instead of exiting it with an exit code when execv fails. The behavior does not change. ExecUtilsTest is still passing. Bug: 229268202 Test: m test-art-host-gtest-art_runtime_tests Test: atest ArtGtestsTargetChroot:ExecUtilsTest Change-Id: I375034162cded6fdf09ee4d4cd783a0d3987af49 Merged-In: I375034162cded6fdf09ee4d4cd783a0d3987af49 (cherry picked from commit b48b732c535894bbae8f3c19eceeda67c40e9d61)
2021-09-17Fix art compiling against musl Colin Cross
Fix various issues when compling art against musl: Check for ANDROID_HOST_MUSL when defining strlcpy and sig*64. Remove error.h, its not used and doesn't exist in musl. Include time.h that was being included transitively in glibc but not in musl. Add the musl libc library name to the list. pthread_sigqueue takes a sigval, not a sigval_t. Bug: 190084016 Test: m USE_HOST_MUSL=true Change-Id: I2548ef0013234c42efded411c733450c19434855
2021-08-24Revert^2 "Add unit tests for odrefresh - step 2" Jiakai Zhang
This reverts commit b89649bd95cffec48f6f6746054553f71ab3e807. Reason for revert: Fixed the fugu build breakage The test failed on fugu because fugu is running Android O, while the test depends on a system property introduced in S. Since the whole odrefresh program is for S and later, we don't need to run the test on older platforms. This failure is fixed by adding a check on the API level and skipping the test if the API level is below S. Bug: 196188549 Test: atest art_standalone_odrefresh_tests Change-Id: I484696d065d715da65ae262a5aa8b3e1b30ffdcf
2021-08-23Revert "Add unit tests for odrefresh - step 2" Ulyana Trafimovich
This reverts commit b91dad2b98e8c562aed7c4471615d7c325756c08. Reason for revert: breaks builds on fugu. Bug: 196188549 Change-Id: Iec08674c2ed53b8e6048c044d5e72fdd26518a83
2021-08-20Add unit tests for odrefresh - step 2 Jiakai Zhang
- Define MockableExecUtils, which is a wrapper class to make exec_utils mockable. - Add another constructor to the OnDeviceRefresh class to support injections. - Update OdrConfig to support overriding the staging directory. - Add a unit test to verify that odrefresh sets compiler filter based on "dalvik.vm.systemservercompilerfilter". Bug: 196188549 Test: atest art_standalone_odrefresh_tests Test: atest odsign_e2e_tests Change-Id: Ia7b4347bba6873878490a513b8a5ff6642122d71
2021-01-18Add an overload of ExecAndReturnCode taking a timeout Orion Hodson
Enables callers to timeout waiting on a subprocess. Bug: 177432913 Test: test-art-host-gtest-art_runtime_tests32 Change-Id: I7a27e0ca4679f45daf815d7e2563ca9b723bd701
2017-02-01Separate art::Exec from utils David Sehr
The rest of utils.cc does not depend on art::Runtime. This separates the part dependent on that class, so that including utils.cc in the build does not require the entire Runtime. Another preparatory cleanup to getting tools to build on Windows. Bug: 22322814 Test: test-art Change-Id: I194ff363fc2ab87e5311ecea6973a2d0fad2621d