blob: a173ac2d4d7b0eb51b273eb9563f8ef1a098b04a [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_BASE_LOGGING_H_
18#define ART_RUNTIME_BASE_LOGGING_H_
Carl Shapiro6c21dc12011-06-20 15:20:52 -070019
Ian Rogerscf7f1912014-10-22 22:06:39 -070020#include <ostream>
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070021#include <sstream>
Ian Rogers700a4022014-05-19 16:49:03 -070022
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070023#include "android-base/logging.h"
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Carl Shapiro6c21dc12011-06-20 15:20:52 -070025
Ian Rogersc7dd2952014-10-21 23:31:19 -070026namespace art {
27
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070028// Make libbase's LogSeverity more easily available.
Andreas Gamped6e54bb2016-09-26 14:07:57 -070029using ::android::base::LogSeverity;
30using ::android::base::ScopedLogSeverity;
Ian Rogersc7dd2952014-10-21 23:31:19 -070031
David Sehrf57589f2016-10-17 10:09:33 -070032// Abort function.
33using AbortFunction = void(const char*);
34
Ian Rogersc7dd2952014-10-21 23:31:19 -070035// The members of this struct are the valid arguments to VLOG and VLOG_IS_ON in code,
36// and the "-verbose:" command line argument.
37struct LogVerbosity {
38 bool class_linker; // Enabled with "-verbose:class".
Mathieu Chartier66a55392016-02-19 10:25:39 -080039 bool collector;
Ian Rogersc7dd2952014-10-21 23:31:19 -070040 bool compiler;
Andreas Gampef3d1f942015-05-18 21:41:13 -070041 bool deopt;
Ian Rogersc7dd2952014-10-21 23:31:19 -070042 bool gc;
43 bool heap;
44 bool jdwp;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080045 bool jit;
Ian Rogersc7dd2952014-10-21 23:31:19 -070046 bool jni;
47 bool monitor;
Richard Uhler66d874d2015-01-15 09:37:19 -080048 bool oat;
Ian Rogersc7dd2952014-10-21 23:31:19 -070049 bool profiler;
50 bool signals;
Phil Wang751beff2015-08-28 15:17:15 +080051 bool simulator;
Ian Rogersc7dd2952014-10-21 23:31:19 -070052 bool startup;
53 bool third_party_jni; // Enabled with "-verbose:third-party-jni".
54 bool threads;
55 bool verifier;
Mathieu Chartierfbc31082016-01-24 11:59:56 -080056 bool image;
Andreas Gampec7ed09b2016-04-25 20:08:55 -070057 bool systrace_lock_logging; // Enabled with "-verbose:sys-locks".
Alex Light7233c7e2016-07-28 10:07:45 -070058 bool agents;
Ian Rogersc7dd2952014-10-21 23:31:19 -070059};
60
61// Global log verbosity setting, initialized by InitLogging.
62extern LogVerbosity gLogVerbosity;
63
Nicolas Geoffraydb978712014-12-09 13:33:38 +000064// 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive
65// aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown
66// makes forward progress.
67extern unsigned int gAborting;
68
Ian Rogersc7dd2952014-10-21 23:31:19 -070069// Configure logging based on ANDROID_LOG_TAGS environment variable.
70// We need to parse a string that looks like
71//
72// *:v jdwp:d dalvikvm:d dalvikvm-gc:i dalvikvmi:i
73//
74// The tag (or '*' for the global level) comes first, followed by a colon
75// and a letter indicating the minimum priority level we're expected to log.
76// This can be used to reveal or conceal logs with specific tags.
David Sehrf57589f2016-10-17 10:09:33 -070077extern void InitLogging(char* argv[], AbortFunction& default_aborter);
Ian Rogersc7dd2952014-10-21 23:31:19 -070078
Mathieu Chartier2cebb242015-04-21 16:50:40 -070079// Returns the command line used to invoke the current tool or null if InitLogging hasn't been
Ian Rogersc7dd2952014-10-21 23:31:19 -070080// performed.
81extern const char* GetCmdLine();
82
83// The command used to start the ART runtime, such as "/system/bin/dalvikvm". If InitLogging hasn't
84// been performed then just returns "art"
85extern const char* ProgramInvocationName();
86
87// A short version of the command used to start the ART runtime, such as "dalvikvm". If InitLogging
88// hasn't been performed then just returns "art"
89extern const char* ProgramInvocationShortName();
90
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070091class LogHelper {
92 public:
93 // A logging helper for logging a single line. Can be used with little stack.
94 static void LogLineLowStack(const char* file,
95 unsigned int line,
96 android::base::LogSeverity severity,
97 const char* msg);
Ian Rogersc7dd2952014-10-21 23:31:19 -070098
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070099 private:
100 DISALLOW_ALLOCATION();
101 DISALLOW_COPY_AND_ASSIGN(LogHelper);
102};
Ian Rogersc7dd2952014-10-21 23:31:19 -0700103
104// Is verbose logging enabled for the given module? Where the module is defined in LogVerbosity.
105#define VLOG_IS_ON(module) UNLIKELY(::art::gLogVerbosity.module)
106
107// Variant of LOG that logs when verbose logging is enabled for a module. For example,
108// VLOG(jni) << "A JNI operation was performed";
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700109#define VLOG(module) if (VLOG_IS_ON(module)) LOG(INFO)
Ian Rogersc7dd2952014-10-21 23:31:19 -0700110
111// Return the stream associated with logging for the given module.
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700112#define VLOG_STREAM(module) LOG_STREAM(INFO)
Andreas Gampe369810a2015-01-14 19:53:31 -0800113
Elliott Hughes3ea7e992011-10-11 18:48:16 -0700114} // namespace art
115
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700116#endif // ART_RUNTIME_BASE_LOGGING_H_