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

相关文章

Linux中shell解析脚本的通配符、元字符、转义符说明

《Linux中shell解析脚本的通配符、元字符、转义符说明》:本文主要介绍shell通配符、元字符、转义符以及shell解析脚本的过程,通配符用于路径扩展,元字符用于多命令分割,转义符用于将特殊... 目录一、linux shell通配符(wildcard)二、shell元字符(特殊字符 Meta)三、s

Linux使用fdisk进行磁盘的相关操作

《Linux使用fdisk进行磁盘的相关操作》fdisk命令是Linux中用于管理磁盘分区的强大文本实用程序,这篇文章主要为大家详细介绍了如何使用fdisk进行磁盘的相关操作,需要的可以了解下... 目录简介基本语法示例用法列出所有分区查看指定磁盘的区分管理指定的磁盘进入交互式模式创建一个新的分区删除一个存

关于Maven生命周期相关命令演示

《关于Maven生命周期相关命令演示》Maven的生命周期分为Clean、Default和Site三个主要阶段,每个阶段包含多个关键步骤,如清理、编译、测试、打包等,通过执行相应的Maven命令,可以... 目录1. Maven 生命周期概述1.1 Clean Lifecycle1.2 Default Li

numpy求解线性代数相关问题

《numpy求解线性代数相关问题》本文主要介绍了numpy求解线性代数相关问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 在numpy中有numpy.array类型和numpy.mat类型,前者是数组类型,后者是矩阵类型。数组

使用Python实现批量访问URL并解析XML响应功能

《使用Python实现批量访问URL并解析XML响应功能》在现代Web开发和数据抓取中,批量访问URL并解析响应内容是一个常见的需求,本文将详细介绍如何使用Python实现批量访问URL并解析XML响... 目录引言1. 背景与需求2. 工具方法实现2.1 单URL访问与解析代码实现代码说明2.2 示例调用

SSID究竟是什么? WiFi网络名称及工作方式解析

《SSID究竟是什么?WiFi网络名称及工作方式解析》SID可以看作是无线网络的名称,类似于有线网络中的网络名称或者路由器的名称,在无线网络中,设备通过SSID来识别和连接到特定的无线网络... 当提到 Wi-Fi 网络时,就避不开「SSID」这个术语。简单来说,SSID 就是 Wi-Fi 网络的名称。比如

SpringCloud配置动态更新原理解析

《SpringCloud配置动态更新原理解析》在微服务架构的浩瀚星海中,服务配置的动态更新如同魔法一般,能够让应用在不重启的情况下,实时响应配置的变更,SpringCloud作为微服务架构中的佼佼者,... 目录一、SpringBoot、Cloud配置的读取二、SpringCloud配置动态刷新三、更新@R

使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)

《使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)》在现代软件开发中,处理JSON数据是一项非常常见的任务,无论是从API接口获取数据,还是将数据存储为JSON格式,解析... 目录1. 背景介绍1.1 jsON简介1.2 实际案例2. 准备工作2.1 环境搭建2.1.1 添加

Redis的Hash类型及相关命令小结

《Redis的Hash类型及相关命令小结》edisHash是一种数据结构,用于存储字段和值的映射关系,本文就来介绍一下Redis的Hash类型及相关命令小结,具有一定的参考价值,感兴趣的可以了解一下... 目录HSETHGETHEXISTSHDELHKEYSHVALSHGETALLHMGETHLENHSET

在C#中合并和解析相对路径方式

《在C#中合并和解析相对路径方式》Path类提供了几个用于操作文件路径的静态方法,其中包括Combine方法和GetFullPath方法,Combine方法将两个路径合并在一起,但不会解析包含相对元素... 目录C#合并和解析相对路径System.IO.Path类幸运的是总结C#合并和解析相对路径对于 C