1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.testapp 18 19 import android.os.Bundle 20 import android.widget.TextView 21 import androidx.appcompat.app.AppCompatActivity 22 23 @ExperimentalUnsignedTypes 24 class MainActivity : AppCompatActivity() { 25 onCreatenull26 override fun onCreate(savedInstanceState: Bundle?) { 27 super.onCreate(savedInstanceState) 28 setContentView(R.layout.activity_main) 29 30 // To debug resources not destroyed 31 // "A resource failed to call destroy." 32 try { 33 Class.forName("dalvik.system.CloseGuard") 34 .getMethod("setEnabled", Boolean::class.javaPrimitiveType) 35 .invoke(null, true) 36 } catch (e: ReflectiveOperationException) { 37 throw RuntimeException(e) 38 } 39 40 val validate = true 41 val tester = Tester(this, validate) 42 val numberOfIterations = if (validate) 1 else 28 43 val t = TimingTracker(numberOfIterations, 0) 44 for (i in 1..numberOfIterations) { 45 println("*** Iteration $i of $numberOfIterations ****") 46 //startMethodTracing("myTracing") 47 //startMethodTracingSampling("myTracing_sample", 8000000, 10) 48 val r = tester.testAll(t) 49 //stopMethodTracing() 50 findViewById<TextView>(R.id.sample_text).text = "$r\n\n${t.report()}" 51 t.nextIteration() 52 } 53 tester.destroy() 54 } 55 } 56