onnxruntime/tools/python
Jian Chen 6c2ff5fc55
Refactor emulator start and stop functions for clarity and efficiency (#22861)
### Description
This pull request introduces several enhancements and new
functionalities to the `tools/python/util/android/android.py` file,
focusing on improving the management of Android emulators. The most
important changes include adding a timeout parameter to the
`start_emulator` function, adding checks to prevent multiple emulators
from running simultaneously, and introducing new utility functions to
manage emulator processes more effectively.

Enhancements to `start_emulator` function:

* Added a `timeout_minutes` parameter to the `start_emulator` function
to make the startup timeout configurable.
[[1]](diffhunk://#diff-c54db556a9c445989f830c09ab90ce2704e648deaccce9c9e0ee4875ddaa864dL108-R117)
[[2]](diffhunk://#diff-c54db556a9c445989f830c09ab90ce2704e648deaccce9c9e0ee4875ddaa864dL158-R170)
* Added a check to prevent starting a new emulator if one with the same
AVD name is already running.
* Included additional emulator arguments `-verbose` for better control
and debugging.
* Added a final verification step to ensure the emulator has started
successfully.

New utility functions for managing emulator processes:

* Introduced `check_emulator_running_using_avd_name `,
`check_emulator_running_using_process`, and
`check_emulator_running_using_pid` to check if an emulator is running
based on AVD name, process instance, or PID, respectively.
* Added `stop_emulator_by_proc` and `stop_emulator_by_pid` functions to
stop the emulator process using a `subprocess.Popen` instance or PID,
with a configurable timeout.
* Updated the `stop_emulator` function to use the new utility functions
for stopping the emulator process.

These changes enhance the robustness and flexibility of the emulator
management utilities, making it easier to handle different scenarios in
CI environments and development workflows.



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Scott McKay <skottmckay@gmail.com>
2024-12-02 09:29:17 -08:00
..
util Refactor emulator start and stop functions for clarity and efficiency (#22861) 2024-12-02 09:29:17 -08:00
PythonTools.md Adopt linrtunner as the linting tool - take 2 (#15085) 2023-03-24 15:29:03 -07:00
__init__.py Add a couple of utility scripts to tools/python (#3621) 2020-05-02 17:35:43 +10:00
check_onnx_model_mobile_usability.py Format all python files under onnxruntime with black and isort (#11324) 2022-04-26 09:35:16 -07:00
convert_onnx_models_to_ort.py Add ability to create ort format models from training offline utility (#16360) 2023-06-21 18:51:43 -07:00
create_reduced_build_config.py Bump ruff in CI (#15533) 2023-04-17 10:11:44 -07:00
dump_ort_model.py Bump ruff to 0.3.2 and black to 24 (#19878) 2024-03-13 10:00:32 -07:00
dump_subgraphs.py [Linter] Bump ruff and remove pylint (#17797) 2023-10-05 21:07:33 -07:00
example_operator_perf_test.py Adopt linrtunner as the linting tool - take 2 (#15085) 2023-03-24 15:29:03 -07:00
find_optimizer_opset_version_updates_required.py Bump ruff to 0.3.2 and black to 24 (#19878) 2024-03-13 10:00:32 -07:00
fix_long_lines.py Bump ruff linter to 0.2.1 (#19471) 2024-02-08 16:08:27 -08:00
gen_contrib_doc.py Bump ruff to 0.3.2 and black to 24 (#19878) 2024-03-13 10:00:32 -07:00
gen_opkernel_doc.py Bump ruff linter to 0.2.1 (#19471) 2024-02-08 16:08:27 -08:00
get_submodules.py Bump ruff in CI (#15533) 2023-04-17 10:11:44 -07:00
onnx2tfevents.py Disable PERF* rules in ruff to allow better readability (#16834) 2023-07-25 15:38:22 -07:00
onnx_test_data_utils.py Update ruff and clang-format versions (#21479) 2024-07-24 11:50:11 -07:00
ort_test_dir_utils.py Bump ruff linter to 0.2.1 (#19471) 2024-02-08 16:08:27 -08:00
remove_initializer_from_input.py Format all python files under onnxruntime with black and isort (#11324) 2022-04-26 09:35:16 -07:00
run_CIs_for_branch.py Update script to run CIs for a branch. (#19797) 2024-03-08 17:52:47 +10:00
run_CIs_for_external_pr.py update pipeline name list in run_CIs_for_external_pr.py (#22540) 2024-10-22 17:14:48 -07:00
run_adb.py [React Native CI] Record more info to debug E2E test (#13329) 2022-10-18 17:21:28 -07:00
run_android_emulator.py Attempt to make the usage of the Android emulator in CIs more robust (#17903) 2023-10-15 08:42:36 +10:00
sparsify_initializers.py [Linter] Bump ruff and remove pylint (#17797) 2023-10-05 21:07:33 -07:00
update_version.py [js] add API that allows to get package version (#16207) 2023-06-09 16:18:53 -07:00
upload_and_run_browserstack_tests.py Add Android QNN Browserstack test (#22434) 2024-11-10 16:10:29 -08:00