Commit 5695cd2207664aebc5e3431e122419399a467bc9
Committed by
Jordan Cheney
1 parent
b510d010
Decided on the TimeVaryingTransform implementation
Showing
1 changed file
with
23 additions
and
26 deletions
openbr/plugins/time.cpp
| ... | ... | @@ -3,66 +3,63 @@ |
| 3 | 3 | namespace br |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | -class StopWatchTransform : public UntrainableTransform | |
| 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 | |
| 7 | 12 | { |
| 8 | 13 | Q_OBJECT |
| 9 | 14 | |
| 10 | 15 | Q_PROPERTY(br::Transform* child READ get_child WRITE set_child RESET reset_child) |
| 11 | 16 | BR_PROPERTY(br::Transform*, child, NULL) |
| 12 | 17 | |
| 13 | - mutable QMutex watchLock; | |
| 14 | 18 | mutable long timeElapsed; |
| 15 | 19 | mutable long numImgs; |
| 16 | 20 | mutable long numPixels; |
| 17 | 21 | |
| 18 | - ~StopWatchTransform() { | |
| 19 | - printf("Profiled %lu images:\n" | |
| 20 | - "\tavg time per image: %f ms\n" | |
| 21 | - "\tavg time per pixel: %f ms\n", | |
| 22 | - numImgs, (double) timeElapsed / numImgs, (double) timeElapsed / numPixels); | |
| 22 | +public: | |
| 23 | + StopWatchTransform() : TimeVaryingTransform(false, false) | |
| 24 | + { | |
| 25 | + timeElapsed = 0; | |
| 26 | + numImgs = 0; | |
| 27 | + numPixels = 0; | |
| 23 | 28 | } |
| 24 | 29 | |
| 25 | - void project(const Template &src, Template &dst) const | |
| 30 | +private: | |
| 31 | + void projectUpdate(const Template &src, Template &dst) | |
| 26 | 32 | { |
| 27 | 33 | QTime watch; |
| 28 | 34 | |
| 29 | 35 | if (child == NULL) |
| 30 | 36 | qFatal("Can't find child transform! Command line syntax is StopWatch(name of transform to profile)"); |
| 31 | 37 | |
| 32 | - watchLock.lock(); | |
| 33 | 38 | watch.start(); |
| 34 | 39 | |
| 35 | 40 | child->project(src, dst); |
| 36 | 41 | |
| 37 | 42 | int time = watch.elapsed(); |
| 38 | - watchLock.unlock(); | |
| 39 | 43 | |
| 40 | 44 | timeElapsed += time; |
| 41 | 45 | numImgs++; |
| 42 | 46 | numPixels += (src.m().rows * src.m().cols); |
| 43 | 47 | } |
| 44 | 48 | |
| 45 | - void project(const TemplateList &src, TemplateList &dst) const | |
| 49 | + void finalize(TemplateList &output) | |
| 46 | 50 | { |
| 47 | - QTime watch; | |
| 48 | - foreach (const Template &t, src) { | |
| 49 | - watchLock.lock(); | |
| 50 | - watch.start(); | |
| 51 | - | |
| 52 | - Template u; | |
| 53 | - child->project(t, u); | |
| 51 | + (void)output; | |
| 54 | 52 | |
| 55 | - int time = watch.elapsed(); | |
| 56 | - watchLock.unlock(); | |
| 53 | + printf("\n\nProfiled %lu images:\n" | |
| 54 | + "\tavg time per image: %f ms\n" | |
| 55 | + "\tavg time per pixel: %f ms\n",numImgs, (double)timeElapsed / numImgs, (double)timeElapsed / numPixels); | |
| 57 | 56 | |
| 58 | - timeElapsed += time; | |
| 59 | - numImgs++; | |
| 60 | - numPixels += (t.m().rows * t.m().cols); | |
| 61 | - | |
| 62 | - dst << u; | |
| 63 | - } | |
| 57 | + timeElapsed = 0; | |
| 58 | + numImgs = 0; | |
| 59 | + numPixels = 0; | |
| 64 | 60 | } |
| 65 | 61 | }; |
| 62 | + | |
| 66 | 63 | BR_REGISTER(Transform, StopWatchTransform) |
| 67 | 64 | |
| 68 | 65 | } //namespace br | ... | ... |