Skip to content

Commit

Permalink
trace developing
Browse files Browse the repository at this point in the history
  • Loading branch information
Knight-ZXW committed Jul 23, 2023
1 parent edb610e commit 1bb60de
Show file tree
Hide file tree
Showing 31 changed files with 1,749 additions and 311 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
.cxx
local.properties
cUploadSetting.gradle
rheatrace.workspace
output.pb
*.jar

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ dependencies {
implementation project(path: ':optimize-other')
implementation project(path: ':message-observer')
implementation project(path: ':kprofiler')
implementation project(path: ':atrace-server')
implementation 'org.nanohttpd:nanohttpd:2.2.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.bytedance.android:shadowhook:1.0.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.SystemClock
import android.util.Log
import android.view.View
import android.webkit.WebView
import com.knightboost.appoptimizeframework.tests.preloadtest.*
import com.knightboost.optimize.looperopt.LooperMsgOptimizeManager
import com.knightboost.optimize.looperopt.MsgOptimizeType

Expand All @@ -18,28 +17,11 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// ColdLaunchBoost.getInstance().log("before super onCreate")
super.onCreate(savedInstanceState)
classLoadTest()
setContentView(R.layout.activity_main)
Log.d("MainLooperBoost","MainActivity onCreate");

}

private fun classLoadTest() {
var begin = SystemClock.elapsedRealtimeNanos()
PreloadClass1.map1
PreloadClass2.map1
PreloadClass3.map1
PreloadClass4.map1
PreloadClass5.map1
PreloadClass6.map1
PreloadClass7.map1
PreloadClass8.map1
PreloadClass9.map1
PreloadClass10.map1
var end = SystemClock.elapsedRealtimeNanos()
Log.e("classPreload", "access classes cost ${(end - begin) / 1000}us")
}

override fun onStart() {
val decorView = window.decorView
super.onStart()
Expand Down
65 changes: 12 additions & 53 deletions app/src/main/java/com/knightboost/appoptimizeframework/MyApp.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package com.knightboost.appoptimizeframework

//import com.knightboost.kprofiler.KProfiler
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.util.Log
import com.bytedance.rheatrace.core.TraceApplicationLike
import com.bytedance.shadowhook.ShadowHook
import com.knightboost.appoptimizeframework.tests.preloadtest.*
import com.knightboost.appoptimizeframework.tests.retrofit.BilibiliService
import com.knightboost.appoptimizeframework.tests.retrofit.HttpService
import com.knightboost.kprofiler.atrace.RheaATrace
import com.knightboost.messageobserver.MessageObserverManager
import com.knightboost.optimize.looperopt.LooperMsgOptimizeManager
import com.knightboost.optimize.looperopt.StateListener
import com.knightboost.optimize.preload.ClassPreloadExecutor
import timber.log.Timber
import java.io.File


class MyApp : Application() {
@SuppressLint("BinaryOperationInTimber")
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
TraceApplicationLike.attachBaseContext(base)
try {


}catch (e:java.lang.Exception){
e.stackTraceToString()
}
ShadowHook.init(
ShadowHook.ConfigBuilder()
.setMode(ShadowHook.Mode.UNIQUE)
Expand All @@ -34,23 +35,11 @@ class MyApp : Application() {
// RheaATrace.start(baseContext,
// dir)

// MonitorClassLoader.hook(this,true)
// 打印 类加载信息
// MonitorClassLoader.printClassEnable = false


//hidden api exemption 是必要的
Timber.plant(Timber.DebugTree())
MessageObserverManager.setUsePrinterToWatch(true)
// HiddenApi.getDefault().exempt("Landroid/os/Handler")
// HiddenApi.getDefault().exempt("Landroid/os/Looper")
// HiddenApi.getDefault().exempt("Landroid/os/MessageQueue")
// HiddenApi.getDefault().exempt("Landroid/app/servertransaction")
// HiddenApi.getDefault().exempt("Landroid/util/BoostFramework")
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// HiddenApiBypass.addHiddenApiExemptions("")
// };

Log.e("MainLooperBoost","Application attachBaseContext")

Thread{
Timber.tag("App").e("开始初始化")
Expand All @@ -68,54 +57,24 @@ class MyApp : Application() {

}.start()

ClassPreloadExecutor.addDemander {
listOf<Class<*>>(
PreloadClass1::class.java,
PreloadClass2::class.java,
PreloadClass3::class.java,
PreloadClass4::class.java,
PreloadClass5::class.java,
PreloadClass6::class.java,
PreloadClass7::class.java,
PreloadClass8::class.java,
PreloadClass9::class.java,
PreloadClass10::class.java,
).toTypedArray()
}

Thread{
ClassPreloadExecutor.doPreload()
}.start()
asyncPreParseRetrofitService()
}

private fun enableMonitorClassLoad(base: Context) {
// KProfiler.init(base);
var file = File(base.cacheDir, "temp.txt")
if (file.exists()) {
file.delete();
}
file.createNewFile();
val absolutePath = file.absolutePath
Log.e("Demo", "类加载文件保存在 ${absolutePath}")
// KProfiler.startMonitorClassLoad(absolutePath, Thread.currentThread());
override fun onCreate() {
super.onCreate()
Log.e("MainLooperBoost","Application onCreate")
}

private fun asyncPreParseRetrofitService(){
//这行是为了避免类加载带来的差异
HttpService.retrofit.create(BilibiliService::class.java).archiveStat2(0)

// Thread{
// val retrofit = HttpService.retrofit
// RetrofitPreloadUtil.preloadClassMethods(retrofit,
// BilibiliService::class.java,
// arrayOf("archiveStat"))
// }.start()

}

override fun onCreate() {
super.onCreate()
Log.e("MainLooperBoost","Application onCreate")
}


}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1bb60de

Please sign in to comment.