blob: 047780171e65f5c4615cef23c4ca9f439c51132e [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>
Eric Jeong9b6bcca2019-11-08 16:37:13 -080019#include <android-base/properties.h>
Kweku Adams5ce418d2018-02-05 16:43:53 -080020#include <android-base/stringprintf.h>
Eric Jeong9b6bcca2019-11-08 16:37:13 -080021#include <android-base/strings.h>
Kweku Adams5ce418d2018-02-05 16:43:53 -080022#include <android/hidl/manager/1.0/IServiceManager.h>
23#include <dumputils/dump_utils.h>
24#include <log/log.h>
25
26/* list of native processes to include in the native dumps */
27// This matches the /proc/pid/exe link instead of /proc/pid/cmdline.
28static const char* native_processes_to_dump[] = {
29 "/system/bin/audioserver",
30 "/system/bin/cameraserver",
31 "/system/bin/drmserver",
32 "/system/bin/mediadrmserver",
33 "/system/bin/mediaextractor", // media.extractor
34 "/system/bin/mediametrics", // media.metrics
35 "/system/bin/mediaserver",
Chalard Jeanbd526942019-04-04 18:23:04 +090036 "/system/bin/netd",
Nikita Ioffea8b9c4b2019-05-20 13:53:20 +010037 "/system/bin/vold",
Kweku Adams5ce418d2018-02-05 16:43:53 -080038 "/system/bin/sdcard",
39 "/system/bin/statsd",
40 "/system/bin/surfaceflinger",
41 "/system/bin/vehicle_network_service",
42 "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec
Chong Zhang31f68992019-03-27 16:08:53 -070043 "/apex/com.android.media.swcodec/bin/mediaswcodec", // media.swcodec
Kweku Adams5ce418d2018-02-05 16:43:53 -080044 NULL,
45};
46
47/* list of hal interface to dump containing process during native dumps */
48static const char* hal_interfaces_to_dump[] {
49 "android.hardware.audio@2.0::IDevicesFactory",
Mikhail Naganovac1e32c2018-05-01 09:03:40 -070050 "android.hardware.audio@4.0::IDevicesFactory",
Carter Hsu723e8cd2019-09-11 13:57:58 +080051 "android.hardware.audio@5.0::IDevicesFactory",
Kevin Chyn3bad8102019-06-19 11:05:53 -070052 "android.hardware.biometrics.face@1.0::IBiometricsFace",
Kweku Adams5ce418d2018-02-05 16:43:53 -080053 "android.hardware.bluetooth@1.0::IBluetoothHci",
54 "android.hardware.camera.provider@2.4::ICameraProvider",
Jeff Tinker5fce8822018-04-02 17:24:41 -070055 "android.hardware.drm@1.0::IDrmFactory",
Chia-I Wu078dc422018-08-09 16:04:51 -070056 "android.hardware.graphics.allocator@2.0::IAllocator",
Kweku Adams5ce418d2018-02-05 16:43:53 -080057 "android.hardware.graphics.composer@2.1::IComposer",
Yifan Hong77a56172018-11-27 16:43:49 -080058 "android.hardware.health@2.0::IHealth",
Chong Zhang31f68992019-03-27 16:08:53 -070059 "android.hardware.media.c2@1.0::IComponentStore",
Kweku Adams5ce418d2018-02-05 16:43:53 -080060 "android.hardware.media.omx@1.0::IOmx",
Pawin Vongmasab4c85df2018-04-18 07:00:30 -070061 "android.hardware.media.omx@1.0::IOmxStore",
Wei Wang07735612019-04-23 14:12:24 -070062 "android.hardware.power@1.3::IPower",
Benjamin Schwartz525651b2019-04-08 15:26:10 -070063 "android.hardware.power.stats@1.0::IPowerStats",
Kweku Adams5ce418d2018-02-05 16:43:53 -080064 "android.hardware.sensors@1.0::ISensors",
Wei Wang07735612019-04-23 14:12:24 -070065 "android.hardware.thermal@2.0::IThermal",
Kweku Adams5ce418d2018-02-05 16:43:53 -080066 "android.hardware.vr@1.0::IVr",
Eric Jeong5331b632019-11-14 17:07:25 -080067 "android.hardware.automotive.audiocontrol@1.0::IAudioControl",
68 "android.hardware.automotive.vehicle@2.0::IVehicle",
69 "android.hardware.automotive.evs@1.0::IEvsCamera",
Kweku Adams5ce418d2018-02-05 16:43:53 -080070 NULL,
71};
72
Eric Jeong9b6bcca2019-11-08 16:37:13 -080073/* list of extra hal interfaces to dump containing process during native dumps */
74// This is filled when dumpstate is called.
75static std::set<const std::string> extra_hal_interfaces_to_dump;
76
77static void read_extra_hals_to_dump_from_property() {
78 // extra hals to dump are already filled
79 if (extra_hal_interfaces_to_dump.size() > 0) {
80 return;
81 }
82 std::string value = android::base::GetProperty("ro.dump.hals.extra", "");
83 std::vector<std::string> tokens = android::base::Split(value, ",");
84 for (const auto &token : tokens) {
85 std::string trimmed_token = android::base::Trim(token);
86 if (trimmed_token.length() == 0) {
87 continue;
88 }
89 extra_hal_interfaces_to_dump.insert(trimmed_token);
90 }
91}
92
93// check if interface is included in either default hal list or extra hal list
94bool should_dump_hal_interface(const std::string& interface) {
Kweku Adams5ce418d2018-02-05 16:43:53 -080095 for (const char** i = hal_interfaces_to_dump; *i; i++) {
Eric Jeong9b6bcca2019-11-08 16:37:13 -080096 if (interface == *i) {
Kweku Adams5ce418d2018-02-05 16:43:53 -080097 return true;
98 }
99 }
Eric Jeong9b6bcca2019-11-08 16:37:13 -0800100 return extra_hal_interfaces_to_dump.find(interface) != extra_hal_interfaces_to_dump.end();
Kweku Adams5ce418d2018-02-05 16:43:53 -0800101}
102
103bool should_dump_native_traces(const char* path) {
104 for (const char** p = native_processes_to_dump; *p; p++) {
105 if (!strcmp(*p, path)) {
106 return true;
107 }
108 }
109 return false;
110}
111
112std::set<int> get_interesting_hal_pids() {
113 using android::hidl::manager::V1_0::IServiceManager;
114 using android::sp;
115 using android::hardware::Return;
116
117 sp<IServiceManager> manager = IServiceManager::getService();
118 std::set<int> pids;
119
Eric Jeong9b6bcca2019-11-08 16:37:13 -0800120 read_extra_hals_to_dump_from_property();
121
Kweku Adams5ce418d2018-02-05 16:43:53 -0800122 Return<void> ret = manager->debugDump([&](auto& hals) {
123 for (const auto &info : hals) {
124 if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) {
125 continue;
126 }
127
Eric Jeong9b6bcca2019-11-08 16:37:13 -0800128 if (!should_dump_hal_interface(info.interfaceName)) {
Kweku Adams5ce418d2018-02-05 16:43:53 -0800129 continue;
130 }
131
132 pids.insert(info.pid);
133 }
134 });
135
136 if (!ret.isOk()) {
137 ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str());
138 }
139
140 return pids; // whether it was okay or not
141}
142
143bool IsZygote(int pid) {
Kweku Adams5ce418d2018-02-05 16:43:53 -0800144 std::string cmdline;
145 if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid),
146 &cmdline)) {
147 return true;
148 }
149
Josh Gao33e622a2019-05-16 16:05:04 -0700150 // cmdline has embedded nulls; only consider argv[0].
151 cmdline = std::string(cmdline.c_str());
152
153 return cmdline == "zygote" || cmdline == "zygote64" || cmdline == "usap32" ||
154 cmdline == "usap64";
Kweku Adams5ce418d2018-02-05 16:43:53 -0800155}