From 433f1dae19b63f263af8a3d3cc9b3e328171d9ca Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 31 Aug 2022 13:51:58 -0400 Subject: Add --report-mem-usage option for debugging/testing --- libqpdf/QPDFJob.cc | 11 ++++++++++- libqpdf/QPDFJob_config.cc | 7 +++++++ libqpdf/qpdf/auto_job_help.hh | 3 +++ libqpdf/qpdf/auto_job_init.hh | 1 + libqpdf/qpdf/auto_job_json_init.hh | 3 +++ libqpdf/qpdf/auto_job_schema.hh | 1 + 6 files changed, 25 insertions(+), 1 deletion(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 15a81854..7bd563aa 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -417,7 +417,8 @@ QPDFJob::Members::Members() : check_is_encrypted(false), check_requires_password(false), json_input(false), - json_output(false) + json_output(false), + report_mem_usage(false) { } @@ -625,6 +626,14 @@ QPDFJob::run() << ": operation succeeded with warnings\n"; } } + if (m->report_mem_usage) { + // Call get_max_memory_usage before generating output. When + // debugging, it's easier if print statements from + // get_max_memory_usage are not interleaved with the output. + auto mem_usage = QUtil::get_max_memory_usage(); + *this->m->log->getWarn() + << "qpdf-max-memory-usage " << mem_usage << "\n"; + } } bool diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index 8a9c1470..3e148fca 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -502,6 +502,13 @@ QPDFJob::Config::removePageLabels() return this; } +QPDFJob::Config* +QPDFJob::Config::reportMemUsage() +{ + o.m->report_mem_usage = true; + return this; +} + QPDFJob::Config* QPDFJob::Config::requiresPassword() { diff --git a/libqpdf/qpdf/auto_job_help.hh b/libqpdf/qpdf/auto_job_help.hh index 7c3bb266..eb272a04 100644 --- a/libqpdf/qpdf/auto_job_help.hh +++ b/libqpdf/qpdf/auto_job_help.hh @@ -883,6 +883,9 @@ for debugging qpdf. ap.addOptionHelp("--test-json-schema", "testing", "test generated json against schema", R"(This is used by qpdf's test suite to check consistency between the output of qpdf --json and the output of qpdf --json-help. )"); +ap.addOptionHelp("--report-mem-usage", "testing", "best effort report of memory usage", R"(This is used by qpdf's performance test suite to report the +maximum amount of memory used in supported environments. +)"); } static void add_help(QPDFArgParser& ap) { diff --git a/libqpdf/qpdf/auto_job_init.hh b/libqpdf/qpdf/auto_job_init.hh index b90592e0..ad110d16 100644 --- a/libqpdf/qpdf/auto_job_init.hh +++ b/libqpdf/qpdf/auto_job_init.hh @@ -69,6 +69,7 @@ this->ap.addBare("raw-stream-data", [this](){c_main->rawStreamData();}); this->ap.addBare("recompress-flate", [this](){c_main->recompressFlate();}); this->ap.addBare("remove-page-labels", [this](){c_main->removePageLabels();}); this->ap.addBare("replace-input", b(&ArgParser::argReplaceInput)); +this->ap.addBare("report-mem-usage", [this](){c_main->reportMemUsage();}); this->ap.addBare("requires-password", [this](){c_main->requiresPassword();}); this->ap.addBare("show-encryption", [this](){c_main->showEncryption();}); this->ap.addBare("show-encryption-key", [this](){c_main->showEncryptionKey();}); diff --git a/libqpdf/qpdf/auto_job_json_init.hh b/libqpdf/qpdf/auto_job_json_init.hh index 8f8fb987..1cd69368 100644 --- a/libqpdf/qpdf/auto_job_json_init.hh +++ b/libqpdf/qpdf/auto_job_json_init.hh @@ -409,6 +409,9 @@ popHandler(); // key: pages pushKey("removePageLabels"); addBare([this]() { c_main->removePageLabels(); }); popHandler(); // key: removePageLabels +pushKey("reportMemUsage"); +addBare([this]() { c_main->reportMemUsage(); }); +popHandler(); // key: reportMemUsage pushKey("rotate"); addParameter([this](std::string const& p) { c_main->rotate(p); }); popHandler(); // key: rotate diff --git a/libqpdf/qpdf/auto_job_schema.hh b/libqpdf/qpdf/auto_job_schema.hh index aa69c192..9272c596 100644 --- a/libqpdf/qpdf/auto_job_schema.hh +++ b/libqpdf/qpdf/auto_job_schema.hh @@ -144,6 +144,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({ } ], "removePageLabels": "remove explicit page numbers", + "reportMemUsage": "best effort report of memory usage", "rotate": "rotate pages", "overlay": { "file": "source file for overlay", -- cgit v1.2.3-70-g09d2