Skip to content

Instantly share code, notes, and snippets.

@agentzh
Created July 12, 2013 19:02
Show Gist options
  • Select an option

  • Save agentzh/5986885 to your computer and use it in GitHub Desktop.

Select an option

Save agentzh/5986885 to your computer and use it in GitHub Desktop.
WalkBin sample
enum {
LUA_NOREF = -2
};
void
ngx_lua_code_cache(ngx_http_request_t *r)
{
ngx_http_lua_loc_conf_t *loc_conf;
loc_conf = r->loc_conf[ngx_http_lua_module.ctx_index];
if (loc_conf->enable_code_cache == 0) {
say("lua code cache off");
} else {
say("lua code cache on");
}
}
static void
ngx_lua_thread(ngx_http_lua_co_ctx_t *coctx)
{
printf("thread is %p, L=%p, status=%s\n",
coctx, coctx->co,
ngx_http_lua_co_status_names[coctx->co_status]);
}
void *
ngx_http_get_module_ctx(ngx_http_request_t *r, ngx_module_t *module)
{
return r->ctx[module.ctx_index];
}
void
ngx_lua_uthreads(ngx_http_request_t *r)
{
ngx_http_lua_ctx_t *ctx;
ngx_list_part_t *part;
ngx_http_lua_co_ctx_t *cc, *coctx;
int n;
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx->on_abort_co_ctx) {
printf("it has an on_abort thread: %p\n", ctx->on_abort_co_ctx);
}
entry_coctx = &ctx->entry_co_ctx;
if (entry_coctx->co_ref != LUA_NOREF) {
printf("entry ");
ngx_lua_thread(entry_coctx);
}
printf("there are %d user threads.\n", ctx->uthreads);
if (ctx->flushing_coros) {
printf("there are %d coroutines waiting on ngx.flush.\n",
ctx->flushing_coros);
}
part = &ctx->user_co_ctx->part;
cc = part->elts;
for (i = 0; /* void */; i++) {
if (i >= part->nelts) {
if (part->next == NULL) {
break;
}
part = part->next;
cc = part->elts;
i = 0;
}
coctx = &cc[i];
if (coctx->ref != LUA_NOREF) {
printf("#%d user ", ++n);
ngx_http_thread(coctx);
}
}
printf("found %d user threads.\n", n);
if (ctx->exited) {
printf("request already exited with code %d.\n", ctx->exit_code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment