refactored GPU performance sample, added filter suport

This commit is contained in:
Alexey Spizhevoy
2011-02-17 15:25:50 +00:00
parent 12c2ead83f
commit e5b563b3fd
2 changed files with 92 additions and 80 deletions

View File

@@ -13,9 +13,7 @@ class Runnable
{
public:
explicit Runnable(const std::string& name): name_(name) {}
const std::string& name() const { return name_; }
virtual void run() = 0;
private:
@@ -32,70 +30,67 @@ public:
return me;
}
void setWorkingDir(const std::string& val);
const std::string& workingDir() const { return working_dir_; }
void setTestFilter(const std::string& val);
const std::string& testFilter() const { return test_filter_; }
void addInit(Runnable* init) { inits_.push_back(init); }
void addTest(Runnable* test) { tests_.push_back(test); }
void run();
// Ends current subtest and starts new one
std::stringstream& subtest()
// It's public because OpenCV callback uses it
void printError(const std::string& msg);
std::stringstream& startNewSubtest()
{
flushSubtestData();
return description_;
finishCurrentSubtest();
return cur_subtest_description_;
}
void cpuOn() { cpu_started_ = cv::getTickCount(); }
void cpuOff()
{
int64 delta = cv::getTickCount() - cpu_started_;
cpu_elapsed_ += delta;
can_flush_ = true;
cur_subtest_is_empty_ = false;
}
void gpuOn() { gpu_started_ = cv::getTickCount(); }
void gpuOff()
{
int64 delta = cv::getTickCount() - gpu_started_;
gpu_elapsed_ += delta;
can_flush_ = true;
cur_subtest_is_empty_ = false;
}
void setWorkingDir(const std::string& val);
const std::string& workingDir() const { return working_dir_; }
void printError(const std::string& msg);
private:
TestSystem(): can_flush_(false), cpu_elapsed_(0), gpu_elapsed_(0),
speedup_total_(0.0), num_subtests_called_(0) {}
TestSystem(): cur_subtest_is_empty_(true), cpu_elapsed_(0),
gpu_elapsed_(0), speedup_total_(0.0),
num_subtests_called_(0) {}
void flushSubtestData();
void resetSubtestData()
void finishCurrentSubtest();
void resetCurrentSubtest()
{
cpu_elapsed_ = 0;
gpu_elapsed_ = 0;
description_.str("");
can_flush_ = false;
cur_subtest_description_.str("");
cur_subtest_is_empty_ = true;
}
void printHeading();
void printSummary();
void printItem(double cpu_time, double gpu_time, double speedup);
void printMetrics(double cpu_time, double gpu_time, double speedup);
std::string working_dir_;
std::string test_filter_;
std::vector<Runnable*> inits_;
std::vector<Runnable*> tests_;
// Current test (subtest) description
std::stringstream description_;
bool can_flush_;
std::stringstream cur_subtest_description_;
bool cur_subtest_is_empty_;
int64 cpu_started_, cpu_elapsed_;
int64 gpu_started_, gpu_elapsed_;
@@ -124,15 +119,17 @@ private:
} name##_test_instance; \
void name##_test::run()
#define SUBTEST TestSystem::instance().subtest()
#define SUBTEST TestSystem::instance().startNewSubtest()
#define CPU_ON TestSystem::instance().cpuOn()
#define GPU_ON TestSystem::instance().gpuOn()
#define CPU_OFF TestSystem::instance().cpuOff()
#define GPU_OFF TestSystem::instance().gpuOff()
// Generates matrix
void gen(cv::Mat& mat, int rows, int cols, int type, cv::Scalar low,
cv::Scalar high);
// Returns abs path taking into account test system working dir
std::string abspath(const std::string& relpath);
#endif // OPENCV_GPU_SAMPLE_PERFORMANCE_H_