ArmNN
 24.08
IProfiler.hpp
Go to the documentation of this file.
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
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,
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
armnn::Optional< arm::pipe::ProfilingGuid >
armnn::IProfiler::ProfilingUpdateDescriptions
friend void ProfilingUpdateDescriptions(const std::string &name, const DescriptorType &desc, const WorkloadInfo &infos, const arm::pipe::ProfilingGuid guid)
Definition: Profiling.hpp:180
armnn::IProfiler::GetProfilerEventSequenceSize
friend size_t GetProfilerEventSequenceSize(armnn::IProfiler *profiler)
armnn::IProfiler::IProfiler
IProfiler()
Definition: Profiling.cpp:653
armnn::IProfiler::IsProfilingEnabled
bool IsProfilingEnabled()
Checks whether profiling is enabled.
Definition: Profiling.cpp:629
armnn::IProfiler::~IProfiler
~IProfiler()
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::IProfiler::EnableProfiling
void EnableProfiling(bool enableProfiling)
Enables/disables profiling for this profiler.
Definition: Profiling.cpp:619
armnn::Event
Event class records measurements reported by BeginEvent()/EndEvent() and returns measurements when Ev...
Definition: ProfilingEvent.hpp:27
armnn::ProfilingDetailsMethod
ProfilingDetailsMethod
Define the behaviour of the internal profiler when outputting network details.
Definition: Types.hpp:71
armnn::ScopedProfilingEvent
Definition: Profiling.hpp:130
armnn::IProfiler::AnalyzeEventsAndWriteResults
void AnalyzeEventsAndWriteResults(std::ostream &outStream) const
Analyzes the tracked events and writes the results to the given output stream.
Definition: Profiling.cpp:634
armnn::JsonObjectType::Event
@ Event
armnn::BackendId
Definition: BackendId.hpp:75
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::IProfiler::Print
void Print(std::ostream &outStream) const
Print stats for events in JSON Format to the given output stream.
Definition: Profiling.cpp:639
armnn::IProfiler
Definition: IProfiler.hpp:21
armnn::IProfiler::EnableNetworkDetailsToStdOut
void EnableNetworkDetailsToStdOut(ProfilingDetailsMethod detailsMethod)
Print out details of each layer within the network that possesses a descriptor.
Definition: Profiling.cpp:624