xref: /aosp_15_r20/external/armnn/include/armnn/IProfiler.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <iostream>
9 #include <memory>
10 #include <vector>
11 
12 namespace armnn
13 {
14 
15 class ProfilerImpl;
16 class BackendId;
17 class Instrument;
18 class Event;
19 struct WorkloadInfo;
20 
21 class IProfiler
22 {
23 public:
24     /// Enables/disables profiling for this profiler.
25     /// @param [in] enableProfiling A flag that indicates whether profiling should be enabled or not.
26     void EnableProfiling(bool enableProfiling);
27 
28     /// Checks whether profiling is enabled.
29     /// Profiling is disabled by default.
30     /// @return true if profiling is enabled, false otherwise.
31     bool IsProfilingEnabled();
32 
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.
36     void AnalyzeEventsAndWriteResults(std::ostream& outStream) const;
37 
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.
40     void Print(std::ostream& outStream) const;
41 
42     /// Print out details of each layer within the network that possesses a descriptor.
43     /// Also outputs tensor info. This will be part of the profiling json output
44     void EnableNetworkDetailsToStdOut(ProfilingDetailsMethod detailsMethod);
45 
46     ~IProfiler();
47     IProfiler();
48 
49 private:
50 
51     using InstrumentPtr = std::unique_ptr<Instrument>;
52 
53     template<typename DescriptorType>
54     void AddLayerDetails(const std::string& name,
55                          const DescriptorType& desc,
56                          const WorkloadInfo& infos,
57                          const arm::pipe::ProfilingGuid guid);
58 
59     Event* BeginEvent(const BackendId& backendId,
60                       const std::string& label,
61                       std::vector<InstrumentPtr>&& instruments,
62                       const Optional<arm::pipe::ProfilingGuid>& guid);
63 
64     std::unique_ptr<ProfilerImpl> pProfilerImpl;
65 
66     friend class ScopedProfilingEvent;
67 
68     template<typename DescriptorType>
69     friend inline void ProfilingUpdateDescriptions(const std::string& name,
70                                                    const DescriptorType& desc,
71                                                    const WorkloadInfo& infos,
72                                                    const arm::pipe::ProfilingGuid guid);
73 
74     // Friend functions for unit testing, see ProfilerTests.cpp.
75     friend size_t GetProfilerEventSequenceSize(armnn::IProfiler* profiler);
76 };
77 
78 } // namespace armnn
79