Memory就很好地實(shí)現(xiàn)了這 2 個(gè)條件:[3 hours]: 表示統(tǒng)計(jì)過(guò)去 3 小..."/>
溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

性能測(cè)試指標(biāo)

發(fā)布時(shí)間:2020-07-12 21:56:45 來(lái)源:網(wǎng)絡(luò) 閱讀:987 作者:白眼郎 欄目:開(kāi)發(fā)技術(shù)

一個(gè)好的性能測(cè)試指標(biāo)應(yīng)該滿足 2 個(gè)條件:

  1. 對(duì)過(guò)去發(fā)生的事情做總結(jié).

  2. 對(duì)未來(lái)做預(yù)期.

 

Settings->Memory就很好地實(shí)現(xiàn)了這 2 個(gè)條件:

性能測(cè)試指標(biāo)

  1. [3 hours]: 表示統(tǒng)計(jì)過(guò)去 3 小時(shí) RAM 的使用情況. 使用者還可以選擇 6 小時(shí), 12 小時(shí), 1 .

  2. [Performance]: 表示手機(jī)當(dāng)前的性能情況. 這里有一套 Google 的性能評(píng)價(jià)標(biāo)準(zhǔn).

  3. [Total memory]/[Average used]/[Free]: 統(tǒng)計(jì)時(shí)間內(nèi) RAM 的平均使用情況. 特別是 Free, 這里也有一套 Google 的性能評(píng)價(jià)標(biāo)準(zhǔn).

—— 2 個(gè)評(píng)價(jià)標(biāo)準(zhǔn)是本次的重點(diǎn).

 

[Performance] —— 該指標(biāo)的評(píng)價(jià)標(biāo)準(zhǔn).

這是 Google 的即時(shí)指標(biāo). 僅表示打開(kāi) memory 這個(gè)頁(yè)面時(shí), 手機(jī)的 RAM 情況.

Google 的理念仍然是: RAM 不使用就是浪費(fèi), 與其浪費(fèi), 不如用來(lái)做 Cached. 所以, 當(dāng) Cached 數(shù)量少于一定數(shù)值的時(shí)候, 就表示內(nèi)存不足了. Kernel Space, 使用 minfree 來(lái)做衡量 Cached 是否充足的指標(biāo); User Space, 使用 memFactor 來(lái)做衡量 Cached 是否充足的指標(biāo).

memFactor是這樣定義的:

android/platform/frameworks/base/nougat-release/./services/core/java/com/android/server/am/ActivityManagerService.java

        // Now determine the memory trimming  level of background processes.

        // Unfortunately we need to start at  the back of the list to do this

        // properly.  We only do this if the number of background  apps we

        // are managing to keep around is  less than half the maximum we desire;

        // if we are keeping a good number  around, we'll let them use whatever

        // memory they want.

        final int numCachedAndEmpty =  numCached + numEmpty;

        int memFactor;

        if (numCached <= ProcessList.TRIM_CACHED_APPS

                && numEmpty <=  ProcessList.TRIM_EMPTY_APPS)  {

            if (numCachedAndEmpty <=  ProcessList.TRIM_CRITICAL_THRESHOLD)  {

                memFactor =  ProcessStats.ADJ_MEM_FACTOR_CRITICAL;

            } else if (numCachedAndEmpty  <= ProcessList.TRIM_LOW_THRESHOLD)  {

                memFactor =  ProcessStats.ADJ_MEM_FACTOR_LOW;

            } else {

                memFactor =  ProcessStats.ADJ_MEM_FACTOR_MODERATE;

            }

        } else {

            memFactor =  ProcessStats.ADJ_MEM_FACTOR_NORMAL;

        }

也就是:

Cached Process + Empty Process <= 3 個(gè), 則認(rèn)為 Critical Memory

Cached Process + Empty Process <= 5 個(gè), 則認(rèn)為 Low Memory

Cached Process <= 5 個(gè), 而且 Empty Process <= 8 個(gè), 則認(rèn)為 Moderate Memory

其他情況則認(rèn)為 Normal Memory

