cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[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 <inttypes.h>
13 #include <babeltrace2/babeltrace.h>
14 #include "lib/trace-ir/utils.h"
15
16 BT_EXPORT
17 bt_util_clock_cycles_to_ns_from_origin_status
18 bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles,
19 uint64_t frequency, int64_t offset_seconds,
20 uint64_t offset_cycles, int64_t *ns)
21 {
22 bool overflows;
23 int64_t base_offset_ns;
24 bt_util_clock_cycles_to_ns_from_origin_status status =
25 BT_FUNC_STATUS_OK;
26 int ret;
27
28 BT_ASSERT_PRE_NO_ERROR();
29 BT_ASSERT_PRE_NON_NULL("nanoseconds-output", ns,
30 "Nanoseconds (output)");
31 BT_ASSERT_PRE("valid-frequency",
32 frequency != UINT64_C(-1) && frequency != 0,
33 "Invalid frequency: freq=%" PRIu64, frequency);
34 BT_ASSERT_PRE("offset-cycles-lt-frequency",
35 offset_cycles < frequency,
36 "Offset (cycles) is greater than frequency: "
37 "offset-cycles=%" PRIu64 ", freq=%" PRIu64,
38 offset_cycles, frequency);
39
40 overflows = bt_util_get_base_offset_ns(offset_seconds, offset_cycles,
41 frequency, &base_offset_ns);
42 if (overflows) {
43 status = BT_FUNC_STATUS_OVERFLOW_ERROR;
44 goto end;
45 }
46
47 ret = bt_util_ns_from_origin_inline(base_offset_ns, frequency, cycles, ns);
48 if (ret) {
49 status = BT_FUNC_STATUS_OVERFLOW_ERROR;
50 }
51
52 end:
53 return status;
54 }
This page took 0.029734 seconds and 4 git commands to generate.