blob: 26c2a0d8022223ab5105c1f029f71d0d7a2de9ce [file] [log] [blame]
Kweku Adams5ce418d2018-02-05 16:43:53 -08001/*
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.
26static 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 Jeanbd526942019-04-04 18:23:04 +090034 "/system/bin/netd",
Kweku Adams5ce418d2018-02-05 16:43:53 -080035 "/system/bin/sdcard",
36 "/system/bin/statsd",
37 "/system/bin/surfaceflinger",
38 "/system/bin/vehicle_network_service",
39 "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec
Chong Zhang31f68992019-03-27 16:08:53 -070040 "/apex/com.android.media.swcodec/bin/mediaswcodec", // media.swcodec
Kweku Adams5ce418d2018-02-05 16:43:53 -080041 NULL,
42};
43
44/* list of hal interface to dump containing process during native dumps */
45static const char* hal_interfaces_to_dump[] {
46 "android.hardware.audio@2.0::IDevicesFactory",
Mikhail Naganovac1e32c2018-05-01 09:03:40 -070047 "android.hardware.audio@4.0::IDevicesFactory",
Kweku Adams5ce418d2018-02-05 16:43:53 -080048 "android.hardware.bluetooth@1.0::IBluetoothHci",
49 "android.hardware.camera.provider@2.4::ICameraProvider",
Jeff Tinker5fce8822018-04-02 17:24:41 -070050 "android.hardware.drm@1.0::IDrmFactory",
Chia-I Wu078dc422018-08-09 16:04:51 -070051 "android.hardware.graphics.allocator@2.0::IAllocator",
Kweku Adams5ce418d2018-02-05 16:43:53 -080052 "android.hardware.graphics.composer@2.1::IComposer",
Yifan Hong77a56172018-11-27 16:43:49 -080053 "android.hardware.health@2.0::IHealth",
Chong Zhang31f68992019-03-27 16:08:53 -070054 "android.hardware.media.c2@1.0::IComponentStore",
Kweku Adams5ce418d2018-02-05 16:43:53 -080055 "android.hardware.media.omx@1.0::IOmx",
Pawin Vongmasab4c85df2018-04-18 07:00:30 -070056 "android.hardware.media.omx@1.0::IOmxStore",
Wei Wang07735612019-04-23 14:12:24 -070057 "android.hardware.power@1.3::IPower",
Benjamin Schwartz525651b2019-04-08 15:26:10 -070058 "android.hardware.power.stats@1.0::IPowerStats",
Kweku Adams5ce418d2018-02-05 16:43:53 -080059 "android.hardware.sensors@1.0::ISensors",
Wei Wang07735612019-04-23 14:12:24 -070060 "android.hardware.thermal@2.0::IThermal",
Kweku Adams5ce418d2018-02-05 16:43:53 -080061 "android.hardware.vr@1.0::IVr",
62 NULL,
63};
64
65bool should_dump_hal_interface(const char* interface) {
66 for (const char** i = hal_interfaces_to_dump; *i; i++) {
67 if (!strcmp(*i, interface)) {
68 return true;
69 }
70 }
71 return false;
72}
73
74bool should_dump_native_traces(const char* path) {
75 for (const char** p = native_processes_to_dump; *p; p++) {
76 if (!strcmp(*p, path)) {
77 return true;
78 }
79 }
80 return false;
81}
82
83std::set<int> get_interesting_hal_pids() {
84 using android::hidl::manager::V1_0::IServiceManager;
85 using android::sp;
86 using android::hardware::Return;
87
88 sp<IServiceManager> manager = IServiceManager::getService();
89 std::set<int> pids;
90
91 Return<void> ret = manager->debugDump([&](auto& hals) {
92 for (const auto &info : hals) {
93 if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) {
94 continue;
95 }
96
97 if (!should_dump_hal_interface(info.interfaceName.c_str())) {
98 continue;
99 }
100
101 pids.insert(info.pid);
102 }
103 });
104
105 if (!ret.isOk()) {
106 ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str());
107 }
108
109 return pids; // whether it was okay or not
110}
111
112bool IsZygote(int pid) {
113 static const std::string kZygotePrefix = "zygote";
114
115 std::string cmdline;
116 if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid),
117 &cmdline)) {
118 return true;
119 }
120
121 return (cmdline.find(kZygotePrefix) == 0);
122}