aboutsummaryrefslogtreecommitdiff
path: root/tests/framework/instruments/SchedulerTimer.cpp
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-11-07 17:33:54 +0000
committerAnthony Barbier <Anthony.barbier@arm.com>2018-11-08 14:19:59 +0000
commit72f4ae5a53fe24226ff16ed9c339171887d74874 (patch)
treed43c9b20a3420e0785bec0c4439763411439b891 /tests/framework/instruments/SchedulerTimer.cpp
parentd2048ce58a88853cee6cdd67fe0d6f09c3e212b0 (diff)
downloadComputeLibrary-72f4ae5a53fe24226ff16ed9c339171887d74874.tar.gz
COMPMID-1777: Add option to make instruments output timestamps instead of duration
Change-Id: Iafc1d6cd8003de64a3439ad807f4002036c73a73
Diffstat (limited to 'tests/framework/instruments/SchedulerTimer.cpp')
-rw-r--r--tests/framework/instruments/SchedulerTimer.cpp77
1 files changed, 58 insertions, 19 deletions
diff --git a/tests/framework/instruments/SchedulerTimer.cpp b/tests/framework/instruments/SchedulerTimer.cpp
index 76f1a58e9c..bd84a777a9 100644
--- a/tests/framework/instruments/SchedulerTimer.cpp
+++ b/tests/framework/instruments/SchedulerTimer.cpp
@@ -34,16 +34,25 @@ namespace test
{
namespace framework
{
-std::string SchedulerTimer::id() const
+template <bool output_timestamps>
+std::string SchedulerClock<output_timestamps>::id() const
{
- return "SchedulerTimer";
+ if(output_timestamps)
+ {
+ return "SchedulerTimestamps";
+ }
+ else
+ {
+ return "SchedulerTimer";
+ }
}
+template <bool output_timestamps>
class Interceptor final : public IScheduler
{
public:
/** Default constructor. */
- Interceptor(std::list<SchedulerTimer::kernel_info> &kernels, IScheduler &real_scheduler, ScaleFactor scale_factor)
+ Interceptor(std::list<struct SchedulerClock<output_timestamps>::kernel_info> &kernels, IScheduler &real_scheduler, ScaleFactor scale_factor)
: _kernels(kernels), _real_scheduler(real_scheduler), _timer(scale_factor), _prefix()
{
}
@@ -69,7 +78,7 @@ public:
_real_scheduler.schedule(kernel, hints.split_dimension());
_timer.stop();
- SchedulerTimer::kernel_info info;
+ typename SchedulerClock<output_timestamps>::kernel_info info;
info.name = kernel->name();
info.prefix = _prefix;
info.measurements = _timer.measurements();
@@ -82,7 +91,7 @@ public:
_real_scheduler.run_tagged_workloads(workloads, tag);
_timer.stop();
- SchedulerTimer::kernel_info info;
+ typename SchedulerClock<output_timestamps>::kernel_info info;
info.name = tag != nullptr ? tag : "Unknown";
info.prefix = _prefix;
info.measurements = _timer.measurements();
@@ -97,28 +106,30 @@ protected:
}
private:
- std::list<SchedulerTimer::kernel_info> &_kernels;
- IScheduler &_real_scheduler;
- WallClockTimer _timer;
- std::string _prefix;
+ std::list<struct SchedulerClock<output_timestamps>::kernel_info> &_kernels;
+ IScheduler &_real_scheduler;
+ WallClock<output_timestamps> _timer;
+ std::string _prefix;
};
-SchedulerTimer::SchedulerTimer(ScaleFactor scale_factor)
+template <bool output_timestamps>
+SchedulerClock<output_timestamps>::SchedulerClock(ScaleFactor scale_factor)
: _kernels(), _real_scheduler(nullptr), _real_scheduler_type(), _real_graph_function(nullptr), _scale_factor(scale_factor), _interceptor(nullptr)
{
}
-void SchedulerTimer::test_start()
+template <bool output_timestamps>
+void SchedulerClock<output_timestamps>::test_start()
{
// Start intercepting tasks:
ARM_COMPUTE_ERROR_ON(_real_graph_function != nullptr);
_real_graph_function = graph::TaskExecutor::get().execute_function;
auto task_interceptor = [this](graph::ExecutionTask & task)
{
- Interceptor *scheduler = nullptr;
- if(dynamic_cast<Interceptor *>(this->_interceptor.get()) != nullptr)
+ Interceptor<output_timestamps> *scheduler = nullptr;
+ if(dynamic_cast<Interceptor<output_timestamps> *>(this->_interceptor.get()) != nullptr)
{
- scheduler = arm_compute::utils::cast::polymorphic_downcast<Interceptor *>(_interceptor.get());
+ scheduler = arm_compute::utils::cast::polymorphic_downcast<Interceptor<output_timestamps> *>(_interceptor.get());
if(task.node != nullptr && !task.node->name().empty())
{
scheduler->set_prefix(task.node->name() + "/");
@@ -143,18 +154,20 @@ void SchedulerTimer::test_start()
if(_real_scheduler_type != Scheduler::Type::CUSTOM)
{
_real_scheduler = &Scheduler::get();
- _interceptor = std::make_shared<Interceptor>(_kernels, *_real_scheduler, _scale_factor);
+ _interceptor = std::make_shared<Interceptor<output_timestamps>>(_kernels, *_real_scheduler, _scale_factor);
Scheduler::set(std::static_pointer_cast<IScheduler>(_interceptor));
graph::TaskExecutor::get().execute_function = task_interceptor;
}
}
-void SchedulerTimer::start()
+template <bool output_timestamps>
+void SchedulerClock<output_timestamps>::start()
{
_kernels.clear();
}
-void SchedulerTimer::test_stop()
+template <bool output_timestamps>
+void SchedulerClock<output_timestamps>::test_stop()
{
// Restore real scheduler
Scheduler::set(_real_scheduler_type);
@@ -164,17 +177,43 @@ void SchedulerTimer::test_stop()
_real_graph_function = nullptr;
}
-Instrument::MeasurementsMap SchedulerTimer::measurements() const
+template <bool output_timestamps>
+Instrument::MeasurementsMap SchedulerClock<output_timestamps>::measurements() const
{
MeasurementsMap measurements;
unsigned int kernel_number = 0;
for(auto kernel : _kernels)
{
- measurements.emplace(kernel.prefix + kernel.name + " #" + support::cpp11::to_string(kernel_number++), kernel.measurements.begin()->second);
+ std::string name = kernel.prefix + kernel.name + " #" + support::cpp11::to_string(kernel_number++);
+ if(output_timestamps)
+ {
+ ARM_COMPUTE_ERROR_ON(kernel.measurements.size() != 2);
+ for(auto m : kernel.measurements)
+ {
+ if(m.first.find("[start]") != std::string::npos)
+ {
+ measurements.emplace("[start]" + name, m.second);
+ }
+ else if(m.first.find("[end]") != std::string::npos)
+ {
+ measurements.emplace("[end]" + name, m.second);
+ }
+ else
+ {
+ ARM_COMPUTE_ERROR("Measurement not handled");
+ }
+ }
+ }
+ else
+ {
+ measurements.emplace(name, kernel.measurements.begin()->second);
+ }
}
return measurements;
}
+template class SchedulerClock<true>;
+template class SchedulerClock<false>;
} // namespace framework
} // namespace test
} // namespace arm_compute