ArmNN
 20.02
FileOnlyProfilingDecoratorTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "../FileOnlyProfilingConnection.hpp"
7 
8 #include <ProfilingService.hpp>
9 #include <Runtime.hpp>
10 #include <Filesystem.hpp>
12 
13 #include <boost/filesystem.hpp>
14 #include <boost/numeric/conversion/cast.hpp>
15 #include <boost/test/unit_test.hpp>
16 
17 #include <cstdio>
18 #include <fstream>
19 #include <sstream>
20 #include <sys/stat.h>
21 
22 using namespace armnn::profiling;
23 using namespace armnn;
24 
25 using namespace std::chrono_literals;
26 
27 class FileOnlyHelperService : public ProfilingService
28 {
29  public:
30  // Wait for a notification from the send thread
31  bool WaitForPacketsSent(uint32_t timeout = 1000)
32  {
34  }
35 };
36 
37 BOOST_AUTO_TEST_SUITE(FileOnlyProfilingDecoratorTests)
38 
39 BOOST_AUTO_TEST_CASE(DumpOutgoingValidFileEndToEnd, * boost::unit_test::disabled())
40 {
41  // Create a temporary file name.
42  boost::filesystem::path tempPath = boost::filesystem::temp_directory_path();
43  boost::filesystem::path tempFile = boost::filesystem::unique_path();
44  tempPath = tempPath / tempFile;
45  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
46  options.m_EnableProfiling = true;
47  options.m_FileOnly = true;
48  options.m_IncomingCaptureFile = "";
49  options.m_OutgoingCaptureFile = tempPath.string();
50  options.m_CapturePeriod = 100;
51 
52  FileOnlyHelperService helper;
53 
54  // Enable the profiling service
56  profilingService.ResetExternalProfilingOptions(options, true);
57  // Bring the profiling service to the "WaitingForAck" state
58  profilingService.Update();
59  profilingService.Update();
60 
61 
63 
64  profilingService.Update();
65  // First packet sent will be the SendStreamMetaDataPacket, it's possible though unlikely that it will be sent twice
66  // The second or possibly third packet will be the CounterDirectoryPacket which means the
67  // ConnectionAcknowledgedCommandHandler has set the state to active
68  uint32_t packetCount = 0;
69  while(profilingService.GetCurrentState() != ProfilingState::Active && packetCount < 3)
70  {
71  if(!helper.WaitForPacketsSent())
72  {
73  BOOST_FAIL("Timeout waiting for packets");
74  }
75  packetCount++;
76  }
77 
78  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
79  // Minimum test here is to check that the file was created.
80  BOOST_CHECK(boost::filesystem::exists(tempPath.c_str()) == true);
81 
82  // Increment a counter.
83  BOOST_CHECK(profilingService.IsCounterRegistered(0) == true);
84  profilingService.IncrementCounterValue(0);
85  BOOST_CHECK(profilingService.GetCounterValue(0) > 0);
86 
87  // At this point the profiling service is active and we've activated all the counters. Waiting a collection
88  // period should be enough to have some data in the file.
89 
90  // Wait for 1 collection period plus a bit of overhead..
91  helper.WaitForPacketsSent();
92 
93  // In order to flush the files we need to gracefully close the profiling service.
94  options.m_EnableProfiling = false;
95  profilingService.ResetExternalProfilingOptions(options, true);
96 
97  // The output file size should be greater than 0.
98  BOOST_CHECK(armnnUtils::Filesystem::GetFileSize(tempPath.string().c_str()) > 0);
99 
100  // Delete the tmp file.
101  BOOST_CHECK(armnnUtils::Filesystem::Remove(tempPath.string().c_str()));
102 }
103 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
bool IsCounterRegistered(uint16_t counterUid) const override
static ProfilingService & Instance()
ProfilingState GetCurrentState() const
uint32_t GetCounterValue(uint16_t counterUid) const override
Copyright (c) 2020 ARM Limited.
ProfilingService & profilingService
uint32_t IncrementCounterValue(uint16_t counterUid) override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
bool WaitForPacketSent(ProfilingService &instance, uint32_t timeout=1000)
bool Remove(const char *path)
Definition: Filesystem.cpp:47
boost::filesystem::path tempFile
long long GetFileSize(const char *path)
Definition: Filesystem.cpp:21
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
BOOST_AUTO_TEST_SUITE_END()
helper WaitForPacketsSent()
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper