From ea7af5f2fdf2bfb5e11305ee1e8dead5a4cb28de Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 5 Apr 2017 13:44:45 +0200 Subject: [PATCH] Show LZMA block size --- contrib/liblzma/api/lzma/container.h | 3 ++- contrib/liblzma/common/stream_encoder_mt.c | 8 ++++---- contrib/liblzma/compress_easy_mt.cpp | 7 ++++--- contrib/liblzma/precomp_xz.h | 2 +- precomp.cpp | 9 ++++++--- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/contrib/liblzma/api/lzma/container.h b/contrib/liblzma/api/lzma/container.h index 86991ad..ef5d1d7 100644 --- a/contrib/liblzma/api/lzma/container.h +++ b/contrib/liblzma/api/lzma/container.h @@ -331,8 +331,9 @@ extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm, * given options. If an error occurs, for example due to * unsupported preset or filter chain, UINT64_MAX is returned. */ + // schnaader: modified to report block size, too extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage( - const lzma_mt *options) lzma_nothrow lzma_attr_pure; + const lzma_mt *options, uint64_t *block_size) lzma_nothrow lzma_attr_pure; /** diff --git a/contrib/liblzma/common/stream_encoder_mt.c b/contrib/liblzma/common/stream_encoder_mt.c index 9780ed0..79a5652 100644 --- a/contrib/liblzma/common/stream_encoder_mt.c +++ b/contrib/liblzma/common/stream_encoder_mt.c @@ -1083,19 +1083,19 @@ lzma_stream_encoder_mt(lzma_stream *strm, const lzma_mt *options) // monster names. :-( 31 chars is the max that C99 requires so in that // sense it's not too long. ;-) extern LZMA_API(uint64_t) -lzma_stream_encoder_mt_memusage(const lzma_mt *options) +lzma_stream_encoder_mt_memusage(const lzma_mt *options, uint64_t *block_size) { lzma_options_easy easy; const lzma_filter *filters; - uint64_t block_size; + *block_size = 0; uint64_t outbuf_size_max; - if (get_options(options, &easy, &filters, &block_size, + if (get_options(options, &easy, &filters, block_size, &outbuf_size_max) != LZMA_OK) return UINT64_MAX; // Memory usage of the input buffers - const uint64_t inbuf_memusage = options->threads * block_size; + const uint64_t inbuf_memusage = options->threads * (*block_size); // Memory usage of the filter encoders uint64_t filters_memusage = lzma_raw_encoder_memusage(filters); diff --git a/contrib/liblzma/compress_easy_mt.cpp b/contrib/liblzma/compress_easy_mt.cpp index dc0b3d1..c487002 100644 --- a/contrib/liblzma/compress_easy_mt.cpp +++ b/contrib/liblzma/compress_easy_mt.cpp @@ -45,7 +45,7 @@ bool init_decoder(lzma_stream *strm) return check(ret); } -bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage) +bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage, uint64_t &block_size) { // The threaded encoder takes the options as pointer to // a lzma_mt structure. @@ -77,7 +77,7 @@ bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64 int preset_to_use = 0; for (int preset = 1; preset <= 9; preset++) { mt.preset = preset; - preset_memory_usage = lzma_stream_encoder_mt_memusage(&mt); + preset_memory_usage = lzma_stream_encoder_mt_memusage(&mt, &block_size); if (preset_memory_usage > max_memory) break; memory_usage = preset_memory_usage; preset_to_use = preset; @@ -90,7 +90,8 @@ bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64 // Initialize the threaded encoder. lzma_ret ret = lzma_stream_encoder_mt(strm, &mt); - memory_usage = lzma_stream_encoder_mt_memusage(&mt); + // Determine memory usage and block size + memory_usage = lzma_stream_encoder_mt_memusage(&mt, &block_size); return check(ret); } \ No newline at end of file diff --git a/contrib/liblzma/precomp_xz.h b/contrib/liblzma/precomp_xz.h index e7a3e62..09e080f 100644 --- a/contrib/liblzma/precomp_xz.h +++ b/contrib/liblzma/precomp_xz.h @@ -3,7 +3,7 @@ #include "api/lzma.h" -bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage); +bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage, uint64_t &block_size); bool init_decoder(lzma_stream *strm); diff --git a/precomp.cpp b/precomp.cpp index bc8cac7..762d757 100644 --- a/precomp.cpp +++ b/precomp.cpp @@ -9173,6 +9173,7 @@ void init_compress_otf() { } case OTF_XZ_MT: { uint64_t memory_usage = 0; + uint64_t block_size = 0; // As default, use 2 GB memory for LZMA, only 1 GB in the 32-bit windows variant uint64_t max_memory = 2 * 1024 * 1024 * 1024LL; #ifndef UNIX @@ -9182,13 +9183,15 @@ void init_compress_otf() { #endif int threads = std::thread::hardware_concurrency(); if (threads == 0) threads = 2; - if (!init_encoder_mt(&otf_xz_stream_c, threads, max_memory, memory_usage)) { + if (!init_encoder_mt(&otf_xz_stream_c, threads, max_memory, memory_usage, block_size)) { printf("ERROR: xz Multi-Threaded init failed\n"); exit(1); } - printf("Using LZMA for compression, %i threads, memory usage: ", threads); + printf("Compressing with LZMA, %i threads, memory usage: ", threads); print64(memory_usage / (1024 * 1024)); - printf(" MiB\n\n"); + printf(" MiB, block size: "); + print64(block_size / (1024 * 1024)); + printf(" MiB\n\n"); break; } }