blob: 209777671b2b92be7ea3316b99f84394d586628c [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
6#pragma once
7
8#include <iostream>
Francis Murtagh33199c22021-02-15 10:11:28 +00009#include <memory>
10#include <vector>
telsoa01c577f2c2018-08-31 09:22:23 +010011
12namespace armnn
13{
14
Francis Murtagh33199c22021-02-15 10:11:28 +000015class ProfilerImpl;
16class BackendId;
17class Instrument;
18class Event;
Keith Davis554fa092021-07-20 11:25:22 +010019struct WorkloadInfo;
20
telsoa01c577f2c2018-08-31 09:22:23 +010021class IProfiler
22{
23public:
24 /// Enables/disables profiling for this profiler.
25 /// @param [in] enableProfiling A flag that indicates whether profiling should be enabled or not.
Francis Murtagh33199c22021-02-15 10:11:28 +000026 void EnableProfiling(bool enableProfiling);
telsoa01c577f2c2018-08-31 09:22:23 +010027
28 /// Checks whether profiling is enabled.
29 /// Profiling is disabled by default.
30 /// @return true if profiling is enabled, false otherwise.
Francis Murtagh33199c22021-02-15 10:11:28 +000031 bool IsProfilingEnabled();
telsoa01c577f2c2018-08-31 09:22:23 +010032
33 /// Analyzes the tracked events and writes the results to the given output stream.
34 /// Please refer to the configuration variables in Profiling.cpp to customize the information written.
35 /// @param [out] outStream The stream where to write the profiling results to.
Francis Murtagh33199c22021-02-15 10:11:28 +000036 void AnalyzeEventsAndWriteResults(std::ostream& outStream) const;
telsoa01c577f2c2018-08-31 09:22:23 +010037
38 /// Print stats for events in JSON Format to the given output stream.
39 /// @param [out] outStream The stream where to write the profiling results to.
Francis Murtagh33199c22021-02-15 10:11:28 +000040 void Print(std::ostream& outStream) const;
telsoa01c577f2c2018-08-31 09:22:23 +010041
Keith Davisf4874862021-08-09 16:49:18 +010042 /// Print out details of each layer within the network that possesses a descriptor.
Keith Davis4914d0c2021-08-18 17:14:05 +010043 /// Also outputs tensor info. This will be part of the profiling json output
44 void EnableNetworkDetailsToStdOut(ProfilingDetailsMethod detailsMethod);
Keith Davisf4874862021-08-09 16:49:18 +010045
Francis Murtagh33199c22021-02-15 10:11:28 +000046 ~IProfiler();
47 IProfiler();
48
49private:
Keith Davis554fa092021-07-20 11:25:22 +010050
Francis Murtagh33199c22021-02-15 10:11:28 +000051 using InstrumentPtr = std::unique_ptr<Instrument>;
Keith Davis554fa092021-07-20 11:25:22 +010052
53 template<typename DescriptorType>
54 void AddLayerDetails(const std::string& name,
55 const DescriptorType& desc,
Keith Davis5a64f222021-08-04 10:35:20 +010056 const WorkloadInfo& infos,
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000057 const arm::pipe::ProfilingGuid guid);
Keith Davis554fa092021-07-20 11:25:22 +010058
Francis Murtagh33199c22021-02-15 10:11:28 +000059 Event* BeginEvent(const BackendId& backendId,
60 const std::string& label,
Keith Davis5a64f222021-08-04 10:35:20 +010061 std::vector<InstrumentPtr>&& instruments,
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000062 const Optional<arm::pipe::ProfilingGuid>& guid);
Keith Davis554fa092021-07-20 11:25:22 +010063
Francis Murtagh33199c22021-02-15 10:11:28 +000064 std::unique_ptr<ProfilerImpl> pProfilerImpl;
Keith Davis554fa092021-07-20 11:25:22 +010065
Francis Murtagh33199c22021-02-15 10:11:28 +000066 friend class ScopedProfilingEvent;
Keith Davis5a64f222021-08-04 10:35:20 +010067
68 template<typename DescriptorType>
69 friend inline void ProfilingUpdateDescriptions(const std::string& name,
70 const DescriptorType& desc,
71 const WorkloadInfo& infos,
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000072 const arm::pipe::ProfilingGuid guid);
Francis Murtagh33199c22021-02-15 10:11:28 +000073
74 // Friend functions for unit testing, see ProfilerTests.cpp.
75 friend size_t GetProfilerEventSequenceSize(armnn::IProfiler* profiler);
telsoa01c577f2c2018-08-31 09:22:23 +010076};
77
78} // namespace armnn