Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
cd /sys/kernel/debug/tracing
echo >| trace
echo ext4_* >| set_graph_function
for i in printk irq_exit local_apic_timer_interrupt smp_apic_timer_interrupt; do
echo $i >> set_graph_notrace
done
echo function_graph >| current_tracer
#!/usr/bin/env bash
#
# http://en.opensuse.org/SDB:XFStests
#
export TEST_DIR=/xfs-playground/test
#export TEST_DEV=/dev/sdb1
#export SCRATCH_DEV=/dev/sdb1
export TEST_DEV=/dev/sdb1
typedef unsigned char u8;
size_t ffsn(u8 *a, size_t len)
{
const size_t chunk_size = sizeof(long long int);
const size_t bits_in_byte = 8;
u8 *begin = a;
u8 *end = a + len;
size_t pos = 0;
typedef unsigned char u8;
static inline uint64_t bswapu64(uint64_t a)
{
uint64_t b = 0;
for (u8 i = 0; i < sizeof(uint64_t); ++i) {
b = (b << __CHAR_BIT__) | (u8)a;
a >>= __CHAR_BIT__;
}
return b;
/**
* @example 0x1122334455667788 => 0x4477225588336611
*
* NB: Do not use this functin like a {cryptographic,} hash function
*/
static inline uint64_t memfryu64(uint64_t a, u8 off)
{
uint64_t b = 0;
for (u8 i = 0; i < sizeof(uint64_t); ++i) {
u8 aOff = (i + ((i % 2) ? 0 : off)) % sizeof(uint64_t);
ROOT=$(dirname $0)
DYNAMORIO=$ROOT/../../../dynamorio/exports
DRMEMORY=$ROOT/../../../drmemory/.cmake/exported
MSAN_OPTIONS='verbosity=1:sleep_before_dying=10' \
MSAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 \
LD_LIBRARY_PATH=$DYNAMORIO/ext/lib64/release/:$DYNAMORIO/lib64/release/:$DRMEMORY/drmf/lib64/release/:$ROOT \
LD_USE_LOAD_BIAS=1 \
$DYNAMORIO/bin64/drrun -v -64 -c $ROOT/libmsandr.so -- \
$*
#!/usr/bin/env bash
# Here we use pmap(1), but it can use smaps instead of it
# not do depends from pmap, but for now it's simpler
pid="$1"
# pmap -x $pid | tail -n+3 | awk '{ size = $2; addr = sprintf("%.f\n", "0x" $1); if (addr-size == prev_addr) { printf "%s # can merged with prev", $1}; prev_addr = addr; }'
pmap -x $pid | tail -n+3 | awk '{ size = $2; addr = sprintf("%.f\n", "0x" $1); printf("%.f vs %.f diff %.f\n", prev_addr, addr-size, addr-size-prev_addr); prev_addr = addr; }' | awk '{print $NF}' | sort | uniq -c | sort -nr -k1,1 | head
# Will print commands to run on another machine
# to validate that all symbols/versions available there.
env LD_DEBUG=all /path/to/bin -h 2>&1 | fgrep 'checking for version' | awk '{sym=$5; gsub(/[^a-zA-Z.0-9_]/, "", sym); printf "echo %s:%s && nm -D %s | fgrep %s || echo NOT FOUND\n", $8, sym, $8, sym}'
lsof -n | awk '{ i = 1; i += !!index($0, "deleted"); i += !!index($0, "TCP"); printf "%i: ", i; for (j = 0; j < i; ++j) { printf "%s ", $(NF-j) }; printf "\n"; }' | less