blob: 484db87b9a421d170a1530e921c7848a2de115b0 [file] [log] [blame]
Elliott Hughes42ee1422011-09-06 12:33:32 -07001/*
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 Shapiro6c21dc12011-06-20 15:20:52 -070016
David Sehrc431b9d2018-03-02 12:01:51 -080017#ifndef ART_LIBARTBASE_BASE_LOGGING_H_
18#define ART_LIBARTBASE_BASE_LOGGING_H_
Carl Shapiro6c21dc12011-06-20 15:20:52 -070019
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070020#include "android-base/logging.h"
David Sehr1979c642018-04-26 14:41:18 -070021#include "macros.h"
Carl Shapiro6c21dc12011-06-20 15:20:52 -070022
Ian Rogersc7dd2952014-10-21 23:31:19 -070023namespace art {
24
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070025// Make libbase's LogSeverity more easily available.
Andreas Gamped6e54bb2016-09-26 14:07:57 -070026using ::android::base::LogSeverity;
27using ::android::base::ScopedLogSeverity;
Ian Rogersc7dd2952014-10-21 23:31:19 -070028
David Sehrf57589f2016-10-17 10:09:33 -070029// Abort function.
30using AbortFunction = void(const char*);
31
Ian Rogersc7dd2952014-10-21 23:31:19 -070032// The members of this struct are the valid arguments to VLOG and VLOG_IS_ON in code,
33// and the "-verbose:" command line argument.
34struct LogVerbosity {
35 bool class_linker; // Enabled with "-verbose:class".
Mathieu Chartier66a55392016-02-19 10:25:39 -080036 bool collector;
Ian Rogersc7dd2952014-10-21 23:31:19 -070037 bool compiler;
Andreas Gampef3d1f942015-05-18 21:41:13 -070038 bool deopt;
Ian Rogersc7dd2952014-10-21 23:31:19 -070039 bool gc;
40 bool heap;
41 bool jdwp;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080042 bool jit;
Ian Rogersc7dd2952014-10-21 23:31:19 -070043 bool jni;
44 bool monitor;
Richard Uhler66d874d2015-01-15 09:37:19 -080045 bool oat;
Ian Rogersc7dd2952014-10-21 23:31:19 -070046 bool profiler;
47 bool signals;
Phil Wang751beff2015-08-28 15:17:15 +080048 bool simulator;
Ian Rogersc7dd2952014-10-21 23:31:19 -070049 bool startup;
50 bool third_party_jni; // Enabled with "-verbose:third-party-jni".
51 bool threads;
52 bool verifier;
Andreas Gampe92d77202017-12-06 20:49:00 -080053 bool verifier_debug; // Only works in debug builds.
Mathieu Chartierfbc31082016-01-24 11:59:56 -080054 bool image;
Andreas Gampec7ed09b2016-04-25 20:08:55 -070055 bool systrace_lock_logging; // Enabled with "-verbose:sys-locks".
Alex Light7233c7e2016-07-28 10:07:45 -070056 bool agents;
Andreas Gampebec07a02017-04-11 13:48:37 -070057 bool dex; // Some dex access output etc.
Ian Rogersc7dd2952014-10-21 23:31:19 -070058};
59
60// Global log verbosity setting, initialized by InitLogging.
61extern LogVerbosity gLogVerbosity;
62
Ian Rogersc7dd2952014-10-21 23:31:19 -070063// Configure logging based on ANDROID_LOG_TAGS environment variable.
64// We need to parse a string that looks like
65//
66// *:v jdwp:d dalvikvm:d dalvikvm-gc:i dalvikvmi:i
67//
68// The tag (or '*' for the global level) comes first, followed by a colon
69// and a letter indicating the minimum priority level we're expected to log.
70// This can be used to reveal or conceal logs with specific tags.
David Sehrf57589f2016-10-17 10:09:33 -070071extern void InitLogging(char* argv[], AbortFunction& default_aborter);
Ian Rogersc7dd2952014-10-21 23:31:19 -070072
Mathieu Chartier2cebb242015-04-21 16:50:40 -070073// Returns the command line used to invoke the current tool or null if InitLogging hasn't been
Ian Rogersc7dd2952014-10-21 23:31:19 -070074// performed.
75extern const char* GetCmdLine();
76
Roland Levillain38a938e2018-09-21 10:55:51 +010077// The command used to start the ART runtime, such as "/apex/com.android.runtime/bin/dalvikvm". If
78// InitLogging hasn't been performed then just returns "art".
Ian Rogersc7dd2952014-10-21 23:31:19 -070079extern const char* ProgramInvocationName();
80
81// A short version of the command used to start the ART runtime, such as "dalvikvm". If InitLogging
Roland Levillain38a938e2018-09-21 10:55:51 +010082// hasn't been performed then just returns "art".
Ian Rogersc7dd2952014-10-21 23:31:19 -070083extern const char* ProgramInvocationShortName();
84
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070085class LogHelper {
86 public:
87 // A logging helper for logging a single line. Can be used with little stack.
88 static void LogLineLowStack(const char* file,
89 unsigned int line,
90 android::base::LogSeverity severity,
91 const char* msg);
Ian Rogersc7dd2952014-10-21 23:31:19 -070092
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070093 private:
94 DISALLOW_ALLOCATION();
95 DISALLOW_COPY_AND_ASSIGN(LogHelper);
96};
Ian Rogersc7dd2952014-10-21 23:31:19 -070097
David Sehr79e26072018-04-06 17:58:50 -070098// Copy the contents of file_name to the log stream for level.
99bool PrintFileToLog(const std::string& file_name, android::base::LogSeverity level);
100
Ian Rogersc7dd2952014-10-21 23:31:19 -0700101// 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 Gampe3fec9ac2016-09-13 10:47:28 -0700106#define VLOG(module) if (VLOG_IS_ON(module)) LOG(INFO)
Ian Rogersc7dd2952014-10-21 23:31:19 -0700107
108// Return the stream associated with logging for the given module.
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700109#define VLOG_STREAM(module) LOG_STREAM(INFO)
Andreas Gampe369810a2015-01-14 19:53:31 -0800110
Elliott Hughes3ea7e992011-10-11 18:48:16 -0700111} // namespace art
112
David Sehrc431b9d2018-03-02 12:01:51 -0800113#endif // ART_LIBARTBASE_BASE_LOGGING_H_