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