Commit 43cd10509f633a34e4660d74536593b7f01987dd

Authored by JordanCheney
2 parents 36d2607d ebad5d1c

Merge pull request #219 from biometrics/stopwatch

A stopwatch and profiler to get time data for specified openbr transforms
Showing 1 changed file with 67 additions and 0 deletions
openbr/plugins/time.cpp 0 → 100644
  1 +#include <openbr/plugins/openbr_internal.h>
  2 +
  3 +namespace br
  4 +{
  5 +
  6 +/*!
  7 + * \ingroup transforms
  8 + * \brief Gives time elapsed over a specified transform as a function of both images (or frames) and pixels.
  9 + * \author Jordan Cheney \cite JordanCheney
  10 + */
  11 +class StopWatchTransform : public TimeVaryingTransform
  12 +{
  13 + Q_OBJECT
  14 +
  15 + Q_PROPERTY(br::Transform* child READ get_child WRITE set_child RESET reset_child)
  16 + BR_PROPERTY(br::Transform*, child, NULL)
  17 +
  18 + long timeElapsed;
  19 + long numImgs;
  20 + long numPixels;
  21 +
  22 +public:
  23 + StopWatchTransform() : TimeVaryingTransform(false, false)
  24 + {
  25 + timeElapsed = 0;
  26 + numImgs = 0;
  27 + numPixels = 0;
  28 + }
  29 +
  30 +private:
  31 + void projectUpdate(const Template &src, Template &dst)
  32 + {
  33 + QTime watch;
  34 +
  35 + if (child == NULL)
  36 + qFatal("Can't find child transform! Command line syntax is StopWatch(name of transform to profile)");
  37 +
  38 + watch.start();
  39 +
  40 + child->project(src, dst);
  41 +
  42 + int time = watch.elapsed();
  43 +
  44 + timeElapsed += time;
  45 + numImgs++;
  46 + numPixels += (src.m().rows * src.m().cols);
  47 + }
  48 +
  49 + void finalize(TemplateList &output)
  50 + {
  51 + (void)output;
  52 +
  53 + qDebug() << "\n\nProfiled " << numImgs << " images:\n" <<
  54 + "\tavg time per image: " << (double)timeElapsed / numImgs << " ms\n" <<
  55 + "\tavg time per pixel: " << (double)timeElapsed / numPixels << " ms\n";
  56 +
  57 + timeElapsed = 0;
  58 + numImgs = 0;
  59 + numPixels = 0;
  60 + }
  61 +};
  62 +
  63 +BR_REGISTER(Transform, StopWatchTransform)
  64 +
  65 +} //namespace br
  66 +
  67 +#include "time.moc"
... ...