Elliott Hughes | 42ee142 | 2011-09-06 12:33:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Carl Shapiro | 6c21dc1 | 2011-06-20 15:20:52 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_BASE_LOGGING_H_ |
| 18 | #define ART_RUNTIME_BASE_LOGGING_H_ |
Carl Shapiro | 6c21dc1 | 2011-06-20 15:20:52 -0700 | [diff] [blame] | 19 | |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 20 | #include <ostream> |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 21 | #include <sstream> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 22 | |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 23 | #include "android-base/logging.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 24 | #include "base/macros.h" |
Carl Shapiro | 6c21dc1 | 2011-06-20 15:20:52 -0700 | [diff] [blame] | 25 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 26 | namespace art { |
| 27 | |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 28 | // Make libbase's LogSeverity more easily available. |
Andreas Gampe | d6e54bb | 2016-09-26 14:07:57 -0700 | [diff] [blame] | 29 | using ::android::base::LogSeverity; |
| 30 | using ::android::base::ScopedLogSeverity; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 31 | |
| 32 | // The members of this struct are the valid arguments to VLOG and VLOG_IS_ON in code, |
| 33 | // and the "-verbose:" command line argument. |
| 34 | struct LogVerbosity { |
| 35 | bool class_linker; // Enabled with "-verbose:class". |
Mathieu Chartier | 66a5539 | 2016-02-19 10:25:39 -0800 | [diff] [blame] | 36 | bool collector; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 37 | bool compiler; |
Andreas Gampe | f3d1f94 | 2015-05-18 21:41:13 -0700 | [diff] [blame] | 38 | bool deopt; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 39 | bool gc; |
| 40 | bool heap; |
| 41 | bool jdwp; |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 42 | bool jit; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 43 | bool jni; |
| 44 | bool monitor; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 45 | bool oat; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 46 | bool profiler; |
| 47 | bool signals; |
Phil Wang | 751beff | 2015-08-28 15:17:15 +0800 | [diff] [blame] | 48 | bool simulator; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 49 | bool startup; |
| 50 | bool third_party_jni; // Enabled with "-verbose:third-party-jni". |
| 51 | bool threads; |
| 52 | bool verifier; |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 53 | bool image; |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 54 | bool systrace_lock_logging; // Enabled with "-verbose:sys-locks". |
Alex Light | 7233c7e | 2016-07-28 10:07:45 -0700 | [diff] [blame] | 55 | bool agents; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | // Global log verbosity setting, initialized by InitLogging. |
| 59 | extern LogVerbosity gLogVerbosity; |
| 60 | |
Nicolas Geoffray | db97871 | 2014-12-09 13:33:38 +0000 | [diff] [blame] | 61 | // 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive |
| 62 | // aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown |
| 63 | // makes forward progress. |
| 64 | extern unsigned int gAborting; |
| 65 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 66 | // Configure logging based on ANDROID_LOG_TAGS environment variable. |
| 67 | // We need to parse a string that looks like |
| 68 | // |
| 69 | // *:v jdwp:d dalvikvm:d dalvikvm-gc:i dalvikvmi:i |
| 70 | // |
| 71 | // The tag (or '*' for the global level) comes first, followed by a colon |
| 72 | // and a letter indicating the minimum priority level we're expected to log. |
| 73 | // This can be used to reveal or conceal logs with specific tags. |
| 74 | extern void InitLogging(char* argv[]); |
| 75 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 76 | // Returns the command line used to invoke the current tool or null if InitLogging hasn't been |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 77 | // performed. |
| 78 | extern const char* GetCmdLine(); |
| 79 | |
| 80 | // The command used to start the ART runtime, such as "/system/bin/dalvikvm". If InitLogging hasn't |
| 81 | // been performed then just returns "art" |
| 82 | extern const char* ProgramInvocationName(); |
| 83 | |
| 84 | // A short version of the command used to start the ART runtime, such as "dalvikvm". If InitLogging |
| 85 | // hasn't been performed then just returns "art" |
| 86 | extern const char* ProgramInvocationShortName(); |
| 87 | |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 88 | class LogHelper { |
| 89 | public: |
| 90 | // A logging helper for logging a single line. Can be used with little stack. |
| 91 | static void LogLineLowStack(const char* file, |
| 92 | unsigned int line, |
| 93 | android::base::LogSeverity severity, |
| 94 | const char* msg); |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 95 | |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 96 | private: |
| 97 | DISALLOW_ALLOCATION(); |
| 98 | DISALLOW_COPY_AND_ASSIGN(LogHelper); |
| 99 | }; |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 100 | |
| 101 | // Is verbose logging enabled for the given module? Where the module is defined in LogVerbosity. |
| 102 | #define VLOG_IS_ON(module) UNLIKELY(::art::gLogVerbosity.module) |
| 103 | |
| 104 | // Variant of LOG that logs when verbose logging is enabled for a module. For example, |
| 105 | // VLOG(jni) << "A JNI operation was performed"; |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 106 | #define VLOG(module) if (VLOG_IS_ON(module)) LOG(INFO) |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 107 | |
| 108 | // Return the stream associated with logging for the given module. |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 109 | #define VLOG_STREAM(module) LOG_STREAM(INFO) |
Andreas Gampe | 369810a | 2015-01-14 19:53:31 -0800 | [diff] [blame] | 110 | |
Elliott Hughes | 3ea7e99 | 2011-10-11 18:48:16 -0700 | [diff] [blame] | 111 | } // namespace art |
| 112 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 113 | #endif // ART_RUNTIME_BASE_LOGGING_H_ |