mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-26 08:38:20 -04:00
MINOR: sample: store location for fetch/conv via initcalls
Now keywords are registered with an exec_ctx and this one is passed
when calling ->process. The ctx is of type INITCALL when passed via
an initcall where we know the file name and line number.
This was tested with and extra "malloc(15)" added in smp_fetch_path()
which shows that it works:
$ socat /tmp/sock1 - <<< "show profiling memory"|grep via
Calls | Tot Bytes | Caller and method [via]
1893399 0 60592592 0| 0x78b2ec task_run_applet+0x3339c malloc(32) [via initcall @http_fetch.c:2416]
This commit is contained in:
parent
2cd0cd84c6
commit
6e819dc4fa
3 changed files with 29 additions and 5 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#define _HAPROXY_SAMPLE_T_H
|
||||
|
||||
#include <haproxy/api-t.h>
|
||||
#include <haproxy/tinfo-t.h>
|
||||
#include <haproxy/sample_data-t.h>
|
||||
|
||||
/* input and output sample types
|
||||
|
|
@ -265,6 +266,7 @@ struct sample_conv {
|
|||
unsigned int in_type; /* expected input sample type */
|
||||
unsigned int out_type; /* output sample type */
|
||||
void *private; /* private values. only used by maps and Lua */
|
||||
struct thread_exec_ctx exec_ctx; /* execution context */
|
||||
};
|
||||
|
||||
/* sample conversion expression */
|
||||
|
|
@ -288,6 +290,7 @@ struct sample_fetch {
|
|||
unsigned int use; /* fetch source (SMP_USE_*) */
|
||||
unsigned int val; /* fetch validity (SMP_VAL_*) */
|
||||
void *private; /* private values. only used by Lua */
|
||||
struct thread_exec_ctx exec_ctx; /* execution context */
|
||||
};
|
||||
|
||||
/* sample expression */
|
||||
|
|
|
|||
|
|
@ -4926,7 +4926,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
|
|||
|
||||
/* Run the sample fetch process. */
|
||||
smp_set_owner(&smp, hsmp->p, hsmp->s->sess, hsmp->s, hsmp->dir & SMP_OPT_DIR);
|
||||
if (!f->process(args, &smp, f->kw, f->private)) {
|
||||
if (!EXEC_CTX_WITH_RET(f->exec_ctx, f->process(args, &smp, f->kw, f->private))) {
|
||||
if (hsmp->flags & HLUA_F_AS_STRING)
|
||||
lua_pushstring(L, "");
|
||||
else
|
||||
|
|
@ -5059,7 +5059,7 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
|
|||
}
|
||||
|
||||
/* Run the sample conversion process. */
|
||||
if (!conv->process(args, &smp, conv->private)) {
|
||||
if (!EXEC_CTX_WITH_RET(conv->exec_ctx, conv->process(args, &smp, conv->private))) {
|
||||
if (hsmp->flags & HLUA_F_AS_STRING)
|
||||
lua_pushstring(L, "");
|
||||
else
|
||||
|
|
|
|||
27
src/sample.c
27
src/sample.c
|
|
@ -451,6 +451,14 @@ void sample_register_fetches(struct sample_fetch_kw_list *kwl)
|
|||
for (bit = 0; bit < SMP_SRC_ENTRIES; bit++)
|
||||
if (sf->use & (1 << bit))
|
||||
sf->val |= fetch_cap[bit];
|
||||
/* store declaration file/line if known */
|
||||
if (sf->exec_ctx.type)
|
||||
continue;
|
||||
|
||||
if (caller_initcall) {
|
||||
sf->exec_ctx.type = TH_EX_CTX_INITCALL;
|
||||
sf->exec_ctx.initcall = caller_initcall;
|
||||
}
|
||||
}
|
||||
LIST_APPEND(&sample_fetches.list, &kwl->list);
|
||||
}
|
||||
|
|
@ -461,6 +469,18 @@ void sample_register_fetches(struct sample_fetch_kw_list *kwl)
|
|||
*/
|
||||
void sample_register_convs(struct sample_conv_kw_list *pckl)
|
||||
{
|
||||
struct sample_conv *sc;
|
||||
|
||||
/* store declaration file/line if known */
|
||||
for (sc = pckl->kw; sc->kw != NULL; sc++) {
|
||||
if (sc->exec_ctx.type)
|
||||
continue;
|
||||
|
||||
if (caller_initcall) {
|
||||
sc->exec_ctx.type = TH_EX_CTX_INITCALL;
|
||||
sc->exec_ctx.initcall = caller_initcall;
|
||||
}
|
||||
}
|
||||
LIST_APPEND(&sample_convs.list, &pckl->list);
|
||||
}
|
||||
|
||||
|
|
@ -1337,8 +1357,8 @@ int sample_process_cnv(struct sample_expr *expr, struct sample *p)
|
|||
}
|
||||
|
||||
/* OK cast succeeded */
|
||||
|
||||
if (!conv_expr->conv->process(conv_expr->arg_p, p, conv_expr->conv->private))
|
||||
if (!EXEC_CTX_WITH_RET(conv_expr->conv->exec_ctx,
|
||||
conv_expr->conv->process(conv_expr->arg_p, p, conv_expr->conv->private)))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
@ -1378,7 +1398,8 @@ struct sample *sample_process(struct proxy *px, struct session *sess,
|
|||
}
|
||||
|
||||
smp_set_owner(p, px, sess, strm, opt);
|
||||
if (!expr->fetch->process(expr->arg_p, p, expr->fetch->kw, expr->fetch->private))
|
||||
if (!EXEC_CTX_WITH_RET(expr->fetch->exec_ctx,
|
||||
expr->fetch->process(expr->arg_p, p, expr->fetch->kw, expr->fetch->private)))
|
||||
return NULL;
|
||||
|
||||
if (!sample_process_cnv(expr, p))
|
||||
|
|
|
|||
Loading…
Reference in a new issue