dumpsys相关解析

2023-12-01 04:12
文章标签 解析 相关 dumpsys

本文主要是介绍dumpsys相关解析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

(1)命令使用

dumpsys命令功能很强大,能dump系统服务的各种状态,这里以AMS为例子,它在ServiceManager中的名字为activity,所以使用dumpsys activity便可,同理,其他service的dump方法也是一样的。

常用的一些命令如下:

//dumpsys activity:查询AMS服务相关信息,相当于 ActivityManagerService.dump()
dumpsys activity intents:查询系统所有待处理intent信息;
dumpsys activity broadcasts:可查询所有注册广播接收者、前台广播、后台广播信息;
dumpsys activity providers:查询系统组件provider相关信息;
dumpsys activity activitys:查询系统组件activity相关信息;
dumpsys activity services:查询系统组件service相关信息;
dumpsys activity top | grep ACTIVITY:查询当前界面显示的top Activity//dumpsys window:查询WMS服务相关信息
dumpsys window:可获取当前界面所在的应用,可看到获取焦点的window和应用;//dumpsys cpuinfo:查询CPU情况
dumpsys cpuinfo:获取当前cpu使用情况,也可已使用top命令;//dumpsys meminfo:查询内存情况
dumpsys meminfo + 包名:查看应用内存占用信息;
dumpsys meminfo --oom:查看应用内存层级;//dumpsys package:查询PMS相关信息
dumpsys package + 包名:查看应用相关信息;
dumpsys package + 包名 |grep version:查看应用的版本信息;
dumpsys package + 包名 |grep apk:查看应用安装路径信息;//dumpsys gfxinfo:查询图像相关信息
dumpsys gfxinfo+ 包名:查看应用的丢帧情况;
activity				ActivityManagerService			AMS相关信息
package			PackageManagerService			PMS相关信息
window			WindowManagerService			WMS相关信息
input					InputManagerService				IMS相关信息
power				PowerManagerService				PMS相关信息
batterystats	BatterystatsService					电池统计信息
battery				BatteryService								电池信息
alarm				AlarmManagerService				闹钟信息
dropbox			DropboxManagerService			调试相关
procstats			ProcessStatsService					进程统计
cpuinfo			CpuBinder										CPU
meminfo			MemBinder									内存
gfxinfo				GraphicsBinder							图像
dbinfo				DbBinder										数据库

可查询的服务有很多,可通过下面命令查看当前系统所支持的dump服务:

adb shell dumpsys -l
adb shell service list

(2)代码逻辑

如下目录是framework处理dumpsys命令的入口:

//frameworks/native/cmds/dumpsys/main.cppint main(int argc, char* const argv[]) {signal(SIGPIPE, SIG_IGN);sp<IServiceManager> sm = defaultServiceManager();fflush(stdout);if (sm == nullptr) {ALOGE("Unable to get default service manager!");std::cerr << "dumpsys: Unable to get default service manager!" << std::endl;return 20;}Dumpsys dumpsys(sm.get());return dumpsys.main(argc, argv);
}

如果ServiceManager还没起来,无法处理命令,所以需要判空,SM进程起来的时候是在开机流程中,init进程里面实例化。命令主要在如下逻辑中处理:

