Skip to content

Instantly share code, notes, and snippets.

View Morfly's full-sized avatar

Pavlo Stavytskyi Morfly

View GitHub Profile
@Morfly
Morfly / uuid_ab_distribution.kt
Last active April 16, 2023 19:09
Example of a 50/50 distribution for an A/B test based on randomly generated UUIDs
import java.util.*
import kotlin.math.abs
fun main() {
var a = 0
var b = 0
for (i in 1..1000) {
val id = UUID.randomUUID().toString()
when (abs(id.hashCode() % 2)) {
0 -> a++
import android.os.Debug.MemoryInfo
val memoryInfo: MemoryInfo = ...
val ussKb = with(memoryInfo) {
getTotalPrivateClean() + getTotalPrivateDirty()
}
import android.os.Debug
val pssKb: Long = Debug.getPss()
import android.os.Debug
import android.os.Debug.MemoryInfo
val memoryInfo = MemoryInfo()
Debug.getMemoryInfo(memoryInfo)
val summary: Map<String, String> = memoryInfo.getMemoryStats()
code: 12128 kB
stack: 496 kB
graphics: 996 kB
java-heap: 8160 kB
native-heap: 4516 kB
private-other: 2720 kB
system: 4955 kB // Includes all shared memory
total-pss: 33971 kB // A sum of everything except 'total-swap'
total-swap: 17520 kB
import android.os.Debug.MemoryInfo
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val pid = intArrayOf(android.os.Process.myPid())
// The sample rate for calling this API is limited to once per 5 minutes.
// If called more frequently, it returns the same data as pverious call.
val memoryInfo: MemoryInfo = activityManager.getProcessMemoryInfo(pid).first()
import android.os.Debug
val nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / 1024
val totalMemoryKb = Runtime.getRuntime().totalMemory() / 1024
val freeMemoryKb = Runtime.getRuntime().freeMemory() / 1024
val jvmHeapAllocatedKb = totalMemoryKb - freeMemoryKb
// triangle/main.cpp
...
void createGraphicsPipeline() {
auto vertShaderCode = readFile("triangle/shaders/shader.vert.spv");
auto fragShaderCode = readFile("triangle/shaders/shader.frag.spv");
...
}
# triangle/BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "triangle",
srcs = glob(["*.cpp"]),
data = [
"//triangle/shaders:vert_shader",
"//triangle/shaders:frag_shader",
],