android dumpsys

331 阅读8分钟

1. dumpsys命令

1.1. dumpsys --help

usage: dumpsys

        To dump all services.

        or:

        dumpsys [-t TIMEOUT] [--priority LEVEL] [--clients] [--dump] [--pid] [--thread] [--help | -l | --skip SERVICES | SERVICE [ARGS]]

        --help: shows this help

        -l: only list services, do not dump them

        -t TIMEOUT_SEC: TIMEOUT to use in seconds instead of default 10 seconds

        -T TIMEOUT_MS: TIMEOUT to use in milliseconds instead of default 10 seconds

        --clients: dump client PIDs instead of usual dump

        --dump: ask the service to dump itself (this is the default)

        --pid: dump PID instead of usual dump

        --proto: filter services that support dumping data in proto format. Dumps

        will be in proto format.

        --priority LEVEL: filter services based on specified priority

        LEVEL must be one of CRITICAL | HIGH | NORMAL

        --skip SERVICES: dumps all services but SERVICES (comma-separated list)

        --stability: dump binder stability information instead of usual dump

        --thread: dump thread usage instead of usual dump

        SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it`

1.2. dumpsys activity -h

  Activity manager dump options:

  [-a] [-c] [-p PACKAGE] [-h] [WHAT] ...

  WHAT may be one of:

    a[ctivities]: activity stack state

    r[recents]: recent activities state

    b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state

    broadcast-stats [PACKAGE_NAME]: aggregated broadcast statistics

    i[ntents] [PACKAGE_NAME]: pending intent state

    p[rocesses] [PACKAGE_NAME]: process state

    o[om]: out of memory management

    perm[issions]: URI permission grant state

    prov[iders] [COMP_SPEC ...]: content provider state

    provider [COMP_SPEC]: provider client-side state

    s[ervices] [COMP_SPEC ...]: service state

    allowed-associations: current package association restrictions

    as[sociations]: tracked app associations

    exit-info [PACKAGE_NAME]: historical process exit information

    lmk: stats on low memory killer

    lru: raw LRU process list

    binder-proxies: stats on binder objects and IPCs

    settings: currently applied config settings

    service [COMP_SPEC]: service client-side state

    package [PACKAGE_NAME]: all state related to given package

    all: dump all activities

    top: dump the top activity

  WHAT may also be a COMP_SPEC to dump activities.

  COMP_SPEC may be a component name (com.foo/.myApp),

    a partial substring in a component name, a

    hex object identifier.

  -a: include all available server state.

  -c: include client state.

  -p: limit output to given package.

  --checkin: output checkin format, resetting data.

  --C: output checkin format, not resetting data.

  --proto: output dump in protocol buffer format.

  --dump-dumpable: dump just the DUMPABLE-related state of an activity. Use the --list-dumpables option to list the supported DUMPABLEs

  --list-dumpables: show the available dumpables in an activity

1.3. dumpsys window -h

Window manager dump options:

  [-a] [-h] [cmd] ...

  cmd may be one of:

    l[astanr]: last ANR information

    p[policy]: policy state

    a[animator]: animator state

    s[essions]: active sessions

    surfaces: active surfaces (debugging enabled only)

    d[isplays]: active display contents

    t[okens]: token list

    w[indows]: window list

    package-config: installed packages having app-specific config

    trace: print trace status and write Winscope trace to file

  cmd may also be a NAME to dump windows.  NAME may

    be a partial substring in a window name, a

    Window hex object identifier, or

    "all" for all windows, or

    "visible" for the visible windows.

    "visible-apps" for the visible app windows.

  -a: include all available server state.

  --proto: output dump in protocol buffer format.

1.4. dumpsys power

1.4.1. 查看亮灭屏状态

dumpsys power | grep mWakefulness  Asleep表示休眠

1.5. dumpsys battery -h

Battery service (battery) commands:

  help

    Print this help text.

  get [-f] [ac|usb|wireless|status|level|temp|present|counter|invalid]

  set [-f] [ac|usb|wireless|status|level|temp|present|counter|invalid] <value>

    Force a battery property value, freezing battery state.

    -f: force a battery change broadcast be sent, prints new sequence.

  unplug [-f]

    Force battery unplugged, freezing battery state.

    -f: force a battery change broadcast be sent, prints new sequence.

  reset [-f]

    Unfreeze battery state, returning to current hardware values.

    -f: force a battery change broadcast be sent, prints new sequence.

  suspend_input

    Suspend charging even if plugged in.

1.5.1. 查看电量百分比

dumpsys battery | grep level  中level字段  或者 dumpsys power | grep mBatteryLevel   对应的数字就是电量百分比

1.6. dumpsys batterystats -h

Battery stats (batterystats) dump options:

  [--checkin] [--proto] [--history] [--history-start] [--charged] [-c]

  [--daily] [--reset] [--reset-all] [--write] [--new-daily] [--read-daily]

  [-h] [<package.name>]

  --checkin: generate output for a checkin report; will write (and clear) the

             last old completed stats when they had been reset.

  -c: write the current stats in checkin format.

  --proto: write the current aggregate stats (without history) in proto format.

  --history: show only history data.

  --history-start <num>: show only history data starting at given time offset.

  --history-create-events <num>: create <num> of battery history events.

  --charged: only output data since last charged.

  --daily: only output full daily data.

  --reset: reset the stats, clearing all current data.

  --reset-all: reset the stats, clearing all current and past data.

  --write: force write current collected stats to disk.

  --new-daily: immediately create and write new daily stats record.

  --read-daily: read-load last written daily stats.

  --settings: dump the settings key/values related to batterystats

  --cpu: dump cpu stats for debugging purpose

  --power-profile: dump the power profile constants

  <package.name>: optional name of package to filter output by.

  -h: print this help text.

Battery stats (batterystats) commands:

  enable|disable <option>

    Enable or disable a running option.  Option state is not saved across boots.

    Options are:

      full-history: include additional detailed events in battery history:

          wake_lock_in, alarms and proc events

      no-auto-reset: don't automatically reset stats when unplugged

      pretend-screen-off: pretend the screen is off, even if screen state changes

Statistics since last charge:

System starts: 系统重启次数

Estimated battery capacity:电池总容量

Time on battery:电池使用时间。

Time on battery screen off:在灭屏状态下,电池的使用时间。

Total run time:总共的电池使用时间

Discharge:放电量,既总共使用的电量

Screen off discharge:灭屏状态下的放电量

Start clock time:开始电量统计的时刻

Total partial wakelock time:应用层持有wakelock的总时间

1.6.1. 重置数据****

dumpsys batterystats --reset  重置数据

 

1.6.2. 设置不会自动触发重置****

dumpsys batterystats --enable no-auto-reset  设置不会触发重置.

1.6.3. 模拟断电场景****

dumpsys battery unplug  模拟拔下设备电源,手机上看不到充电标志

1.6.4. 查看电流基准值****

dumpsys batterystats --power-profile

1.7. dumpsys SurfaceFlinger

1.8. dumpsys alarm

1.9. dumpsys appops -h

AppOps service (appops) dump options:

  -h

    Print this help text.

  --op [OP]

    Limit output to data associated with the given app op code.

  --mode [MODE]

    Limit output to data associated with the given app op mode.

  --package [PACKAGE]

    Limit output to data associated with the given package name.

  --attributionTag [attributionTag]

    Limit output to data associated with the given attribution tag.

  --include-discrete [n]

    Include discrete ops limited to n per dimension. Use zero for no limit.

  --watchers

    Only output the watcher sections.

  --history

    Only output history.

1.10. dumpsys deviceidle -h

Device idle controller (deviceidle) commands:

  help

    Print this help text.

  step [light|deep]

    Immediately step to next state, without waiting for alarm.

  force-idle [light|deep]

    Force directly into idle mode, regardless of other device state.

  force-inactive

    Force to be inactive, ready to freely step idle states.

  unforce

    Resume normal functioning after force-idle or force-inactive.

  get [light|deep|force|screen|charging|network]

    Retrieve the current given state.

  disable [light|deep|all]

    Completely disable device idle mode.

  enable [light|deep|all]

    Re-enable device idle mode after it had previously been disabled.

  enabled [light|deep|all]

    Print 1 if device idle mode is currently enabled, else 0.

  whitelist

    Print currently whitelisted apps.

  whitelist [package ...]

    Add (prefix with +) or remove (prefix with -) packages.

  sys-whitelist [package ...|reset]

    Prefix the package with '-' to remove it from the system whitelist or '+' to put it back in the system whitelist.

    Note that only packages that were earlier removed from the system whitelist can be added back.

    reset will reset the whitelist to the original state

    Prints the system whitelist if no arguments are specified

  except-idle-whitelist [package ...|reset]

    Prefix the package with '+' to add it to whitelist or '=' to check if it is already whitelisted

    [reset] will reset the whitelist to it's original state

    Note that unlike <whitelist> cmd, changes made using this won't be persisted across boots

  tempwhitelist

    Print packages that are temporarily whitelisted.

  tempwhitelist [-u USER] [-d DURATION] [-r] [package]

    Temporarily place package in whitelist for DURATION milliseconds.

    If no DURATION is specified, 10 seconds is used

    If [-r] option is used, then the package is removed from temp whitelist and any [-d] is ignored

  motion

    Simulate a motion event to bring the device out of deep doze

  pre-idle-factor [0|1|2]

    Set a new factor to idle time before step to idle(inactive_to and idle_after_inactive_to)

  reset-pre-idle-factor

    Reset factor to idle time to default

1.11. dumpsys dropbox -h

Dropbox (dropbox) dump options:

  [-h|--help] [-p|--print] [-f|--file] [timestamp]

    -h|--help: print this help

    -p|--print: print full contents of each entry

    -f|--file: print path of each entry's file

    --proto: dump data to proto

  [timestamp] optionally filters to only those entries.

1.12. dumpsys input

1.13. dumpsys jobscheduler -h

Job Scheduler (jobscheduler) dump options:

  [-h] [package] ...

    -h: print this help

  [package] is an optional package name to limit the output to.

1.14. dumpsys location

1.15. dumpsys meminfo -h

meminfo dump options: [-a] [-d] [-c] [-s] [--oom] [process]

  -a: include all available information for each process.

  -d: include dalvik details.

  -c: dump in a compact machine-parseable representation.

  -s: dump only summary of application memory usage.

  -S: dump also SwapPss.

  --oom: only show processes organized by oom adj.

  --local: only collect details locally, don't call process.

  --package: interpret process arg as package, dumping all

             processes that have loaded that package.

  --checkin: dump data for a checkin

  --proto: dump data to proto

If [process] is specified it can be the name or

pid of a specific process to dump.

  

1.16. dumpsys package -h

 

Package manager dump options:

  [-h] [-f] [--checkin] [--all-components] [cmd] ...

    --checkin: dump for a checkin

    -f: print details of intent filters

    -h: print this help

    --all-components: include all component names in package dump

  cmd may be one of:

    apex: list active APEXes and APEX session state

    l[ibraries]: list known shared libraries

    f[eatures]: list device features

    k[eysets]: print known keysets

    r[esolvers] [activity|service|receiver|content]: dump intent resolvers

    perm[issions]: dump permissions

    permission [name ...]: dump declaration and use of given permission

    pref[erred]: print preferred package settings

    preferred-xml [--full]: print preferred package settings as xml

    prov[iders]: dump content providers

    p[ackages]: dump installed packages

    q[ueries]: dump app queryability calculations

    s[hared-users]: dump shared user IDs

    m[essages]: print collected runtime messages

    v[erifiers]: print package verifier info

    d[omain-preferred-apps]: print domains preferred apps

    i[ntent-filter-verifiers]|ifv: print intent filter verifier info

    t[imeouts]: print read timeouts for known digesters

    version: print database version info

    write: write current settings now

    installs: details about install sessions

    check-permission <permission> <package> [<user>]: does pkg hold perm?

    dexopt: dump dexopt state

    compiler-stats: dump compiler statistics

    service-permissions: dump permissions required by services

    snapshot: dump snapshot statistics

    protected-broadcasts: print list of protected broadcast actions

    known-packages: dump known packages

    <package.name>: info about given package

1.17. dumpsys procstats -h

Process stats (procstats) dump options:

    [--checkin|-c|--csv] [--csv-screen] [--csv-proc] [--csv-mem]

    [--details] [--full-details] [--current] [--hours N] [--last N]

    [--max N] --active] [--commit] [--reset] [--clear] [--write] [-h]

    [--start-testing] [--stop-testing]

    [--pretend-screen-on] [--pretend-screen-off] [--stop-pretend-screen]

    [<package.name>]

  --checkin: perform a checkin: print and delete old committed states.

  -c: print only state in checkin format.

  --csv: output data suitable for putting in a spreadsheet.

  --csv-screen: on, off.

  --csv-mem: norm, mod, low, crit.

  --csv-proc: pers, top, fore, vis, precept, backup,

    service, home, prev, cached

  --details: dump per-package details, not just summary.

  --full-details: dump all timing and active state details.

  --current: only dump current state.

  --hours: aggregate over about N last hours.

  --last: only show the last committed stats at index N (starting at 1).

  --max: for -a, max num of historical batches to print.

  --active: only show currently active processes/services.

  --commit: commit current stats to disk and reset to start new stats.

  --section: proc|pkg-proc|pkg-svc|pkg-asc|pkg-all|all

    options can be combined to select desired stats

  --reset: reset current stats, without committing.

  --clear: clear all stats; does both --reset and deletes old stats.

  --write: write current in-memory stats to disk.

  --read: replace current stats with last-written stats.

  --start-testing: clear all stats and starting high frequency pss sampling.

  --stop-testing: stop high frequency pss sampling.

  --pretend-screen-on: pretend screen is on.

  --pretend-screen-off: pretend screen is off.

  --stop-pretend-screen: forget "pretend screen" and use the real state.

  -a: print everything.

  -h: print this help text.

  <package.name>: optional name of package to filter output by.

 

1.18. dumpsys settings -h

Settings provider dump options:

  [-h] [--proto]

  -h: print this help.

  --proto: dump as protobuf.

1.19. dumpsys wallpaper

1.20. dumpsys sensorservice

dumpsys sensorservice restrict com.aa.aa  // 开启限制模式,最后一个字段追加白名单包名

dumpsys sensorservice enable // 关闭限制模式,与上面一条命令对立

1.21. dumpsys suspend_control_internal -h

Usage: adb shell dumpsys suspend_control_internal [option]

 

   Options:

       --wakelocks        : returns wakelock stats.

       --wakeups          : returns wakeup stats.

       --kernel_suspends  : returns suspend success/error stats from the kernel

       --suspend_controls : returns suspend control stats

       --all or -a        : returns all stats.

       --help or -h       : prints this message.

 

   Note: All stats are returned  if no or (an

         invalid) option is specified.

total suspend time: 7584940 ms ;表示休眠的总时长 ,dumpsys gfxinfo | grep Uptime中可以用realtime - uptime = 休眠总时长