1 // Copyright 2007-2008 The Android Open Source Project
2 //
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 #pragma once
16 
17 #include <stdarg.h>
18 #include <stdbool.h>
19 #include <stdint.h>
20 
21 #include "android/utils/compiler.h"
22 
23 ANDROID_BEGIN_HEADER
24 
25 #define VERBOSE_TAG_LIST                                                       \
26     _VERBOSE_TAG(init, "emulator initialization")                              \
27     _VERBOSE_TAG(console, "control console")                                   \
28     _VERBOSE_TAG(modem, "emulated GSM modem")                                  \
29     _VERBOSE_TAG(radio, "emulated GSM AT Command channel")                     \
30     _VERBOSE_TAG(keys, "key bindings & presses")                               \
31     _VERBOSE_TAG(events, "events sent to the emulator")                        \
32     _VERBOSE_TAG(slirp, "internal router/firewall")                            \
33     _VERBOSE_TAG(timezone, "host timezone detection")                          \
34     _VERBOSE_TAG(socket, "network sockets")                                    \
35     _VERBOSE_TAG(proxy, "network proxy support")                               \
36     _VERBOSE_TAG(audio, "audio sub-system")                                    \
37     _VERBOSE_TAG(audioin, "audio input backend")                               \
38     _VERBOSE_TAG(audioout, "audio output backend")                             \
39     _VERBOSE_TAG(surface, "video surface support")                             \
40     _VERBOSE_TAG(qemud, "qemud multiplexer daemon")                            \
41     _VERBOSE_TAG(gps, "emulated GPS")                                          \
42     _VERBOSE_TAG(nand_limits, "nand/flash read/write thresholding")            \
43     _VERBOSE_TAG(hw_control, "emulated power/flashlight/led/vibrator")         \
44     _VERBOSE_TAG(avd_config, "android virtual device configuration")           \
45     _VERBOSE_TAG(sensors, "emulated sensors")                                  \
46     _VERBOSE_TAG(memcheck, "memory checker")                                   \
47     _VERBOSE_TAG(camera, "camera")                                             \
48     _VERBOSE_TAG(adevice, "android device connected via port forwarding")      \
49     _VERBOSE_TAG(sensors_port, "sensors emulator connected to android device") \
50     _VERBOSE_TAG(mtport, "multi-touch emulator connected to android device")   \
51     _VERBOSE_TAG(mtscreen, "multi-touch screen emulation")                     \
52     _VERBOSE_TAG(gles, "hardware OpenGLES emulation")                          \
53     _VERBOSE_TAG(gles1emu, "emulated GLESv1 renderer")                         \
54     _VERBOSE_TAG(adbserver, "ADB server")                                      \
55     _VERBOSE_TAG(adbclient, "ADB QEMU client")                                 \
56     _VERBOSE_TAG(adb, "ADB debugger")                                          \
57     _VERBOSE_TAG(asconnector, "Asynchronous socket connector")                 \
58     _VERBOSE_TAG(asyncsocket, "Asynchronous socket")                           \
59     _VERBOSE_TAG(sdkctlsocket, "Socket tethering to SdkControl server")        \
60     _VERBOSE_TAG(updater, "Update checker")                                    \
61     _VERBOSE_TAG(metrics, "Metrics reporting")                                 \
62     _VERBOSE_TAG(rotation, "Device rotation debugging")                        \
63     _VERBOSE_TAG(goldfishsync, "Goldfish Sync Device")                         \
64     _VERBOSE_TAG(syncthreads, "HostGPU Sync Threads")                          \
65     _VERBOSE_TAG(memory, "Memory Usage Report")                                \
66     _VERBOSE_TAG(car, "Emulated car data")                                     \
67     _VERBOSE_TAG(record, "Screen recording")                                   \
68     _VERBOSE_TAG(snapshot, "Snapshots")                                        \
69     _VERBOSE_TAG(virtualscene, "Virtual scene rendering")                      \
70     _VERBOSE_TAG(automation, "Automation")                                     \
71     _VERBOSE_TAG(offworld, "Offworld")                                         \
72 
73 #define  _VERBOSE_TAG(x,y)  VERBOSE_##x,
74 typedef enum {
75     VERBOSE_TAG_LIST
76     VERBOSE_MAX  /* do not remove */
77 } VerboseTag;
78 #undef  _VERBOSE_TAG
79 
80 extern uint64_t android_verbose;
81 
82 // Enable/disable verbose logs from the base/* family.
83 extern void base_enable_verbose_logs();
84 extern void base_disable_verbose_logs();
85 
86 #define  VERBOSE_ENABLE(tag)    \
87     android_verbose |= (1ULL << VERBOSE_##tag)
88 
89 #define  VERBOSE_DISABLE(tag)   \
90     android_verbose &= (1ULL << VERBOSE_##tag)
91 
92 #define  VERBOSE_CHECK(tag)    \
93     ((android_verbose & (1ULL << VERBOSE_##tag)) != 0)
94 
95 #define  VERBOSE_CHECK_ANY()    \
96     (android_verbose != 0)
97 
98 #define  VERBOSE_PRINT(tag,...)  \
99     do { if (VERBOSE_CHECK(tag)) dprint(__VA_ARGS__); } while (0)
100 
101 // This omits the "emulator: " prefix.
102 #define  VERBOSE_DPRINT(tag,format,...)  \
103     do { if (VERBOSE_CHECK(tag)) { \
104          dprintn(format "\n", \
105                  ##__VA_ARGS__); } } while(0)
106 
107 #define  VERBOSE_FUNCTION_PRINT(tag,format,...)  \
108     do { if (VERBOSE_CHECK(tag)) \
109          dprintn("emulator: %s: " format "\n", \
110                  __func__, ##__VA_ARGS__); } while(0)
111 
112 // This omits the "emulator: " prefix.
113 #define  VERBOSE_FUNCTION_DPRINT(tag,format,...)  \
114     do { if (VERBOSE_CHECK(tag)) \
115          dprintn("%s: " format "\n", \
116                  __func__, ##__VA_ARGS__); } while(0)
117 
118 #define  VERBOSE_TID_PRINT(tag,...)  \
119     do { if (VERBOSE_CHECK(tag)) \
120          android_tid_function_print(true, NULL, __VA_ARGS__); \
121     } while (0)
122 
123 // This omits the "emulator: " prefix.
124 #define  VERBOSE_TID_DPRINT(tag,...)  \
125     do { if (VERBOSE_CHECK(tag)) \
126          android_tid_function_print(false, NULL, __VA_ARGS__); } \
127     while (0)
128 
129 #define  VERBOSE_TID_FUNCTION_PRINT(tag,...) \
130     do { if (VERBOSE_CHECK(tag)) \
131          android_tid_function_print(true, __func__, __VA_ARGS__); } \
132     while (0)
133 
134 // This omits the "emulator: " prefix.
135 #define  VERBOSE_TID_FUNCTION_DPRINT(tag,...) \
136     do { if (VERBOSE_CHECK(tag)) \
137          android_tid_function_print(false, __func__, __VA_ARGS__); } \
138     while (0)
139 
140 /** DEBUG TRACE SUPPORT
141  **
142  ** Debug messages can be sent by calling these functions:
143  **
144  ** 'dprint' prints "emulator: ", the message, then appends a '\n'
145  ** 'dprintn' prints the message as is
146  ** 'dprintnv' is 'dprintn' but allows you to use a va_list argument
147  ** 'dwarning' prints "emulator: WARNING: ", then appends a '\n'
148  ** 'derror' prints "emulator: ERROR: ", then appends a '\n'
149  */
150 
151 extern void   dprint( const char*  format, ... );
152 extern void   dprintn( const char*  format, ... );
153 extern void   dprintnv( const char*  format, va_list  args );
154 extern void   dwarning( const char*  format, ... );
155 extern void   derror( const char*  format, ... );
156 
157 /** MULTITHREADED DEBUG TRACING
158  **
159  ** 'android_tid_function_print' is for tracing in multi-threaded situations.
160  ** It prints "emulator: " or not (depending on |use_emulator_prefix|),
161  ** the thread id, a function name (|function|), the message, and finally '\n'.
162  */
163 extern void   android_tid_function_print(bool use_emulator_prefix,
164                                          const char* function,
165                                          const char*  format, ... );
166 
167 /** STDOUT/STDERR REDIRECTION
168  **
169  ** allows you to shut temporarily shutdown stdout/stderr
170  ** this is useful to get rid of debug messages from ALSA and esd
171  ** on Linux.
172  **/
173 
174 extern void  stdio_disable( void );
175 extern void  stdio_enable( void );
176 
177 ANDROID_END_HEADER
178