Revert "Add freebsd support for getcpu (use cpu nr 0)"
[lttng-ust.git] / liblttng-ust / lttng-context-procname.c
CommitLineData
4847e9bb
MD
1/*
2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * LTTng UST procname context.
6 *
7 * Dual LGPL v2.1/GPL v2 license.
8 */
9
4318ae1b
MD
10#include <lttng/ust-events.h>
11#include <lttng/ust-tracer.h>
12#include <lttng/ringbuffer-config.h>
4847e9bb 13#include <assert.h>
48621a42 14#include "compat.h"
4847e9bb
MD
15
16/*
17 * We cache the result to ensure we don't trigger a system call for
18 * each event.
19 * Upon exec, procname changes, but exec takes care of throwing away
20 * this cached version.
21 */
22static char cached_procname[17];
23
24static inline
25char *wrapper_getprocname(void)
26{
b5a3dfa5 27 if (caa_unlikely(!cached_procname[0])) {
48621a42
MD
28 lttng_ust_getprocname(cached_procname);
29 cached_procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0';
4847e9bb
MD
30 }
31 return cached_procname;
32}
33
34void lttng_context_procname_reset(void)
35{
36 cached_procname[0] = '\0';
37}
38
39static
40size_t procname_get_size(size_t offset)
41{
42 size_t size = 0;
43
48621a42 44 size += LTTNG_UST_PROCNAME_LEN;
4847e9bb
MD
45 return size;
46}
47
48static
49void procname_record(struct lttng_ctx_field *field,
4cfec15c 50 struct lttng_ust_lib_ring_buffer_ctx *ctx,
4847e9bb
MD
51 struct ltt_channel *chan)
52{
53 char *procname;
54
55 procname = wrapper_getprocname();
48621a42 56 chan->ops->event_write(ctx, procname, LTTNG_UST_PROCNAME_LEN);
4847e9bb
MD
57}
58
59int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
60{
61 struct lttng_ctx_field *field;
62
63 field = lttng_append_context(ctx);
64 if (!field)
65 return -ENOMEM;
66 if (lttng_find_context(*ctx, "procname")) {
67 lttng_remove_context_field(ctx, field);
68 return -EEXIST;
69 }
70 field->event_field.name = "procname";
71 field->event_field.type.atype = atype_array;
72 field->event_field.type.u.array.elem_type.atype = atype_integer;
73 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
74 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
75 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char);
76 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
77 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
78 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
48621a42 79 field->event_field.type.u.array.length = LTTNG_UST_PROCNAME_LEN;
4847e9bb
MD
80 field->get_size = procname_get_size;
81 field->record = procname_record;
82 return 0;
83}
This page took 0.030991 seconds and 4 git commands to generate.