didi / DoKit

一款面向泛前端产品研发全生命周期的效率平台。
Apache License 2.0
20.22k stars 3.11k forks source link

【Android 10】Android Studio log: E/memtrack: Couldn't load memtrack module #773

Open VomPom opened 3 years ago

VomPom commented 3 years ago

Android Studio frantically logs when using memory detection.

2021-03-30 16:15:14.876 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:15.450 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:15.450 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:16.026 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:16.026 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:16.596 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:16.596 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:17.171 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:17.171 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:17.746 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:17.746 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:18.318 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:18.318 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:18.893 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:18.894 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:19.467 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:19.467 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1 2021-03-30 16:15:20.040 9572-10483/com.didichuxing.doraemondemo.java E/memtrack: Couldn't load memtrack module 2021-03-30 16:15:20.040 9572-10483/com.didichuxing.doraemondemo.java W/android.os.Debug: failed to get memory consumption info: -1

In DoraemonKit:

if (Build.VERSION.SDK_INT > 28) {
    memInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memInfo);
 } 

try many phones which API > 28, got same results

Source from: https://android.googlesource.com/platform/frameworks/base/+/master/core/jni/android_os_Debug.cpp https://android.googlesource.com/platform/system/core/+/refs/tags/android-10.0.0_r34/libmemtrack/memtrack.cpp

System code as follow :

android_os_Debug_getDirtyPagesPid-> read_memtrack_memory-> memtrack_proc_get->android::sp memtrack = get_instance();->

static android::sp<IMemtrack> get_instance() {
static android::sp<IMemtrack> module = IMemtrack::getService();
    if (module == nullptr) {
        ALOGE("Couldn't load memtrack module");
    }
    return module;
}

This caused Log, but don't know why module == nullptr is nullptr, how can we fix it?

Info: HUAWEI TNY-AL00 (Android 10) Android:4.1.1

WeiLingQiang commented 8 months ago

I also encountered the same problem. Is there a solution?