Add ETA to to status when nwipe is sent a SIGUSR1

If a sudo kill -s USR1 (Nwipe's PID) is issued
on the command line while nwipe is operating in
--nogui mode, ETA is now displayed along with
percentage completion, pass and round information.

Note! Because we rely upon cached I/O at the moment
the calculated ETA early in the wipe is very inaccurate
but becomes more accurate as CPU memory cache is filled.
This commit is contained in:
PartialVolume
2020-03-20 17:52:35 +00:00
parent 7ac7c80731
commit d59e0323de
3 changed files with 78 additions and 25 deletions

View File

@@ -645,30 +645,33 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected )
total_duration_seconds = (u64) c[i]->duration;
if( total_duration_seconds % 60 )
{
minutes = total_duration_seconds / 60;
// if( total_duration_seconds % 60 )
// {
// minutes = total_duration_seconds / 60;
//
// seconds = total_duration_seconds - ( minutes * 60 );
// }
// else
// {
// minutes = total_duration_seconds / 60;
//
// seconds = 0;
// }
// if( minutes > 59 )
// {
// hours = minutes / 60;
// if( minutes % 60 )
// {
// minutes = minutes - ( hours * 60 );
// }
// else
// {
// minutes = 0;
// }
// }
seconds = total_duration_seconds - ( minutes * 60 );
}
else
{
minutes = total_duration_seconds / 60;
seconds = 0;
}
if( minutes > 59 )
{
hours = minutes / 60;
if( minutes % 60 )
{
minutes = minutes - ( hours * 60 );
}
else
{
minutes = 0;
}
}
/* Convert binary seconds into three binary variables, hours, minutes and seconds */
convert_seconds_to_hours_minutes_seconds( total_duration_seconds, &hours, &minutes, &seconds );
/* Device Model */
strncpy( model, c[i]->device_model, 17 );
@@ -779,3 +782,33 @@ void Determine_bandwidth_nomenclature( u64 speed, char* result, int result_array
snprintf( result, result_array_size, "%4llu B/s", speed / INT64_C( 1 ) );
}
}
void convert_seconds_to_hours_minutes_seconds( u64 total_seconds, int* hours, int* minutes, int* seconds )
{
/* Convert binary seconds into binary hours, minutes and seconds */
if( total_seconds % 60 )
{
*minutes = total_seconds / 60;
*seconds = total_seconds - ( *minutes * 60 );
}
else
{
*minutes = total_seconds / 60;
*seconds = 0;
}
if( *minutes > 59 )
{
*hours = *minutes / 60;
if( *minutes % 60 )
{
*minutes = *minutes - ( *hours * 60 );
}
else
{
*minutes = 0;
}
}
}

View File

@@ -41,5 +41,6 @@ void nwipe_perror( int nwipe_errno, const char* f, const char* s );
int nwipe_log_sysinfo();
void nwipe_log_summary( nwipe_context_t**, int ); // This produces the wipe status table on exit
void Determine_bandwidth_nomenclature( u64, char*, int );
void convert_seconds_to_hours_minutes_seconds( u64, int*, int*, int* );
#endif /* LOGGING_H_ */

View File

@@ -437,6 +437,10 @@ int main( int argc, char** argv )
}
/* Wait for all the wiping threads to finish, but don't wait if we receive the terminate signal */
/* set getch delay to 2/10th second. */
halfdelay( 10 );
i = 0;
while( i < nwipe_selected && terminate_signal == 0 )
{
@@ -454,7 +458,7 @@ int main( int argc, char** argv )
i++;
continue;
}
sleep( 2 ); /* DO NOT REMOVE ! Stops the routine hogging CPU cycles */
sleep( 1 ); /* DO NOT REMOVE ! Stops the routine hogging CPU cycles */
}
if( terminate_signal != 1 )
@@ -464,6 +468,7 @@ int main( int argc, char** argv )
do
{
sleep( 1 );
} while( terminate_signal != 1 );
}
}
@@ -577,6 +582,13 @@ int main( int argc, char** argv )
void* signal_hand( void* ptr )
{
int sig;
int hours;
int minutes;
int seconds;
hours = 0;
minutes = 0;
seconds = 0;
// Define signals that this handler should react to
sigset_t sigset;
@@ -588,6 +600,7 @@ void* signal_hand( void* ptr )
sigaddset( &sigset, SIGUSR1 );
int i;
char eta[9];
/* Set up the structs we will use for the data required. */
nwipe_thread_data_ptr_t* nwipe_thread_data_ptr;
@@ -642,14 +655,20 @@ void* signal_hand( void* ptr )
{
status = "[syncing]";
}
convert_seconds_to_hours_minutes_seconds( c[i]->eta, &hours, &minutes, &seconds );
nwipe_log( NWIPE_LOG_INFO,
"%s: %05.2f%%, round %i of %i, pass %i of %i %s",
"%s: %05.2f%%, round %i of %i, pass %i of %i, eta %02i:%02i:%02i, %s",
c[i]->device_name,
c[i]->round_percent,
c[i]->round_working,
c[i]->round_count,
c[i]->pass_working,
c[i]->pass_count,
hours,
minutes,
seconds,
status );
}
else