profiler.hpp 1.9 KB
Newer Older
1 2
#ifndef OPENPOSE_UTILITIES_PROFILER_HPP
#define OPENPOSE_UTILITIES_PROFILER_HPP
G
gineshidalgo99 已提交
3 4

#include <string>
G
Gines 已提交
5
#include <openpose/core/macros.hpp>
G
gineshidalgo99 已提交
6 7 8 9 10 11 12 13 14 15 16

// Enable PROFILER_ENABLED on Makefile.config in order to use this function. Otherwise nothing will be outputted.

// How to use - example:
// For GPU - It can only be applied in the main.cpp file:
    // Profiler::profileGpuMemory(__LINE__, __FUNCTION__, __FILE__);
// For time:
    // // ... inside continuous loop ...
    // const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
    // // functions to do...
    // Profiler::timerEnd(profilerKey);
17
    // Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, NUMBER_ITERATIONS);
G
gineshidalgo99 已提交
18 19 20

namespace op
{
G
Gines 已提交
21
    class OP_API Profiler
G
gineshidalgo99 已提交
22 23
    {
    public:
24 25 26 27
        static unsigned long long DEFAULT_X;

        // Non-thread safe, it must be performed at the beginning of the code before any parallelization occurs
        static void setDefaultX(const unsigned long long defaultX);
G
gineshidalgo99 已提交
28

G
gineshidalgo99 已提交
29 30 31 32
        static const std::string timerInit(const int line, const std::string& function, const std::string& file);

        static void timerEnd(const std::string& key);

33 34 35
        static void printAveragedTimeMsOnIterationX(const std::string& key, const int line,
                                                    const std::string& function, const std::string& file,
                                                    const unsigned long long x = DEFAULT_X);
G
gineshidalgo99 已提交
36

37 38 39
        static void printAveragedTimeMsEveryXIterations(const std::string& key, const int line,
                                                        const std::string& function, const std::string& file,
                                                        const unsigned long long x = DEFAULT_X);
G
gineshidalgo99 已提交
40 41 42 43 44

        static void profileGpuMemory(const int line, const std::string& function, const std::string& file);
    };
}

45
#endif // OPENPOSE_UTILITIES_PROFILER_HPP