1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HIDUMPER_COMMON_H 16 #define HIDUMPER_COMMON_H 17 #include <ctime> 18 #include <sys/time.h> 19 namespace OHOS { 20 namespace HiviewDFX { 21 enum DumpStatus { 22 DUMP_REQUEST_MAX = -5, 23 DUMP_TIMEOUT = -4, 24 DUMP_INVALID_ARG = -3, 25 DUMP_NOPERMISSION = -2, 26 DUMP_FAIL = -1, 27 DUMP_OK = 0, 28 DUMP_HELP, 29 DUMP_CHECK_OK, 30 DUMP_MORE_DATA, 31 }; 32 33 #define LOG_TIME() \ 34 do { \ 35 struct timeval tp; \ 36 gettimeofday(&tp, nullptr); \ 37 struct tm curTime = {0}; \ 38 if (localtime_r(&tp.tv_sec, &curTime) != nullptr) { \ 39 fprintf(stdout, "[%04d%02d%02d %02d:%02d:%02d]", curTime.tm_year + 1900, 1 + curTime.tm_mon, \ 40 curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec); \ 41 } \ 42 } while (0) 43 44 #define LOG_ERR(format, ...) \ 45 do { \ 46 LOG_TIME(); \ 47 fprintf(stdout, "Error:" format "", ##__VA_ARGS__); \ 48 } while (0) 49 50 #define HIDUMPER_DEBUG 51 #ifdef HIDUMPER_DEBUG 52 #define LOG_DEBUG(format, ...) \ 53 do { \ 54 LOG_TIME(); \ 55 fprintf(stdout, "Debug:" format "(%s %d)\n", ##__VA_ARGS__, __FILE__, __LINE__); \ 56 } while (0) 57 #else 58 #define LOG_DEBUG(format, ...) 59 #endif 60 } // namespace HiviewDFX 61 } // namespace OHOS 62 #endif 63