Skip to content

Commit

Permalink
add option prog_second to display in seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Tsai committed Jun 21, 2024
1 parent 1fc4ad9 commit 4db7f48
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ int main(int argc, char **argv) {
else
flag = IO;
progress_init(&prog, start, stop, fs_info.totalblock, flag, fs_info.block_size);
prog.binary_prefix = opt.binary_prefix;
prog.prog_second = opt.prog_second;
prog.binary_prefix = opt.binary_prefix;
if (opt.prog_second)
strncpy(prog.time_unit, "sec", 4);
copied = 0; /// initial number is 0

/**
Expand Down
11 changes: 9 additions & 2 deletions src/partclone.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int log_y_line = 0;
#define OPT_WRITE_DIRECT_IO 1001
#define OPT_READ_DIRECT_IO 1002
#define OPT_BINARY_PREFIX 1003
#define OPT_PROG_SEC 1004
//
//enum {
// OPT_OFFSET_DOMAIN = 1000
Expand Down Expand Up @@ -269,7 +270,8 @@ void usage(void) {
" -F, --force Force progress\n"
" -f, --UI-fresh Fresh times of progress\n"
" -B, --no_block_detail Show progress message without block detail\n"
" --binary-prefix Show progress with bit size(MiB, GiB...)\n"
" --binary-prefix Show progress with bit size (default is MB, GB...)\n"
" --prog-second Show progress with second (default is minute)\n"
" -z, --buffer_size SIZE Read/write buffer size (default: %d)\n"
#ifndef CHKIMG
" -q, --quiet Disable progress message\n"
Expand Down Expand Up @@ -357,6 +359,7 @@ void parse_options(int argc, char **argv, cmd_opt* opt) {
{ "no_block_detail", no_argument, NULL, 'B' },
{ "buffer_size", required_argument, NULL, 'z' },
{ "binary-prefix", no_argument, NULL, OPT_BINARY_PREFIX },
{ "prog-second", no_argument, NULL, OPT_PROG_SEC },
{ "write-direct-io", no_argument, NULL, OPT_WRITE_DIRECT_IO },
{ "read-direct-io", no_argument, NULL, OPT_READ_DIRECT_IO },
// not RESTORE and not CHKIMG
Expand Down Expand Up @@ -418,6 +421,7 @@ void parse_options(int argc, char **argv, cmd_opt* opt) {
opt->write_direct_io = 0;
opt->read_direct_io = 0;
opt->binary_prefix = 0;
opt->prog_second = 0;


#ifdef DD
Expand Down Expand Up @@ -448,6 +452,9 @@ void parse_options(int argc, char **argv, cmd_opt* opt) {
case 'v':
print_version();
break;
case OPT_PROG_SEC:
opt->prog_second = 1;
break;
case OPT_BINARY_PREFIX:
opt->binary_prefix = 1;
break;
Expand Down Expand Up @@ -1909,7 +1916,7 @@ void print_partclone_info(cmd_opt opt) {
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
log_mesg(0, 0, 1, debug, _("Partclone v%s (%s) http://partclone.org\n"), VERSION, git_version);
log_mesg(0, 0, 1, debug, _("Partclone v%s http://partclone.org\n"), VERSION);
if (opt.chkimg)
log_mesg(0, 0, 1, debug, _("Starting to check image (%s)\n"), opt.source);
else if (opt.clone) {
Expand Down
1 change: 1 addition & 0 deletions src/partclone.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct cmd_opt
int write_direct_io;
int read_direct_io;
int binary_prefix;
int prog_second;
unsigned int buffer_size;
off_t offset;
unsigned long fresh;
Expand Down
23 changes: 14 additions & 9 deletions src/progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern void progress_init(struct progress_bar *prog, int start, unsigned long lo
prog->stop = stop;
prog->total = total;
prog->binary_prefix = 0;
prog->prog_second = 0;
strncpy(prog->time_unit, "min", 4);

prog->unit = 100.0 / (stop - start);
prog->total_unit = 100.0 / (total - start);
Expand Down Expand Up @@ -95,10 +97,10 @@ extern void close_pui(int pui){

extern void update_pui(struct progress_bar *prog, unsigned long long copied, unsigned long long current, int done){


if (done != 1) {
if ((difftime(time(0), prog->resolution_time) < prog->interval_time) && copied != 0)
return;

}
if (prog->pui == NCURSES)
Ncurses_progress_update(prog, copied, current, done);
Expand Down Expand Up @@ -137,7 +139,10 @@ static void calculate_speed(struct progress_bar *prog, unsigned long long copied
elapsed = 1;

speedps = prog->block_size * copied / elapsed;
speed = speedps * 60.0;
if (prog->prog_second)
speed = speedps;
else
speed = speedps * 60.0;

prog_stat->percent = percent;
if ( prefered_bits_size ){
Expand Down Expand Up @@ -241,7 +246,7 @@ extern void progress_update(struct progress_bar *prog, unsigned long long copied
fprintf(stderr, _("\r%80c\rElapsed: %s, Remaining: %s, Completed: %6.2f%%"), clear_buf, prog_stat.Eformated, prog_stat.Rformated, prog_stat.percent);

if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
fprintf(stderr, _(", %6.2f%s/min,"), prog_stat.speed, prog_stat.speed_unit);
fprintf(stderr, _(", %6.2f%s/%s,"), prog_stat.speed, prog_stat.speed_unit, prog->time_unit);
if(prog->flag == IO)
fprintf(stderr, _("\n\r%80c\rCurrent block: %10Lu, Total block: %10Lu, Complete: %6.2f%%%s\r"), clear_buf, current, prog->total, prog_stat.total_percent, "\x1b[A");
} else {
Expand All @@ -251,16 +256,16 @@ extern void progress_update(struct progress_bar *prog, unsigned long long copied

fprintf(stderr, _("\r%80c\rElapsed: %s, Remaining: %s, Completed: 100.00%%"), clear_buf, prog_stat.Eformated, prog_stat.Rformated);
if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
fprintf(stderr, _(", Rate: %6.2f%s/min,"), prog_stat.speed, prog_stat.speed_unit);
fprintf(stderr, _(", Rate: %6.2f%s/%s,"), prog_stat.speed, prog_stat.speed_unit, prog->time_unit);
if(prog->flag == IO)
fprintf(stderr, _("\n\r%80c\rCurrent block: %10Lu, Total block: %10Lu, Complete: 100.00%%\r"), clear_buf, current, prog->total);

fprintf(stderr, _("\nTotal Time: %s, "), prog_stat.Eformated);
if(prog->flag == IO)
fprintf(stderr, _("Ave. Rate: %6.2f%s/min, "), prog_stat.speed, prog_stat.speed_unit);
fprintf(stderr, _("Ave. Rate: %6.2f%s/%s, "), prog_stat.speed, prog_stat.speed_unit, prog->time_unit);
fprintf(stderr, _("%s"), "100.00% completed!\n");

log_mesg(1, 0, 0, PUI_DEBUG, "Total Time: %s, Ave. Rate: %6.2f%s/min, %s\n", prog_stat.Eformated, prog_stat.speed, prog_stat.speed_unit, "100.00% completed!");
log_mesg(1, 0, 0, PUI_DEBUG, "Total Time: %s, Ave. Rate: %6.2f%s/%s, %s\n", prog_stat.Eformated, prog_stat.speed, prog_stat.speed_unit, prog->time_unit, "100.00% completed!");
}
}

Expand Down Expand Up @@ -289,7 +294,7 @@ extern void Ncurses_progress_update(struct progress_bar *prog, unsigned long lon

mvwprintw(p_win, 0, 0, _("Elapsed: %s Remaining: %s ") , prog_stat.Eformated, prog_stat.Rformated);
if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
mvwprintw(p_win, 0, 40, _("Rate: %6.2f%s/min"), prog_stat.speed, prog_stat.speed_unit);
mvwprintw(p_win, 0, 40, _("Rate: %6.2f%s/%s"), prog_stat.speed, prog_stat.speed_unit, prog->time_unit);
if (prog->flag == IO)
mvwprintw(p_win, 1, 0, _("Current Block: %llu Total Block: %llu ") , current, prog->total);

Expand Down Expand Up @@ -324,7 +329,7 @@ extern void Ncurses_progress_update(struct progress_bar *prog, unsigned long lon
} else {
mvwprintw(p_win, 0, 0, _("Total Time: %s Remaining: %s "), prog_stat.Eformated, prog_stat.Rformated);
if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
mvwprintw(p_win, 1, 0, _("Ave. Rate: %6.2f%s/min"), prog_stat.speed, prog_stat.speed_unit);
mvwprintw(p_win, 1, 0, _("Ave. Rate: %6.2f%s/%s"), prog_stat.speed, prog_stat.speed_unit, prog->time_unit);

if (prog->flag == IO)
mvwprintw(p_win, 3, 0, _("Data Block Process:"));
Expand All @@ -348,7 +353,7 @@ extern void Ncurses_progress_update(struct progress_bar *prog, unsigned long lon
wrefresh(bar_win);
wrefresh(tbar_win);
refresh();
log_mesg(1, 0, 0, PUI_DEBUG, "Total Time: %s, Ave. Rate: %6.2f%s/min, %s\n", prog_stat.Eformated, prog_stat.speed, prog_stat.speed_unit, "100.00% completed!");
log_mesg(1, 0, 0, PUI_DEBUG, "Total Time: %s, Ave. Rate: %6.2f%s/%s, %s\n", prog_stat.Eformated, prog_stat.speed, prog_stat.speed_unit, prog->time_unit, "100.00% completed!");
sleep(1);
}

Expand Down
3 changes: 2 additions & 1 deletion src/progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct progress_bar {
int pui;
int flag;
int binary_prefix;
int prog_second;
char time_unit[4];
};
typedef struct progress_bar progress_bar;

Expand All @@ -45,7 +47,6 @@ struct prog_stat_t{
float total_percent;
float speed;
char speed_unit[5];

};
typedef struct prog_stat_t prog_stat_t;

Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* WHETHER THEY ARE BUILT BY OTHERS OR DURING DEVELOPMENT OR FOR THE
* OFFICIAL PARTCLONE RELEASES.
*/
#define git_version "28c97b3"
#define git_version "1fc4ad9"

0 comments on commit 4db7f48

Please sign in to comment.