250ce8a413aa07c1485d80a9642fab39cdc62482
2 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB/UTIL"
24 #include "lib/lib-logging.h"
26 #include "lib/assert-pre.h"
31 #include <babeltrace2/util.h>
32 #include "lib/trace-ir/utils.h"
34 bt_util_status
bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles
,
35 uint64_t frequency
, int64_t offset_seconds
,
36 uint64_t offset_cycles
, int64_t *ns
)
39 int64_t base_offset_ns
;
40 bt_util_status status
= BT_UTIL_STATUS_OK
;
43 BT_ASSERT_PRE_NON_NULL(ns
, "Nanoseconds (output)");
44 BT_ASSERT_PRE(frequency
!= UINT64_C(-1) && frequency
!= 0,
45 "Invalid frequency: freq=%" PRIu64
, frequency
);
46 BT_ASSERT_PRE(offset_cycles
< frequency
,
47 "Offset (cycles) is greater than frequency: "
48 "offset-cycles=%" PRIu64
", freq=%" PRIu64
,
49 offset_cycles
, frequency
);
51 overflows
= bt_util_get_base_offset_ns(offset_seconds
, offset_cycles
,
52 frequency
, &base_offset_ns
);
54 status
= BT_UTIL_STATUS_OVERFLOW
;
58 ret
= bt_util_ns_from_origin_inline(base_offset_ns
,
59 offset_seconds
, offset_cycles
,
60 frequency
, cycles
, ns
);
62 status
= BT_UTIL_STATUS_OVERFLOW
;
This page took 0.03016 seconds and 4 git commands to generate.