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.* | |
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++ |
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 android.os.Debug.MemoryInfo | |
val memoryInfo: MemoryInfo = ... | |
val ussKb = with(memoryInfo) { | |
getTotalPrivateClean() + getTotalPrivateDirty() | |
} |
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 android.os.Debug | |
val pssKb: Long = Debug.getPss() |
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 android.os.Debug | |
import android.os.Debug.MemoryInfo | |
val memoryInfo = MemoryInfo() | |
Debug.getMemoryInfo(memoryInfo) | |
val summary: Map<String, String> = memoryInfo.getMemoryStats() |
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
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 |
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 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() |
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 android.os.Debug | |
val nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / 1024 |
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 totalMemoryKb = Runtime.getRuntime().totalMemory() / 1024 | |
val freeMemoryKb = Runtime.getRuntime().freeMemory() / 1024 | |
val jvmHeapAllocatedKb = totalMemoryKb - freeMemoryKb |
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
// triangle/main.cpp | |
... | |
void createGraphicsPipeline() { | |
auto vertShaderCode = readFile("triangle/shaders/shader.vert.spv"); | |
auto fragShaderCode = readFile("triangle/shaders/shader.frag.spv"); | |
... | |
} |
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
# 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", | |
], |
NewerOlder