| 105 | static struct span *current; |
| 106 | |
| 107 | static void init_span(struct span *s, size_t key, const char *name, |
| 108 | struct span *parent) |
| 109 | { |
| 110 | struct timeabs now = |
| 111 | time_now(); /* discouraged: but tracing wants non-dev time */ |
| 112 | |
| 113 | s->key = key; |
| 114 | s->id = pseudorand_u64(); |
| 115 | s->start_time = (now.ts.tv_sec * 1000000) + now.ts.tv_nsec / 1000; |
| 116 | s->parent = parent; |
| 117 | s->name = name; |
| 118 | s->suspended = false; |
| 119 | for (size_t i = 0; i < SPAN_MAX_TAGS; i++) |
| 120 | s->tags[i].name = NULL; |
| 121 | |
| 122 | /* If this is a new root span we also need to associate a new |
| 123 | * trace_id with it. */ |
| 124 | if (!s->parent) { |
| 125 | s->trace_id_hi = pseudorand_u64(); |
| 126 | s->trace_id_lo = pseudorand_u64(); |
| 127 | } else { |
| 128 | s->trace_id_hi = current->trace_id_hi; |
| 129 | s->trace_id_lo = current->trace_id_lo; |
| 130 | } |
| 131 | span_htable_add(spans, s); |
| 132 | } |
| 133 | |
| 134 | /* FIXME: forward decls for minimal patch size */ |
| 135 | static struct span *trace_span_slot(void); |
no test coverage detected