aboutsummaryrefslogtreecommitdiff
path: root/include/armnn/IProfiler.hpp
blob: 1d350855f66394e77faefeeace1789b9585a55a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include <iostream>
#include <memory>
#include <vector>

namespace armnn
{

class ProfilerImpl;
class BackendId;
class Instrument;
class Event;
struct WorkloadInfo;

class IProfiler
{
public:
    /// Enables/disables profiling for this profiler.
    /// @param [in] enableProfiling A flag that indicates whether profiling should be enabled or not.
    void EnableProfiling(bool enableProfiling);

    /// Checks whether profiling is enabled.
    /// Profiling is disabled by default.
    /// @return true if profiling is enabled, false otherwise.
    bool IsProfilingEnabled();

    /// Analyzes the tracked events and writes the results to the given output stream.
    /// Please refer to the configuration variables in Profiling.cpp to customize the information written.
    /// @param [out] outStream The stream where to write the profiling results to.
    void AnalyzeEventsAndWriteResults(std::ostream& outStream) const;

    /// Print stats for events in JSON Format to the given output stream.
    /// @param [out] outStream The stream where to write the profiling results to.
    void Print(std::ostream& outStream) const;

    ~IProfiler();
    IProfiler();

private:

    using InstrumentPtr = std::unique_ptr<Instrument>;

    template<typename DescriptorType>
    void AddLayerDetails(const std::string& name,
                         const DescriptorType& desc,
                         const WorkloadInfo& infos);

    Event* BeginEvent(const BackendId& backendId,
                      const std::string& label,
                      std::vector<InstrumentPtr>&& instruments);

    std::unique_ptr<ProfilerImpl> pProfilerImpl;

    friend class ScopedProfilingEvent;
    friend class ScopedProfilingUpdateDescriptions;

    // Friend functions for unit testing, see ProfilerTests.cpp.
    friend size_t GetProfilerEventSequenceSize(armnn::IProfiler* profiler);
};

} // namespace armnn