ArmNN
 21.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.
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 profiling::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 profiling::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
Event class records measurements reported by BeginEvent()/EndEvent() and returns measurements when Ev...
friend size_t GetProfilerEventSequenceSize(armnn::IProfiler *profiler)
void Print(std::ostream &outStream) const
Print stats for events in JSON Format to the given output stream.
Definition: Profiling.cpp:563
void AnalyzeEventsAndWriteResults(std::ostream &outStream) const
Analyzes the tracked events and writes the results to the given output stream.
Definition: Profiling.cpp:558
friend void ProfilingUpdateDescriptions(const std::string &name, const DescriptorType &desc, const WorkloadInfo &infos, const profiling::ProfilingGuid guid)
Definition: Profiling.hpp:179
Copyright (c) 2021 ARM Limited and Contributors.
void EnableNetworkDetailsToStdOut()
Print out details of each layer within the network that possesses a descriptor.
Definition: Profiling.cpp:548
void EnableProfiling(bool enableProfiling)
Enables/disables profiling for this profiler.
Definition: Profiling.cpp:543
bool IsProfilingEnabled()
Checks whether profiling is enabled.
Definition: Profiling.cpp:553
Contains information about TensorInfos of a layer.