//frameworks/native/cmds/dumpsys/dumpsys.cppint Dumpsys::main(int argc, char* const argv[]) {//...static struct option longOptions[] = {{"help", no_argument, 0, 0},           {"clients", no_argument, 0, 0},{"dump", no_argument, 0, 0},           {"pid", no_argument, 0, 0},{"priority", required_argument, 0, 0}, {"proto", no_argument, 0, 0},{"skip", no_argument, 0, 0},           {"stability", no_argument, 0, 0},{"thread", no_argument, 0, 0},         {0, 0, 0, 0}};//...switch (c) {case 0:if (!strcmp(longOptions[optionIndex].name, "skip")) {skipServices = true;} else if (!strcmp(longOptions[optionIndex].name, "proto")) {asProto = true;} else if (!strcmp(longOptions[optionIndex].name, "help")) {usage();return 0;} else if (!strcmp(longOptions[optionIndex].name, "priority")) {priorityType = String16(String8(optarg));if (!ConvertPriorityTypeToBitmask(priorityType, priorityFlags)) {fprintf(stderr, "\n");usage();return -1;}} else if (!strcmp(longOptions[optionIndex].name, "dump")) {dumpTypeFlags |= TYPE_DUMP;} else if (!strcmp(longOptions[optionIndex].name, "pid")) {dumpTypeFlags |= TYPE_PID;} else if (!strcmp(longOptions[optionIndex].name, "stability")) {dumpTypeFlags |= TYPE_STABILITY;} else if (!strcmp(longOptions[optionIndex].name, "thread")) {dumpTypeFlags |= TYPE_THREAD;} else if (!strcmp(longOptions[optionIndex].name, "clients")) {dumpTypeFlags |= TYPE_CLIENTS;}break;//...}}//...for (size_t i = 0; i < N; i++) {const String16& serviceName = services[i];if (IsSkipped(skippedServices, serviceName)) continue;//这里通过startDumpThread来启动dump threadif (startDumpThread(dumpTypeFlags, serviceName, args) == OK) {bool addSeparator = (N > 1);if (addSeparator) {writeDumpHeader(STDOUT_FILENO, serviceName, priorityFlags);}std::chrono::duration<double> elapsedDuration;size_t bytesWritten = 0;status_t status =writeDump(STDOUT_FILENO, serviceName, std::chrono::milliseconds(timeoutArgMs),asProto, elapsedDuration, bytesWritten);if (status == TIMED_OUT) {std::cout << std::endl<< "*** SERVICE '" << serviceName << "' DUMP TIMEOUT (" << timeoutArgMs<< "ms) EXPIRED ***" << std::endl<< std::endl;}if (addSeparator) {writeDumpFooter(STDOUT_FILENO, serviceName, elapsedDuration);}bool dumpComplete = (status == OK);stopDumpThread(dumpComplete);}}return 0;
}

通过startDumpThread来调用dump函数进行处理。

status_t Dumpsys::startDumpThread(int dumpTypeFlags, const String16& serviceName,const Vector<String16>& args) {//通过serviceName来获取service对象sp<IBinder> service = sm_->checkService(serviceName);if (service == nullptr) {std::cerr << "Can't find service: " << serviceName << std::endl;return NAME_NOT_FOUND;}int sfd[2];if (pipe(sfd) != 0) {std::cerr << "Failed to create pipe to dump service info for " << serviceName << ": "<< strerror(errno) << std::endl;return -errno;}redirectFd_ = unique_fd(sfd[0]);unique_fd remote_end(sfd[1]);sfd[0] = sfd[1] = -1;// dump blocks until completion, so spawn a thread..activeThread_ = std::thread([=, remote_end{std::move(remote_end)}]() mutable {if (dumpTypeFlags & TYPE_PID) {status_t err = dumpPidToFd(service, remote_end, dumpTypeFlags == TYPE_PID);reportDumpError(serviceName, err, "dumping PID");}if (dumpTypeFlags & TYPE_STABILITY) {status_t err = dumpStabilityToFd(service, remote_end);reportDumpError(serviceName, err, "dumping stability");}if (dumpTypeFlags & TYPE_THREAD) {status_t err = dumpThreadsToFd(service, remote_end);reportDumpError(serviceName, err, "dumping thread info");}if (dumpTypeFlags & TYPE_CLIENTS) {status_t err = dumpClientsToFd(service, remote_end);reportDumpError(serviceName, err, "dumping clients info");}// other types always act as a header, this is usually longerif (dumpTypeFlags & TYPE_DUMP) {//调用相应service的dump函数status_t err = service->dump(remote_end.get(), args);reportDumpError(serviceName, err, "dumping");}});return OK;
}

在新起的线程中,执行某个service的dump函数,如此我们就只要看某个service的dump函数实现就好了,注意我们这些处理逻辑目前都是在native层,但是我们知道安卓是建立在Binder通信的CS架构,该dump()函数的声明是在Binder类中的,也就是我们需要找到服务端的dump()函数的真正实现哪里,如果是dumpsys activity a,那么真正实现是在java层的ActivityManagerService中,其他服务同理。

(3)部分示例

(A)PowerManagerService.java

