Files
BPI-CM9-Linux/aml-comp/vendor/amlogic/meson_videoserver/display/DispAdptLog.h
T

113 lines
3.7 KiB
C++

/*
* Copyright (C) 2024 Amlogic Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISP_ADPT_LOG_H
#define DISP_ADPT_LOG_H
#include <chrono>
#include <string>
#include <cstdarg>
#ifdef MESON_RELEASE
#define DISPLAY_DEBUG_LEVEL 0
#else
#define DISPLAY_DEBUG_LEVEL 1
#endif
#define DISPLAY_TAG "DisplayAdapter"
#define MESON_MAX_STR_LEN 4096
#define DEFAULT_LOG_LEVEL 1
#define ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1))
#define VIDEO_ALIGN(value) ALIGN(value, 32)
void DispAdptLog(int level, const char *fmt, ...);
#ifdef DISPLAY_LOGLIB
void DispAdptLogPrint(int prio, const char* tag, const char* fmt, va_list args);
#endif
void TracePrint(const char *fmt, ...);
#if DISPLAY_DEBUG_LEVEL > 0
#define DISPLAY_LOGV(fmt,...) DispAdptLog(4, "[V] %s: " fmt "\n", DISPLAY_TAG, ##__VA_ARGS__)
#define DISPLAY_LOGD(fmt,...) DispAdptLog(3, "[D] %s: " fmt "\n", DISPLAY_TAG, ##__VA_ARGS__)
#define DISPLAY_LOGI(fmt,...) DispAdptLog(2, "[I] %s: " fmt "\n", DISPLAY_TAG, ##__VA_ARGS__)
#define DISPLAY_LOGW(fmt,...) DispAdptLog(1, "[W] %s: " fmt "\n", DISPLAY_TAG, ##__VA_ARGS__)
#define DISPLAY_LOGD_IF(level, fmt, ...) if (level) DISPLAY_LOGD(fmt, ##__VA_ARGS__)
#define DISPLAY_LOGT(fmt,...) TracePrint("[T] %s: " fmt "\n", DISPLAY_TAG, ##__VA_ARGS__)
#else
#define DISPLAY_LOGV(fmt,...) ((void)0)
#define DISPLAY_LOGD(fmt,...) ((void)0)
#define DISPLAY_LOGI(fmt,...) ((void)0)
#define DISPLAY_LOGW(fmt,...) ((void)0)
#define DISPLAY_LOGD_IF(level, fmt, ...) ((void)0)
#define DISPLAY_LOGT(fmt,...) ((void)0)
#endif
#define DISPLAY_LOGE(fmt,...) DispAdptLog(0, "[E] %s: " fmt "\n", DISPLAY_TAG, ##__VA_ARGS__)
#if DISPLAY_DEBUG_LEVEL > 0
#define DISPLAY_ASSERT(condition,fmt,...) \
if (!(condition)) { \
DISPLAY_LOGE(fmt, ##__VA_ARGS__); \
abort(); \
}
#else
#define DISPLAY_ASSERT(condition,fmt,...) \
if (!(condition)) { \
DISPLAY_LOGE(fmt, ##__VA_ARGS__); \
}
#endif
long long DispAdptGetCurrentTime(void);
long long DispAdptGetCurrentTimeUs(void);
void DispAdptLogInit();
int DispAdptReadFile(const char *path, char *val, bool original, int valSize);
int DispAdptWriteFile(const char *path, const char *val);
int DispAdptGetDiNumber();
int DispAdptGetDiLog();
int DispAdptDebugSetting(char *content);
void DispAdptLogDestroy();
class Timer {
public:
explicit Timer(const std::string& name)
: name_(name), start_(std::chrono::high_resolution_clock::now()), timeout_(0) {}
explicit Timer(const std::string& name, int timeout)
: name_(name), start_(std::chrono::high_resolution_clock::now()), timeout_(timeout) {}
~Timer() {
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> diff = end - start_;
if (timeout_ == 0 || (timeout_ > 0 && diff.count() > timeout_))
DISPLAY_LOGT("%s: %f ms", name_.c_str(), diff.count());
}
private:
std::string name_;
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
int timeout_;
};
#define DTRACE_ALL() Timer _timer_##__LINE__(__func__)
#define DTRACE_TIMEOUT(timeout) Timer _timer_##__LINE__(__func__, timeout)
#define DTRACE_TIMEOUT_N(name, timeout) Timer _timer_##__LINE__(name, timeout)
#endif