Project
Loading...
Searching...
No Matches
TimingHelpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <uv.h>
14#include <chrono>
15
16namespace o2::framework
17{
18
19std::function<void(int64_t&, int64_t&)> TimingHelpers::defaultRealtimeBaseConfigurator(uint64_t startTimeOffset, uv_loop_t* loop)
20{
21 return [startTimeOffset, loop](int64_t& base, int64_t& offset) {
22 uv_update_time(loop);
23 auto now = uv_now(loop);
24 base = startTimeOffset + now;
25 offset = now;
26 };
27}
28
29// Implement getTimestampConfigurator based on getRealtimeBaseConfigurator
30std::function<int64_t(int64_t, int64_t)> TimingHelpers::defaultCPUTimeConfigurator(uv_loop_t* loop)
31{
32 return [loop](int64_t base, int64_t offset) -> int64_t {
33 return base + (uv_now(loop) - offset);
34 };
35}
36
38{
41 static int64_t base = 0;
42 static int64_t offset = 0;
43
44 // Get the time with the std system clock
45 if (base == 0) {
46 base = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
47 offset = uv_hrtime();
48 }
49 uint64_t current = uv_hrtime();
50 if (current - offset > 60000000000) {
51 base = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
52 offset = uv_hrtime();
53 current = offset;
54 }
55 return base + (current - offset) / 1000000;
56}
57
58} // namespace o2::framework
struct uv_loop_s uv_loop_t
GLintptr offset
Definition glcorearb.h:660
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
static int64_t getRealtimeSinceEpochStandalone()
static std::function< int64_t(int64_t base, int64_t offset)> defaultCPUTimeConfigurator(uv_loop_t *loop)
static std::function< void(int64_t &base, int64_t &offset)> defaultRealtimeBaseConfigurator(uint64_t offset, uv_loop_t *loop)