如果修改了 MAX_CACHED_APPS, 如上的 Threshold 也會(huì)被重新計(jì)算.

    // The maximum number of cached processes  we will keep around before killing them.

    // NOTE: this constant is *only* a  control to not let us go too crazy with

    // keeping around processes on devices  with large amounts of RAM.  For devices  that

    // are tighter on RAM, the out of memory  killer is responsible for killing background

    // processes as RAM is needed, and we  should *never* be relying on this limit to

    // kill them.  Also note that this limit only applies to  cached background processes;

    // we have no limit on the number of  service, visible, foreground, or other such

    // processes and the number of those  processes does not count against the cached

    // process limit.

    static final int MAX_CACHED_APPS = 32;

 

[Free] —— 該指標(biāo)的評(píng)價(jià)標(biāo)準(zhǔn).

這是 Google M 上加入的歷史指標(biāo). 該指標(biāo)不僅僅計(jì)算了過(guò)去一段時(shí)間的 Free RAM 情況, 而且特別在算法上加入了 Safe RAM 對(duì)未來(lái)的手機(jī)性能做預(yù)測(cè).

android/platform/packages/apps/Settings/nougat-release/./src/com/android/settings/applications/ProcStatsData.java

            if (memInfo.hiddenAppThreshold  >= realFreeRam) {

                realUsedRam = freeRam;

                realFreeRam = 0;

                baseCacheRam = (long) realFreeRam;

            } else {

                realUsedRam +=  memInfo.hiddenAppThreshold;

                realFreeRam -= memInfo.hiddenAppThreshold;

                baseCacheRam =  memInfo.hiddenAppThreshold;

            }

在這里有 2 個(gè)點(diǎn)需要注意:

  1. memInfo.hiddenAppThreshold. 這是 ADJ=9 對(duì)應(yīng)的水位. 也就是如下的 55296 x 4K = 216M

>adb shell cat  /sys/module/lowmemorykiller/parameters/minfree

18432,23040,27648,32256,55296,80640

  1. realFreeRam. 它包括 4 個(gè)部分, 分別是 Free + Cached + Buffer Mapped.

如果統(tǒng)計(jì)得到的 realFreeRam 多于216M, 就在 realFreeRam 中扣除 216M, 獲得的就是 App 可以使用的 Free RAM.

如果統(tǒng)計(jì)得到的 realFreeRam 少于216M, 那么表示 safe 空間已經(jīng)被用完, App 可以使用的 Free RAM 就是 0.

 

會(huì)有這樣的聲音: 當(dāng) Free 0 時(shí), 手機(jī)還是可以正常運(yùn)行啊? 這個(gè)數(shù)據(jù)是不是錯(cuò)誤的?

Google 之所以設(shè)計(jì)這個(gè)算法, 是因?yàn)橛羞@樣一個(gè)事實(shí): 當(dāng) LMK 殺到 ADJ<9 的進(jìn)程后, 手機(jī)性能會(huì)開(kāi)始下降. 一開(kāi)始并不明顯, 但隨著使用時(shí)間的增加, 下降會(huì)越來(lái)越明顯, 越來(lái)越快.

所以 Google 使用 ADJ=9 minfree Safe RAM, 是有價(jià)值并且很明智的.

對(duì)于使用者, 通過(guò)這個(gè)指標(biāo), 可以很簡(jiǎn)單知道自己的操作習(xí)慣對(duì)手機(jī)性能的影響.

 

因?yàn)檫@套指標(biāo)會(huì)讓數(shù)據(jù)變得很不漂亮, 很多產(chǎn)品會(huì)排斥. 但是作為 PM, 這套指標(biāo)會(huì)讓你的產(chǎn)品變得更 safe.

為了數(shù)據(jù)漂亮, 減少 minfree 會(huì)是一個(gè)做法. 但是另一個(gè)事實(shí)是, 調(diào)低水位, 會(huì)讓 RAM 變得緊張, 增加 swap, 從而使得手機(jī)變慢. 如果使用的 eMMC 性能并不好, 請(qǐng)不要這樣做. 增加 RAM, 減少預(yù)置功能, 積極做進(jìn)程清理才是王道.


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI