Skip to content

Instantly share code, notes, and snippets.

@fcamel
fcamel / benchmark_gzip_brotli.sh
Created February 5, 2018 08:30
benchmark gzip / brotli
#!/bin/bash
rm -rf output
mkdir output
ls -l input | awk '{ s += $5 } END { print s }'
# compress
begin=$(date +%s%N)
for f in input/*
@fcamel
fcamel / skia_stap_output.txt
Created January 7, 2018 07:41
SystemTap output for Skia viewer
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("SkAutoCanvasRestore@../../include/core/SkCanvas.h:2788").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("getSaveCount@../../src/core/SkCanvas.cpp:874").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("SkCanvas@../../src/core/SkCanvas.cpp:710").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("init@../../src/core/SkCanvas.cpp:629").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("MCRec@../../src/core/SkCanvas.cpp:296").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("DeviceCM@../../src/core/SkCanvas.cpp:256").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("qr_clip_bounds@../../src/core/SkCanvas.cpp:606").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("setSurfaceBase@../../include/core/SkCanvas.h:2663").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("save@../../src/core/
@fcamel
fcamel / gist:878c843badde0d177c57734d0094ac01
Last active January 6, 2018 09:13
strace -f -s 1024 host ubuntu
[pid 32630] socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 6
[pid 32630] fcntl(6, F_DUPFD, 20) = 20
[pid 32630] close(6) = 0
...
[pid 32630] bind(20, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
...
[pid 32630] sendmsg(20, {msg_name(16)={sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.1.1")}, msg_iov(1)=[{"J\311\1\0\0\1\0\0\0\0\0\0\6ubuntu\0\0\1\0\1", 24}], msg_controllen=0, msg_flags=0}, 0 <unfinished ...>
...
[pid 32630] recvmsg(20, {msg_name(16)={sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.1.1")}, msg_iov(1)=[{"J\311\200\200\0\1\0\1\0\0\0\0\6ubuntu\0\0\1\0\1\300\f\0\1\0\1ZQ\1\343\0\4\300\250\1j", 65535}], msg_controllen=56, [{cmsg_len=32,
...
@fcamel
fcamel / sleep_sort.py
Created June 23, 2011 16:09
Sleep Sort: an amazing sorting algorithm!!
#!/usr/bin/env python2.6
# -*- encoding: utf8 -*-
'''
An advanced version of Sleep Sort.
The original idea is from: http://coolshell.cn/articles/4883.html
Use the concept of radix sort to speed it up.
The newer version references WanCW's implementation in Ruby:
1 0.000000000 192.168.1.109 → 192.168.1.109 TCP 74 46672 → 8000 [SYN] Seq=0 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=40124281 TSecr=0 WS=128
2 0.000005978 192.168.1.109 → 192.168.1.109 TCP 74 8000 → 46672 [SYN, ACK] Seq=0 Ack=1 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=40124281 TSecr=40124281 WS=128
3 0.000010862 192.168.1.109 → 192.168.1.109 TCP 66 46672 → 8000 [ACK] Seq=1 Ack=1 Win=43776 Len=0 TSval=40124281 TSecr=40124281
4 0.000056512 192.168.1.109 → 192.168.1.109 TCP 76 8000 → 46672 [PSH, ACK] Seq=1 Ack=1 Win=43776 Len=10 TSval=40124281 TSecr=40124281
5 0.000088529 192.168.1.109 → 192.168.1.109 TCP 66 46672 → 8000 [ACK] Seq=1 Ack=11 Win=43776 Len=0 TSval=40124281 TSecr=40124281
6 0.000109539 192.168.1.109 → 192.168.1.109 TCP 1056 8000 → 46672 [PSH, ACK] Seq=11 Ack=1 Win=43776 Len=990 TSval=40124281 TSecr=40124281
7 0.000112096 192.168.1.109 → 192.168.1.109 TCP 66 46672 → 8000 [ACK] Seq=1 Ack=1001 Win=45696 Len=0 TSval=40124281 TSecr=40124281
8 0.000131095 192.168.1.10
1 0.000000000 192.168.1.109 → 192.168.1.109 TCP 74 46664 → 8000 [SYN] Seq=0 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=40119763 TSecr=0 WS=128
2 0.000005810 192.168.1.109 → 192.168.1.109 TCP 74 8000 → 46664 [SYN, ACK] Seq=0 Ack=1 Win=43690 Len=0 MSS=65495 SACK_PERM=1 TSval=40119763 TSecr=40119763 WS=128
3 0.197946013 192.168.1.109 → 192.168.1.109 TCP 66 46664 → 8000 [ACK] Seq=1 Ack=1 Win=43776 Len=0 TSval=40119813 TSecr=40119763
4 0.198082252 192.168.1.109 → 192.168.1.109 TCP 76 8000 → 46664 [PSH, ACK] Seq=1 Ack=1 Win=43776 Len=10 TSval=40119813 TSecr=40119813
5 0.198142202 192.168.1.109 → 192.168.1.109 TCP 66 46664 → 8000 [ACK] Seq=1 Ack=11 Win=43776 Len=0 TSval=40119813 TSecr=40119813
6 0.198146792 192.168.1.109 → 192.168.1.109 TCP 1056 8000 → 46664 [PSH, ACK] Seq=11 Ack=1 Win=43776 Len=990 TSval=40119813 TSecr=40119813
7 0.198149046 192.168.1.109 → 192.168.1.109 TCP 66 46664 → 8000 [ACK] Seq=1 Ack=1001 Win=45696 Len=0 TSval=40119813 TSecr=40119813
8 0.198176219 192.168.1.10
$ stap -L 'kernel.function("tcp_advertise_mss").return'
$ stap -L 'kernel.function("tcp_advertise_mss").inline'
kernel.function("tcp_advertise_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:121").inline
$ stap -L 'kernel.statement("tcp_advertise_mss@*:*")'
( No output )
$ stap -L 'kernel.statement("__tcp_mtu_to_mss@*:*")'
kernel.statement("__tcp_mtu_to_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1302")
kernel.statement("__tcp_mtu_to_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1305")
kernel.statement("__tcp_mtu_to_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1308")
kernel.statement("__tcp_mtu_to_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1309")
kernel.statement("__tcp_mtu_to_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1313")
kernel.statement("__tcp_mtu_to_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1317")
$ stap -L 'kernel.statement("tcp_sync_mss@*:*")'
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1395") $sk:struct sock* $pmtu:u32
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1400") $sk:struct sock* $pmtu:u32
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1401") $sk:struct sock* $pmtu:u32
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1407") $sk:struct sock* $pmtu:u32
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1408") $sk:struct sock* $pmtu:u32
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1409") $_min1:int $sk:struct sock*
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1410") $sk:struct sock* $pmtu:u32
kernel.statement("tcp_sync_mss@/build/linux-3phnTq/linux-4.4.0/net/ipv4/tcp_output.c:1413") $sk:struct sock* $pmtu:u32
@fcamel
fcamel / fib.s
Created October 7, 2017 08:17
fib(n)
0000000000400ef0 <_Z3fibi>:
long long fib(int n) {
400ef0: b8 01 00 00 00 mov $0x1,%eax
if (n <= 1)
400ef5: 83 ff 02 cmp $0x2,%edi
400ef8: 0f 8c 8f 00 00 00 jl 400f8d <_Z3fibi+0x9d>
long long a = 1;
long long b = 1;