2003-12-31 05:40:02 +00:00
|
|
|
//===-- SlowOperationInformer.cpp - Keep the user informed ----------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-12-31 05:40:02 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-12-31 05:40:02 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-12-31 05:40:02 +00:00
|
|
|
// This file implements the SlowOperationInformer class for the LLVM debugger.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/SlowOperationInformer.h"
|
2009-08-23 08:43:55 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2005-12-22 03:31:26 +00:00
|
|
|
#include "llvm/System/Alarm.h"
|
2003-12-31 05:40:02 +00:00
|
|
|
#include <sstream>
|
2003-12-31 07:31:10 +00:00
|
|
|
#include <cassert>
|
2003-12-31 05:40:02 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
SlowOperationInformer::SlowOperationInformer(const std::string &Name)
|
|
|
|
: OperationName(Name), LastPrintAmount(0) {
|
2005-12-22 03:31:26 +00:00
|
|
|
sys::SetupAlarm(1);
|
2003-12-31 05:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SlowOperationInformer::~SlowOperationInformer() {
|
2005-12-22 03:31:26 +00:00
|
|
|
sys::TerminateAlarm();
|
2003-12-31 10:20:38 +00:00
|
|
|
if (LastPrintAmount) {
|
|
|
|
// If we have printed something, make _sure_ we print the 100% amount, and
|
|
|
|
// also print a newline.
|
2009-08-23 08:43:55 +00:00
|
|
|
outs() << std::string(LastPrintAmount, '\b') << "Progress "
|
|
|
|
<< OperationName << ": 100% \n";
|
2003-12-31 10:20:38 +00:00
|
|
|
}
|
2003-12-31 05:40:02 +00: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-06 22:34:06 +00:00
|
|
|
bool SlowOperationInformer::progress(unsigned Amount) {
|
2005-12-22 03:31:26 +00:00
|
|
|
int status = sys::AlarmStatus();
|
|
|
|
if (status == -1) {
|
2009-08-23 08:43:55 +00:00
|
|
|
outs() << "\n";
|
2003-12-31 05:40:02 +00:00
|
|
|
LastPrintAmount = 0;
|
2006-07-06 22:34:06 +00:00
|
|
|
return true;
|
2003-12-31 05:40:02 +00: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 03:31:26 +00:00
|
|
|
if (status == 0)
|
2006-07-06 22:34:06 +00:00
|
|
|
return false;
|
2003-12-31 05:40:02 +00:00
|
|
|
|
|
|
|
// Delete whatever we printed last time.
|
|
|
|
std::string ToPrint = std::string(LastPrintAmount, '\b');
|
|
|
|
|
|
|
|
std::ostringstream OS;
|
2003-12-31 10:20:38 +00:00
|
|
|
OS << "Progress " << OperationName << ": " << Amount/10;
|
|
|
|
if (unsigned Rem = Amount % 10)
|
|
|
|
OS << "." << Rem << "%";
|
|
|
|
else
|
|
|
|
OS << "% ";
|
2003-12-31 05:40:02 +00:00
|
|
|
|
|
|
|
LastPrintAmount = OS.str().size();
|
2009-08-23 08:43:55 +00:00
|
|
|
outs() << ToPrint+OS.str();
|
|
|
|
outs().flush();
|
2006-07-06 22:34:06 +00:00
|
|
|
return false;
|
2003-12-31 05:40:02 +00:00
|
|
|
}
|