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

相关文章

SpringCloud动态配置注解@RefreshScope与@Component的深度解析

《SpringCloud动态配置注解@RefreshScope与@Component的深度解析》在现代微服务架构中,动态配置管理是一个关键需求,本文将为大家介绍SpringCloud中相关的注解@Re... 目录引言1. @RefreshScope 的作用与原理1.1 什么是 @RefreshScope1.

Java并发编程必备之Synchronized关键字深入解析

《Java并发编程必备之Synchronized关键字深入解析》本文我们深入探索了Java中的Synchronized关键字,包括其互斥性和可重入性的特性,文章详细介绍了Synchronized的三种... 目录一、前言二、Synchronized关键字2.1 Synchronized的特性1. 互斥2.

Java的IO模型、Netty原理解析

《Java的IO模型、Netty原理解析》Java的I/O是以流的方式进行数据输入输出的,Java的类库涉及很多领域的IO内容:标准的输入输出,文件的操作、网络上的数据传输流、字符串流、对象流等,这篇... 目录1.什么是IO2.同步与异步、阻塞与非阻塞3.三种IO模型BIO(blocking I/O)NI

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

JavaScript Array.from及其相关用法详解(示例演示)

《JavaScriptArray.from及其相关用法详解(示例演示)》Array.from方法是ES6引入的一个静态方法,用于从类数组对象或可迭代对象创建一个新的数组实例,本文将详细介绍Array... 目录一、Array.from 方法概述1. 方法介绍2. 示例演示二、结合实际场景的使用1. 初始化二

Redis中高并发读写性能的深度解析与优化

《Redis中高并发读写性能的深度解析与优化》Redis作为一款高性能的内存数据库,广泛应用于缓存、消息队列、实时统计等场景,本文将深入探讨Redis的读写并发能力,感兴趣的小伙伴可以了解下... 目录引言一、Redis 并发能力概述1.1 Redis 的读写性能1.2 影响 Redis 并发能力的因素二、

Spring MVC使用视图解析的问题解读

《SpringMVC使用视图解析的问题解读》:本文主要介绍SpringMVC使用视图解析的问题解读,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Spring MVC使用视图解析1. 会使用视图解析的情况2. 不会使用视图解析的情况总结Spring MVC使用视图

利用Python和C++解析gltf文件的示例详解

《利用Python和C++解析gltf文件的示例详解》gltf,全称是GLTransmissionFormat,是一种开放的3D文件格式,Python和C++是两个非常强大的工具,下面我们就来看看如何... 目录什么是gltf文件选择语言的原因安装必要的库解析gltf文件的步骤1. 读取gltf文件2. 提

Java中的runnable 和 callable 区别解析

《Java中的runnable和callable区别解析》Runnable接口用于定义不需要返回结果的任务,而Callable接口可以返回结果并抛出异常,通常与Future结合使用,Runnab... 目录1. Runnable接口1.1 Runnable的定义1.2 Runnable的特点1.3 使用Ru

使用EasyExcel实现简单的Excel表格解析操作

《使用EasyExcel实现简单的Excel表格解析操作》:本文主要介绍如何使用EasyExcel完成简单的表格解析操作,同时实现了大量数据情况下数据的分次批量入库,并记录每条数据入库的状态,感兴... 目录前言固定模板及表数据格式的解析实现Excel模板内容对应的实体类实现AnalysisEventLis