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
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and 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"
|
2006-11-26 11:52:51 +01:00
|
|
|
#include "llvm/Support/Streams.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.
|
2006-11-26 11:52:51 +01:00
|
|
|
llvm_cout << std::string(LastPrintAmount, '\b') << "Progress "
|
2003-12-31 11:20:38 +01:00
|
|
|
<< OperationName << ": 100% \n";
|
|
|
|
}
|
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) {
|
2006-11-26 11:52:51 +01:00
|
|
|
llvm_cout << "\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();
|
2006-11-26 11:52:51 +01:00
|
|
|
llvm_cout << ToPrint+OS.str() << std::flush;
|
2006-07-07 00:34:06 +02:00
|
|
|
return false;
|
2003-12-31 06:40:02 +01:00
|
|
|
}
|