//frameworks/base/services/core/java/com/android/server/power/PowerManagerService.javaprivate void dumpInternal(PrintWriter pw) {pw.println("POWER MANAGER (dumpsys power)\n");final WirelessChargerDetector wcd;final LowPowerStandbyController lowPowerStandbyController;synchronized (mLock) {pw.println("Power Manager State:");mConstants.dump(pw);pw.println("  mDirty=0x" + Integer.toHexString(mDirty));pw.println("  mWakefulness="+ PowerManagerInternal.wakefulnessToString(getGlobalWakefulnessLocked()));pw.println("  mWakefulnessChanging=" + mWakefulnessChanging);pw.println("  mIsPowered=" + mIsPowered);pw.println("  mPlugType=" + mPlugType);pw.println("  mBatteryLevel=" + mBatteryLevel);pw.println("  mBatteryLevelWhenDreamStarted=" + mBatteryLevelWhenDreamStarted);pw.println("  mDockState=" + mDockState);pw.println("  mStayOn=" + mStayOn);pw.println("  mProximityPositive=" + mProximityPositive);pw.println("  mBootCompleted=" + mBootCompleted);pw.println("  mSystemReady=" + mSystemReady);synchronized (mEnhancedDischargeTimeLock) {pw.println("  mEnhancedDischargeTimeElapsed=" + mEnhancedDischargeTimeElapsed);pw.println("  mLastEnhancedDischargeTimeUpdatedElapsed="+ mLastEnhancedDischargeTimeUpdatedElapsed);pw.println("  mEnhancedDischargePredictionIsPersonalized="+ mEnhancedDischargePredictionIsPersonalized);}pw.println("  mHalAutoSuspendModeEnabled=" + mHalAutoSuspendModeEnabled);pw.println("  mHalInteractiveModeEnabled=" + mHalInteractiveModeEnabled);pw.println("  mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary));pw.print("  mNotifyLongScheduled=");if (mNotifyLongScheduled == 0) {pw.print("(none)");} else {TimeUtils.formatDuration(mNotifyLongScheduled, mClock.uptimeMillis(), pw);}pw.println();pw.print("  mNotifyLongDispatched=");if (mNotifyLongDispatched == 0) {pw.print("(none)");} else {TimeUtils.formatDuration(mNotifyLongDispatched, mClock.uptimeMillis(), pw);}pw.println();pw.print("  mNotifyLongNextCheck=");if (mNotifyLongNextCheck == 0) {pw.print("(none)");} else {TimeUtils.formatDuration(mNotifyLongNextCheck, mClock.uptimeMillis(), pw);}pw.println();pw.println("  mRequestWaitForNegativeProximity=" + mRequestWaitForNegativeProximity);pw.println("  mInterceptedPowerKeyForProximity="+ mInterceptedPowerKeyForProximity);pw.println("  mSandmanScheduled=" + mSandmanScheduled);pw.println("  mBatteryLevelLow=" + mBatteryLevelLow);pw.println("  mLightDeviceIdleMode=" + mLightDeviceIdleMode);pw.println("  mDeviceIdleMode=" + mDeviceIdleMode);pw.println("  mDeviceIdleWhitelist=" + Arrays.toString(mDeviceIdleWhitelist));pw.println("  mDeviceIdleTempWhitelist=" + Arrays.toString(mDeviceIdleTempWhitelist));pw.println("  mLowPowerStandbyActive=" + mLowPowerStandbyActive);pw.println("  mLastWakeTime=" + TimeUtils.formatUptime(mLastGlobalWakeTime));pw.println("  mLastSleepTime=" + TimeUtils.formatUptime(mLastGlobalSleepTime));pw.println("  mLastSleepReason=" + PowerManager.sleepReasonToString(mLastGlobalSleepReason));pw.println("  mLastInteractivePowerHintTime="+ TimeUtils.formatUptime(mLastInteractivePowerHintTime));pw.println("  mLastScreenBrightnessBoostTime="+ TimeUtils.formatUptime(mLastScreenBrightnessBoostTime));pw.println("  mScreenBrightnessBoostInProgress="+ mScreenBrightnessBoostInProgress);pw.println("  mHoldingWakeLockSuspendBlocker=" + mHoldingWakeLockSuspendBlocker);pw.println("  mHoldingDisplaySuspendBlocker=" + mHoldingDisplaySuspendBlocker);pw.println("  mLastFlipTime=" + mLastFlipTime);pw.println("  mIsFaceDown=" + mIsFaceDown);pw.println();pw.println("Settings and Configuration:");pw.println("  mDecoupleHalAutoSuspendModeFromDisplayConfig="+ mDecoupleHalAutoSuspendModeFromDisplayConfig);pw.println("  mDecoupleHalInteractiveModeFromDisplayConfig="+ mDecoupleHalInteractiveModeFromDisplayConfig);pw.println("  mWakeUpWhenPluggedOrUnpluggedConfig="+ mWakeUpWhenPluggedOrUnpluggedConfig);pw.println("  mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig="+ mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig);pw.println("  mTheaterModeEnabled="+ mTheaterModeEnabled);pw.println("  mSuspendWhenScreenOffDueToProximityConfig="+ mSuspendWhenScreenOffDueToProximityConfig);pw.println("  mDreamsSupportedConfig=" + mDreamsSupportedConfig);pw.println("  mDreamsEnabledByDefaultConfig=" + mDreamsEnabledByDefaultConfig);pw.println("  mDreamsActivatedOnSleepByDefaultConfig="+ mDreamsActivatedOnSleepByDefaultConfig);pw.println("  mDreamsActivatedOnDockByDefaultConfig="+ mDreamsActivatedOnDockByDefaultConfig);pw.println("  mDreamsEnabledOnBatteryConfig="+ mDreamsEnabledOnBatteryConfig);pw.println("  mDreamsBatteryLevelMinimumWhenPoweredConfig="+ mDreamsBatteryLevelMinimumWhenPoweredConfig);pw.println("  mDreamsBatteryLevelMinimumWhenNotPoweredConfig="+ mDreamsBatteryLevelMinimumWhenNotPoweredConfig);pw.println("  mDreamsBatteryLevelDrainCutoffConfig="+ mDreamsBatteryLevelDrainCutoffConfig);pw.println("  mDreamsEnabledSetting=" + mDreamsEnabledSetting);pw.println("  mDreamsActivateOnSleepSetting=" + mDreamsActivateOnSleepSetting);pw.println("  mDreamsActivateOnDockSetting=" + mDreamsActivateOnDockSetting);pw.println("  mDozeAfterScreenOff=" + mDozeAfterScreenOff);pw.println("  mMinimumScreenOffTimeoutConfig=" + mMinimumScreenOffTimeoutConfig);pw.println("  mMaximumScreenDimDurationConfig=" + mMaximumScreenDimDurationConfig);pw.println("  mMaximumScreenDimRatioConfig=" + mMaximumScreenDimRatioConfig);pw.println("  mAttentiveTimeoutConfig=" + mAttentiveTimeoutConfig);pw.println("  mAttentiveTimeoutSetting=" + mAttentiveTimeoutSetting);pw.println("  mAttentiveWarningDurationConfig=" + mAttentiveWarningDurationConfig);pw.println("  mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting);pw.println("  mSleepTimeoutSetting=" + mSleepTimeoutSetting);pw.println("  mMaximumScreenOffTimeoutFromDeviceAdmin="+ mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced="+ isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")");pw.println("  mStayOnWhilePluggedInSetting=" + mStayOnWhilePluggedInSetting);pw.println("  mScreenBrightnessModeSetting=" + mScreenBrightnessModeSetting);pw.println("  mScreenBrightnessOverrideFromWindowManager="+ mScreenBrightnessOverrideFromWindowManager);pw.println("  mUserActivityTimeoutOverrideFromWindowManager="+ mUserActivityTimeoutOverrideFromWindowManager);pw.println("  mUserInactiveOverrideFromWindowManager="+ mUserInactiveOverrideFromWindowManager);pw.println("  mDozeScreenStateOverrideFromDreamManager="+ mDozeScreenStateOverrideFromDreamManager);pw.println("  mDrawWakeLockOverrideFromSidekick=" + mDrawWakeLockOverrideFromSidekick);pw.println("  mDozeScreenBrightnessOverrideFromDreamManager="+ mDozeScreenBrightnessOverrideFromDreamManager);pw.println("  mScreenBrightnessMinimum=" + mScreenBrightnessMinimum);pw.println("  mScreenBrightnessMaximum=" + mScreenBrightnessMaximum);pw.println("  mScreenBrightnessDefault=" + mScreenBrightnessDefault);pw.println("  mDoubleTapWakeEnabled=" + mDoubleTapWakeEnabled);pw.println("  mIsVrModeEnabled=" + mIsVrModeEnabled);pw.println("  mForegroundProfile=" + mForegroundProfile);pw.println("  mUserId=" + mUserId);final long attentiveTimeout = getAttentiveTimeoutLocked();final long sleepTimeout = getSleepTimeoutLocked(attentiveTimeout);final long screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout, attentiveTimeout);final long screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);pw.println();pw.println("Attentive timeout: " + attentiveTimeout + " ms");pw.println("Sleep timeout: " + sleepTimeout + " ms");pw.println("Screen off timeout: " + screenOffTimeout + " ms");pw.println("Screen dim duration: " + screenDimDuration + " ms");pw.println();pw.print("UID states (changing=");pw.print(mUidsChanging);pw.print(" changed=");pw.print(mUidsChanged);pw.println("):");for (int i=0; i<mUidState.size(); i++) {final UidState state = mUidState.valueAt(i);pw.print("  UID "); UserHandle.formatUid(pw, mUidState.keyAt(i));pw.print(": ");if (state.mActive) pw.print("  ACTIVE ");else pw.print("INACTIVE ");pw.print(" count=");pw.print(state.mNumWakeLocks);pw.print(" state=");pw.println(state.mProcState);}pw.println();pw.println("Looper state:");mHandler.getLooper().dump(new PrintWriterPrinter(pw), "  ");pw.println();pw.println("Wake Locks: size=" + mWakeLocks.size());for (WakeLock wl : mWakeLocks) {pw.println("  " + wl);}pw.println();pw.println("Suspend Blockers: size=" + mSuspendBlockers.size());for (SuspendBlocker sb : mSuspendBlockers) {pw.println("  " + sb);}pw.println();pw.println("Display Power: " + mDisplayPowerCallbacks);mBatterySaverPolicy.dump(pw);mBatterySaverStateMachine.dump(pw);mAttentionDetector.dump(pw);pw.println();final int numProfiles = mProfilePowerState.size();pw.println("Profile power states: size=" + numProfiles);for (int i = 0; i < numProfiles; i++) {final ProfilePowerState profile = mProfilePowerState.valueAt(i);pw.print("  mUserId=");pw.print(profile.mUserId);pw.print(" mScreenOffTimeout=");pw.print(profile.mScreenOffTimeout);pw.print(" mWakeLockSummary=");pw.print(profile.mWakeLockSummary);pw.print(" mLastUserActivityTime=");pw.print(profile.mLastUserActivityTime);pw.print(" mLockingNotified=");pw.println(profile.mLockingNotified);}pw.println("Display Group User Activity:");for (int idx = 0; idx < mPowerGroups.size(); idx++) {final PowerGroup powerGroup = mPowerGroups.valueAt(idx);pw.println("  displayGroupId=" + powerGroup.getGroupId());pw.println("  userActivitySummary=0x" + Integer.toHexString(powerGroup.getUserActivitySummaryLocked()));pw.println("  lastUserActivityTime=" + TimeUtils.formatUptime(powerGroup.getLastUserActivityTimeLocked()));pw.println("  lastUserActivityTimeNoChangeLights=" + TimeUtils.formatUptime(powerGroup.getLastUserActivityTimeNoChangeLightsLocked()));pw.println("  mWakeLockSummary=0x" + Integer.toHexString(powerGroup.getWakeLockSummaryLocked()));}wcd = mWirelessChargerDetector;}if (wcd != null) {wcd.dump(pw);}if (mNotifier != null) {mNotifier.dump(pw);}mFaceDownDetector.dump(pw);mAmbientDisplaySuppressionController.dump(pw);mLowPowerStandbyController.dump(pw);}

