1

和你一起终身学习,这里是程序员 Android

利用在高通平台中的Performance机制,可以提高性能,比如应用的启动速度,滑动流畅性等。接下来就看下高通给我们提供的Performance机制
1.该机制的JNI层实现部分位于

./vendor/qcom/proprietary/android-perf/QPerformance/jni/com_qualcomm_qti_Performance.cpp  

上层实现位于 
Java代码

./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[].class};

之前调用的方法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;  
    }  
原文链接:https://www.iteye.com/blog/42...

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!


程序员Android
112 声望23 粉丝

和您一起终身学习,这里是程序员Android。