diff options
author | Eanna O Cathain <eanna.ocathain@arm.com> | 2022-03-03 15:58:10 +0000 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2022-04-13 14:27:44 +0000 |
commit | 2f0ddb67d8f9267ab600a8a26308cab32f9e16ac (patch) | |
tree | 0eab15a96ebf1e21e60347804a08144380e53800 /samples/common/include/Utils | |
parent | bab8fa9a11cf3bfef4b72fb757b81575b6fd75f0 (diff) | |
download | armnn-2f0ddb67d8f9267ab600a8a26308cab32f9e16ac.tar.gz |
MLECO-2492 Add CPP OD example with TFLITE-ArmnnDelegate
Signed-off-by: Dvir Markovich <dvir.markovich@arm.com>
Change-Id: If412c15ba49abe8370a570260b0a8ed8de305b7c
Diffstat (limited to 'samples/common/include/Utils')
-rw-r--r-- | samples/common/include/Utils/Profiling.hpp | 90 | ||||
-rw-r--r-- | samples/common/include/Utils/Types.hpp | 1 |
2 files changed, 91 insertions, 0 deletions
diff --git a/samples/common/include/Utils/Profiling.hpp b/samples/common/include/Utils/Profiling.hpp new file mode 100644 index 0000000000..cca5632b02 --- /dev/null +++ b/samples/common/include/Utils/Profiling.hpp @@ -0,0 +1,90 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once +#include <chrono> +#include <iostream> +#include <string> + +using namespace std::chrono; + +namespace common +{ +/** +* @brief Used for meausuring performance of specific actions in the code. + * Profiling should be enabled with a parameter passed to the constructor and + * it's disabled by default. + * In order to measure timing, wrap the desired code section with + * ProfilingStart() and ProfilingStopAndPrintUs(title) +*/ +class Profiling { +private: + + struct group_thousands : std::numpunct<char> + { + std::string do_grouping() const override { return "\3"; } + }; + + bool mProfilingEnabled{}; + steady_clock::time_point mStart{}; + steady_clock::time_point mStop{}; +public: + Profiling() : mProfilingEnabled(false) {}; + + /** + * @brief Initializes the profiling object. + * + * * @param[in] isEnabled - Enables the profiling computation and prints. + */ + explicit Profiling(bool isEnabled) : mProfilingEnabled(isEnabled) {}; + +/** +* @brief Starts the profiling measurement. +* +*/ + + void ProfilingStart() + { + if (mProfilingEnabled) + { + mStart = steady_clock::now(); + } + } + +/** +* @brief Stops the profiling measurement, without printing the results. +* +*/ + auto ProfilingStop() + { + if (mProfilingEnabled) + { + mStop = steady_clock::now(); + } + } + +/** +* @brief Get the measurement result in micro-seconds. +* +*/ + auto ProfilingGetUs() + { + return mProfilingEnabled ? duration_cast<microseconds>(mStop - mStart).count() : 0; + } + +/** +* @brief Stop the profiling measurement and print the result in micro-seconds. +* +*/ + void ProfilingStopAndPrintUs(const std::string &title) + { + ProfilingStop(); + if (mProfilingEnabled) { + std::cout.imbue(std::locale(std::cout.getloc(), new group_thousands)); + std::cout << "Profiling: " << title << ": " << ProfilingGetUs() << " uSeconds" << std::endl; + } + } +}; +}// namespace common
\ No newline at end of file diff --git a/samples/common/include/Utils/Types.hpp b/samples/common/include/Utils/Types.hpp index 4d1f708844..184e02aa09 100644 --- a/samples/common/include/Utils/Types.hpp +++ b/samples/common/include/Utils/Types.hpp @@ -44,6 +44,7 @@ struct PipelineOptions std::string m_ModelName; std::string m_ModelFilePath; std::vector<armnn::BackendId> m_backends; + bool m_ProfilingEnabled = false; }; template<typename T> |