display shred speed
This commit is contained in:
		@ -1 +1,2 @@
 | 
			
		||||
4673974d
 | 
			
		||||
2cb3dea4
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,13 @@ public:
 | 
			
		||||
                    FROZEN
 | 
			
		||||
                   } state;
 | 
			
		||||
 | 
			
		||||
     struct {
 | 
			
		||||
        time_t u32ShredTimeDelta;
 | 
			
		||||
        std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp;
 | 
			
		||||
        unsigned long ulWrittenBytes;
 | 
			
		||||
    } sShredSpeed;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    bool bWasShredded = false;
 | 
			
		||||
    bool bWasDeleteted = false;
 | 
			
		||||
    bool bIsOffline = false;
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Logic
 | 
			
		||||
#define DRYRUN //don´t touch the drives
 | 
			
		||||
//#define DRYRUN //don´t touch the drives
 | 
			
		||||
#define FROZEN_ALERT //show alert if drive is frozen
 | 
			
		||||
 | 
			
		||||
//IPC pipes
 | 
			
		||||
 | 
			
		||||
@ -56,7 +56,7 @@ private:
 | 
			
		||||
    static WINDOW *createOverViewWindow( int iXSize, int iYSize);
 | 
			
		||||
    static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
 | 
			
		||||
    static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart);
 | 
			
		||||
    static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, bool bSelected);
 | 
			
		||||
    static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected);
 | 
			
		||||
    static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart);
 | 
			
		||||
    static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);
 | 
			
		||||
    static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB);
 | 
			
		||||
@ -65,6 +65,7 @@ private:
 | 
			
		||||
 | 
			
		||||
    void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY);
 | 
			
		||||
    string formatTimeDuration(time_t u32Duration);
 | 
			
		||||
    string formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
#endif  // TUI_H_
 | 
			
		||||
@ -70,6 +70,9 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
 | 
			
		||||
 | 
			
		||||
    blockcount_max = SHRED_ITERATIONS*(drive->getCapacity()/4096);
 | 
			
		||||
 | 
			
		||||
    drive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();; //set inital timestamp for speed metric
 | 
			
		||||
    unsigned long ulSpeedMetricBytesWritten = 0U; //uses to calculate speed metric
 | 
			
		||||
 | 
			
		||||
#ifdef LOG_LEVEL_HIGH
 | 
			
		||||
    Logger::logThis()->info("Shred-Task: Max-BlockCount: " + to_string(blockcount_max) + " - Drive: " + drive->getSerial());
 | 
			
		||||
#endif
 | 
			
		||||
@ -177,6 +180,14 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
 | 
			
		||||
#ifdef LOG_LEVEL_HIGH
 | 
			
		||||
                            Logger::logThis()->info("Shred-Task: BlockCount: " + to_string(blockcount) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
                            //set metrics for calculating shred speed
 | 
			
		||||
                            std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now();
 | 
			
		||||
                            drive->sShredSpeed.u32ShredTimeDelta = (chronoCurrentTimestamp - drive->sShredSpeed.chronoShredTimestamp).count();
 | 
			
		||||
                            drive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();
 | 
			
		||||
                            drive->sShredSpeed.ulWrittenBytes = ulSpeedMetricBytesWritten;
 | 
			
		||||
                            ulSpeedMetricBytesWritten = 0U;
 | 
			
		||||
 | 
			
		||||
                            write(*ipSignalFd, "A",1);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
@ -194,7 +205,9 @@ void Shred::shredDrive(Drive* drive, int* ipSignalFd)
 | 
			
		||||
                            last = 1;
 | 
			
		||||
                        }
 | 
			
		||||
                    errno = 0;
 | 
			
		||||
                    l -= write(f, buf, (noround && last) ? l : blksz);
 | 
			
		||||
                    size_t write_return = write(f, buf, (noround && last) ? l : blksz);
 | 
			
		||||
                    ulSpeedMetricBytesWritten += write_return;
 | 
			
		||||
                    l -= write_return;
 | 
			
		||||
                    if (errno)
 | 
			
		||||
                        {
 | 
			
		||||
                            perror(cpDrivePath);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								src/tui.cpp
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/tui.cpp
									
									
									
									
									
								
							@ -78,7 +78,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
 | 
			
		||||
            string sCapacity = it->sCapacityToText();
 | 
			
		||||
            string sState = " ";
 | 
			
		||||
            string sTime = " ";
 | 
			
		||||
 | 
			
		||||
            string sSpeed = " ";
 | 
			
		||||
 | 
			
		||||
            bool bSelectedEntry = false;
 | 
			
		||||
 | 
			
		||||
@ -107,6 +107,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
 | 
			
		||||
 | 
			
		||||
                    it->calculateTaskDuration();
 | 
			
		||||
                    sTime = this->formatTimeDuration(it->getTaskDuration());
 | 
			
		||||
                    sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes);
 | 
			
		||||
                    break;
 | 
			
		||||
                case Drive::DELETE_ACTIVE:
 | 
			
		||||
                    sState = "Deleting ...";
 | 
			
		||||
@ -142,7 +143,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, bSelectedEntry);
 | 
			
		||||
            WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, sSpeed, bSelectedEntry);
 | 
			
		||||
            wrefresh(tmp);
 | 
			
		||||
            u8Index++;
 | 
			
		||||
        }//end loop though drives
 | 
			
		||||
@ -296,7 +297,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart)
 | 
			
		||||
    return newWindow;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, bool bSelected)
 | 
			
		||||
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected)
 | 
			
		||||
{
 | 
			
		||||
    WINDOW *newWindow;
 | 
			
		||||
    newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
 | 
			
		||||
@ -320,8 +321,9 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
 | 
			
		||||
    mvwaddstr(newWindow,2, 1, sModelName.c_str());
 | 
			
		||||
    mvwaddstr(newWindow,3, 1, sCapacity.c_str());
 | 
			
		||||
 | 
			
		||||
    mvwaddstr(newWindow,1, iXSize-sSpeed.length()-5, sSpeed.c_str());
 | 
			
		||||
    mvwaddstr(newWindow,2, iXSize-sState.length()-5, sState.c_str());
 | 
			
		||||
    mvwaddstr(newWindow,3, iXSize-sState.length()-5, sTime.c_str());
 | 
			
		||||
    mvwaddstr(newWindow,3, iXSize-sTime.length()-5, sTime.c_str());
 | 
			
		||||
 | 
			
		||||
    return newWindow;
 | 
			
		||||
}
 | 
			
		||||
@ -461,6 +463,16 @@ string TUI::formatTimeDuration(time_t u32Duration)
 | 
			
		||||
    return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
string TUI::formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes){
 | 
			
		||||
    std::ostringstream out;
 | 
			
		||||
    double dDeltaSec = ((double)((u32ShredTimeDelta)/1000000000.0)); //convert nano in sec
 | 
			
		||||
    double speed = ((ulWrittenBytes/1000000.0)/dDeltaSec);
 | 
			
		||||
    char s[25];
 | 
			
		||||
    sprintf(s, "%0.2lf MB/s", speed);
 | 
			
		||||
    out << s;
 | 
			
		||||
    return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
 | 
			
		||||
{
 | 
			
		||||
    struct MenuState menustate;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user