aboutsummaryrefslogtreecommitdiff
path: root/utils/optimin/src
diff options
context:
space:
mode:
authorAdrian Herrera <adrian.herrera02@gmail.com>2021-07-28 04:47:20 +0000
committerAdrian Herrera <adrian.herrera02@gmail.com>2021-07-28 06:50:41 +0000
commit0dbd37a20b90284201a117192d126cbeee998663 (patch)
tree17db921ce1319f7df0f6064ab12e7721001e530a /utils/optimin/src
parent036282185b0f06df7b7ba354f41159d682853008 (diff)
downloadafl++-0dbd37a20b90284201a117192d126cbeee998663.tar.gz
optimin: removed progress bar
It was hard to get working with showmap's directory mode
Diffstat (limited to 'utils/optimin/src')
-rw-r--r--utils/optimin/src/OptiMin.cpp62
-rw-r--r--utils/optimin/src/ProgressBar.h71
2 files changed, 24 insertions, 109 deletions
diff --git a/utils/optimin/src/OptiMin.cpp b/utils/optimin/src/OptiMin.cpp
index 242eeea9..4f0cb4f7 100644
--- a/utils/optimin/src/OptiMin.cpp
+++ b/utils/optimin/src/OptiMin.cpp
@@ -23,7 +23,6 @@
#include <llvm/Support/WithColor.h>
#include "EvalMaxSAT.h"
-#include "ProgressBar.h"
using namespace llvm;
@@ -131,7 +130,6 @@ static cl::opt<std::string> InputDir("i", cl::desc("Input directory"),
static cl::opt<std::string> OutputDir("o", cl::desc("Output directory"),
cl::value_desc("dir"), cl::Required);
-static cl::opt<bool> ShowProgBar("p", cl::desc("Display progress bar"));
static cl::opt<bool> EdgesOnly("f", cl::desc("Include edge hit counts"),
cl::init(true));
static cl::opt<std::string> WeightsFile("w", cl::desc("Weights file"),
@@ -302,22 +300,19 @@ static Error runShowmap(AFLCoverageMap &CovMap) {
}
-static inline void StartTimer(bool ShowProgBar) {
+static inline void StartTimer() {
StartTime = std::chrono::system_clock::now();
}
-static inline void EndTimer(bool ShowProgBar) {
+static inline void EndTimer() {
EndTime = std::chrono::system_clock::now();
Duration =
std::chrono::duration_cast<std::chrono::seconds>(EndTime - StartTime);
- if (ShowProgBar)
- outs() << '\n';
- else
- outs() << Duration.count() << "s\n";
+ SuccMsg() << " Completed in " << Duration.count() << " s\n";
}
@@ -328,7 +323,6 @@ static inline void EndTimer(bool ShowProgBar) {
int main(int argc, char *argv[]) {
WeightsMap Weights;
- ProgressBar ProgBar;
std::error_code EC;
// ------------------------------------------------------------------------ //
@@ -377,8 +371,8 @@ int main(int argc, char *argv[]) {
if (WeightsFile != "") {
- StatMsg() << "Reading weights from '" << WeightsFile << "'... ";
- StartTimer(/*ShowProgBar=*/false);
+ StatMsg() << "Reading weights from '" << WeightsFile << "'...\n";
+ StartTimer();
const auto WeightsOrErr = MemoryBuffer::getFile(WeightsFile);
if ((EC = WeightsOrErr.getError())) {
@@ -391,7 +385,7 @@ int main(int argc, char *argv[]) {
GetWeights(*WeightsOrErr.get(), Weights);
- EndTimer(/*ShowProgBar=*/false);
+ EndTimer();
}
@@ -401,8 +395,8 @@ int main(int argc, char *argv[]) {
// Find the seed files inside this directory (and subdirectories).
// ------------------------------------------------------------------------ //
- StatMsg() << "Locating seeds in '" << InputDir << "'... ";
- StartTimer(/*ShowProgBar=*/false);
+ StatMsg() << "Locating seeds in '" << InputDir << "'...\n";
+ StartTimer();
bool IsDirResult;
if ((EC = sys::fs::is_directory(InputDir, IsDirResult))) {
@@ -451,7 +445,7 @@ int main(int argc, char *argv[]) {
}
- EndTimer(/*ShowProgBar=*/false);
+ EndTimer();
if (SeedFiles.empty()) {
@@ -491,8 +485,8 @@ int main(int argc, char *argv[]) {
if (!SkipBinCheck) {
- StatMsg() << "Testing the target binary... ";
- StartTimer(/*ShowProgBar=*/false);
+ StatMsg() << "Testing the target binary...\n";
+ StartTimer();
// if (auto Err = runShowmap(TestSeed, Cov, /*BinCheck=*/true)) {
//
@@ -503,7 +497,7 @@ int main(int argc, char *argv[]) {
//
// }
- EndTimer(/*ShowProgBar=*/false);
+ EndTimer();
SuccMsg() << "OK, " << Cov.size() << " tuples recorded\n";
}
@@ -517,7 +511,7 @@ int main(int argc, char *argv[]) {
// ------------------------------------------------------------------------ //
StatMsg() << "Running afl-showmap on " << SeedFiles.size() << " seeds...\n";
- StartTimer(/*ShowProgBar=*/false);
+ StartTimer();
AFLCoverageMap CovMap;
MaxSATSeeds SeedVars;
@@ -557,14 +551,14 @@ int main(int argc, char *argv[]) {
}
SuccMsg() << "afl-showmap completed in ";
- EndTimer(/*ShowProgBar=*/false);
+ EndTimer();
// ------------------------------------------------------------------------ //
// Set the hard and soft constraints in the solver
// ------------------------------------------------------------------------ //
- if (!ShowProgBar) StatMsg() << "Generating constraints... ";
- StartTimer(ShowProgBar);
+ StatMsg() << "Generating constraints...\n";
+ StartTimer();
size_t SeedCount = 0;
@@ -581,10 +575,6 @@ int main(int argc, char *argv[]) {
Solver.addClause(Clauses);
- if ((++SeedCount % 10 == 0) && ShowProgBar)
- ProgBar.update(SeedCount * 100 / SeedCoverage.size(),
- "Generating clauses");
-
}
// Select the minimum number of seeds that cover a particular set of edges
@@ -592,18 +582,18 @@ int main(int argc, char *argv[]) {
for (const auto &[Var, Seed] : SeedVars)
Solver.addWeightedClause({-Var}, Weights[sys::path::filename(Seed)]);
- EndTimer(ShowProgBar);
+ EndTimer();
// ------------------------------------------------------------------------ //
// Generate a solution
// ------------------------------------------------------------------------ //
- StatMsg() << "Solving... ";
- StartTimer(/*ShowProgBar=*/false);
+ StatMsg() << "Solving...\n";
+ StartTimer();
const bool Solved = Solver.solve();
- EndTimer(/*ShowProgBar=*/false);
+ EndTimer();
// ------------------------------------------------------------------------ //
// Save the solution
@@ -626,10 +616,9 @@ int main(int argc, char *argv[]) {
}
- SuccMsg() << "Minimized corpus size: " << Solution.size() << " seeds\n";
-
- if (!ShowProgBar) StatMsg() << "Copying to '" << OutputDir << "'... ";
- StartTimer(ShowProgBar);
+ StatMsg() << "Copying " << Solution.size() << " seeds to '"
+ << OutputDir << "'...\n";
+ StartTimer();
SeedCount = 0;
@@ -649,12 +638,9 @@ int main(int argc, char *argv[]) {
}
- if ((++SeedCount % 10 == 0) && ShowProgBar)
- ProgBar.update(SeedCount * 100 / Solution.size(), "Copying seeds");
-
}
- EndTimer(ShowProgBar);
+ EndTimer();
SuccMsg() << "Done!\n";
return 0;
diff --git a/utils/optimin/src/ProgressBar.h b/utils/optimin/src/ProgressBar.h
deleted file mode 100644
index 9b75594b..00000000
--- a/utils/optimin/src/ProgressBar.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Progress bar.
- *
- * Adapted from https://www.bfilipek.com/2020/02/inidicators.html
- */
-
-#pragma once
-
-#include <llvm/ADT/StringRef.h>
-#include <llvm/Support/raw_ostream.h>
-
-/// Display a progress bar in the terminal
-class ProgressBar {
-
- private:
- const size_t BarWidth;
- const std::string Fill;
- const std::string Remainder;
-
- public:
- ProgressBar() : ProgressBar(60, "#", " ") {
-
- }
-
- ProgressBar(size_t Width, const llvm::StringRef F, const llvm::StringRef R)
- : BarWidth(Width), Fill(F), Remainder(R) {
-
- }
-
- void update(float Progress, const llvm::StringRef Status = "",
- llvm::raw_ostream &OS = llvm::outs()) {
-
- // No need to write once progress is 100%
- if (Progress > 100.0f) return;
-
- // Move cursor to the first position on the same line and flush
- OS << '\r';
- OS.flush();
-
- // Start bar
- OS << '[';
-
- const auto Completed =
- static_cast<size_t>(Progress * static_cast<float>(BarWidth) / 100.0);
- for (size_t I = 0; I < BarWidth; ++I) {
-
- if (I <= Completed) {
-
- OS << Fill;
-
- } else {
-
- OS << Remainder;
-
- }
-
- }
-
- // End bar
- OS << ']';
-
- // Write progress percentage
- OS << ' ' << std::min(static_cast<size_t>(Progress), size_t(100)) << '%';
-
- // Write status text
- OS << " " << Status;
-
- }
-
-};
-