Implement libcounter
[lttng-ust.git] / liblttng-ust / ust-core.c
CommitLineData
5e96a467
MD
1/*
2 * ust-core.c
3 *
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
3fbec7dc 21#define _LGPL_SOURCE
fb31eb73 22#include <stdint.h>
b4051ad8 23#include <stddef.h>
5e96a467 24#include <stdlib.h>
44c72f10
MD
25#include <lttng/ust-events.h>
26#include <usterr-signal-safe.h>
797b05f6 27#include "lttng-tracer-core.h"
c785c634 28#include "jhash.h"
5e96a467 29
7dd08bec 30static CDS_LIST_HEAD(lttng_transport_list);
ebabbf58 31static CDS_LIST_HEAD(lttng_counter_transport_list);
c1fca457 32
7dd08bec 33struct lttng_transport *lttng_transport_find(const char *name)
c1fca457 34{
7dd08bec 35 struct lttng_transport *transport;
c1fca457 36
7dd08bec 37 cds_list_for_each_entry(transport, &lttng_transport_list, node) {
c1fca457
MD
38 if (!strcmp(transport->name, name))
39 return transport;
40 }
41 return NULL;
42}
43
ebabbf58
MD
44struct lttng_counter_transport *lttng_counter_transport_find(const char *name)
45{
46 struct lttng_counter_transport *transport;
47
48 cds_list_for_each_entry(transport, &lttng_counter_transport_list, node) {
49 if (!strcmp(transport->name, name))
50 return transport;
51 }
52 return NULL;
53}
54
c1fca457 55/**
7dd08bec 56 * lttng_transport_register - LTT transport registration
c1fca457
MD
57 * @transport: transport structure
58 *
59 * Registers a transport which can be used as output to extract the data out of
60 * LTTng. Called with ust_lock held.
61 */
7dd08bec 62void lttng_transport_register(struct lttng_transport *transport)
c1fca457 63{
7dd08bec 64 cds_list_add_tail(&transport->node, &lttng_transport_list);
c1fca457
MD
65}
66
67/**
7dd08bec 68 * lttng_transport_unregister - LTT transport unregistration
c1fca457
MD
69 * @transport: transport structure
70 * Called with ust_lock held.
71 */
7dd08bec 72void lttng_transport_unregister(struct lttng_transport *transport)
c1fca457
MD
73{
74 cds_list_del(&transport->node);
75}
c785c634 76
ebabbf58
MD
77/**
78 * lttng_counter_transport_register - LTTng counter transport registration
79 * @transport: transport structure
80 *
81 * Registers a counter transport which can be used as output to extract
82 * the data out of LTTng. Called with ust_lock held.
83 */
84void lttng_counter_transport_register(struct lttng_counter_transport *transport)
85{
86 cds_list_add_tail(&transport->node, &lttng_counter_transport_list);
87}
88
89/**
90 * lttng_counter_transport_unregister - LTTng counter transport unregistration
91 * @transport: transport structure
92 * Called with ust_lock held.
93 */
94void lttng_counter_transport_unregister(struct lttng_counter_transport *transport)
95{
96 cds_list_del(&transport->node);
97}
98
c785c634
MD
99/*
100 * Needed by comm layer.
101 */
b33b46f7
FD
102struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
103 const struct lttng_enum_desc *enum_desc)
c785c634
MD
104{
105 struct lttng_enum *_enum;
106 struct cds_hlist_head *head;
107 struct cds_hlist_node *node;
b33b46f7 108 size_t name_len = strlen(enum_desc->name);
c785c634
MD
109 uint32_t hash;
110
b33b46f7 111 hash = jhash(enum_desc->name, name_len, 0);
c785c634
MD
112 head = &session->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)];
113 cds_hlist_for_each_entry(_enum, node, head, hlist) {
114 assert(_enum->desc);
b33b46f7 115 if (_enum->desc == enum_desc)
c785c634
MD
116 return _enum;
117 }
118 return NULL;
119}
797b05f6
MD
120
121size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset)
122{
123 size_t size = 0;
124
125 size += lib_ring_buffer_align(offset, lttng_alignof(char));
126 size += sizeof(char); /* tag */
127 return size;
128}
129
130void lttng_ust_dummy_record(struct lttng_ctx_field *field,
131 struct lttng_ust_lib_ring_buffer_ctx *ctx,
132 struct lttng_channel *chan)
133{
134 char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE;
135
136 lib_ring_buffer_align_ctx(ctx, lttng_alignof(sel_char));
137 chan->ops->event_write(ctx, &sel_char, sizeof(sel_char));
138}
139
140void lttng_ust_dummy_get_value(struct lttng_ctx_field *field,
141 struct lttng_ctx_value *value)
142{
143 value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE;
144}
ce47f5d8
MD
145
146int lttng_context_is_app(const char *name)
147{
148 if (strncmp(name, "$app.", strlen("$app.")) != 0) {
149 return 0;
150 }
151 return 1;
152}
This page took 0.037133 seconds and 4 git commands to generate.