Commit | Line | Data |
---|---|---|
842c2b97 JD |
1 | /* |
2 | * trace_handle.c | |
3 | * | |
4 | * Babeltrace Library | |
5 | * | |
6 | * Copyright 2012 EfficiOS Inc. and Linux Foundation | |
7 | * | |
8 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
9 | * Julien Desfossez <julien.desfossez@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
c462e188 MD |
20 | * |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
842c2b97 JD |
28 | */ |
29 | ||
30 | #include <stdint.h> | |
31 | #include <stdlib.h> | |
32 | #include <babeltrace/babeltrace.h> | |
33 | #include <babeltrace/context.h> | |
08c22d05 | 34 | #include <babeltrace/context-internal.h> |
842c2b97 JD |
35 | #include <babeltrace/trace-handle.h> |
36 | #include <babeltrace/trace-handle-internal.h> | |
37 | ||
38 | struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx) | |
39 | { | |
40 | struct bt_trace_handle *th; | |
41 | ||
7f89ddce MD |
42 | if (!ctx) |
43 | return NULL; | |
44 | ||
6cba487f | 45 | th = g_new0(struct bt_trace_handle, 1); |
842c2b97 JD |
46 | th->id = ctx->last_trace_handle_id++; |
47 | return th; | |
48 | } | |
49 | ||
6cba487f MD |
50 | void bt_trace_handle_destroy(struct bt_trace_handle *th) |
51 | { | |
52 | g_free(th); | |
53 | } | |
54 | ||
e3d12cf9 | 55 | const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id) |
842c2b97 | 56 | { |
e3d12cf9 JD |
57 | struct bt_trace_handle *handle; |
58 | ||
7f89ddce MD |
59 | if (!ctx) |
60 | return NULL; | |
61 | ||
e3d12cf9 JD |
62 | handle = g_hash_table_lookup(ctx->trace_handles, |
63 | (gpointer) (unsigned long) handle_id); | |
5d95b2db JD |
64 | if (!handle) |
65 | return NULL; | |
e3d12cf9 | 66 | return handle->path; |
842c2b97 JD |
67 | } |
68 | ||
61cf588b MD |
69 | int bt_trace_handle_get_timestamp_begin(struct bt_context *ctx, |
70 | int handle_id, enum bt_clock_type type, | |
71 | int64_t *timestamp) | |
842c2b97 | 72 | { |
e3d12cf9 | 73 | struct bt_trace_handle *handle; |
61cf588b | 74 | int ret = 0; |
e3d12cf9 | 75 | |
61cf588b MD |
76 | if (!ctx || !timestamp) |
77 | return -1; | |
7f89ddce | 78 | |
e3d12cf9 JD |
79 | handle = g_hash_table_lookup(ctx->trace_handles, |
80 | (gpointer) (unsigned long) handle_id); | |
03798a93 | 81 | if (!handle) { |
61cf588b | 82 | ret = -1; |
03798a93 JD |
83 | goto end; |
84 | } | |
85 | if (type == BT_CLOCK_REAL) { | |
61cf588b | 86 | *timestamp = handle->real_timestamp_begin; |
03798a93 | 87 | } else if (type == BT_CLOCK_CYCLES) { |
61cf588b | 88 | *timestamp = handle->cycles_timestamp_begin; |
03798a93 | 89 | } else { |
61cf588b | 90 | ret = -1; |
03798a93 JD |
91 | } |
92 | ||
93 | end: | |
94 | return ret; | |
842c2b97 JD |
95 | } |
96 | ||
61cf588b MD |
97 | int bt_trace_handle_get_timestamp_end(struct bt_context *ctx, |
98 | int handle_id, enum bt_clock_type type, | |
99 | int64_t *timestamp) | |
842c2b97 | 100 | { |
e3d12cf9 | 101 | struct bt_trace_handle *handle; |
61cf588b | 102 | int ret = 0; |
e3d12cf9 | 103 | |
61cf588b MD |
104 | if (!ctx || !timestamp) |
105 | return -1; | |
7f89ddce | 106 | |
e3d12cf9 JD |
107 | handle = g_hash_table_lookup(ctx->trace_handles, |
108 | (gpointer) (unsigned long) handle_id); | |
03798a93 | 109 | if (!handle) { |
61cf588b | 110 | ret = -1; |
03798a93 JD |
111 | goto end; |
112 | } | |
113 | if (type == BT_CLOCK_REAL) { | |
61cf588b | 114 | *timestamp = handle->real_timestamp_end; |
03798a93 | 115 | } else if (type == BT_CLOCK_CYCLES) { |
61cf588b | 116 | *timestamp = handle->cycles_timestamp_end; |
03798a93 | 117 | } else { |
61cf588b | 118 | ret = -1; |
03798a93 JD |
119 | } |
120 | ||
121 | end: | |
122 | return ret; | |
842c2b97 | 123 | } |