Skip to content

Instantly share code, notes, and snippets.

View pyricau's full-sized avatar

py - Pierre Yves Ricau pyricau

View GitHub Profile
@pyricau
pyricau / compare.benchmarks.main.kts
Created September 7, 2023 00:22
A Kotlin script to compare the output of two Macrobenchmark runs, validating the data and computing the confidence interval for a difference between two means
#!/usr/bin/env kotlin
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("com.datumbox:datumbox-framework-lib:0.8.2")
@file:DependsOn("com.squareup.okio:okio:3.3.0")
@file:DependsOn("com.squareup.moshi:moshi:1.13.0")
@file:DependsOn("com.squareup.moshi:moshi-adapters:1.13.0")
@file:DependsOn("com.squareup.moshi:moshi-kotlin:1.13.0")
import com.squareup.moshi.Moshi
@pyricau
pyricau / graphviz.views.main.kts
Last active October 4, 2024 18:15
A Kotlin script that will explore & render the view hierarchy of any activity in the heap
#!/usr/bin/env kotlin -language-version 1.9
// Make sure you run "brew install kotlin graphviz" first.
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:Repository("https://dl.google.com/dl/android/maven2/")
@file:DependsOn("com.squareup.leakcanary:shark-android:3.0-alpha-8")
import java.io.File
import shark.ActualMatchingReferenceReaderFactory
@pyricau
pyricau / graphviz.dominators.main.kts
Last active September 25, 2024 06:19
A Kotlin script that generates the dominator tree of a heap dump, as a CSV file for importing into Google Spreadsheets
#!/usr/bin/env kotlin -language-version 1.9
// Make sure you run "brew install kotlin graphviz" first.
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:Repository("https://dl.google.com/dl/android/maven2/")
@file:DependsOn("com.squareup.leakcanary:shark-android:3.0-alpha-8")
@file:DependsOn("androidx.collection:collection-jvm:1.4.0")
import androidx.collection.IntList
@pyricau
pyricau / graphviz.views.dominators.main.kts
Last active September 24, 2024 22:12
A Kotlin script that generates the dominator tree of the view hierarchy of any activity in the heap, as a CSV file for importing into Google Spreadsheets
#!/usr/bin/env kotlin -language-version 1.9
// Make sure you run "brew install kotlin graphviz" first.
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:Repository("https://dl.google.com/dl/android/maven2/")
@file:DependsOn("com.squareup.leakcanary:shark-android:3.0-alpha-8")
@file:DependsOn("androidx.collection:collection-jvm:1.4.0")
import androidx.collection.IntList
@pyricau
pyricau / OomExceptionHandler.java
Created May 6, 2015 17:18
Dump the heap on OutOfMemoryError crashes in your debug builds.
import android.content.Context;
import android.os.Debug;
import java.io.File;
public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final String FILENAME = "out-of-memory.hprof";
public static void install(Context context) {
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
@pyricau
pyricau / shark-custom-script.main.kts
Created March 27, 2024 20:57
A standalone Kotlin script that shows how to do custom heap analysis work with Shark, the heap parsing library that powers LeakCanary (see https://square.github.io/leakcanary/shark)
#!/usr/bin/env kotlin
// Before running this script, install Kotlin with `brew install kotlin`
// Then run this with `kotlin shark-custom-script.main.kts`
// Edit this script in the latest Android Studio or IntelliJ IDEA releases to get dependency import and auto completion.
@file:Repository("https://repo.maven.apache.org/maven2/")
@file:DependsOn("com.squareup.leakcanary:shark-android:2.13")
import java.io.File
@pyricau
pyricau / CoffeeParts.kt
Last active January 17, 2024 08:43
A Dependency Injection Framework that fits in a toot: https://androiddev.social/@py/111769799220786590
class CoffeeLogger {
fun log(msg: String) {
println(msg)
}
}
interface Heater {
fun on()
fun off()
val isHot: Boolean
package com.example
import android.app.Instrumentation
import android.os.Bundle
import android.util.Log
import androidx.test.internal.runner.listener.InstrumentationResultPrinter
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.runner.Description
import org.junit.runner.notification.RunListener
@pyricau
pyricau / ClassShot.java
Last active December 19, 2022 19:13
ClassShot: detect which classes have been loaded at runtime
import android.content.Context;
import android.os.Debug;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.squareup.haha.perflib.ClassObj;
import com.squareup.haha.perflib.HprofParser;
import com.squareup.haha.perflib.Snapshot;
import com.squareup.haha.perflib.io.HprofBuffer;
@pyricau
pyricau / SortAlgoTest.java
Created May 8, 2012 20:09
Implementation of various sorting algorithms in Java
import static java.util.Arrays.asList;
import static org.fest.assertions.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;
import org.junit.Test;
import org.junit.runner.RunWith;