4 * LTTng UST vpid context.
6 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
26 #include <lttng/ust-events.h>
27 #include <lttng/ust-tracer.h>
28 #include <lttng/ringbuffer-config.h>
32 pid_t
wrapper_getpid(void)
37 void lttng_context_vpid_reset(void)
42 * We cache the result to ensure we don't trigger a system call for
45 static pid_t cached_vpid
;
48 pid_t
wrapper_getpid(void)
50 if (caa_unlikely(!cached_vpid
))
51 cached_vpid
= getpid();
56 * Upon fork or clone, the PID assigned to our thread is not the same as
59 void lttng_context_vpid_reset(void)
66 size_t vpid_get_size(struct lttng_ctx_field
*field
, size_t offset
)
70 size
+= lib_ring_buffer_align(offset
, lttng_alignof(pid_t
));
71 size
+= sizeof(pid_t
);
76 void vpid_record(struct lttng_ctx_field
*field
,
77 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
78 struct lttng_channel
*chan
)
82 pid
= wrapper_getpid();
83 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(pid
));
84 chan
->ops
->event_write(ctx
, &pid
, sizeof(pid
));
88 void vpid_get_value(struct lttng_ctx_field
*field
,
89 struct lttng_ctx_value
*value
)
93 pid
= wrapper_getpid();
97 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
)
99 struct lttng_ctx_field
*field
;
101 field
= lttng_append_context(ctx
);
104 if (lttng_find_context(*ctx
, "vpid")) {
105 lttng_remove_context_field(ctx
, field
);
108 field
->event_field
.name
= "vpid";
109 field
->event_field
.type
.atype
= atype_integer
;
110 field
->event_field
.type
.u
.basic
.integer
.size
= sizeof(pid_t
) * CHAR_BIT
;
111 field
->event_field
.type
.u
.basic
.integer
.alignment
= lttng_alignof(pid_t
) * CHAR_BIT
;
112 field
->event_field
.type
.u
.basic
.integer
.signedness
= lttng_is_signed_type(pid_t
);
113 field
->event_field
.type
.u
.basic
.integer
.reverse_byte_order
= 0;
114 field
->event_field
.type
.u
.basic
.integer
.base
= 10;
115 field
->event_field
.type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
116 field
->get_size
= vpid_get_size
;
117 field
->record
= vpid_record
;
118 field
->get_value
= vpid_get_value
;
119 lttng_context_update(*ctx
);