Skip to content

Commit 41e4702

Browse files
authored
time read, filter and writer operations (GPSBabel#1150)
* time read, filter and writer operations when using -D > 0. * take stray dog to the pound.
1 parent c9dd6e3 commit 41e4702

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

main.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <cstring> // for strcmp
2525

2626
#include <QCoreApplication> // for QCoreApplication
27+
#include <QElapsedTimer> // for QElapsedTimer
2728
#include <QFile> // for QFile
2829
#include <QIODevice> // for QIODevice::ReadOnly
2930
#include <QLocale> // for QLocale
@@ -61,6 +62,8 @@ static constexpr bool DEBUG_LOCALE = false;
6162
// be careful not to advance argn passed the end of the list, i.e. ensure argn < qargs.size()
6263
#define FETCH_OPTARG qargs.at(argn).size() > 2 ? QString(qargs.at(argn)).remove(0,2) : qargs.size()>(argn+1) ? qargs.at(++argn) : QString()
6364

65+
static QElapsedTimer timer;
66+
6467
class QargStackElement
6568
{
6669
public:
@@ -247,6 +250,9 @@ class FallbackOutput
247250
static void
248251
run_reader(Vecs::fmtinfo_t& ivecs, const QString& fname)
249252
{
253+
if (global_opts.debug_level > 0) {
254+
timer.start();
255+
}
250256
start_session(ivecs.fmtname, fname);
251257
if (ivecs.isDynamic()) {
252258
ivecs.fmt = ivecs.factory(fname);
@@ -268,11 +274,18 @@ run_reader(Vecs::fmtinfo_t& ivecs, const QString& fname)
268274
ivecs->read();
269275
ivecs->rd_deinit();
270276
}
277+
if (global_opts.debug_level > 0) {
278+
Warning().noquote() << QStringLiteral("%1: reader %2 took %3 seconds.")
279+
.arg(MYNAME, ivecs.fmtname, QString::number(timer.elapsed()/1000.0, 'f', 3));
280+
}
271281
}
272282

273283
static void
274284
run_writer(Vecs::fmtinfo_t& ovecs, const QString& ofname)
275285
{
286+
if (global_opts.debug_level > 0) {
287+
timer.start();
288+
}
276289
if (ovecs.isDynamic()) {
277290
ovecs.fmt = ovecs.factory(ofname);
278291
Vecs::init_vec(ovecs.fmt);
@@ -293,6 +306,10 @@ run_writer(Vecs::fmtinfo_t& ovecs, const QString& ofname)
293306
ovecs->write();
294307
ovecs->wr_deinit();
295308
}
309+
if (global_opts.debug_level > 0) {
310+
Warning().noquote() << QStringLiteral("%1: writer %2 took %3 seconds.")
311+
.arg(MYNAME, ovecs.fmtname, QString::number(timer.elapsed()/1000.0, 'f', 3));
312+
}
296313
}
297314

298315
static int
@@ -451,6 +468,9 @@ run(const char* prog_name)
451468
filter = FilterVecs::Instance().find_filter_vec(argument);
452469

453470
if (filter) {
471+
if (global_opts.debug_level > 0) {
472+
timer.start();
473+
}
454474
if (filter.isDynamic()) {
455475
filter.flt = filter.factory();
456476
FilterVecs::init_filter_vec(filter.flt);
@@ -471,6 +491,10 @@ run(const char* prog_name)
471491
filter->deinit();
472492
FilterVecs::free_filter_vec(filter.flt);
473493
}
494+
if (global_opts.debug_level > 0) {
495+
Warning().noquote() << QStringLiteral("%1: filter %2 took %3 seconds.")
496+
.arg(MYNAME, filter.fltname, QString::number(timer.elapsed()/1000.0, 'f', 3));
497+
}
474498
} else {
475499
fatal("Unknown filter '%s'\n",qPrintable(argument));
476500
}

0 commit comments

Comments
 (0)