Skip to content

Instantly share code, notes, and snippets.

View wenjianhn's full-sized avatar
🐢

Jian Wen wenjianhn

🐢
  • Xiaomi
  • Beijing, China
  • 12:34 (UTC +08:00)
View GitHub Profile
@wenjianhn
wenjianhn / mem_by_stack.py
Created October 25, 2021 08:33
Analyzing allocation and freeing events(includes kmem:mm_page_alloc, kmem:mm_page_alloc_zone_locked, kmem:mm_page_free, kmem:mm_page_free_batched and kmem:mm_page_pcpu_drain)
#!/usr/bin/env python
from __future__ import print_function
import sys
from collections import Counter
def get_order(head):
h = head.split()
@wenjianhn
wenjianhn / slab_content_top.py
Created April 17, 2021 04:54
A simple script that helps find the root cause of a memory leak issue
#!/usr/bin/env python
from __future__ import print_function
import re
import shlex
import sys
import subprocess
from collections import Counter
@wenjianhn
wenjianhn / perf_record_when_high_sys.py
Created December 2, 2020 14:18
perf_record_when_high_sys
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import time
def perf_record(sys_threshold, interval, count):
while True:
@wenjianhn
wenjianhn / uaf.c
Created October 23, 2020 02:04
Bench mark the cost of doing kmalloc() then kfree()
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/slab.h>
static u64 read_tsc(void)
{
return (u64)rdtsc_ordered();
}
/sbin/modprobe pktgen
neigh_ip=$1
ping -c 1 ${neigh_ip}
DST=${neigh_ip}
DST_MAC=$(ip neigh | grep ${neigh_ip} | awk '{print $5}')
# DEVICE=$(ip neigh | grep ${neigh_ip} | awk '{print $3}')
DEVICE=eth0
@wenjianhn
wenjianhn / prometheus.yaml
Created August 25, 2015 08:24
For monitoring MidoNet
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
rule_files:
- /prometheus.rules
scrape_configs:
#!/bin/bash
SESSIONNAME="MidoNet"
tmux has-session -t $SESSIONNAME &> /dev/null
if [ $? != 0 ]
then
tmux new-session -s $SESSIONNAME -n script -d
tmux send-keys -t $SESSIONNAME "tailf /var/log/midolman/midolman.log" C-m
tmux new-window -t $SESSIONNAME '/bin/bash'
@wenjianhn
wenjianhn / pm-suspend
Created July 14, 2015 03:28
Suspend my workstation at 8pm everyday. /etc/cron.daily/pm-suspend
#!/bin/bash
/usr/bin/echo '/usr/sbin/pm-suspend' | /usr/bin/at 8pm
@wenjianhn
wenjianhn / DivideByThree.tla
Created July 14, 2015 03:06
Prove (x + y) % 3 = 0 => (10*x + y) % 3 = 0
---------------------------- MODULE DivideByThree ----------------------------
EXTENDS Integers
VARIABLES x, y
vars == <<x, y>>
Init == /\ x \in 1..9
/\ y \in 0..9
Next == \//\ x' = x + 1
@wenjianhn
wenjianhn / GCD.tla
Created June 26, 2015 04:19
The Greatest Common Divisor
-------------------------------- MODULE GCD --------------------------------
EXTENDS Integers
Divides(p, n) ==
\E q \in -n..n : n = q * p
DivisorsOf(n) == {p \in -n..n : Divides(p, n)}
SetMax(S) ==
CHOOSE i \in S : \A j \in S : i >= j