From e9957e1115cfdf330ec1ad5ab62a432ead999133 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 13 Nov 2010 08:33:30 +1100 Subject: [PATCH] Fix zpaq compression now updating the console too much because it's now so much faster it uses up a lot of CPU time just ouputting to the screen. Do this by updating only every 10%, and print separate updates for each thread. --- rzip.h | 2 +- stream.c | 7 ++++--- zpipe.cpp | 22 ++++++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/rzip.h b/rzip.h index b2f4fb6..7d54861 100644 --- a/rzip.h +++ b/rzip.h @@ -275,7 +275,7 @@ void flush_buffer(struct stream_info *sinfo, int stream); void read_config(struct rzip_control *s); ssize_t write_1g(int fd, void *buf, i64 len); ssize_t read_1g(int fd, void *buf, i64 len); -void zpipe_compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress); +void zpipe_compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress, long thread); void zpipe_decompress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress); const i64 two_gig; diff --git a/stream.c b/stream.c index 69c597b..0c6d618 100644 --- a/stream.c +++ b/stream.c @@ -140,7 +140,7 @@ static inline int fake_open_memstream_update_buffer(FILE *fp, uchar **buf, size_ length in c_len */ -static void zpaq_compress_buf(struct compress_thread *cthread) +static void zpaq_compress_buf(struct compress_thread *cthread, long thread) { uchar *c_buf = NULL; size_t dlen = 0; @@ -156,7 +156,8 @@ static void zpaq_compress_buf(struct compress_thread *cthread) if (unlikely(!out)) fatal("Failed to open_memstream in zpaq_compress_buf\n"); - zpipe_compress(in, out, control.msgout, cthread->s_len, (int)(SHOW_PROGRESS)); + zpipe_compress(in, out, control.msgout, cthread->s_len, (int)(SHOW_PROGRESS), + thread); if (unlikely(memstream_update_buffer(out, &c_buf, &dlen))) fatal("Failed to memstream_update_buffer in zpaq_compress_buf"); @@ -823,7 +824,7 @@ void *compthread(void *t) else if (ZLIB_COMPRESS) gzip_compress_buf(cti); else if (ZPAQ_COMPRESS) - zpaq_compress_buf(cti); + zpaq_compress_buf(cti, i); else fatal("Dunno wtf compression to use!\n"); } diff --git a/zpipe.cpp b/zpipe.cpp index cb47d1e..c63eabd 100644 --- a/zpipe.cpp +++ b/zpipe.cpp @@ -1694,7 +1694,8 @@ void Encoder::compress(int c) { //////////////////////////// Compress //////////////////////////// // Compress to 1 segment in 1 block -static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress) { +static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, + int progress, long thread) { // Compiled initialization lists generated by "zpaq vtrmid.cfg" static U8 header[71]={ // COMP 34 bytes from mid.cfg @@ -1708,7 +1709,7 @@ static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, i long long int len = 0; static int last_pct = 0, chunk = 0; - int pct = 0; + int i, pct = 0; // Initialize ZPAQL z; // model z.load(34, 37, header); // initialize model @@ -1737,8 +1738,12 @@ static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, i if (progress) { len++; pct = (len * 100 / buf_len); - if (pct != last_pct) { - fprintf(msgout, "\r\t\t\tZPAQ Chunk %i of 2 compress: %i%% \r", (chunk + 1), pct); + if (pct != last_pct && !(pct % 10)) { + fprintf(msgout, "\r\t\t\t\tZPAQ\t"); + for (i = 0; i < thread; i++) + fprintf(msgout, "\t\t"); + fprintf(msgout, "%d: %i/2: %i%%\r", + thread, (chunk + 1), pct); fflush(msgout); last_pct = pct; } @@ -1747,8 +1752,8 @@ static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, i sha1.put(c); } if (progress) { - fprintf(msgout, "\t \r"); - fflush(msgout); + //fprintf(msgout, "\t \r"); + //fflush(msgout); } enc.compress(-1); // end of segment @@ -1765,7 +1770,8 @@ static void compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, i chunk ^= 1; } -extern "C" void zpipe_compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, int progress) +extern "C" void zpipe_compress(FILE *in, FILE *out, FILE *msgout, long long int buf_len, + int progress, long thread) { - compress(in, out, msgout, buf_len, progress); + compress(in, out, msgout, buf_len, progress, thread); }