Commit b510d0105084a9bb9997f3002943a9c8ba303d1a
Committed by
Jordan Cheney
1 parent
f97be21d
Cleaned up
Showing
1 changed file
with
17 additions
and
52 deletions
openbr/plugins/time.cpp
| ... | ... | @@ -11,6 +11,16 @@ class StopWatchTransform : public UntrainableTransform |
| 11 | 11 | BR_PROPERTY(br::Transform*, child, NULL) |
| 12 | 12 | |
| 13 | 13 | mutable QMutex watchLock; |
| 14 | + mutable long timeElapsed; | |
| 15 | + mutable long numImgs; | |
| 16 | + mutable long numPixels; | |
| 17 | + | |
| 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); | |
| 23 | + } | |
| 14 | 24 | |
| 15 | 25 | void project(const Template &src, Template &dst) const |
| 16 | 26 | { |
| ... | ... | @@ -27,7 +37,9 @@ class StopWatchTransform : public UntrainableTransform |
| 27 | 37 | int time = watch.elapsed(); |
| 28 | 38 | watchLock.unlock(); |
| 29 | 39 | |
| 30 | - dst.file.set("time", QVariant::fromValue(time)); | |
| 40 | + timeElapsed += time; | |
| 41 | + numImgs++; | |
| 42 | + numPixels += (src.m().rows * src.m().cols); | |
| 31 | 43 | } |
| 32 | 44 | |
| 33 | 45 | void project(const TemplateList &src, TemplateList &dst) const |
| ... | ... | @@ -43,63 +55,16 @@ class StopWatchTransform : public UntrainableTransform |
| 43 | 55 | int time = watch.elapsed(); |
| 44 | 56 | watchLock.unlock(); |
| 45 | 57 | |
| 46 | - u.file.set("time", QVariant::fromValue(time)); | |
| 58 | + timeElapsed += time; | |
| 59 | + numImgs++; | |
| 60 | + numPixels += (t.m().rows * t.m().cols); | |
| 61 | + | |
| 47 | 62 | dst << u; |
| 48 | 63 | } |
| 49 | 64 | } |
| 50 | 65 | }; |
| 51 | 66 | BR_REGISTER(Transform, StopWatchTransform) |
| 52 | 67 | |
| 53 | -class StopWatchProfiler : public TimeVaryingTransform | |
| 54 | -{ | |
| 55 | - Q_OBJECT | |
| 56 | - | |
| 57 | - TemplateList buffer; | |
| 58 | - | |
| 59 | -public: | |
| 60 | - StopWatchProfiler() : TimeVaryingTransform(false, false) {} | |
| 61 | - | |
| 62 | -private: | |
| 63 | - void train(const TemplateList &data) | |
| 64 | - { | |
| 65 | - (void) data; | |
| 66 | - } | |
| 67 | - void projectUpdate(const Template &src, Template &dst) | |
| 68 | - { | |
| 69 | - dst = src; | |
| 70 | - buffer.append(src); | |
| 71 | - } | |
| 72 | - void projectUpdate(const TemplateList &src, TemplateList &dst) | |
| 73 | - { | |
| 74 | - dst = src; | |
| 75 | - buffer.append(src); | |
| 76 | - } | |
| 77 | - | |
| 78 | - void finalize(TemplateList &output) { | |
| 79 | - printf("\n\nProfiling data....\n\n"); | |
| 80 | - | |
| 81 | - output = buffer; | |
| 82 | - | |
| 83 | - if (buffer.isEmpty()) | |
| 84 | - qFatal("Empty buffer! Something must have gone wrong."); | |
| 85 | - | |
| 86 | - if (!buffer.first().file.contains("time")) | |
| 87 | - qFatal("No time attribute in the metadata! Did you forget your StopWatch?"); | |
| 88 | - | |
| 89 | - unsigned long imgs = buffer.length(); | |
| 90 | - unsigned long totalTime = 0; | |
| 91 | - | |
| 92 | - foreach(const Template &t, buffer) { | |
| 93 | - totalTime += t.file.value("time").toUInt(); | |
| 94 | - } | |
| 95 | - | |
| 96 | - printf("Profiled %lu images:\n" | |
| 97 | - "\tavg time per image: %f ms\n", | |
| 98 | - imgs, (double)totalTime / imgs); | |
| 99 | - } | |
| 100 | -}; | |
| 101 | -BR_REGISTER(Transform, StopWatchProfiler) | |
| 102 | - | |
| 103 | 68 | } //namespace br |
| 104 | 69 | |
| 105 | 70 | #include "time.moc" | ... | ... |