XROAD
xroad_tracing_nonsdk.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <common/xroad_spsc_queue.h>
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
15 // For internal usage xroad_trace_stream_t is basically a xroad_spsc_producer_t
16 // NB we've got to make it a structure instead of a typedef to xroad_spsc_producer_t because we need a forward
17 // declaration of it.
18 typedef struct xroad_trace_stream_s
19 {
20  xroad_spsc_producer_t prod;
22 
23 #define XROAD_TRACE_SDK_NONINLINE inline
24 
25 //--------------------------------------------------------------------------------------------------------------------//
26 inline bool xroad_traces_writer_write_record(xroad_trace_stream_t* writer, const void* rec_data, size_t rec_size)
27 {
28  xroad_data_buf_t b = xroad_spsc_prod_alloc(&writer->prod, rec_size);
29  if (xroad_unlikely(b.size < rec_size))
30  {
31  xroad_spsc_prod_drop_inc(&writer->prod);
32  return false;
33  }
34  memcpy(b.ptr, rec_data, rec_size);
35  xroad_spsc_prod_commit(&writer->prod, rec_size);
36  return true;
37 }
38 
39 //--------------------------------------------------------------------------------------------------------------------//
41 {
42  return writer->prod.buf_size;
43 }
44 
45 #ifdef __cplusplus
46 }
47 #endif
Basic data buffer (either with data or for data)
Definition: xroad_common_types.h:117
size_t size
Size of the buffer.
Definition: xroad_common_types.h:119
char * ptr
Pointer to the buffer start.
Definition: xroad_common_types.h:118
Definition: xroad_tracing_nonsdk.h:19
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 dis...
Definition: xroad_tracing_nonsdk.h:40
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.
Definition: xroad_tracing_nonsdk.h:26