| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2018 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 | #include <set> | 
|  | 17 |  | 
|  | 18 | #include <android-base/file.h> | 
|  | 19 | #include <android-base/stringprintf.h> | 
|  | 20 | #include <android/hidl/manager/1.0/IServiceManager.h> | 
|  | 21 | #include <dumputils/dump_utils.h> | 
|  | 22 | #include <log/log.h> | 
|  | 23 |  | 
|  | 24 | /* list of native processes to include in the native dumps */ | 
|  | 25 | // This matches the /proc/pid/exe link instead of /proc/pid/cmdline. | 
|  | 26 | static const char* native_processes_to_dump[] = { | 
|  | 27 | "/system/bin/audioserver", | 
|  | 28 | "/system/bin/cameraserver", | 
|  | 29 | "/system/bin/drmserver", | 
|  | 30 | "/system/bin/mediadrmserver", | 
|  | 31 | "/system/bin/mediaextractor", // media.extractor | 
|  | 32 | "/system/bin/mediametrics", // media.metrics | 
|  | 33 | "/system/bin/mediaserver", | 
| Chalard Jean | bd52694 | 2019-04-04 18:23:04 +0900 | [diff] [blame] | 34 | "/system/bin/netd", | 
| Nikita Ioffe | a8b9c4b | 2019-05-20 13:53:20 +0100 | [diff] [blame] | 35 | "/system/bin/vold", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 36 | "/system/bin/sdcard", | 
|  | 37 | "/system/bin/statsd", | 
|  | 38 | "/system/bin/surfaceflinger", | 
|  | 39 | "/system/bin/vehicle_network_service", | 
|  | 40 | "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec | 
| Chong Zhang | 31f6899 | 2019-03-27 16:08:53 -0700 | [diff] [blame] | 41 | "/apex/com.android.media.swcodec/bin/mediaswcodec", // media.swcodec | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 42 | NULL, | 
|  | 43 | }; | 
|  | 44 |  | 
|  | 45 | /* list of hal interface to dump containing process during native dumps */ | 
|  | 46 | static const char* hal_interfaces_to_dump[] { | 
|  | 47 | "android.hardware.audio@2.0::IDevicesFactory", | 
| Mikhail Naganov | ac1e32c | 2018-05-01 09:03:40 -0700 | [diff] [blame] | 48 | "android.hardware.audio@4.0::IDevicesFactory", | 
| Carter Hsu | 723e8cd | 2019-09-11 13:57:58 +0800 | [diff] [blame] | 49 | "android.hardware.audio@5.0::IDevicesFactory", | 
| Kevin Chyn | 3bad810 | 2019-06-19 11:05:53 -0700 | [diff] [blame] | 50 | "android.hardware.biometrics.face@1.0::IBiometricsFace", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 51 | "android.hardware.bluetooth@1.0::IBluetoothHci", | 
|  | 52 | "android.hardware.camera.provider@2.4::ICameraProvider", | 
| Jeff Tinker | 5fce882 | 2018-04-02 17:24:41 -0700 | [diff] [blame] | 53 | "android.hardware.drm@1.0::IDrmFactory", | 
| Chia-I Wu | 078dc42 | 2018-08-09 16:04:51 -0700 | [diff] [blame] | 54 | "android.hardware.graphics.allocator@2.0::IAllocator", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 55 | "android.hardware.graphics.composer@2.1::IComposer", | 
| Yifan Hong | 77a5617 | 2018-11-27 16:43:49 -0800 | [diff] [blame] | 56 | "android.hardware.health@2.0::IHealth", | 
| Chong Zhang | 31f6899 | 2019-03-27 16:08:53 -0700 | [diff] [blame] | 57 | "android.hardware.media.c2@1.0::IComponentStore", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 58 | "android.hardware.media.omx@1.0::IOmx", | 
| Pawin Vongmasa | b4c85df | 2018-04-18 07:00:30 -0700 | [diff] [blame] | 59 | "android.hardware.media.omx@1.0::IOmxStore", | 
| Wei Wang | 0773561 | 2019-04-23 14:12:24 -0700 | [diff] [blame] | 60 | "android.hardware.power@1.3::IPower", | 
| Benjamin Schwartz | 525651b | 2019-04-08 15:26:10 -0700 | [diff] [blame] | 61 | "android.hardware.power.stats@1.0::IPowerStats", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 62 | "android.hardware.sensors@1.0::ISensors", | 
| Wei Wang | 0773561 | 2019-04-23 14:12:24 -0700 | [diff] [blame] | 63 | "android.hardware.thermal@2.0::IThermal", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 64 | "android.hardware.vr@1.0::IVr", | 
|  | 65 | NULL, | 
|  | 66 | }; | 
|  | 67 |  | 
|  | 68 | bool should_dump_hal_interface(const char* interface) { | 
|  | 69 | for (const char** i = hal_interfaces_to_dump; *i; i++) { | 
|  | 70 | if (!strcmp(*i, interface)) { | 
|  | 71 | return true; | 
|  | 72 | } | 
|  | 73 | } | 
|  | 74 | return false; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | bool should_dump_native_traces(const char* path) { | 
|  | 78 | for (const char** p = native_processes_to_dump; *p; p++) { | 
|  | 79 | if (!strcmp(*p, path)) { | 
|  | 80 | return true; | 
|  | 81 | } | 
|  | 82 | } | 
|  | 83 | return false; | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | std::set<int> get_interesting_hal_pids() { | 
|  | 87 | using android::hidl::manager::V1_0::IServiceManager; | 
|  | 88 | using android::sp; | 
|  | 89 | using android::hardware::Return; | 
|  | 90 |  | 
|  | 91 | sp<IServiceManager> manager = IServiceManager::getService(); | 
|  | 92 | std::set<int> pids; | 
|  | 93 |  | 
|  | 94 | Return<void> ret = manager->debugDump([&](auto& hals) { | 
|  | 95 | for (const auto &info : hals) { | 
|  | 96 | if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) { | 
|  | 97 | continue; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | if (!should_dump_hal_interface(info.interfaceName.c_str())) { | 
|  | 101 | continue; | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | pids.insert(info.pid); | 
|  | 105 | } | 
|  | 106 | }); | 
|  | 107 |  | 
|  | 108 | if (!ret.isOk()) { | 
|  | 109 | ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str()); | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | return pids; // whether it was okay or not | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | bool IsZygote(int pid) { | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 116 | std::string cmdline; | 
|  | 117 | if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid), | 
|  | 118 | &cmdline)) { | 
|  | 119 | return true; | 
|  | 120 | } | 
|  | 121 |  | 
| Josh Gao | 33e622a | 2019-05-16 16:05:04 -0700 | [diff] [blame] | 122 | // cmdline has embedded nulls; only consider argv[0]. | 
|  | 123 | cmdline = std::string(cmdline.c_str()); | 
|  | 124 |  | 
|  | 125 | return cmdline == "zygote" || cmdline == "zygote64" || cmdline == "usap32" || | 
|  | 126 | cmdline == "usap64"; | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 127 | } |