blob: 8f6b1bd5d61bca3b4cb24853953ebb50c966b755 [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",
34 "/system/bin/sdcard",
35 "/system/bin/statsd",
36 "/system/bin/surfaceflinger",
37 "/system/bin/vehicle_network_service",
38 "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec
39 NULL,
40};
41
42/* list of hal interface to dump containing process during native dumps */
43static const char* hal_interfaces_to_dump[] {
44 "android.hardware.audio@2.0::IDevicesFactory",
45 "android.hardware.bluetooth@1.0::IBluetoothHci",
46 "android.hardware.camera.provider@2.4::ICameraProvider",
Jeff Tinker5fce8822018-04-02 17:24:41 -070047 "android.hardware.drm@1.0::IDrmFactory",
Kweku Adams5ce418d2018-02-05 16:43:53 -080048 "android.hardware.graphics.composer@2.1::IComposer",
49 "android.hardware.media.omx@1.0::IOmx",
Pawin Vongmasab4c85df2018-04-18 07:00:30 -070050 "android.hardware.media.omx@1.0::IOmxStore",
Kweku Adams5ce418d2018-02-05 16:43:53 -080051 "android.hardware.sensors@1.0::ISensors",
52 "android.hardware.vr@1.0::IVr",
53 NULL,
54};
55
56bool should_dump_hal_interface(const char* interface) {
57 for (const char** i = hal_interfaces_to_dump; *i; i++) {
58 if (!strcmp(*i, interface)) {
59 return true;
60 }
61 }
62 return false;
63}
64
65bool should_dump_native_traces(const char* path) {
66 for (const char** p = native_processes_to_dump; *p; p++) {
67 if (!strcmp(*p, path)) {
68 return true;
69 }
70 }
71 return false;
72}
73
74std::set<int> get_interesting_hal_pids() {
75 using android::hidl::manager::V1_0::IServiceManager;
76 using android::sp;
77 using android::hardware::Return;
78
79 sp<IServiceManager> manager = IServiceManager::getService();
80 std::set<int> pids;
81
82 Return<void> ret = manager->debugDump([&](auto& hals) {
83 for (const auto &info : hals) {
84 if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) {
85 continue;
86 }
87
88 if (!should_dump_hal_interface(info.interfaceName.c_str())) {
89 continue;
90 }
91
92 pids.insert(info.pid);
93 }
94 });
95
96 if (!ret.isOk()) {
97 ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str());
98 }
99
100 return pids; // whether it was okay or not
101}
102
103bool IsZygote(int pid) {
104 static const std::string kZygotePrefix = "zygote";
105
106 std::string cmdline;
107 if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid),
108 &cmdline)) {
109 return true;
110 }
111
112 return (cmdline.find(kZygotePrefix) == 0);
113}