This is an archive of the discontinued LLVM Phabricator instance.

[RFC] Add a LIT-style Progress Bar to libSupport
Needs ReviewPublic

Authored by jroelofs on Sep 29 2017, 10:26 AM.

Details

Reviewers
chandlerc
Summary

I've built this for an out-of-tree use case where we have a tool runs for a very long time. The task itself happens to be reasonably predictable in the amount of work completed, much like the corpus of LIT tests. Since we've already got such a thing in-tree (in python), namely the LIT one, I figured I'd model it off of that.

Usage is something like:

llvm::ProgressBar PB(llvm::outs(), "Performing Tasks");
for (int I = 0, E = 100; I != E; ++I) {
  PB.update(I / float(E), (I < 30 ? "Task A" : "Task B"));
  sleep(1);
}
PB.clear();

And with that, you get a nice familiar progress bar that looks like:

             Performing Tasks
 20% [=====--------------------] ETA 00:01:20
Task A

with different colors, to distinguish it from LIT's (sigh... bikeshed away).

Is this something that would be useful upstream? I've thought about tying this into the pass manager, but I don't yet see a consistent way to estimate the total amount of work there. Even then, are there cases where Clang runs for long enough for this to matter?... I don't want this to be an admission of defeat when it comes to compile times. Are there other use cases?

Suggestions on how to write a UnitTest for it are most welcome. As-is, that's a little tricky because this depends on the width of the terminal, so printing it to a raw_string_ostream isn't going to give consistent results. I've tested this on Darwin, but I have no idea whether it'll DTRT on other platforms. If it's not platform-agnostic enough, suggestions on how to fix that would also be quite welcome.

Diff Detail

Event Timeline

jroelofs created this revision.Sep 29 2017, 10:26 AM
jroelofs added subscribers: aaron.ballman, chandlerc.

@aaron.ballman suggested adding @chandlerc as a reviewer

It occurs to me that Chandler's also the right person to ask about ideas on how to estimate the progress of a PassManager.

jroelofs updated this revision to Diff 117205.Sep 29 2017, 12:51 PM

Rate-limit it, since it'll look awful if you call update() really often.

jroelofs updated this revision to Diff 117232.Sep 29 2017, 3:11 PM
jroelofs added a subscriber: bogner.

Add a testcase per @bogner's advice (sort of). I tried doing the setenv trick, but that only worked when the testcase is ran not under LIT. Since I have to inject other state in anyway for testing, may as well just use that flag to force 60 cols too.

meadori added a subscriber: meadori.Oct 3 2017, 9:29 AM

Is this something that would be useful upstream?

One application where it might be helpful is in LLD. I could see enabling something like this for linking (since that can be long at times).