mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-22 22:23:44 +00:00
committed by
Konstantin Pastbin
parent
c9cbb64f12
commit
76ffc99abd
52
libs/platform/trace.hpp
Normal file
52
libs/platform/trace.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/macros.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace platform
|
||||
{
|
||||
class TraceImpl;
|
||||
|
||||
// API is inspired by https://developer.android.com/ndk/reference/group/tracing
|
||||
class Trace
|
||||
{
|
||||
public:
|
||||
static Trace & Instance() noexcept;
|
||||
|
||||
void BeginSection(char const * name) noexcept;
|
||||
void EndSection() noexcept;
|
||||
void SetCounter(char const * name, int64_t value) noexcept;
|
||||
|
||||
private:
|
||||
Trace();
|
||||
~Trace();
|
||||
|
||||
std::unique_ptr<TraceImpl> m_impl;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(Trace);
|
||||
};
|
||||
|
||||
class TraceSection
|
||||
{
|
||||
public:
|
||||
inline TraceSection(char const * section) noexcept
|
||||
{
|
||||
Trace::Instance().BeginSection(section);
|
||||
}
|
||||
|
||||
inline ~TraceSection() noexcept
|
||||
{
|
||||
Trace::Instance().EndSection();
|
||||
}
|
||||
};
|
||||
} // namespace platform
|
||||
|
||||
#if defined(ENABLE_TRACE) && defined(OMIM_OS_ANDROID)
|
||||
#define TRACE_SECTION(section) platform::TraceSection ___section(section)
|
||||
#define TRACE_COUNTER(name, value) platform::Trace::Instance().SetCounter(name, value)
|
||||
#else
|
||||
#define TRACE_SECTION(section) static_cast<void>(0)
|
||||
#define TRACE_COUNTER(name, value) static_cast<void>(0)
|
||||
#endif
|
||||
Reference in New Issue
Block a user