(B)PackageManagerService.java

//frameworks/base/services/core/java/com/android/server/pm/DumpHelper.javapublic void doDump(Computer snapshot, FileDescriptor fd, PrintWriter pw, String[] args) {DumpState dumpState = new DumpState();ArraySet<String> permissionNames = null;int opti = 0;while (opti < args.length) {String opt = args[opti];if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {break;}opti++;if ("-a".equals(opt)) {// Right now we only know how to print all.} else if ("-h".equals(opt)) {printHelp(pw);return;} else if ("--checkin".equals(opt)) {dumpState.setCheckIn(true);} else if ("--all-components".equals(opt)) {dumpState.setOptionEnabled(DumpState.OPTION_DUMP_ALL_COMPONENTS);} else if ("-f".equals(opt)) {dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);} else if ("--proto".equals(opt)) {dumpProto(snapshot, fd);return;} else {pw.println("Unknown argument: " + opt + "; use -h for help");}}// Is the caller requesting to dump a particular piece of data?if (opti < args.length) {String cmd = args[opti];opti++;// Is this a package name?if ("android".equals(cmd) || cmd.contains(".")) {dumpState.setTargetPackageName(cmd);// When dumping a single package, we always dump all of its// filter information since the amount of data will be reasonable.dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);} else if ("check-permission".equals(cmd)) {if (opti >= args.length) {pw.println("Error: check-permission missing permission argument");return;}String perm = args[opti];opti++;if (opti >= args.length) {pw.println("Error: check-permission missing package argument");return;}String pkg = args[opti];opti++;int user = UserHandle.getUserId(Binder.getCallingUid());if (opti < args.length) {try {user = Integer.parseInt(args[opti]);} catch (NumberFormatException e) {pw.println("Error: check-permission user argument is not a number: "+ args[opti]);return;}}// Normalize package name to handle renamed packages and static libspkg = snapshot.resolveInternalPackageName(pkg,PackageManager.VERSION_CODE_HIGHEST);pw.println(mPermissionManager.checkPermission(perm, pkg, user));return;} else if ("l".equals(cmd) || "libraries".equals(cmd)) {dumpState.setDump(DumpState.DUMP_LIBS);} else if ("f".equals(cmd) || "features".equals(cmd)) {dumpState.setDump(DumpState.DUMP_FEATURES);} else if ("r".equals(cmd) || "resolvers".equals(cmd)) {if (opti >= args.length) {dumpState.setDump(DumpState.DUMP_ACTIVITY_RESOLVERS| DumpState.DUMP_SERVICE_RESOLVERS| DumpState.DUMP_RECEIVER_RESOLVERS| DumpState.DUMP_CONTENT_RESOLVERS);} else {while (opti < args.length) {String name = args[opti];if ("a".equals(name) || "activity".equals(name)) {dumpState.setDump(DumpState.DUMP_ACTIVITY_RESOLVERS);} else if ("s".equals(name) || "service".equals(name)) {dumpState.setDump(DumpState.DUMP_SERVICE_RESOLVERS);} else if ("r".equals(name) || "receiver".equals(name)) {dumpState.setDump(DumpState.DUMP_RECEIVER_RESOLVERS);} else if ("c".equals(name) || "content".equals(name)) {dumpState.setDump(DumpState.DUMP_CONTENT_RESOLVERS);} else {pw.println("Error: unknown resolver table type: " + name);return;}opti++;}}} else if ("perm".equals(cmd) || "permissions".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PERMISSIONS);} else if ("permission".equals(cmd)) {if (opti >= args.length) {pw.println("Error: permission requires permission name");return;}permissionNames = new ArraySet<>();while (opti < args.length) {permissionNames.add(args[opti]);opti++;}dumpState.setDump(DumpState.DUMP_PERMISSIONS| DumpState.DUMP_PACKAGES | DumpState.DUMP_SHARED_USERS);} else if ("pref".equals(cmd) || "preferred".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PREFERRED);} else if ("preferred-xml".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PREFERRED_XML);if (opti < args.length && "--full".equals(args[opti])) {dumpState.setFullPreferred(true);opti++;}} else if ("d".equals(cmd) || "domain-preferred-apps".equals(cmd)) {dumpState.setDump(DumpState.DUMP_DOMAIN_PREFERRED);} else if ("p".equals(cmd) || "packages".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PACKAGES);} else if ("q".equals(cmd) || "queries".equals(cmd)) {dumpState.setDump(DumpState.DUMP_QUERIES);} else if ("s".equals(cmd) || "shared-users".equals(cmd)) {dumpState.setDump(DumpState.DUMP_SHARED_USERS);if (opti < args.length && "noperm".equals(args[opti])) {dumpState.setOptionEnabled(DumpState.OPTION_SKIP_PERMISSIONS);}} else if ("prov".equals(cmd) || "providers".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PROVIDERS);} else if ("m".equals(cmd) || "messages".equals(cmd)) {dumpState.setDump(DumpState.DUMP_MESSAGES);} else if ("v".equals(cmd) || "verifiers".equals(cmd)) {dumpState.setDump(DumpState.DUMP_VERIFIERS);} else if ("dv".equals(cmd) || "domain-verifier".equals(cmd)) {dumpState.setDump(DumpState.DUMP_DOMAIN_VERIFIER);} else if ("version".equals(cmd)) {dumpState.setDump(DumpState.DUMP_VERSION);} else if ("k".equals(cmd) || "keysets".equals(cmd)) {dumpState.setDump(DumpState.DUMP_KEYSETS);} else if ("installs".equals(cmd)) {dumpState.setDump(DumpState.DUMP_INSTALLS);} else if ("frozen".equals(cmd)) {dumpState.setDump(DumpState.DUMP_FROZEN);} else if ("volumes".equals(cmd)) {dumpState.setDump(DumpState.DUMP_VOLUMES);} else if ("dexopt".equals(cmd)) {dumpState.setDump(DumpState.DUMP_DEXOPT);} else if ("compiler-stats".equals(cmd)) {dumpState.setDump(DumpState.DUMP_COMPILER_STATS);} else if ("changes".equals(cmd)) {dumpState.setDump(DumpState.DUMP_CHANGES);} else if ("service-permissions".equals(cmd)) {dumpState.setDump(DumpState.DUMP_SERVICE_PERMISSIONS);} else if ("known-packages".equals(cmd)) {dumpState.setDump(DumpState.DUMP_KNOWN_PACKAGES);} else if ("t".equals(cmd) || "timeouts".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PER_UID_READ_TIMEOUTS);} else if ("snapshot".equals(cmd)) {dumpState.setDump(DumpState.DUMP_SNAPSHOT_STATISTICS);if (opti < args.length) {if ("--full".equals(args[opti])) {dumpState.setBrief(false);opti++;} else if ("--brief".equals(args[opti])) {dumpState.setBrief(true);opti++;}}} else if ("protected-broadcasts".equals(cmd)) {dumpState.setDump(DumpState.DUMP_PROTECTED_BROADCASTS);} else if (sPmsExt.dumpCmdHandle(cmd, pw, args, opti)) {return;}}//...}}

