added write rate indication

This commit is contained in:
AnonymousShellScripter 2021-03-31 04:41:27 +02:00
parent e380fcd5a8
commit 81f2c1851e

View file

@ -1,14 +1,24 @@
/* standard stuff */
#include <stdio.h>
#include <stdlib.h>
/* malloc */
#include <malloc.h>
/* memset */
#include <string.h>
/* error handling */
#include <errno.h>
/* rate */
#include <time.h>
/* explicitly compile with -D_OFFSET_FILE_BITS=64 if it fails at 2G */
#define _FILE_OFFSET_BITS 64
#define TUI
#define BARLEN 200
#define BARLEN 80
#define NAME "filefiller"
#define VERSION "0.1"
@ -59,7 +69,15 @@ int main(int argc, char **argv) {
puts("FILENAME PERCENT BLOCKS_DONE BLOCKS_LEFT BLOCKS_TOT FILESIZE");
#endif
time_t starttime = time(0);
time_t endtime = time(0);
unsigned long long blocksintime = 0;
unsigned long long totalblocks = 0;
for(unsigned long long i = 1; i <= c; i++) {
if((x = fwrite(b, sizeof(char), BLOCKSIZE, fd)) < BLOCKSIZE) {
#ifdef DEBUG
@ -74,7 +92,7 @@ int main(int argc, char **argv) {
}
else {
printf("\r%d %s \n", errno, strerror(errno));
printf("\r%d %s \n", errno, strerror(errno));
}
printf("Wrote %llu bytes instead of %llu.\n", (unsigned long long)x, BLOCKSIZE);
@ -86,25 +104,46 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
blocksintime++;
endtime = time(0);
if(endtime > starttime) {
totalblocks = blocksintime;
blocksintime = 0;
starttime = endtime;
}
if(i % REFRESHINTERVAL == 0 || i == c) {
#ifdef TUI
printf("\r%-8s %-7.2lf %-11llu %-11llu %-11llu", argv[1], ((double)i/(double)c*100), i, c-i, c);
unsigned long long x = i*BLOCKSIZE;
unsigned long long X = i*BLOCKSIZE;
char *sizes = " KMGTPEZY";
while(x >= 1024) {
x = x >> 10;
while(X >= 1024) {
X >>= 10;
sizes++;
}
printf("%llu%c\033[K\n[\033[7m\033[2G", x, *sizes);
printf("%llu%c ", X, *sizes);
X = totalblocks*BLOCKSIZE;
sizes = " KMGTPEZY";
while(X >= 1024) {
X >>= 10;
sizes++;
}
printf("%lldblk/s %lld%cbits/s\033[K\n[\033[7m\033[2G", totalblocks, X*8, *sizes);
for(unsigned int j = 2; j < (unsigned int)((double)i/(double)c*BARLEN); j++) {
printf(" ");
}
printf("\033[0m\033[200G]\033[1A\r");
printf("\033[0m\033[%dG]\033[1A\r", BARLEN);
#endif
}
}