Skip to content

Commit cdb7443

Browse files
committed
trace: don't copy strings where we don't need to.
1. trace_span_start() is always called with a string literal, so no copy needed (and we can use a macro to enforce this). 2. trace_span_tag() name and value are always longer-lived than the span, so no need to copy these either. Before: real 0m18.524000-19.100000(18.7674+/-0.21)s user 0m16.171000-16.833000(16.424+/-0.26)s sys 0m2.259000-2.400000(2.337+/-0.059)s After: real 0m16.421000-18.407000(17.8128+/-0.72)s user 0m14.242000-16.041000(15.5382+/-0.67)s sys 0m2.179000-2.363000(2.273+/-0.061)s Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e951155 commit cdb7443

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

common/trace.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct span {
6868
size_t key;
6969
struct span *parent;
7070
struct span_tag *tags;
71-
char *name;
71+
const char *name;
7272

7373
bool suspended;
7474
/* Indicate whether this is a remote span, i.e., it was
@@ -94,7 +94,7 @@ static void init_span(struct span *s,
9494
s->start_time = (now.ts.tv_sec * 1000000) + now.ts.tv_nsec / 1000;
9595
s->parent = parent;
9696
s->tags = notleak(tal_arr(NULL, struct span_tag, 0));
97-
s->name = notleak(tal_strdup(NULL, name));
97+
s->name = name;
9898
s->suspended = false;
9999

100100
/* If this is a new root span we also need to associate a new
@@ -308,13 +308,13 @@ static void trace_span_clear(struct span *s)
308308
s->key = 0;
309309
memset(s->id, 0, SPAN_ID_SIZE);
310310
memset(s->trace_id, 0, TRACE_ID_SIZE);
311-
;
311+
312312
s->parent = NULL;
313-
s->name = tal_free(s->name);
313+
s->name = NULL;
314314
s->tags = tal_free(s->tags);
315315
}
316316

317-
void trace_span_start(const char *name, const void *key)
317+
void trace_span_start_(const char *name, const void *key)
318318
{
319319
size_t numkey = trace_key(key);
320320

@@ -380,6 +380,7 @@ void trace_span_tag(const void *key, const char *name, const char *value)
380380
if (disable_trace)
381381
return;
382382

383+
assert(name);
383384
size_t numkey = trace_key(key);
384385
struct span *span = trace_span_find(numkey);
385386
assert(span);
@@ -468,7 +469,7 @@ void trace_cleanup(void)
468469

469470
#else /* HAVE_USDT */
470471

471-
void trace_span_start(const char *name, const void *key) {}
472+
void trace_span_start_(const char *name, const void *key) {}
472473
void trace_span_end(const void *key) {}
473474
void trace_span_suspend_(const void *key, const char *lbl) {}
474475
void trace_span_suspend_may_free_(const void *key, const char *lbl) {}

common/trace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#define TRACE_ID_SIZE 16
88
#undef TRACE_DEBUG
99

10-
void trace_span_start(const char *name, const void *key);
10+
/* name must be a string constant */
11+
#define trace_span_start(name, key) trace_span_start_(name "", (key))
12+
void trace_span_start_(const char *name, const void *key);
1113
void trace_span_end(const void *key);
1214
void trace_span_tag(const void *key, const char *name, const char *value);
1315
void trace_cleanup(void);

lightningd/test/run-find_my_abspath.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ void trace_span_end(const void *key UNNEEDED)
269269
/* Generated stub for trace_span_resume_ */
270270
void trace_span_resume_(const void *key UNNEEDED, const char *lbl UNNEEDED)
271271
{ fprintf(stderr, "trace_span_resume_ called!\n"); abort(); }
272-
/* Generated stub for trace_span_start */
273-
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
274-
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
272+
/* Generated stub for trace_span_start_ */
273+
void trace_span_start_(const char *name UNNEEDED, const void *key UNNEEDED)
274+
{ fprintf(stderr, "trace_span_start_ called!\n"); abort(); }
275275
/* Generated stub for txfilter_add_derkey */
276276
void txfilter_add_derkey(struct txfilter *filter UNNEEDED,
277277
const u8 derkey[PUBKEY_CMPR_LEN])

lightningd/test/run-jsonrpc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
176176
/* Generated stub for trace_span_end */
177177
void trace_span_end(const void *key UNNEEDED)
178178
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
179-
/* Generated stub for trace_span_start */
180-
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
181-
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
179+
/* Generated stub for trace_span_start_ */
180+
void trace_span_start_(const char *name UNNEEDED, const void *key UNNEEDED)
181+
{ fprintf(stderr, "trace_span_start_ called!\n"); abort(); }
182182
/* Generated stub for trace_span_tag */
183183
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
184184
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }

plugins/test/run-route-calc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id U
326326
/* Generated stub for trace_span_end */
327327
void trace_span_end(const void *key UNNEEDED)
328328
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
329-
/* Generated stub for trace_span_start */
330-
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
331-
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
329+
/* Generated stub for trace_span_start_ */
330+
void trace_span_start_(const char *name UNNEEDED, const void *key UNNEEDED)
331+
{ fprintf(stderr, "trace_span_start_ called!\n"); abort(); }
332332
/* Generated stub for trace_span_tag */
333333
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
334334
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }

plugins/test/run-route-overlong.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id U
323323
/* Generated stub for trace_span_end */
324324
void trace_span_end(const void *key UNNEEDED)
325325
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
326-
/* Generated stub for trace_span_start */
327-
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
328-
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
326+
/* Generated stub for trace_span_start_ */
327+
void trace_span_start_(const char *name UNNEEDED, const void *key UNNEEDED)
328+
{ fprintf(stderr, "trace_span_start_ called!\n"); abort(); }
329329
/* Generated stub for trace_span_tag */
330330
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
331331
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }

0 commit comments

Comments
 (0)