2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * LTTng UST procname context.
7 * Dual LGPL v2.1/GPL v2 license.
10 #include <sys/prctl.h>
11 #include <ust/lttng-events.h>
12 #include <ust/lttng-tracer.h>
13 #include <ust/ringbuffer-config.h>
16 #define PROCNAME_LEN 17 /* includes \0 */
19 * We cache the result to ensure we don't trigger a system call for
21 * Upon exec, procname changes, but exec takes care of throwing away
22 * this cached version.
24 static char cached_procname
[17];
27 char *wrapper_getprocname(void)
31 if (caa_unlikely(!cached_procname
[0])) {
32 ret
= prctl(PR_GET_NAME
, (unsigned long) cached_procname
,
36 return cached_procname
;
39 void lttng_context_procname_reset(void)
41 cached_procname
[0] = '\0';
45 size_t procname_get_size(size_t offset
)
54 void procname_record(struct lttng_ctx_field
*field
,
55 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
56 struct ltt_channel
*chan
)
60 procname
= wrapper_getprocname();
61 chan
->ops
->event_write(ctx
, procname
, PROCNAME_LEN
);
64 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
)
66 struct lttng_ctx_field
*field
;
68 field
= lttng_append_context(ctx
);
71 if (lttng_find_context(*ctx
, "procname")) {
72 lttng_remove_context_field(ctx
, field
);
75 field
->event_field
.name
= "procname";
76 field
->event_field
.type
.atype
= atype_array
;
77 field
->event_field
.type
.u
.array
.elem_type
.atype
= atype_integer
;
78 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.size
= sizeof(char) * CHAR_BIT
;
79 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.alignment
= lttng_alignof(char) * CHAR_BIT
;
80 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.signedness
= lttng_is_signed_type(char);
81 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.reverse_byte_order
= 0;
82 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.base
= 10;
83 field
->event_field
.type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
= lttng_encode_UTF8
;
84 field
->event_field
.type
.u
.array
.length
= PROCNAME_LEN
;
85 field
->get_size
= procname_get_size
;
86 field
->record
= procname_record
;