欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

高通平台Performance机制学习总结

程序员文章站 2022-04-29 21:53:18
...
高通平台Performance机制学习总结
利用在高通平台中的Performance机制,可以提高性能,比如应用的启动速度,滑动流畅性等。接下来就看下高通给我们提供的Performance机制
1.该机制的JNI层实现部分位于
./vendor/qcom/proprietary/android-perf/QPerformance/jni/com_qualcomm_qti_Performance.cpp

上层实现位于
./vendor/qcom/proprietary/android-perf/QPerformance/src/com/qualcomm/qti/Performance.java

2.framework层的使用需要通过反射机制调用com.qualcomm.qti.Performance
具体实现在:
./frameworks/base/core/java/android/util/BoostFramework.java

在BoostFramework的构造函数中通过反射调用Performance对象,而BoostFramework中的好多方法是被hide掉的,可能是为了安全考虑吧,在应用层无法使用,只能在系统层使用。现在举一个例子当应用启动时创建进程的时候可以使用高通给我们提供的Performance机制。
在ActivityManagerService中,构造中会判断是否启动该机制
mIsLaunchBoostv2_enabled = mContext.getResources().getBoolean(
                   com.android.internal.R.bool.config_enableLaunchBoostv2);
if(mIsLaunchBoostv2_enabled) {
           lBoost_v2_TimeOut = mContext.getResources().getInteger(
                   com.android.internal.R.integer.lboostv2_timeout_param);
           lBoost_v2_ParamVal = mContext.getResources().getIntArray(
                   com.android.internal.R.array.lboostv2_param_value);
        }

在startProcessLocked中进行判断:
 // Start launch boost v2
                if (mIsLaunchBoostv2_enabled == true && sPerfBoost_v2 == null) {
                    sPerfBoost_v2 = new BoostFramework();
                }
                if (sPerfBoost_v2 != null) {
                   sPerfBoost_v2.perfLockAcquire(lBoost_v2_TimeOut, lBoost_v2_ParamVal);
                   sIsLaunchBoostv2_set = true;
                }

接下来看一下核心部分BoostFramework的实现
构造函数中通过反射获得Performance对象
    public BoostFramework() {

        if (mIsLoaded == false) {
            try {
                Class perfClass;
                PathClassLoader perfClassLoader;

	        perfClassLoader = new PathClassLoader(PERFORMANCE_JAR,
                                  ClassLoader.getSystemClassLoader());
                perfClass = perfClassLoader.loadClass(PERFORMANCE_CLASS);
                mConstructor = perfClass.getConstructor();

                Class[] argClasses = new Class[] {int.class, int[].class};
                mAcquireFunc =  perfClass.getDeclaredMethod("perfLockAcquire", argClasses);
                Log.v(TAG,"mAcquireFunc method = " + mAcquireFunc);

                argClasses = new Class[] {};
                mReleaseFunc =  perfClass.getDeclaredMethod("perfLockRelease", argClasses);
                Log.v(TAG,"mReleaseFunc method = " + mReleaseFunc);

                argClasses = new Class[] {MotionEvent.class, DisplayMetrics.class, int.class, int[].cla

之前调用的方法perfLockAcquire的真是面目
/** @hide */
    public int perfLockAcquire(int duration, int... list) {
        int ret = -1;
        try {
            Object retVal = mAcquireFunc.invoke(mPerf, duration, list);
            ret = (int)retVal;
        } catch(Exception e) {
            Log.e(TAG,"Exception " + e);
        }
        return ret;
    }

通过构造中的mAcquireFunc =  perfClass.getDeclaredMethod("perfLockAcquire", argClasses);看其调用的还是Performance中的perfLockAcquire方法。
在Performance.java中会深入到JNI层:
static {
        try {
            System.loadLibrary("qti_performance");
        } catch (UnsatisfiedLinkError e) {
        }
    }

/** &hide */
    public int perfLockAcquire(int duration, int... list) {
        int rc = REQUEST_SUCCEEDED;
        handle = native_perf_lock_acq(handle, duration, list);
        if (handle == 0)
            rc = REQUEST_FAILED;
        return rc;
    }


相关标签: performance