和你一起一生学习,这里是程序员 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…
至此,本篇已完结。转载网络的文章,小编感觉很优良,欢送点击浏览原文,反对原创作者,如有侵权,恳请分割小编删除,欢迎您的倡议与斧正。同时期待您的关注,感谢您的浏览,谢谢!