Skip to content

Instantly share code, notes, and snippets.

View ZacAttack's full-sized avatar
🀄
Talk to me about Mahjong

Zac Policzer ZacAttack

🀄
Talk to me about Mahjong
  • AnyScale
  • San Francisco
View GitHub Profile
function findThingsInAHashMap(map, things, entryComparator, keyTransformer, entryCallback) {
var results = {};
var mapAsArray = toArray(map.table)
for(i = 0; i < mapAsArray.length; i++) {
var e = mapAsArray[i];
while (e != null) {
if(e.key != null && entryComparator(e, things)) {
var tempResult = entryCallback(e.key, e.value); // NOTE some hashmap implementations use e.val vs. value, so check first!
if (tempResult != null) {
results[keyTransformer(e.key)] = tempResult;
function getProducerStats(topic) {
var kafkaProducers = heap.objects('org.apache.kafka.clients.producer.KafkaProducer', false);
while(kafkaProducers.hasMoreElements()) {
var next = kafkaProducers.nextElement();
if (next.clientId.toString().contains(topic)) {
return printProducerStats(next.metrics.metrics);
}
}
}
function printKafkaMetric(value) {
@ZacAttack
ZacAttack / gdb-summary.txt
Created January 15, 2021 22:17
Output of gdb-heap
------------- Summary -------------
Total Free Chunked Memory:4365301296
Total Chunked Avbl Memory:17963147264
Total Memory Utilization:76%
@ZacAttack
ZacAttack / preload.sh
Created January 15, 2021 22:16
Preload and configure jemalloc
MALLOC_CONF="dirty_decay_ms:0" LD_PRELOAD=/usr/local/lib/libjemalloc.so ./memory-demo
@ZacAttack
ZacAttack / heap-fragmentor.cpp
Created January 15, 2021 22:06
This program shows you how your process heap can become fragmented under some memory allocators!
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
// Define constants to make sure strings are not allocated at the top of the heap
#define HIT_ENTER "Press Enter to continue...\n"
#define ALLOCATED "500k 5KB chunks were just provisioned\n"
#define FREED "The first allocations were just free()'d.\n"