(C)CameraService.cpp(media.camera)

//frameworks/av/services/camera/libcameraservice/CameraService.cppstatus_t CameraService::dump(int fd, const Vector<String16>& args) {ATRACE_CALL();if (checkCallingPermission(sDumpPermission) == false) {dprintf(fd, "Permission Denial: can't dump CameraService from pid=%d, uid=%d\n",CameraThreadState::getCallingPid(),CameraThreadState::getCallingUid());return NO_ERROR;}bool locked = tryLock(mServiceLock);// failed to lock - CameraService is probably deadlockedif (!locked) {dprintf(fd, "!! CameraService may be deadlocked !!\n");}if (!mInitialized) {dprintf(fd, "!! No camera HAL available !!\n");// Dump event log for error informationdumpEventLog(fd);if (locked) mServiceLock.unlock();return NO_ERROR;}dprintf(fd, "\n== Service global info: ==\n\n");dprintf(fd, "Number of camera devices: %d\n", mNumberOfCameras);dprintf(fd, "Number of normal camera devices: %zu\n", mNormalDeviceIds.size());dprintf(fd, "Number of public camera devices visible to API1: %zu\n",mNormalDeviceIdsWithoutSystemCamera.size());for (size_t i = 0; i < mNormalDeviceIds.size(); i++) {dprintf(fd, "    Device %zu maps to \"%s\"\n", i, mNormalDeviceIds[i].c_str());}String8 activeClientString = mActiveClientManager.toString();dprintf(fd, "Active Camera Clients:\n%s", activeClientString.string());dprintf(fd, "Allowed user IDs: %s\n", toString(mAllowedUsers).string());dumpEventLog(fd);bool stateLocked = tryLock(mCameraStatesLock);if (!stateLocked) {dprintf(fd, "CameraStates in use, may be deadlocked\n");}int argSize = args.size();for (int i = 0; i < argSize; i++) {if (args[i] == TagMonitor::kMonitorOption) {if (i + 1 < argSize) {mMonitorTags = String8(args[i + 1]);}break;}}for (auto& state : mCameraStates) {String8 cameraId = state.first;dprintf(fd, "== Camera device %s dynamic info: ==\n", cameraId.string());CameraParameters p = state.second->getShimParams();if (!p.isEmpty()) {dprintf(fd, "  Camera1 API shim is using parameters:\n        ");p.dump(fd, args);}auto clientDescriptor = mActiveClientManager.get(cameraId);if (clientDescriptor != nullptr) {// log the current open session infodumpOpenSessionClientLogs(fd, args, cameraId);} else {dumpClosedSessionClientLogs(fd, cameraId);}}if (stateLocked) mCameraStatesLock.unlock();if (locked) mServiceLock.unlock();mCameraProviderManager->dump(fd, args);dprintf(fd, "\n== Vendor tags: ==\n\n");sp<VendorTagDescriptor> desc = VendorTagDescriptor::getGlobalVendorTagDescriptor();if (desc == NULL) {sp<VendorTagDescriptorCache> cache =VendorTagDescriptorCache::getGlobalVendorTagCache();if (cache == NULL) {dprintf(fd, "No vendor tags.\n");} else {cache->dump(fd, /*verbosity*/2, /*indentation*/2);}} else {desc->dump(fd, /*verbosity*/2, /*indentation*/2);}// Dump camera traces if there were anydprintf(fd, "\n");camera3::CameraTraces::dump(fd);// Process dump arguments, if anyint n = args.size();String16 verboseOption("-v");String16 unreachableOption("--unreachable");for (int i = 0; i < n; i++) {if (args[i] == verboseOption) {// change logging levelif (i + 1 >= n) continue;String8 levelStr(args[i+1]);int level = atoi(levelStr.string());dprintf(fd, "\nSetting log level to %d.\n", level);setLogLevel(level);} else if (args[i] == unreachableOption) {// Dump memory analysis// TODO - should limit be an argument parameter?UnreachableMemoryInfo info;bool success = GetUnreachableMemory(info, /*limit*/ 10000);if (!success) {dprintf(fd, "\n== Unable to dump unreachable memory. ""Try disabling SELinux enforcement. ==\n");} else {dprintf(fd, "\n== Dumping unreachable memory: ==\n");std::string s = info.ToString(/*log_contents*/ true);write(fd, s.c_str(), s.size());}}}bool serviceLocked = tryLock(mServiceLock);// Dump info from previous open sessions.// Reposition the offset to beginning of the file before readingif ((mMemFd >= 0) && (lseek(mMemFd, 0, SEEK_SET) != -1)) {dprintf(fd, "\n**********Dumpsys from previous open session**********\n");ssize_t size_read;char buf[4096];while ((size_read = read(mMemFd, buf, (sizeof(buf) - 1))) > 0) {// Read data from file to a small buffer and write it to fd.write(fd, buf, size_read);if (size_read == -1) {ALOGE("%s: Error during reading the file: %s", __FUNCTION__, sFileName);break;}}dprintf(fd, "\n**********End of Dumpsys from previous open session**********\n");} else {ALOGE("%s: Error during reading the file: %s", __FUNCTION__, sFileName);}if (serviceLocked) mServiceLock.unlock();return NO_ERROR;
}

