Fix trace-collection.h: No such file or directory that build code with libbabeltrace
[babeltrace.git] / lib / trace-handle.c
CommitLineData
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.
20 */
21
22#include <stdint.h>
23#include <stdlib.h>
24#include <babeltrace/babeltrace.h>
25#include <babeltrace/context.h>
08c22d05 26#include <babeltrace/context-internal.h>
842c2b97
JD
27#include <babeltrace/trace-handle.h>
28#include <babeltrace/trace-handle-internal.h>
29
30struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx)
31{
32 struct bt_trace_handle *th;
33
7f89ddce
MD
34 if (!ctx)
35 return NULL;
36
6cba487f 37 th = g_new0(struct bt_trace_handle, 1);
842c2b97
JD
38 th->id = ctx->last_trace_handle_id++;
39 return th;
40}
41
6cba487f
MD
42void bt_trace_handle_destroy(struct bt_trace_handle *th)
43{
44 g_free(th);
45}
46
47int bt_trace_handle_get_id(struct bt_trace_handle *th)
842c2b97 48{
7f89ddce
MD
49 if (!th)
50 return -1;
51
6cba487f 52 return th->id;
842c2b97
JD
53}
54
e3d12cf9 55const 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
03798a93
JD
69uint64_t bt_trace_handle_get_timestamp_begin(struct bt_context *ctx,
70 int handle_id, enum bt_clock_type type)
842c2b97 71{
e3d12cf9 72 struct bt_trace_handle *handle;
03798a93 73 uint64_t ret;
e3d12cf9 74
7f89ddce
MD
75 if (!ctx)
76 return -1ULL;
77
e3d12cf9
JD
78 handle = g_hash_table_lookup(ctx->trace_handles,
79 (gpointer) (unsigned long) handle_id);
03798a93
JD
80 if (!handle) {
81 ret = -1ULL;
82 goto end;
83 }
84 if (type == BT_CLOCK_REAL) {
85 ret = handle->real_timestamp_begin;
86 } else if (type == BT_CLOCK_CYCLES) {
87 ret = handle->cycles_timestamp_begin;
88 } else {
89 ret = -1ULL;
90 }
91
92end:
93 return ret;
842c2b97
JD
94}
95
03798a93
JD
96uint64_t bt_trace_handle_get_timestamp_end(struct bt_context *ctx,
97 int handle_id, enum bt_clock_type type)
842c2b97 98{
e3d12cf9 99 struct bt_trace_handle *handle;
03798a93 100 uint64_t ret;
e3d12cf9 101
7f89ddce
MD
102 if (!ctx)
103 return -1ULL;
104
e3d12cf9
JD
105 handle = g_hash_table_lookup(ctx->trace_handles,
106 (gpointer) (unsigned long) handle_id);
03798a93
JD
107 if (!handle) {
108 ret = -1ULL;
109 goto end;
110 }
111 if (type == BT_CLOCK_REAL) {
112 ret = handle->real_timestamp_end;
113 } else if (type == BT_CLOCK_CYCLES) {
114 ret = handle->cycles_timestamp_end;
115 } else {
116 ret = -1ULL;
117 }
118
119end:
120 return ret;
842c2b97 121}
This page took 0.040063 seconds and 4 git commands to generate.