blob: 4e03165fe1e1a3d2d2622a160d3de50d51e6fcfa [file] [log] [blame]
leozwangf25a6a42014-07-29 12:50:02 -07001/*
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 Albert66a91b02015-02-24 21:26:58 -080022#else
23#include <stdio.h>
leozwangf25a6a42014-07-29 12:50:02 -070024#endif
25
leozwangf25a6a42014-07-29 12:50:02 -070026/* 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 Hughesfe7ff812015-04-17 09:47:42 -070030enum AdbTrace {
leozwangf25a6a42014-07-29 12:50:02 -070031 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 Hughes0ea59242015-08-28 14:46:33 -070043};
leozwangf25a6a42014-07-29 12:50:02 -070044
Dan Albert08d552b2015-05-21 13:58:50 -070045extern int adb_trace_mask;
46extern unsigned char adb_trace_output_count;
47void adb_trace_init(char**);
leozwangf25a6a42014-07-29 12:50:02 -070048
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 Hughes0ea59242015-08-28 14:46:33 -070053# 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 } \
leozwangf25a6a42014-07-29 12:50:02 -070065 } while (0)
Elliott Hughes0ea59242015-08-28 14:46:33 -070066# 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 } \
leozwangf25a6a42014-07-29 12:50:02 -070077 } while (0)
leozwangf25a6a42014-07-29 12:50:02 -070078#else
Elliott Hughes0ea59242015-08-28 14:46:33 -070079# define D(...) \
80 do { \
81 if (ADB_TRACING) { \
82 __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \
83 } \
leozwangf25a6a42014-07-29 12:50:02 -070084 } while (0)
Elliott Hughes0ea59242015-08-28 14:46:33 -070085# define DR(...) \
86 do { \
87 if (ADB_TRACING) { \
88 __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \
89 } \
leozwangf25a6a42014-07-29 12:50:02 -070090 } while (0)
leozwangf25a6a42014-07-29 12:50:02 -070091#endif /* ADB_HOST */
leozwangf25a6a42014-07-29 12:50:02 -070092
leozwangf25a6a42014-07-29 12:50:02 -070093#endif /* __ADB_TRACE_H */