leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __ADB_TRACE_H |
| 18 | #define __ADB_TRACE_H |
| 19 | |
| 20 | #if !ADB_HOST |
| 21 | #include <android/log.h> |
Dan Albert | 66a91b0 | 2015-02-24 21:26:58 -0800 | [diff] [blame] | 22 | #else |
| 23 | #include <stdio.h> |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 24 | #endif |
| 25 | |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 26 | /* IMPORTANT: if you change the following list, don't |
| 27 | * forget to update the corresponding 'tags' table in |
| 28 | * the adb_trace_init() function implemented in adb.c |
| 29 | */ |
Elliott Hughes | fe7ff81 | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 30 | enum AdbTrace { |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 31 | TRACE_ADB = 0, /* 0x001 */ |
| 32 | TRACE_SOCKETS, |
| 33 | TRACE_PACKETS, |
| 34 | TRACE_TRANSPORT, |
| 35 | TRACE_RWX, /* 0x010 */ |
| 36 | TRACE_USB, |
| 37 | TRACE_SYNC, |
| 38 | TRACE_SYSDEPS, |
| 39 | TRACE_JDWP, /* 0x100 */ |
| 40 | TRACE_SERVICES, |
| 41 | TRACE_AUTH, |
| 42 | TRACE_FDEVENT, |
Elliott Hughes | 0ea5924 | 2015-08-28 14:46:33 -0700 | [diff] [blame^] | 43 | }; |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 44 | |
Dan Albert | 08d552b | 2015-05-21 13:58:50 -0700 | [diff] [blame] | 45 | extern int adb_trace_mask; |
| 46 | extern unsigned char adb_trace_output_count; |
| 47 | void adb_trace_init(char**); |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 48 | |
| 49 | # define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0) |
| 50 | |
| 51 | /* you must define TRACE_TAG before using this macro */ |
| 52 | #if ADB_HOST |
Elliott Hughes | 0ea5924 | 2015-08-28 14:46:33 -0700 | [diff] [blame^] | 53 | # define D(fmt, ...) \ |
| 54 | do { \ |
| 55 | if (ADB_TRACING) { \ |
| 56 | int saved_errno = errno; \ |
| 57 | adb_mutex_lock(&D_lock); \ |
| 58 | errno = saved_errno; \ |
| 59 | fprintf(stderr, "%5d:%5lu %s | " fmt, \ |
| 60 | getpid(), adb_thread_id(), __FUNCTION__, ## __VA_ARGS__); \ |
| 61 | fflush(stderr); \ |
| 62 | adb_mutex_unlock(&D_lock); \ |
| 63 | errno = saved_errno; \ |
| 64 | } \ |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 65 | } while (0) |
Elliott Hughes | 0ea5924 | 2015-08-28 14:46:33 -0700 | [diff] [blame^] | 66 | # define DR(...) \ |
| 67 | do { \ |
| 68 | if (ADB_TRACING) { \ |
| 69 | int saved_errno = errno; \ |
| 70 | adb_mutex_lock(&D_lock); \ |
| 71 | errno = saved_errno; \ |
| 72 | fprintf(stderr, __VA_ARGS__); \ |
| 73 | fflush(stderr); \ |
| 74 | adb_mutex_unlock(&D_lock); \ |
| 75 | errno = saved_errno; \ |
| 76 | } \ |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 77 | } while (0) |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 78 | #else |
Elliott Hughes | 0ea5924 | 2015-08-28 14:46:33 -0700 | [diff] [blame^] | 79 | # define D(...) \ |
| 80 | do { \ |
| 81 | if (ADB_TRACING) { \ |
| 82 | __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \ |
| 83 | } \ |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 84 | } while (0) |
Elliott Hughes | 0ea5924 | 2015-08-28 14:46:33 -0700 | [diff] [blame^] | 85 | # define DR(...) \ |
| 86 | do { \ |
| 87 | if (ADB_TRACING) { \ |
| 88 | __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \ |
| 89 | } \ |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 90 | } while (0) |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 91 | #endif /* ADB_HOST */ |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 92 | |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 93 | #endif /* __ADB_TRACE_H */ |