Comments (1)
Knowing more about time_point
, duration
, and clock
helps solve this problem.
chrono::time_point
: Is a point in time. It stores a duration
type value indicating the time since the clock
's epoch.
chrono::duration
: Holds the number of ticks, where the tick period is a compile-time rational fraction representing the time in seconds from one tick to the next.
clock
: Is a bundle containing a time_point
and a duration
. The origin of the clock's time_point
is referred to as the clock's epoch.
To create a time_point
from a number, we should create a TimestampClock::duration
. The given number is used to set the ticks of the duration variable of the time_point
. Since we want this number to represent a duration in nanoseconds, the period of the duration must be in nanoseconds. The problem with the current FromNanoseconds
is that the TimestampClock
can vary from one system to another. Hence, the result will not always be a duration in nanoseconds precision.
To fix this issue, we could write something like this:
std::chrono::nanoseconds duration_ns{nanos};
To create a time_point
from the duration_ns
, we must convert the ticks in duration_ns
into the ticks in a TimestampClock::duration
. To do that, we have to explicitly cast the duration; otherwise, the implicit cast leads to a compile time error when the precision of the TimestampClock::duration
is less than nanoseconds. The explicit cast tells the compiler we are aware of the possible data loss.
TimestampClock::duration casted_dur = std::chrono::duration_cast<TimestampClock::duration>(duration_ns);
Now that we have a duration in TimestampClock::duration
, we can create a TimestampClock::time_point
from it.
TimestampClock::time_point timestamp(casted_dur);
A sample code for different casting scenarios: https://godbolt.org/z/5cEEoGdon
references:
- https://en.cppreference.com/w/cpp/chrono/time_point
- https://en.cppreference.com/w/cpp/chrono/duration
- https://en.cppreference.com/w/cpp/named_req/Clock
from vulkan-performance-layers.
Related Issues (19)
- Fix `return-type` and `comment` warnings. HOT 3
- Update the CI for the common log file. HOT 2
- Broken Script Tracking Issue
- Introduce `LogOutput` abstraction.
- Add runtime layer FileCheck.
- Improve source code directory structure HOT 1
- Event logging implementation for the Chrome Trace Event format. HOT 6
- [CI] Add `FileCheck`-based tests for the Chrome Trace Event format
- Fix Unaligned slack events
- Use dispatchable handles instead of tracking object relationships HOT 6
- Handle vkDestroyShaderModule
- Allow to use libc++ in CMake builds HOT 4
- Remove all Abseil dependencies HOT 3
- Refactor data logging HOT 3
- vkcube hangs with runtime layer enabled on ubuntu 22.04 HOT 2
- Introduce abstractions for loggable events HOT 2
- Introduce event logging abstraction. HOT 4
- Introduce the event dispatch abstraction HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vulkan-performance-layers.