mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-02 01:20:49 +00:00
MINOR: trace: implement a very basic trace() function
For now it remains quite basic. It performs a few state checks, calls the source's sink if defined, and performs the transitions between RUNNING, STOPPED and WAITING when the configured events match.
This commit is contained in:
parent
85b157570b
commit
4c2ae48375
@ -34,6 +34,8 @@
|
|||||||
extern struct list trace_sources;
|
extern struct list trace_sources;
|
||||||
extern THREAD_LOCAL struct buffer trace_buf;
|
extern THREAD_LOCAL struct buffer trace_buf;
|
||||||
|
|
||||||
|
void __trace(uint64_t mask, struct trace_source *src, const struct ist msg);
|
||||||
|
|
||||||
/* return a single char to describe a trace state */
|
/* return a single char to describe a trace state */
|
||||||
static inline char trace_state_char(enum trace_state st)
|
static inline char trace_state_char(enum trace_state st)
|
||||||
{
|
{
|
||||||
@ -63,6 +65,13 @@ static inline void trace_register_source(struct trace_source *source)
|
|||||||
LIST_ADDQ(&trace_sources, &source->source_link);
|
LIST_ADDQ(&trace_sources, &source->source_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* sends a trace for the given source */
|
||||||
|
static inline void trace(uint64_t mask, struct trace_source *src, const struct ist msg)
|
||||||
|
{
|
||||||
|
if (unlikely(src->state != TRACE_STATE_STOPPED))
|
||||||
|
__trace(mask, src, msg);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _PROTO_TRACE_H */
|
#endif /* _PROTO_TRACE_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
40
src/trace.c
40
src/trace.c
@ -48,6 +48,46 @@ static void free_trace_buffers_per_thread()
|
|||||||
REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread);
|
REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread);
|
||||||
REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread);
|
REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread);
|
||||||
|
|
||||||
|
/* write a message for the given trace source */
|
||||||
|
void __trace(uint64_t mask, struct trace_source *src, const struct ist msg)
|
||||||
|
{
|
||||||
|
if (likely(src->state == TRACE_STATE_STOPPED))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* check that at least one action is interested by this event */
|
||||||
|
if (((src->report_events | src->start_events | src->pause_events | src->stop_events) & mask) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* TODO: add handling of filters here, return if no match (not even update states) */
|
||||||
|
|
||||||
|
/* check if we need to start the trace now */
|
||||||
|
if (src->state == TRACE_STATE_WAITING) {
|
||||||
|
if ((src->start_events & mask) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* TODO: add update of lockon+lockon_ptr here */
|
||||||
|
HA_ATOMIC_STORE(&src->state, TRACE_STATE_RUNNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: add check of lockon+lockon_ptr here, return if no match */
|
||||||
|
/* here the trace is running and is tracking a desired item */
|
||||||
|
|
||||||
|
if ((src->report_events & mask) == 0)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
if (src->sink)
|
||||||
|
sink_write(src->sink, &msg, 1);
|
||||||
|
|
||||||
|
end:
|
||||||
|
/* check if we need to stop the trace now */
|
||||||
|
if ((src->stop_events & mask) != 0) {
|
||||||
|
HA_ATOMIC_STORE(&src->state, TRACE_STATE_STOPPED);
|
||||||
|
}
|
||||||
|
else if ((src->pause_events & mask) != 0) {
|
||||||
|
HA_ATOMIC_STORE(&src->state, TRACE_STATE_WAITING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct trace_source *trace_find_source(const char *name)
|
struct trace_source *trace_find_source(const char *name)
|
||||||
{
|
{
|
||||||
struct trace_source *src;
|
struct trace_source *src;
|
||||||
|
Loading…
Reference in New Issue
Block a user