2003-12-31 06:40:02 +01:00
|
|
|
//===-- SlowOperationInformer.cpp - Keep the user informed ----------------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-12-31 06:40:02 +01:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-12-31 06:40:02 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-12-31 06:40:02 +01:00
|
|
|
// This file implements the SlowOperationInformer class for the LLVM debugger.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/SlowOperationInformer.h"
|
2009-08-23 10:43:55 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2005-12-22 04:31:26 +01:00
|
|
|
#include "llvm/System/Alarm.h"
|
2003-12-31 06:40:02 +01:00
|
|
|
#include <sstream>
|
2003-12-31 08:31:10 +01:00
|
|
|
#include <cassert>
|
2003-12-31 06:40:02 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
SlowOperationInformer::SlowOperationInformer(const std::string &Name)
|
|
|
|
: OperationName(Name), LastPrintAmount(0) {
|
2005-12-22 04:31:26 +01:00
|
|
|
sys::SetupAlarm(1);
|
2003-12-31 06:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SlowOperationInformer::~SlowOperationInformer() {
|
2005-12-22 04:31:26 +01:00
|
|
|
sys::TerminateAlarm();
|
2003-12-31 11:20:38 +01:00
|
|
|
if (LastPrintAmount) {
|
|
|
|
// If we have printed something, make _sure_ we print the 100% amount, and
|
|
|
|
// also print a newline.
|
2009-08-23 10:43:55 +02:00
|
|
|
outs() << std::string(LastPrintAmount, '\b') << "Progress "
|
|
|
|
<< OperationName << ": 100% \n";
|
2003-12-31 11:20:38 +01:00
|
|
|
}
|
2003-12-31 06:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// progress - Clients should periodically call this method when they are in
|
|
|
|
/// an exception-safe state. The Amount variable should indicate how far
|
|
|
|
/// along the operation is, given in 1/10ths of a percent (in other words,
|
|
|
|
/// Amount should range from 0 to 1000).
|
2006-07-07 00:34:06 +02:00
|
|
|
bool SlowOperationInformer::progress(unsigned Amount) {
|
2005-12-22 04:31:26 +01:00
|
|
|
int status = sys::AlarmStatus();
|
|
|
|
if (status == -1) {
|
2009-08-23 10:43:55 +02:00
|
|
|
outs() << "\n";
|
2003-12-31 06:40:02 +01:00
|
|
|
LastPrintAmount = 0;
|
2006-07-07 00:34:06 +02:00
|
|
|
return true;
|
2003-12-31 06:40:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we haven't spent enough time in this operation to warrant displaying the
|
|
|
|
// progress bar, don't do so yet.
|
2005-12-22 04:31:26 +01:00
|
|
|
if (status == 0)
|
2006-07-07 00:34:06 +02:00
|
|
|
return false;
|
2003-12-31 06:40:02 +01:00
|
|
|
|
|
|
|
// Delete whatever we printed last time.
|
|
|
|
std::string ToPrint = std::string(LastPrintAmount, '\b');
|
|
|
|
|
|
|
|
std::ostringstream OS;
|
2003-12-31 11:20:38 +01:00
|
|
|
OS << "Progress " << OperationName << ": " << Amount/10;
|
|
|
|
if (unsigned Rem = Amount % 10)
|
|
|
|
OS << "." << Rem << "%";
|
|
|
|
else
|
|
|
|
OS << "% ";
|
2003-12-31 06:40:02 +01:00
|
|
|
|
|
|
|
LastPrintAmount = OS.str().size();
|
2009-08-23 10:43:55 +02:00
|
|
|
outs() << ToPrint+OS.str();
|
|
|
|
outs().flush();
|
2006-07-07 00:34:06 +02:00
|
|
|
return false;
|
2003-12-31 06:40:02 +01:00
|
|
|
}
|