llvm.org GIT mirror llvm / 9e26027
* Add a new helper progress method * Make sure that the user sees the 100% mark * Don't bother printing out X.0%, just print out X% git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10672 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
3 changed file(s) with 31 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
3131 #define SUPPORT_SLOW_OPERATION_INFORMER_H
3232
3333 #include
34 #include
3435
3536 namespace llvm {
3637 class SlowOperationInformer {
4849 /// along the operation is, given in 1/10ths of a percent (in other words,
4950 /// Amount should range from 0 to 1000).
5051 void progress(unsigned Amount);
52
53 /// progress - Same as the method above, but this performs the division for
54 /// you, and helps you avoid overflow if you are dealing with largish
55 /// numbers.
56 void progress(unsigned Current, unsigned Maximum) {
57 assert(Maximum != 0 &&
58 "Shouldn't be doing work if there is nothing to do!");
59 progress(Current*1000ULL/Maximum);
60 }
5161 };
5262 } // end namespace llvm
5363
3131 #define SUPPORT_SLOW_OPERATION_INFORMER_H
3232
3333 #include
34 #include
3435
3536 namespace llvm {
3637 class SlowOperationInformer {
4849 /// along the operation is, given in 1/10ths of a percent (in other words,
4950 /// Amount should range from 0 to 1000).
5051 void progress(unsigned Amount);
52
53 /// progress - Same as the method above, but this performs the division for
54 /// you, and helps you avoid overflow if you are dealing with largish
55 /// numbers.
56 void progress(unsigned Current, unsigned Maximum) {
57 assert(Maximum != 0 &&
58 "Shouldn't be doing work if there is nothing to do!");
59 progress(Current*1000ULL/Maximum);
60 }
5161 };
5262 } // end namespace llvm
5363
5858
5959 SlowOperationInformer::~SlowOperationInformer() {
6060 NestedSOI = false;
61 if (LastPrintAmount)
62 std::cout << "\n";
61 if (LastPrintAmount) {
62 // If we have printed something, make _sure_ we print the 100% amount, and
63 // also print a newline.
64 std::cout << std::string(LastPrintAmount, '\b') << "Progress "
65 << OperationName << ": 100% \n";
66 }
6367
6468 alarm(0);
6569 signal(SIGALRM, SIG_DFL);
8690 std::string ToPrint = std::string(LastPrintAmount, '\b');
8791
8892 std::ostringstream OS;
89 OS << "Progress " << OperationName << ": " << Amount/10 << "." << Amount % 10
90 << "%";
93 OS << "Progress " << OperationName << ": " << Amount/10;
94 if (unsigned Rem = Amount % 10)
95 OS << "." << Rem << "%";
96 else
97 OS << "% ";
9198
9299 LastPrintAmount = OS.str().size();
93100 std::cout << ToPrint+OS.str() << std::flush;