Commit 7f466fd5 authored by Roland Haas's avatar Roland Haas
Browse files

mpitar: add -v and --show-progress options, be less verbose by default

parent 5bacd355
......@@ -38,18 +38,26 @@
#include <cstdlib>
#include <unistd.h>
#define _GNU_SOURCE 1
#include <getopt.h>
namespace {
void usage(const char *cmd) {
fprintf(stdout, "%s: -c -f FILE [-T FILE] [FILE]...\n", cmd);
fprintf(stdout, "%s: -c -f FILE [-v] [--show-progress] [-T FILE] [FILE]...\n", cmd);
}
}
cmdline::cmdline(const int argc, char * const argv[], bool mute) :
action(ACTION_INVALID), entries(), tarfilename()
action(ACTION_INVALID), entries(), tarfilename(), verbose(false),
progress(false)
{
const struct option longopts[] = {
{"show-progress", no_argument, NULL, 'p'},
{NULL, 0, NULL, 0}
};
int opt;
opterr = 0; // we handle our own errors
while((opt = getopt(argc, argv, "-cf:T:h")) != -1) {
while((opt = getopt_long(argc, argv, "-cf:T:hv", longopts, NULL)) != -1) {
switch(opt) {
case 'c':
if(action && action != ACTION_CREATE) {
......@@ -81,6 +89,12 @@ cmdline::cmdline(const int argc, char * const argv[], bool mute) :
action = ACTION_EXIT;
goto quit;
break;
case 'v':
verbose = true;
break;
case 'p':
progress = true;
break;
case 1:
entries.add_entry(new filearg(optarg));
break;
......
......@@ -51,11 +51,15 @@ class cmdline
action get_action() const { return action; };
fileentries& get_fileentries() { return entries; };
const std::string &get_tarfilename() const { return tarfilename; };
const bool get_verbose() const { return verbose; };
const bool get_progress() const { return progress; };
private:
action action;
fileentries entries;
std::string tarfilename;
bool verbose;
bool progress;
};
#endif // CMDLINE_HH_
......@@ -100,6 +100,10 @@ size_t show_progress(size_t total, size_t chunksize, int show_percent);
void master(const char *out_fn, fileentries& entries);
void worker(const char *out_fn);
// control how chatty we are
bool verbose = false; // show file names
bool progress = false; // show % progress
int main(int argc, char **argv)
{
int rc = -1;
......@@ -114,6 +118,9 @@ int main(int argc, char **argv)
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
cmdline args(argc, argv, rank!=0);
verbose = args.get_verbose();
progress = args.get_progress();
const char action = args.get_action();
switch(action) {
case cmdline::ACTION_ERROR:
......@@ -243,6 +250,8 @@ void master(const char *out_fn, fileentries& entries)
done = 1;
break;
}
if(verbose)
printf("%s\n", fn.c_str());
timer_stat.start(__LINE__);
tarentry ent(fn, off);
......@@ -277,14 +286,16 @@ void master(const char *out_fn, fileentries& entries)
}
}
} while(!done);
printf("\rAll done in master, waiting for workers\n");
if(progress)
printf("\rAll done in master, waiting for workers\n");
/* done, wait for everything to settle down */
timer_master_wait.start(__LINE__);
MPI_Waitall((int)send_requests.size(), &send_requests[0], MPI_STATUSES_IGNORE);
MPI_Waitall((int)recv_requests.size(), &recv_requests[0], MPI_STATUSES_IGNORE);
printf("All communication finished in master\n");
if(progress)
printf("All communication finished in master\n");
timer_master_wait.stop(__LINE__);
/* tell all workers to quit */
......@@ -297,14 +308,16 @@ void master(const char *out_fn, fileentries& entries)
timer_master_wait.stop(__LINE__);
}
printf("Closing file.\n");
if(progress)
printf("Closing file.\n");
timer_master_wait.start(__LINE__);
MPI_Barrier(MPI_COMM_WORLD);
timer_master_wait.stop(__LINE__);
size_t current = show_progress(off, size_t(0), 0);
show_progress(off, off-current, 0); /* show 100% written */
printf("\n");
if(progress)
printf("\n");
/* add index file to tarball */
timer_write_index.start(__LINE__);
......@@ -355,7 +368,8 @@ void master(const char *out_fn, fileentries& entries)
exit(1);
}
printf("Done.\n");
if(progress)
printf("Done.\n");
timer_master_wait.start(__LINE__);
MPI_Barrier(MPI_COMM_WORLD);
......@@ -565,14 +579,16 @@ size_t show_progress(size_t total, size_t chunksize, int show_percent)
static size_t written = 0;
written += chunksize;
static const char *units[] = {"B", "kB", "MB", "GB", "TB", "PB"};
int unit = int(written > 0 ? log2(written)/10 : 0);
if(unit >= int(DIM(units)))
unit = DIM(units) - 1;
printf("\r% 6.1f %s done", written/pow(2.,10*unit), units[unit]);
if(show_percent)
printf(" (% 4.1f%%)", 100.*((double)written)/total);
fflush(stdout);
if(progress) {
static const char *units[] = {"B", "kB", "MB", "GB", "TB", "PB"};
int unit = int(written > 0 ? log2(written)/10 : 0);
if(unit >= int(DIM(units)))
unit = DIM(units) - 1;
printf("\r% 6.1f %s done", written/pow(2.,10*unit), units[unit]);
if(show_percent)
printf(" (% 4.1f%%)", 100.*((double)written)/total);
fflush(stdout);
}
return written;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment