#ifndef MEDIAPIPE_FRAMEWORK_PLATFORM_SPECIFIC_PROFILING_H_
#define MEDIAPIPE_FRAMEWORK_PLATFORM_SPECIFIC_PROFILING_H_
#ifdef MEDIAPIPE_PROFILER_AVAILABLE
#include "mediapipe/framework/profiler/graph_profiler.h"
#else
#include "mediapipe/framework/profiler/graph_profiler_stub.h"
#endif
#ifdef ENABLE_PLATFORM_SPECIFIC_PROFILING
namespace mediapipe {
const char kProfilingCategory[] = "Calculators";
void PlatformSpecificTraceEventBegin(const char* name, int64_t id,
const char* category_group,
int64_t packet_timestamp);
void PlatformSpecificTraceEventEnd(const char* name, int64_t id,
const char* category_group,
int64_t packet_timestamp);
class PlatformSpecificProfilingScope {
public:
PlatformSpecificProfilingScope(const char* name, int64_t id,
int64_t packet_timestamp)
: method_name_(TraceEvent::UNKNOWN),
name_(name),
id_(id),
packet_timestamp_(packet_timestamp) {
PlatformSpecificTraceEventBegin(name_, id_, kProfilingCategory,
packet_timestamp_);
}
PlatformSpecificProfilingScope(const char* name, int64_t id,
int64_t packet_timestamp,
TraceEvent::EventType method_name)
: method_name_(method_name),
name_(name),
id_(id),
packet_timestamp_(packet_timestamp) {
if (method_name_ == TraceEvent::PROCESS) {
PlatformSpecificTraceEventBegin(name_, id_, kProfilingCategory,
packet_timestamp_);
}
}
~PlatformSpecificProfilingScope() {
if (method_name_ == TraceEvent::PROCESS ||
method_name_ == TraceEvent::UNKNOWN) {
PlatformSpecificTraceEventEnd(name_, id_, kProfilingCategory,
packet_timestamp_);
}
}
private:
TraceEvent::EventType method_name_;
const char* name_;
int64_t id_;
int64_t packet_timestamp_;
};
}
#define PLATFORM_SPECIFIC_PROFILER …
#define PLATFORM_SPECIFIC_PROCESS_PROFILER …
#else
#define PLATFORM_SPECIFIC_PROFILER(name, id, packet_timestamp) …
#define PLATFORM_SPECIFIC_PROCESS_PROFILER(name, id, method_name, \
packet_timestamp) …
#endif
#endif