Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions samples/luajit21-gc64/lj-find-str.sxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env stap++

@use nginx.lua
@use luajit_gc64

function process() {
if (@defined(@var("globalL", "$^exec_path"))) {
mL = @var("globalL", "$^exec_path")

} else {
mL = ngx_lua_get_main_lua_vm()
}

if (mL == 0) {
return 0
}

g = luajit_G(mL)
if (g == 0) {
return 0
}

gcs = luajit_find_gcstr(g, "$^arg_str")
if (gcs) {
printf("Found: (GCstr*)%p\n", gcs)

} else {
printf("Not found.\n")
}

return 1
}

probe @pfunc(ngx_process_events_and_timers)?, timer.profile
{
if (pid() == target()) {
if (process()) {
exit()
}
}
}

probe begin
{
printf("Start tracing %d ($^exec_path)\n", target())
}
49 changes: 49 additions & 0 deletions samples/luajit21-gc64/lj-lua-bt.sxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env stap++

@use nginx.lua
@use luajit_gc64

function process() {
if (@defined(@var("globalL", "$^exec_path"))) {
mL = @var("globalL", "$^exec_path")

} else {
mL = ngx_lua_get_main_lua_vm()
}

if (mL == 0) {
return 0
}

g = luajit_G(mL)
if (g == 0) {
return 0
}

L = luajit_cur_thread(g)
if (L == 0) {
return 0
}

bt = luajit_backtrace(L, g, 0)
if (bt != "") {
print(bt)
return 1
}

return 0
}

probe timer.profile
{
if (pid() == target()) {
if (process()) {
exit()
}
}
}

probe begin
{
printf("Start tracing %d ($^exec_path)\n", target())
}
98 changes: 98 additions & 0 deletions samples/luajit21-gc64/lj-lua-stacks.sxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env stap++

@use nginx.lua
@use luajit_gc64

global bts, jitted

function process_event()
{
if (@defined(@var("globalL", "$^exec_path"))) {
mL = @var("globalL", "$^exec_path")

} else {
mL = ngx_lua_get_main_lua_vm()
}

if (mL == 0) {
return 0
}

g = luajit_G(mL)
if (g == 0) {
return 0
}

L = luajit_cur_thread(g)
if (L == 0) {
return 0
}

vmstate = luajit_vm_state(g)
if (vmstate >= 0) {
/* compiled Lua code */

jitted++

%( "$^arg_nojit :default()" != "" %?
return 0;
%)
} else {
%( "$^arg_nointerp :default()" != "" %?
return 0
%)
}

bt = luajit_backtrace(L, g, $^arg_detailed :default(0) ? 0 : 1)
if (bt != "") {
f = probefunc()
if (f != "") {
bt = f . "\n" . bt
}
//printf("backtrace: %s\n", bt)
bts[bt] <<< 1
return 1
}

return 0
}

probe $^arg_probe :default(timer.profile)
{
if (pid() == target()) {
process_event()
}
}

function output_report() {
foreach (bt in bts- limit $^arg_limit :default(1000)) {
cnt = @count(bts[bt])
if (cnt <= $^arg_min :default(2)) {
break
}
printf("%s\t%d\n", bt, cnt)
}
}

%( "$^arg_time :default()" != "" %?
probe timer.s($^arg_time)
{
warn("Time's up. Quitting now...\n")
exit()
}
%)

probe end {
output_report()
warn(sprintf("Found %d JITted samples.\n", jitted))
}

probe begin
{
warn(sprintf("Start tracing %d ($^exec_path)\n", target()))
%( "$^arg_time" != "" %?
warn(sprintf("Please wait for $^arg_time seconds...\n"))
%:
warn("Hit Ctrl-C to end.\n")
%)
}
116 changes: 116 additions & 0 deletions samples/luajit21-gc64/lj-str-tab.sxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env stap++

@use nginx.lua
@use luajit_gc64

@define TSTR %( 4 %)

global bucket_lens, bucket_lens2, bucket_len_squared, str_lens

probe @pfunc(ngx_process_events_and_timers)?, timer.profile
{
if (pid() == target()) {
if (@defined(@var("globalL", "$^exec_path"))) {
L = @var("globalL", "$^exec_path")

} else {
L = ngx_lua_get_main_lua_vm()
}

if (L == 0) {
printf("Failed to get the main Lua VM\n")
exit()
}

process(L)
}
}

function process(L)
{
begin = gettimeofday_us()

g = luajit_G(L)
$*g := @cast(g, "global_State", "$^libluajit_path")

strmask = $*g->strmask
strnum = $*g->strnum

printf("string count: %d\n", strnum)
printf("bucket count: %d\n", strmask + 1)
printf("load factor: %d%%\n\n", strnum * 100/(strmask + 1))

strhash = $*g->strhash
$*strhash := @cast(strhash, "GCRef", "$^libluajit_path")

n = 0
done = 0
for (i = 0; i <= strmask; i++) {
p = &$*strhash[i]

depth = 0
while (p) {
o = luajit_gcref(p)
if (o == 0) {
break;
}

$*o := @cast(o, "GCobj", "$^libluajit_path")
gct = $*o->gch->gct
if (gct != @TSTR) {
error(sprintf("Bad string type: %d", gct))
}
size = luajit_objlen(o, @TSTR, g)
str_lens <<< size

depth++

if (++n == strnum) {
done = 1
break
}

p = &$*o->gch->nextgc
}

bucket_lens <<< depth

if (depth > 0) {
bucket_lens2 <<< depth
bucket_len_squared <<< depth * depth
}

if (done) {
break
}
}

if (@count(str_lens) != strnum) {
warn("string count out of sync")
}

printf("%d strings: max=%d, avg=%d, min=%d, sum=%d (in bytes)\n",
@count(str_lens), @max(str_lens),
@avg(str_lens), @min(str_lens), @sum(str_lens))
print(@hist_log(str_lens))

printf("%d buckets: max=%d, avg=%d, min=%d, sum=%d (in entries)\n",
@count(bucket_lens), @max(bucket_lens),
@avg(bucket_lens), @min(bucket_lens), @sum(bucket_lens))
print(@hist_log(bucket_lens))

avg = @avg(bucket_lens2)
printf("%d non-empty buckets: max=%d, avg=%d, min=%d, sum=%d, var=%d (in entries)\n",
@count(bucket_lens2), @max(bucket_lens2),
avg, @min(bucket_lens2), @sum(bucket_lens2),
@avg(bucket_len_squared) - avg * avg)
print(@hist_linear(bucket_lens2, 1, 10, 1))

printf("%d microseconds elapsed in the probe handler.\n",
gettimeofday_us() - begin)
exit()
}

probe begin {
printf("Start tracing %d ($^exec_path)\n\n", target())
}
36 changes: 36 additions & 0 deletions samples/luajit21-gc64/ngx-lj-gc-speed.sxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env stap++

@use nginx.lua
@use luajit_gc64

global old, G, freed

probe process("$^liblua_path").function("lj_gc_step")
{
if (G == 0) {
L = ngx_lua_get_main_lua_vm()
//printf("L = %p\n", L)
G = luajit_G(L)
}

$*G := @cast(G, "global_State", "$^libluajit_path")
old = $*G->gc->total
}

probe process("$^liblua_path").function("lj_gc_step").return
{
if (old && G) {
freed += old - $*G->gc->total
}
}

probe timer.s(1) {
if (target() == pid()) {
printf("LuaJIT GC freed: %d bytes/sec\n", freed)
freed = 0
}
}

probe begin {
printf("Start tracing %d ($^exec_path)\nHit Ctrl-C to end.\n", target())
}
Loading