19762338dSopenharmony_ci/* 29762338dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49762338dSopenharmony_ci * you may not use this file except in compliance with the License. 59762338dSopenharmony_ci * You may obtain a copy of the License at 69762338dSopenharmony_ci * 79762338dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89762338dSopenharmony_ci * 99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129762338dSopenharmony_ci * See the License for the specific language governing permissions and 139762338dSopenharmony_ci * limitations under the License. 149762338dSopenharmony_ci */ 159762338dSopenharmony_ci 169762338dSopenharmony_ci#ifndef KERNEL_LITE_LOG 179762338dSopenharmony_ci#define KERNEL_LITE_LOG 189762338dSopenharmony_ci 199762338dSopenharmony_ci#include <cstdio> 209762338dSopenharmony_ci#include <unistd.h> 219762338dSopenharmony_ci#include <ctime> 229762338dSopenharmony_ci 239762338dSopenharmony_ci#ifdef __cplusplus 249762338dSopenharmony_ciextern "C" { 259762338dSopenharmony_ci#endif 269762338dSopenharmony_ci 279762338dSopenharmony_ci#ifdef DEBUG 289762338dSopenharmony_ci const float SYS_NS_PER_S = 1000 * 1000 * 1000; 299762338dSopenharmony_ci // get current time, for logging only 309762338dSopenharmony_ci static float GetCurTime(void) 319762338dSopenharmony_ci { 329762338dSopenharmony_ci struct timespec time1 = {0, 0}; 339762338dSopenharmony_ci clock_gettime(CLOCK_MONOTONIC, &time1); 349762338dSopenharmony_ci return time1.tv_sec + ((float)time1.tv_nsec) / SYS_NS_PER_S; 359762338dSopenharmony_ci } 369762338dSopenharmony_ci #define LOGD(format, ...) fprintf(stdout, "[%.06f] " format "\n", GetCurTime(), ##__VA_ARGS__) 379762338dSopenharmony_ci #define LOG(format, ...) fprintf(stdout, "[%.06f] " format "\n", GetCurTime(), ##__VA_ARGS__) 389762338dSopenharmony_ci#else 399762338dSopenharmony_ci #define LOGD(...) 409762338dSopenharmony_ci #define LOG(format, ...) fprintf(stdout, format "\n", ##__VA_ARGS__) 419762338dSopenharmony_ci#endif 429762338dSopenharmony_ci 439762338dSopenharmony_ci#define LOGE(format, ...) fprintf(stdout, "\n%s:%d: " format "\n", __FILE__, __LINE__, ##__VA_ARGS__) 449762338dSopenharmony_ci 459762338dSopenharmony_ci#define PANIC(format, ...) do { \ 469762338dSopenharmony_ci LOGE(format, ##__VA_ARGS__); \ 479762338dSopenharmony_ci exit(1); \ 489762338dSopenharmony_ci } while (0) 499762338dSopenharmony_ci 509762338dSopenharmony_ci 519762338dSopenharmony_ci#ifdef __cplusplus 529762338dSopenharmony_ci} 539762338dSopenharmony_ci#endif 549762338dSopenharmony_ci 559762338dSopenharmony_ci#endif 56