This file contains hidden or 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
@file:DependsOn("com.github.ajalt:clikt:2.8.0") | |
@file:DependsOn("org.apache.opennlp:opennlp-tools:1.9.3") | |
import com.github.ajalt.clikt.core.CliktCommand | |
import com.github.ajalt.clikt.parameters.options.option | |
import com.github.ajalt.clikt.parameters.options.prompt | |
import opennlp.tools.stemmer.PorterStemmer | |
import org.xml.sax.Attributes | |
import org.xml.sax.helpers.DefaultHandler | |
import java.io.File |
This file contains hidden or 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
for (ApplicationExitInfo exitInfo: unprocessedExitInfos) { | |
if (exitInfo.getReason() == ApplicationExitInfo.REASON_ANR) { | |
UUID uuid = UUID.randomUUID(); | |
String fileName = "anr_info_" + uuid.toString() + ".trace"; | |
File outFile = new File(getFilesDir().getAbsolutePath() + "/" + fileName); | |
try (InputStream inputStream = exitInfo.getTraceInputStream()) { | |
copyStreamToFile(inputStream, outFile); | |
} catch (IOException e) { | |
Log.e(TAG, "copyStreamToFile: ", e); |
This file contains hidden or 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
for (ApplicationExitInfo exitInfo: unprocessedExitInfos) { | |
Log.e(TAG, String.format("Exit reason: %d, description: %s", exitInfo.getReason(), exitInfo.getDescription())); | |
} |
This file contains hidden or 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
long lastExitTimestamp = getPreferences(0).getLong(PREV_DETECT_TIME_KEY, 0); | |
List<ApplicationExitInfo> unprocessedExitInfos = new ArrayList<>(); | |
for (ApplicationExitInfo exitInfo: applicationExitInfos) { | |
if (exitInfo.getTimestamp() > lastExitTimestamp) { | |
unprocessedExitInfos.add(exitInfo); | |
} else { | |
break; | |
} | |
} |
This file contains hidden or 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
List<ApplicationExitInfo> applicationExitInfos = am.getHistoricalProcessExitReasons(null, 0, 0); |
This file contains hidden or 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
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
This file contains hidden or 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() |
This file contains hidden or 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 hidden or 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 hidden or 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) |
NewerOlder