1 //===-- SlowOperationInformer.cpp - Keep the user informed ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the SlowOperationInformer class for the LLVM debugger.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/SlowOperationInformer.h"
15 #include "llvm/System/IncludeFile.h"
16 #include "llvm/System/Alarm.h"
22 SlowOperationInformer::SlowOperationInformer(const std::string &Name)
23 : OperationName(Name), LastPrintAmount(0) {
27 SlowOperationInformer::~SlowOperationInformer() {
28 sys::TerminateAlarm();
29 if (LastPrintAmount) {
30 // If we have printed something, make _sure_ we print the 100% amount, and
31 // also print a newline.
32 std::cout << std::string(LastPrintAmount, '\b') << "Progress "
33 << OperationName << ": 100% \n";
37 /// progress - Clients should periodically call this method when they are in
38 /// an exception-safe state. The Amount variable should indicate how far
39 /// along the operation is, given in 1/10ths of a percent (in other words,
40 /// Amount should range from 0 to 1000).
41 bool SlowOperationInformer::progress(unsigned Amount) {
42 int status = sys::AlarmStatus();
49 // If we haven't spent enough time in this operation to warrant displaying the
50 // progress bar, don't do so yet.
54 // Delete whatever we printed last time.
55 std::string ToPrint = std::string(LastPrintAmount, '\b');
57 std::ostringstream OS;
58 OS << "Progress " << OperationName << ": " << Amount/10;
59 if (unsigned Rem = Amount % 10)
60 OS << "." << Rem << "%";
64 LastPrintAmount = OS.str().size();
65 std::cout << ToPrint+OS.str() << std::flush;
69 DEFINING_FILE_FOR(SupportSlowOperationInformer)