Skip to content

Instantly share code, notes, and snippets.

View doujiang24's full-sized avatar
😁
happy hacking

doujiang24 doujiang24

😁
happy hacking
View GitHub Profile
reindex: t/010-compile.t: skipped.
/bin/bash -c '(. ../testml-fan/.rc; . .rc; prove -I../test-nginx/lib -r -j1 t/010-compile.t)'
# I found ONLY: maybe you're debugging?
# I found ONLY: maybe you're debugging?
# Failed test 'TEST 4: Explicit list modifiers'
# at /home/dou/work/git/orinc/testml-fan/lib/TestML/Runtime.pm line 597.
# got: '"/test": {
# "pair": [
@doujiang24
doujiang24 / callback-bench.lua
Created May 3, 2017 15:10 — forked from mkfmnn/callback-bench.lua
Benchmark of LuaJIT FFI callbacks from C into Lua
local ffi = require("ffi")
ffi.cdef[[
typedef void (*cb)(void);
void call(int n, void (*)(void));
void loop(int n);
void func(void);
]]
local callback = ffi.load("./callback.so")
local timeit = require("timeit")
@doujiang24
doujiang24 / sample-bt-leaks
Created June 12, 2016 14:59
DWARF-less probing
diff --git a/samples/sample-bt-leaks.sxx b/samples/sample-bt-leaks.sxx
index dba62e7..8dc15a2 100755
--- a/samples/sample-bt-leaks.sxx
+++ b/samples/sample-bt-leaks.sxx
@@ -49,7 +49,7 @@ probe process("$^libc_path").function("malloc").return,
}
}
- ptr = $return
+ ptr = returnval()
{
"a" : {
"foo": [
{
"b": "c",
"d": "f"
}
],
"bar": [
{
@doujiang24
doujiang24 / gist:fd5c7a46831a3df02f57
Created November 23, 2015 03:49
Lua get hostname
local ffi = require "ffi"
local C = ffi.C
ffi.cdef[[
int gethostname(char *name, size_t len);
]]
local size = 50
local buf = ffi.new("unsigned char[?]", size)
local bit = require "bit"
local p20 = math.pow(2, 20)
local page = 1
local bor = bit.bor
local band = bit.band
local lshift = bit.lshift
local rshift = bit.rshift
local str_format = string.format
@doujiang24
doujiang24 / gdb bt
Created October 29, 2014 08:31
ffi openssl rsa Segmentation fault
#0 0x00007fe3cd8d0f5e in lj_alloc_free (msp=0x4051f010, ptr=0x7fe3ccdc2bb0 <RSA_private_decrypt>) at lj_alloc.c:1338
#1 0x00007fe3cd87d09d in gc_sweep (g=g@entry=0x4051f3b8, p=0x40ee28f8, lim=38, lim@entry=40) at lj_gc.c:397
#2 0x00007fe3cd87e11b in gc_onestep (L=L@entry=0x4053e998) at lj_gc.c:627
#3 0x00007fe3cd87eaf0 in lj_gc_fullgc (L=0x4053e998) at lj_gc.c:738
#4 0x00007fe3cd88d565 in lua_gc (L=L@entry=0x4053e998, what=what@entry=2, data=<optimized out>) at lj_api.c:1144
#5 0x00007fe3cd8d28d1 in lj_cf_collectgarbage (L=0x4053e998) at lib_base.c:440
#6 0x00007fe3cd87adf5 in lj_BC_FUNCC () from /usr/local/openresty/luajit/lib/libluajit-5.1.so.2
#7 0x00000000004a90cc in ngx_http_lua_run_thread (L=L@entry=0x4051f378, r=r@entry=0x16d7820, ctx=ctx@entry=0x16d8670, nrets=nrets@entry=0)
at ../ngx_lua-0.9.12/src/ngx_http_lua_util.c:980
#8 0x00000000004ac12e in ngx_http_lua_content_by_chunk (L=L@entry=0x4051f378, r=r@entry=0x16d7820)
@doujiang24
doujiang24 / gist:9895323
Created March 31, 2014 15:46
gdb full backtrace for nginx signal 11
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
ngx_http_lua_socket_keepalive_close_handler (ev=0x1562948) at ../ngx_lua-0.9.6/src/ngx_http_lua_socket_tcp.c:3927
3927 spool = item->socket_pool;
(gdb) bt full
#0 ngx_http_lua_socket_keepalive_close_handler (ev=0x1562948) at ../ngx_lua-0.9.6/src/ngx_http_lua_socket_tcp.c:3927
item = 0x40828c7f
spool = <value optimized out>

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs