Fix: lib: pass down API function name to some helpers
[babeltrace.git] / src / lib / util.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #define BT_LOG_TAG "LIB/UTIL"
8 #include "lib/logging.h"
9
10 #include "lib/assert-cond.h"
11 #include <stdbool.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <inttypes.h>
15 #include <babeltrace2/babeltrace.h>
16 #include "lib/trace-ir/utils.h"
17
18 bt_util_clock_cycles_to_ns_from_origin_status
19 bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles,
20 uint64_t frequency, int64_t offset_seconds,
21 uint64_t offset_cycles, int64_t *ns)
22 {
23 bool overflows;
24 int64_t base_offset_ns;
25 bt_util_clock_cycles_to_ns_from_origin_status status =
26 BT_FUNC_STATUS_OK;
27 int ret;
28
29 BT_ASSERT_PRE_NO_ERROR();
30 BT_ASSERT_PRE_NON_NULL("nanoseconds-output", ns,
31 "Nanoseconds (output)");
32 BT_ASSERT_PRE("valid-frequency",
33 frequency != UINT64_C(-1) && frequency != 0,
34 "Invalid frequency: freq=%" PRIu64, frequency);
35 BT_ASSERT_PRE("offset-cycles-lt-frequency",
36 offset_cycles < frequency,
37 "Offset (cycles) is greater than frequency: "
38 "offset-cycles=%" PRIu64 ", freq=%" PRIu64,
39 offset_cycles, frequency);
40
41 overflows = bt_util_get_base_offset_ns(offset_seconds, offset_cycles,
42 frequency, &base_offset_ns);
43 if (overflows) {
44 status = BT_FUNC_STATUS_OVERFLOW_ERROR;
45 goto end;
46 }
47
48 ret = bt_util_ns_from_origin_inline(base_offset_ns,
49 offset_seconds, offset_cycles,
50 frequency, cycles, ns);
51 if (ret) {
52 status = BT_FUNC_STATUS_OVERFLOW_ERROR;
53 }
54
55 end:
56 return status;
57 }
This page took 0.029282 seconds and 4 git commands to generate.