100600bfbSopenharmony_ci/* 200600bfbSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 300600bfbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 400600bfbSopenharmony_ci * you may not use this file except in compliance with the License. 500600bfbSopenharmony_ci * You may obtain a copy of the License at 600600bfbSopenharmony_ci * 700600bfbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 800600bfbSopenharmony_ci * 900600bfbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1000600bfbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1100600bfbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1200600bfbSopenharmony_ci * See the License for the specific language governing permissions and 1300600bfbSopenharmony_ci * limitations under the License. 1400600bfbSopenharmony_ci */ 1500600bfbSopenharmony_ci#ifndef HIDUMPER_COMMON_H 1600600bfbSopenharmony_ci#define HIDUMPER_COMMON_H 1700600bfbSopenharmony_ci#include <ctime> 1800600bfbSopenharmony_ci#include <sys/time.h> 1900600bfbSopenharmony_cinamespace OHOS { 2000600bfbSopenharmony_cinamespace HiviewDFX { 2100600bfbSopenharmony_cienum DumpStatus { 2200600bfbSopenharmony_ci DUMP_REQUEST_MAX = -5, 2300600bfbSopenharmony_ci DUMP_TIMEOUT = -4, 2400600bfbSopenharmony_ci DUMP_INVALID_ARG = -3, 2500600bfbSopenharmony_ci DUMP_NOPERMISSION = -2, 2600600bfbSopenharmony_ci DUMP_FAIL = -1, 2700600bfbSopenharmony_ci DUMP_OK = 0, 2800600bfbSopenharmony_ci DUMP_HELP, 2900600bfbSopenharmony_ci DUMP_CHECK_OK, 3000600bfbSopenharmony_ci DUMP_MORE_DATA, 3100600bfbSopenharmony_ci}; 3200600bfbSopenharmony_ci 3300600bfbSopenharmony_ci#define LOG_TIME() \ 3400600bfbSopenharmony_ci do { \ 3500600bfbSopenharmony_ci struct timeval tp; \ 3600600bfbSopenharmony_ci gettimeofday(&tp, nullptr); \ 3700600bfbSopenharmony_ci struct tm curTime = {0}; \ 3800600bfbSopenharmony_ci if (localtime_r(&tp.tv_sec, &curTime) != nullptr) { \ 3900600bfbSopenharmony_ci fprintf(stdout, "[%04d%02d%02d %02d:%02d:%02d]", curTime.tm_year + 1900, 1 + curTime.tm_mon, \ 4000600bfbSopenharmony_ci curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec); \ 4100600bfbSopenharmony_ci } \ 4200600bfbSopenharmony_ci } while (0) 4300600bfbSopenharmony_ci 4400600bfbSopenharmony_ci#define LOG_ERR(format, ...) \ 4500600bfbSopenharmony_ci do { \ 4600600bfbSopenharmony_ci LOG_TIME(); \ 4700600bfbSopenharmony_ci fprintf(stdout, "Error:" format "", ##__VA_ARGS__); \ 4800600bfbSopenharmony_ci } while (0) 4900600bfbSopenharmony_ci 5000600bfbSopenharmony_ci#define HIDUMPER_DEBUG 5100600bfbSopenharmony_ci#ifdef HIDUMPER_DEBUG 5200600bfbSopenharmony_ci#define LOG_DEBUG(format, ...) \ 5300600bfbSopenharmony_ci do { \ 5400600bfbSopenharmony_ci LOG_TIME(); \ 5500600bfbSopenharmony_ci fprintf(stdout, "Debug:" format "(%s %d)\n", ##__VA_ARGS__, __FILE__, __LINE__); \ 5600600bfbSopenharmony_ci } while (0) 5700600bfbSopenharmony_ci#else 5800600bfbSopenharmony_ci#define LOG_DEBUG(format, ...) 5900600bfbSopenharmony_ci#endif 6000600bfbSopenharmony_ci} // namespace HiviewDFX 6100600bfbSopenharmony_ci} // namespace OHOS 6200600bfbSopenharmony_ci#endif 63