leozwang | d3fc15f | 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 | |
Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame^] | 20 | #include <base/logging.h> |
| 21 | #include <base/stringprintf.h> |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 22 | |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 23 | /* IMPORTANT: if you change the following list, don't |
| 24 | * forget to update the corresponding 'tags' table in |
| 25 | * the adb_trace_init() function implemented in adb.c |
| 26 | */ |
Elliott Hughes | 2d4121c | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 27 | enum AdbTrace { |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 28 | TRACE_ADB = 0, /* 0x001 */ |
| 29 | TRACE_SOCKETS, |
| 30 | TRACE_PACKETS, |
| 31 | TRACE_TRANSPORT, |
| 32 | TRACE_RWX, /* 0x010 */ |
| 33 | TRACE_USB, |
| 34 | TRACE_SYNC, |
| 35 | TRACE_SYSDEPS, |
| 36 | TRACE_JDWP, /* 0x100 */ |
| 37 | TRACE_SERVICES, |
| 38 | TRACE_AUTH, |
| 39 | TRACE_FDEVENT, |
Elliott Hughes | bd4b1fa | 2015-08-28 14:46:33 -0700 | [diff] [blame] | 40 | }; |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 41 | |
Dan Albert | 9313c0d | 2015-05-21 13:58:50 -0700 | [diff] [blame] | 42 | extern int adb_trace_mask; |
| 43 | extern unsigned char adb_trace_output_count; |
| 44 | void adb_trace_init(char**); |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 45 | |
Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame^] | 46 | #define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0) |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 47 | |
Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame^] | 48 | // You must define TRACE_TAG before using this macro. |
| 49 | #define D(...) \ |
Elliott Hughes | bd4b1fa | 2015-08-28 14:46:33 -0700 | [diff] [blame] | 50 | do { \ |
| 51 | if (ADB_TRACING) { \ |
| 52 | int saved_errno = errno; \ |
Yabin Cui | 7a3f8d6 | 2015-09-02 17:44:28 -0700 | [diff] [blame^] | 53 | LOG(INFO) << android::base::StringPrintf(__VA_ARGS__); \ |
Elliott Hughes | bd4b1fa | 2015-08-28 14:46:33 -0700 | [diff] [blame] | 54 | errno = saved_errno; \ |
| 55 | } \ |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 56 | } while (0) |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 57 | |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 58 | #endif /* __ADB_TRACE_H */ |