28 #include <tas_trace.h> 32 #ifdef FLEXNIC_TRACING 42 static __thread
struct trace *trace;
44 static inline void copy_to_pos(
struct trace *t,
size_t pos,
size_t len,
47 int trace_thread_init(uint16_t
id)
54 fprintf(stderr,
"trace_thread_init: trace already initialized for " 59 if ((t = malloc(
sizeof(*t))) == NULL) {
60 fprintf(stderr,
"trace_thread_init: malloc failed\n");
64 snprintf(name,
sizeof(name), FLEXNIC_TRACE_NAME,
id);
65 if ((t->hdr = util_create_shmsiszed(name, FLEXNIC_TRACE_LEN, NULL))
73 t->len = FLEXNIC_TRACE_LEN -
sizeof(*t->hdr);
78 t->hdr->length = t->len;
84 int trace_event(uint16_t type, uint16_t len,
const void *buf)
86 return trace_event2(type, len, buf, 0, NULL);
89 int trace_event2(uint16_t type, uint16_t len_1,
const void *buf_1,
90 uint16_t len_2,
const void *buf_2)
97 uint16_t len = len_1 + len_2;
101 fprintf(stderr,
"trace_event: thread trace not initialized yet\n");
105 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
106 fprintf(stderr,
"trace_event: clock_gettime failed\n");
110 teh.ts = (uint64_t) ts.tv_sec * 1000000000ULL + ts.tv_nsec;
116 copy_to_pos(t, t->pos,
sizeof(teh), &teh);
117 copy_to_pos(t, t->pos +
sizeof(teh), len_1, buf_1);
119 copy_to_pos(t, t->pos +
sizeof(teh) + len_1, len_2, buf_2);
121 copy_to_pos(t, t->pos +
sizeof(teh) + len,
sizeof(tet), &tet);
123 newpos = t->pos + len +
sizeof(teh) +
sizeof(tet);
124 if (newpos >= t->len) {
129 t->hdr->end_last = newpos;
134 static inline void copy_to_pos(
struct trace *t,
size_t pos,
size_t len,
142 assert(pos < t->len);
144 if (pos + len <= t->len) {
145 memcpy((uint8_t *) t->base + pos, src, len);
147 first = t->len - pos;
148 memcpy((uint8_t *) t->base + pos, src, first);
149 memcpy(t->base, (uint8_t *) src + first, len - first);