Using std::chrono

Hi all,

We’re considering using std::chrono more heavily in lldb. However, A quick search of the llvm, clang, and lld codebases shos almost zero usage of chrono. I wanted to see if this was for technical reasons (eg some compiler doesn’t support it well) or simply because nobody has needed it yet. If it’s the former then I’d like to be aware of the issues so we don’t fall into any traps.

If it’s the latter, then we’re good to go. Would it be worth adding any chrono helper functions to llvm/Support? On the one hand, it seems generally useful. But on the other hand, if nobody’s using it yet, maybe it’s not generally useful enough.

Also, are there any chrono experts around who would be willing to review some patches?

Speaking of LLD, the reason why we don’t use is just because we don’t need it.

Visual Studio up to and including VS2013 implements std::chrono::high_resolution_clock in an absolutely unusable manner (it is a very low resolution clock…) 1. Also, division is implemented incorrectly 2. I have run into both issues in my private developments, so I would avoid them as long as VS2013 is supported by LLVM (I believe it still is?).

VS2013 support is dropped in about 1 week from now :slight_smile:

Hello all,

I'd like to add a std::chrono support header to libSupport
<https://reviews.llvm.org/D25416>. My main motivation is remove LLDB's
TimeValue class in favor of std::chrono, but I think we could do the
same for llvm::sys::TimeValue as well - the class was added a very
long time ago, when std::chrono did not exist yet, but now it should
be supported by all compilers. I've tried rewriting some of the uses
in llvm, and despite the apparent verboseness of std::chrono, it makes
the code shorter most of the time, and (due to the separation between
time points and durations) also safer - I think I also found some bugs
where we were adding two time points, but I'll need to verify that.

What do you think?
pl

From: "Pavel Labath via llvm-dev" <llvm-dev@lists.llvm.org>
To: "Zachary Turner" <zturner@google.com>
Cc: llvm-dev@lists.llvm.org
Sent: Sunday, October 9, 2016 9:29:17 PM
Subject: Re: [llvm-dev] Using std::chrono

Hello all,

I'd like to add a std::chrono support header to libSupport
<https://reviews.llvm.org/D25416>. My main motivation is remove
LLDB's
TimeValue class in favor of std::chrono, but I think we could do the
same for llvm::sys::TimeValue as well - the class was added a very
long time ago, when std::chrono did not exist yet, but now it should
be supported by all compilers. I've tried rewriting some of the uses
in llvm, and despite the apparent verboseness of std::chrono, it
makes
the code shorter most of the time, and (due to the separation between
time points and durations) also safer - I think I also found some
bugs
where we were adding two time points, but I'll need to verify that.

What do you think?

I think this makes sense. As you say, our TimeValue pre-dates std::chrono. If the implementations are now generally usable, we should transition to the standard functionality.

-Hal