9 #include <boost/test/unit_test.hpp> 10 #include <boost/test/tools/output_test_stream.hpp> 11 #include <boost/algorithm/string.hpp> 26 return static_cast<size_t>(-1);
29 return profiler->m_EventSequence.size();
36 void RegisterUnregisterProfilerSingleThreadImpl(
bool &res)
48 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
52 res &= profiler.get() == profilerManager.
GetProfiler();
67 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
70 BOOST_TEST(!profiler->IsProfilingEnabled());
73 profiler->EnableProfiling(
true);
76 BOOST_TEST(profiler->IsProfilingEnabled());
79 profiler->EnableProfiling(
false);
82 BOOST_TEST(!profiler->IsProfilingEnabled());
88 RegisterUnregisterProfilerSingleThreadImpl(res);
94 bool res[3] = {
false,
false,
false};
95 std::thread thread1([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[0]); });
96 std::thread thread2([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[1]); });
97 std::thread thread3([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[2]); });
103 for (
int i = 0 ; i < 3 ; i++)
127 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
140 BOOST_TEST(eventSequenceSizeBefore == eventSequenceSizeAfter);
144 profiler->EnableProfiling(
true);
156 BOOST_TEST(eventSequenceSizeAfter == eventSequenceSizeBefore + 1);
160 profiler->EnableProfiling(
false);
163 #if defined(ARMNNREF_ENABLED) 180 mockNetwork->AddInputLayer(0,
"test layer");
182 runtime->LoadNetwork(networkIdentifier,
armnn::Optimize(*mockNetwork, backends, runtime->GetDeviceSpec()));
188 runtime->UnloadNetwork(networkIdentifier);
202 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
206 profiler->EnableProfiling(
true);
219 std::this_thread::sleep_for(std::chrono::milliseconds(10));
224 BOOST_TEST(eventSequenceSizeAfter == eventSequenceSizeBefore + 1);
226 boost::test_tools::output_test_stream output;
227 profiler->AnalyzeEventsAndWriteResults(output);
228 BOOST_TEST(!output.is_empty(
false));
231 BOOST_CHECK(boost::contains(output.str(),
"test"));
234 BOOST_CHECK(boost::contains(output.str(),
"Event Sequence - Name"));
235 BOOST_CHECK(boost::contains(output.str(),
"Event Stats - Name"));
236 BOOST_CHECK(boost::contains(output.str(),
"Total"));
237 BOOST_CHECK(boost::contains(output.str(),
"Device"));
239 BOOST_CHECK(boost::contains(output.str(),
"CpuAcc"));
241 BOOST_CHECK(!(boost::contains(output.str(),
"e+")));
243 BOOST_CHECK(!(boost::contains(output.str(),
"+")));
245 BOOST_CHECK(!(boost::contains(output.str(),
" 0 ")));
249 profiler->EnableProfiling(
false);
257 virtual ~TestInstrument() {}
258 void Start()
override {}
259 void Stop()
override {}
261 std::vector<armnn::Measurement> GetMeasurements()
const override 263 std::vector<armnn::Measurement> measurements;
266 armnn::Measurement::Unit::TIME_MS));
269 armnn::Measurement::Unit::TIME_US));
273 const char* GetName()
const override 275 return "TestInstrument";
283 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
286 profiler->EnableProfiling(
true);
307 std::stringbuf buffer;
308 std::ostream json(&buffer);
309 profiler->Print(json);
311 std::string output = buffer.str();
312 boost::ignore_unused(output);
315 profiler->EnableProfiling(
false);
319 std::string blessedOutput(
"{\n\t\"ArmNN\": {\n\t\t\"inference_measurements_#1\": {\n\t\t\t\"type\": \"" 320 "Event\",\n\t\t\t\"Measurement1_#1\": {\n\t\t\t\t\"type\": \"" 321 "Measurement\",\n\t\t\t\t\"raw\": [\n\t\t\t\t\t1.000000\n\t\t\t\t],\n\t\t\t\t\"" 322 "unit\": \"ms\"\n\t\t\t},\n\t\t\t\"Measurement2_#1\": {\n\t\t\t\t\"type\": \"" 323 "Measurement\",\n\t\t\t\t\"raw\": [\n\t\t\t\t\t2.000000\n\t\t\t\t],\n\t\t\t\t\"" 324 "unit\": \"us\"\n\t\t\t},\n\t\t\t\"Level 0_#2\": {\n\t\t\t\t\"type\": \"" 325 "Event\",\n\t\t\t\t\"Measurement1_#2\": {\n\t\t\t\t\t\"type\": \"" 326 "Measurement\",\n\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t1.000000\n\t\t\t\t\t],\n\t\t\t\t\t\"" 327 "unit\": \"ms\"\n\t\t\t\t},\n\t\t\t\t\"Measurement2_#2\": {\n\t\t\t\t\t\"type\": \"" 328 "Measurement\",\n\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t2.000000\n\t\t\t\t\t],\n\t\t\t\t\t\"" 329 "unit\": \"us\"\n\t\t\t\t},\n\t\t\t\t\"Level 1A_#3\": {\n\t\t\t\t\t\"type\": \"" 330 "Event\",\n\t\t\t\t\t\"Measurement1_#3\": {\n\t\t\t\t\t\t\"type\": \"" 331 "Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 332 "1.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 333 "unit\": \"ms\"\n\t\t\t\t\t},\n\t\t\t\t\t\"Measurement2_#3\": {\n\t\t\t\t\t\t\"type\": \"" 334 "Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 335 "2.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 336 "unit\": \"us\"\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t\"Level 1B_#4\": {\n\t\t\t\t\t\"" 337 "type\": \"Event\",\n\t\t\t\t\t\"Measurement1_#4\": {\n\t\t\t\t\t\t\"type\": \"" 338 "Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 339 "1.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 340 "unit\": \"ms\"\n\t\t\t\t\t},\n\t\t\t\t\t\"Measurement2_#4\": {\n\t\t\t\t\t\t\"" 341 "type\": \"Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 342 "2.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 343 "unit\": \"us\"\n\t\t\t\t\t},\n\t\t\t\t\t\"Level 2A_#5\": {\n\t\t\t\t\t\t\"" 344 "type\": \"Event\",\n\t\t\t\t\t\t\"Measurement1_#5\": {\n\t\t\t\t\t\t\t\"type\": \"" 345 "Measurement\",\n\t\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t\t" 346 "1.000000\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\"" 347 "unit\": \"ms\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"Measurement2_#5\": {\n\t\t\t\t\t\t\t\"" 348 "type\": \"Measurement\",\n\t\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t\t" 349 "2.000000\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\"" 350 "unit\": \"us\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n");
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
static INetworkPtr Create()
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
#define ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(backendId,...)
CPU Execution: Reference C++ kernels.
size_t GetProfilerEventSequenceSize(armnn::Profiler *profiler)
static IRuntimePtr Create(const CreationOptions &options)
BOOST_AUTO_TEST_SUITE_END()
CPU Execution: NEON: ArmCompute.
void RegisterProfiler(Profiler *profiler)
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
static ProfilerManager & GetInstance()
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr