dtrugman / pfs

Parsing the Linux procfs
Apache License 2.0
99 stars 33 forks source link

Using std::chrono::steady_clock::duration instead of double in uptime struct. #6

Closed kfiros closed 3 years ago

kfiros commented 3 years ago

We should consider changing the uptime struct to hold std::chrono::steady_clock::duration instead of doubles.

dtrugman commented 3 years ago

Just checked. There's a clear correlation between the first value in /proc/uptime and std::chrono::steady_clock. Used the following snippet to validate it:

#include <chrono>
#include <iostream>

int main()
{
    auto boot = std::chrono::time_point<std::chrono::steady_clock>{};
    auto now = std::chrono::steady_clock::now();
    std::cout << std::chrono::duration_cast<std::chrono::seconds>(now - boot).count() << std::endl;
    return 0;
}

When I run: cat /proc/uptime; ./a.out I get:

>>> cat /proc/uptime; ./a.out
651668.56 650711.66
651668

So we can definitely change the values in the struct to hold steady_clock::duration. Wanna do that @kfiros?

kfiros commented 3 years ago

Yes, assign me please.