This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface NetworkEventProvider { | |
void setListener(Listener listener); | |
interface Listener { | |
/** | |
* @param networkStatus {@link com.birbit.android.jobqueue.network.NetworkUtil.NetworkStatus} | |
*/ | |
void onNetworkChange(@NetworkUtil.NetworkStatus int networkStatus); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
/** | |
* Created by yangwei-ms on 2017/7/14. | |
*/ | |
class SkipList<T>(private val comparator: Comparator<T>) { | |
private var curHeight: Int = 1 | |
private val head: Node<T> = Node(null, MAX_HEIGHT) | |
private val rnd: Random = Random(System.currentTimeMillis()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.yangweigbh.traceana; | |
import android.os.Handler; | |
import android.os.HandlerThread; | |
import android.os.Looper; | |
import android.util.Log; | |
import java.util.concurrent.ConcurrentHashMap; | |
public class ThreadWatcher { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class AndroidBenchmarkRunner : AndroidJUnitRunner() { | |
@CallSuper | |
override fun waitForActivitiesToComplete() { | |
// We don't call the super method here, since we have | |
// an activity we intend to persist between tests | |
// TODO: somehow wait for every activity but IsolationActivity | |
// Before/After each test, from the test thread, synchronously launch | |
// our IsolationActivity if it's not already resumed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val dest = "/data/local/tmp/lockClocks.sh" | |
val source = javaClass.classLoader.getResource("scripts/lockClocks.sh") | |
val tmpSource = Files.createTempFile("lockClocks.sh", null).toString() | |
Files.copy( | |
source.openStream(), | |
Paths.get(tmpSource), | |
StandardCopyOption.REPLACE_EXISTING | |
) | |
adb.execSync("push $tmpSource $dest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!CpuInfo.locked && isSustainedPerformanceModeSupported()) { | |
sustainedPerformanceModeInUse = true | |
} | |
private val activityLifecycleCallbacks = object : Application.ActivityLifecycleCallbacks { | |
@SuppressLint("NewApi") // window API guarded by [isSustainedPerformanceModeSupported] | |
override fun onActivityCreated(activity: Activity, bundle: Bundle?) { | |
if (sustainedPerformanceModeInUse) { | |
activity.window.setSustainedPerformanceMode(true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (sustainedPerformanceModeInUse) { | |
// Keep at least one core busy. Together with a single threaded benchmark, this | |
// makes the process get multi-threaded setSustainedPerformanceMode. | |
// | |
// We want to keep to the relatively lower clocks of the multi-threaded benchmark | |
// mode to avoid any benchmarks running at higher clocks than any others. | |
// | |
// Note, thread names have 15 char max in Systrace | |
thread(name = "BenchSpinThread") { | |
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void myBenchmark() { | |
... | |
BenchmarkState state = benchmarkRule.getState(); | |
while (state.keepRunning()) { | |
doSomeWork(); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getState(): BenchmarkState { | |
// Note: this is an explicit method instead of an accessor to help convey it's only for Java | |
// Kotlin users should call the [measureRepeated] method. | |
if (!applied) { | |
throw IllegalStateException( | |
"Cannot get state before BenchmarkRule is applied to a test. Check that your " + | |
"BenchmarkRule is annotated correctly (@Rule in Java, @get:Rule in Kotlin)." | |
) | |
} | |
return internalState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun bumpCurrentThreadPriority() = synchronized(lock) { | |
val myTid = Process.myTid() | |
if (initialTid == myTid) { | |
// already bumped | |
return | |
} | |
// ensure we don't have multiple threads bumped at once | |
resetBumpedThread() |
OlderNewer