Best throughput tracker with chunksize

This commit is contained in:
2026-04-28 21:54:49 +02:00
parent 157e769268
commit 50e88c8e84
4 changed files with 395 additions and 52 deletions
+48 -4
View File
@@ -16,9 +16,28 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <chrono>
#define CHUNK_SIZE 1024 * 1024 * 32 // amount of bytes that are overwritten at once --> 32MB
#define TFNG_DATA_SIZE CHUNK_SIZE // amount of bytes used by tfng
// Adaptive chunk size optimization - uncomment to enable
#define ADAPTIVE_CHUNK_SIZE
// Chunk size configuration
#define CHUNK_SIZE_START 1024 * 1024 * 32 // Starting chunk size: 32MB
#define CHUNK_SIZE_MIN 1024 * 1024 * 4 // Minimum chunk size: 4MB
#define CHUNK_SIZE_MAX 1024 * 1024 * 128 // Maximum chunk size: 128MB
#define CHUNK_SIZE_STEP_UP 1024 * 1024 * 2 // Increase step: 2MB
#define CHUNK_SIZE_STEP_DOWN 1024 * 1024 * 4 // Decrease step: 4MB
#define CHUNK_MEASURE_INTERVAL 64 // Measure performance every 64 chunks
#ifdef ADAPTIVE_CHUNK_SIZE
// Use max buffer size when adaptive mode is enabled
#define CHUNK_SIZE CHUNK_SIZE_MAX
#define TFNG_DATA_SIZE CHUNK_SIZE_MAX
#else
// Use fixed chunk size when adaptive mode is disabled
#define CHUNK_SIZE CHUNK_SIZE_START
#define TFNG_DATA_SIZE CHUNK_SIZE
#endif
// #define DEMO_DRIVE_SIZE 1024*1024*256L // 256MB
// #define DEMO_DRIVE_SIZE 1024*1024*1024L // 1GB
@@ -33,22 +52,47 @@ protected:
public:
Shred();
~Shred();
int shredDrive(Drive *drive, int *ipSignalFd);
int shredDrive(Drive* drive, int* ipSignalFd);
private:
fileDescriptor randomSrcFileDiscr;
fileDescriptor driveFileDiscr;
#ifdef ADAPTIVE_CHUNK_SIZE
unsigned char* caTfngData; // Dynamic buffer allocation for adaptive mode
unsigned char* caReadBuffer; // Dynamic buffer allocation for adaptive mode
#else
unsigned char caTfngData[TFNG_DATA_SIZE];
unsigned char caReadBuffer[CHUNK_SIZE];
#endif
unsigned long ulDriveByteSize;
unsigned long ulDriveByteOverallCount = 0; // all bytes shredded in all iterations + checking -> used for progress calculation
double d32Percent = 0.0;
double d32TmpPercent = 0.0;
#ifdef ADAPTIVE_CHUNK_SIZE
// Adaptive chunk size optimization members
size_t currentChunkSize;
size_t bestChunkSize;
unsigned int chunkCounter;
std::chrono::high_resolution_clock::time_point measurementStartTime;
double bestThroughputMBps;
double lastThroughputMBps;
unsigned long bytesWrittenInMeasurement;
bool throughputIncreasing;
// Adaptive methods
void startMeasurement();
void evaluateThroughput(Drive* drive);
void adjustChunkSize(Drive* drive);
size_t getCurrentChunkSize() const;
#endif
inline double calcProgress();
int iRewindDrive(fileDescriptor file);
long getDriveSizeInBytes(fileDescriptor file);
unsigned int uiCalcChecksum(fileDescriptor file, Drive *drive, int *ipSignalFd);
unsigned int uiCalcChecksum(fileDescriptor file, Drive* drive, int* ipSignalFd);
void cleanup();
};
+20 -20
View File
@@ -49,7 +49,7 @@ public:
static void initTUI();
void updateTUI(std::list<Drive> *plistDrives, uint8_t u8SelectedEntry);
void updateTUI(std::list<Drive>* plistDrives, uint8_t u8SelectedEntry);
static enum UserInput readUserInput();
@@ -60,28 +60,28 @@ private:
static std::string sRamUsage;
static std::string sLocalTime;
WINDOW *overview;
WINDOW *systemview;
WINDOW *detailview;
WINDOW *menuview;
WINDOW *dialog;
WINDOW *smartWarning;
WINDOW* overview;
WINDOW* systemview;
WINDOW* detailview;
WINDOW* menuview;
WINDOW* dialog;
WINDOW* smartWarning;
static void centerTitle(WINDOW *pwin, const char *title);
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, int iListIndex, std::string sModelFamily, std::string sSerial, std::string sCapacity, std::string sState, std::string sTime, std::string sSpeed, std::string sTemp, std::string sConnection, 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, std::string selectedTask, std::string optionA, std::string optionB);
static WINDOW *createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, std::string sModelFamily, std::string sModelName, std::string sSerial, std::string sProgress);
static WINDOW *createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount, uint32_t u32Temperature);
static WINDOW *createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, std::string sModelFamily, std::string sModelName, std::string sSerial, uint32_t u32Checksum);
static void centerTitle(WINDOW* pwin, const char* title);
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, int iListIndex, std::string sModelFamily, std::string sSerial, std::string sCapacity, std::string sState, std::string sTime, std::string sSpeed, std::string sTemp, std::string sConnection, 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, std::string selectedTask, std::string optionA, std::string optionB);
static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, std::string sModelFamily, std::string sModelName, std::string sSerial, std::string sProgress);
static WINDOW* createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount, uint32_t u32Temperature);
static WINDOW* createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, std::string sModelFamily, std::string sModelName, std::string sSerial, uint32_t u32Checksum);
void displaySelectedDrive(Drive &drive, int stdscrX, int stdscrY);
void displaySelectedDrive(Drive& drive, int stdscrX, int stdscrY);
std::string formatTimeDuration(time_t u32Duration);
std::string formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes);
static void vTruncateText(std::string *psText, uint16_t u16MaxLenght);
static void vTruncateText(std::string* psText, uint16_t u16MaxLenght);
};
#endif // TUI_H_