这篇关于dumpsys相关解析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/439752

相关文章

网页解析 lxml 库--实战

lxml库使用流程 lxml 是 Python 的第三方解析库,完全使用 Python 语言编写,它对 XPath表达式提供了良好的支 持,因此能够了高效地解析 HTML/XML 文档。本节讲解如何通过 lxml 库解析 HTML 文档。 pip install lxml lxm| 库提供了一个 etree 模块,该模块专门用来解析 HTML/XML 文档,下面来介绍一下 lxml 库

sqlite3 相关知识

WAL 模式 VS 回滚模式 特性WAL 模式回滚模式(Rollback Journal)定义使用写前日志来记录变更。使用回滚日志来记录事务的所有修改。特点更高的并发性和性能;支持多读者和单写者。支持安全的事务回滚,但并发性较低。性能写入性能更好,尤其是读多写少的场景。写操作会造成较大的性能开销,尤其是在事务开始时。写入流程数据首先写入 WAL 文件,然后才从 WAL 刷新到主数据库。数据在开始

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

OWASP十大安全漏洞解析

OWASP(开放式Web应用程序安全项目)发布的“十大安全漏洞”列表是Web应用程序安全领域的权威指南,它总结了Web应用程序中最常见、最危险的安全隐患。以下是对OWASP十大安全漏洞的详细解析: 1. 注入漏洞(Injection) 描述:攻击者通过在应用程序的输入数据中插入恶意代码,从而控制应用程序的行为。常见的注入类型包括SQL注入、OS命令注入、LDAP注入等。 影响:可能导致数据泄

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

Spring 源码解读:自定义实现Bean定义的注册与解析

引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。

两个月冲刺软考——访问位与修改位的题型(淘汰哪一页);内聚的类型;关于码制的知识点;地址映射的相关内容

1.访问位与修改位的题型(淘汰哪一页) 访问位:为1时表示在内存期间被访问过,为0时表示未被访问;修改位:为1时表示该页面自从被装入内存后被修改过,为0时表示未修改过。 置换页面时,最先置换访问位和修改位为00的,其次是01(没被访问但被修改过)的,之后是10(被访问了但没被修改过),最后是11。 2.内聚的类型 功能内聚:完成一个单一功能,各个部分协同工作,缺一不可。 顺序内聚:

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

log4j2相关配置说明以及${sys:catalina.home}应用

${sys:catalina.home} 等价于 System.getProperty("catalina.home") 就是Tomcat的根目录:  C:\apache-tomcat-7.0.77 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> 2017-08-10

Node Linux相关安装

下载经编译好的文件cd /optwget https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.gztar -xvf node-v10.15.3-linux-x64.tar.gzln -s /opt/node-v10.15.3-linux-x64/bin/npm /usr/local/bin/ln -s /opt/nod