XROAD
xroad_tracing.h File Reference
Include dependency graph for xroad_tracing.h:

Go to the source code of this file.

Classes

struct  xroad_traces_ctl_param_s
 Parameters structure for opening trace series controller. More...
 

Macros

#define XROAD_LOGGER_INCLUDED
 
#define xroad_trace_struct_decl(sname, ...)   _xroad_trace_struct_decl(sname, __VA_ARGS__)
 
#define xroad_traces_writer_decl(traces_type, rec_type)
 
#define xroad_trace_write_rec(traces_writer_var, ...)
 Macro for writing record into trace stream (returns the result of xroad_traces_writer_write_record). More...
 
#define xroad_traces_writer_init(ctl, traces_writer_var)   xroad_traces_ctl_init_writer(ctl, &traces_writer_var.stream)
 Init macro for a trace stream variable.
 
#define xroad_trace_struct_num_fields(sname)   xroad_trace_struct_get_num_fields(xroad_trace_struct_fields(sname))
 Helper macro to obtain the number of fields in a structure sname.
 

Typedefs

typedef struct xroad_tracing_s xroad_tracing_t
 Tracing subsystem. It's in use only for persisting traces.
 
typedef struct xroad_traces_ctl_param_s xroad_traces_ctl_param_t
 Parameters structure for opening trace series controller.
 
typedef struct xroad_traces_ctl_s xroad_traces_ctl_t
 Type of trace series controller (representing single record type and one file at a time) control structure.
 

Functions

xroad_traces_ctl_t * xroad_traces_ctl_open (xroad_tracing_t *tracing, const xroad_traces_ctl_param_t *params)
 Open trace series controller. Consider using xroad_node_trace_init_writer() instead of this function.
 
void xroad_traces_ctl_close (xroad_traces_ctl_t *stream)
 Close trace series controller.
 
bool xroad_traces_ctl_write_record (xroad_traces_ctl_t *ctl, const void *rec_data, size_t rec_size)
 
void xroad_traces_ctl_init_writer (xroad_traces_ctl_t *ctl, xroad_trace_stream_t *writer)
 Init faster writer for the traces series.
 
void xroad_traces_writer_stub_init (xroad_trace_stream_t *writer)
 Init writer stub.
 
XROAD_TRACE_SDK_NONINLINE bool xroad_traces_writer_write_record (xroad_trace_stream_t *writer, const void *rec_data, size_t rec_size)
 Write record to the traces via writer.
 
XROAD_TRACE_SDK_NONINLINE bool xroad_traces_writer_is_enabled (xroad_trace_stream_t *writer)
 Check whether tracing through the writer is enabled (to skip tracing-specific logic if tracing is disabled)
 
unsigned xroad_trace_struct_get_num_fields (const xroad_tracing_field_descr_t descr[])
 Helper method to find number fields in the array of fields description (by finding the first empty description)
 

Detailed Description

Author
Vladimir Solontsov

There're a few steps required to use tracing subsystem:

  1. declare a trace record structure using xroad_trace_struct_decl() macro
  2. declare a trace writer using xroad_traces_writer_decl() macro
  3. initialize a trace writer using xroad_node_trace_init_writer() macro
  4. write trace records using xroad_trace_write_rec() macro
  5. optionally close the trace writer using xroad_node_trace_close() macro. This is not required if the node is going to be destroyed.

Macro Definition Documentation

◆ xroad_trace_struct_decl

#define xroad_trace_struct_decl (   sname,
  ... 
)    _xroad_trace_struct_decl(sname, __VA_ARGS__)

Macro to declare a structure with metainfo available via <type>_get_field_descr() function.

Example: xroad_trace_struct_decl(test_struct_t (int, fld_i), (long, fld_l) ); This macro will declare a structure test_struct_t with two fields: fld_i of type int and fld_l of type long. It also declares a function test_struct_t_get_field_descr() that returns an array of field descriptors for the structure.

◆ xroad_trace_write_rec

#define xroad_trace_write_rec (   traces_writer_var,
  ... 
)
Value:
({ \
__typeof__(*traces_writer_var.rec) _rec = {__VA_ARGS__}; \
xroad_traces_writer_write_record(&traces_writer_var.stream, &_rec, sizeof(_rec)); \
})

Macro for writing record into trace stream (returns the result of xroad_traces_writer_write_record).

◆ xroad_traces_writer_decl

#define xroad_traces_writer_decl (   traces_type,
  rec_type 
)
Value:
typedef union \
{ \
xroad_trace_stream_t stream; \
rec_type* rec; \
} traces_type

Declare a type of trace series controller for specific record type. It's not a real union. Instead it encodes information about record type for compile time.

Note that the stream must be unique

Function Documentation

◆ xroad_traces_ctl_write_record()

bool xroad_traces_ctl_write_record ( xroad_traces_ctl_t *  ctl,
const void *  rec_data,
size_t  rec_size 
)

Write record to the trace series controller (relatively slow, see caution)

Don't mix it with xroad_traces_writer_write_record() or xroad_trace_write_rec(). It temporarily creates a traces stream object and basically invalidates any other stream object.