37dd2562ec
-- 8bdb2020150ed0fd4a4e520e454dc5f54e33f776 by Eric Fiselier <ericwf@google.com>: Workaround bug in GCC 9.2 and after. PiperOrigin-RevId: 291982551 -- 47ff4820e595f96c082a90d733725f6882d83e3b by Abseil Team <absl-team@google.com>: Improve ABSL_ATTRIBUTE_PACKED documentation Recommend to apply ABSL_ATTRIBUTE_PACKED to structure members instead of to an entire structure because applying this attribute to an entire structure may cause the compiler to generate suboptimal code. It reduces the alignment of the data structure from a value larger than one to one. When applied to a structure, ABSL_ATTRIBUTE_PACKED reduces the alignment of a structure (alignof()) to 1. As a result, the compiler can no longer assume that e.g. uint32 members are aligned on a four byte boundary and hence is forced to use single-byte load and store instructions on CPU architectures that do not support non-aligned loads or stores. PiperOrigin-RevId: 291977920 -- 902b7a86f860da699d3a2e5c738be5ef73ede3b4 by Mark Barolak <mbar@google.com>: Internal change PiperOrigin-RevId: 291963048 -- bb3bd3247e376d53a3080b105f13ec7566d3ae50 by Abseil Team <absl-team@google.com>: Support the C++17 insert_or_assign() API in btree_map. PiperOrigin-RevId: 291945474 -- ff3b3cfcbbc64f086f95501f48d49426bcde356f by Gennadiy Rozental <rogeeff@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 291861110 -- fd465cd9cbbacd3962f67a7346d6462edaddd809 by Derek Mauro <dmauro@google.com>: Add flaky=1 to beta_distribution_test. PiperOrigin-RevId: 291757364 -- 3603adfb59c4128c542b670952cce250d59e1f67 by Derek Mauro <dmauro@google.com>: Separate the initialization of NumCPUs() and NominalCPUFrequency() The OSS version of Abseil never needs to call NominalCPUFrequency(). In some configurations, initializing NominalCPUFrequency() requires spending at least 3ms measuring the CPU frequency. By separating the initialization from NumCPUs(), which is called in most configurations, we can save at least 3ms of program startup time. PiperOrigin-RevId: 291737273 -- bea9e4a6bff5a0351d340deab966641867e08c4d by Abseil Team <absl-team@google.com>: Change the cmake library names not to have a redundant `absl_` prefix. PiperOrigin-RevId: 291640501 -- 501b602ef260cd7c8c527342581ceffb3c5b6d4c by Gennadiy Rozental <rogeeff@google.com>: Introducing benchmark for absl::GetFlag. PiperOrigin-RevId: 291433394 -- 4eeaddc788da4b91c272a8adca77ca6dbbbc1d44 by Xiaoyi Zhang <zhangxy@google.com>: fix: Add support for more ARM processors detection Import of https://github.com/abseil/abseil-cpp/pull/608 PiperOrigin-RevId: 291420397 -- a3087a8e883c5d71de7d9bd4ec8f4db5142dfcf5 by Derek Mauro <dmauro@google.com>: Removes the flaky raw_hash_set prefetch test PiperOrigin-RevId: 291197079 -- aad6c2121c102ac36216e771c83227cf3e3bfd66 by Andy Soffer <asoffer@google.com>: Enable building Abseil as a DLL. This is currently experimental and unsupported. This CL does a few things: 1. Adds the ABSL_DLL macro to any class holding a static data member, or to global constants in headers. 2. Adds a whitelist of all files in the DLL and all the build targets that are conglomerated into the DLL. 3. When BUILD_SHARED_LIBS is specified, any build target that would be in the DLL still exists, but we swap out all of it's dependencies so it just depends on abseil_dll PiperOrigin-RevId: 291192055 -- 5e888cd6f2a7722805d41f872108a03a84e421c7 by Mark Barolak <mbar@google.com>: Move absl/strings/internal/escaping.{cc,h} into internal build targets. This puts absl/strings/internal/escaping.h behind a whitelist and it also resolves https://github.com/abseil/abseil-cpp/issues/604. PiperOrigin-RevId: 291173320 -- 166836d24970da87587c1728036f53f05a28f0af by Eric Fiselier <ericwf@google.com>: Internal Change. PiperOrigin-RevId: 291012718 -- 996ddb3dffda02440fa93f30ca5d71b14b688875 by Abseil Team <absl-team@google.com>: Fix shared libraries log spam for built-in types in absl::GetFlag PiperOrigin-RevId: 290772743 GitOrigin-RevId: 8bdb2020150ed0fd4a4e520e454dc5f54e33f776 Change-Id: I8bf2265dd14ebbace220a1b6b982bb5040ad2a26
182 lines
8.6 KiB
C++
182 lines
8.6 KiB
C++
// Copyright 2017 The Abseil Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
// Thread-safe logging routines that do not allocate any memory or
|
|
// acquire any locks, and can therefore be used by low-level memory
|
|
// allocation, synchronization, and signal-handling code.
|
|
|
|
#ifndef ABSL_BASE_INTERNAL_RAW_LOGGING_H_
|
|
#define ABSL_BASE_INTERNAL_RAW_LOGGING_H_
|
|
|
|
#include <string>
|
|
|
|
#include "absl/base/attributes.h"
|
|
#include "absl/base/config.h"
|
|
#include "absl/base/internal/atomic_hook.h"
|
|
#include "absl/base/log_severity.h"
|
|
#include "absl/base/macros.h"
|
|
#include "absl/base/optimization.h"
|
|
#include "absl/base/port.h"
|
|
|
|
// This is similar to LOG(severity) << format..., but
|
|
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
|
// * it is designed to be a low-level logger that does not allocate any
|
|
// memory and does not need any locks, hence:
|
|
// * it logs straight and ONLY to STDERR w/o buffering
|
|
// * it uses an explicit printf-format and arguments list
|
|
// * it will silently chop off really long message strings
|
|
// Usage example:
|
|
// ABSL_RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
|
|
// This will print an almost standard log line like this to stderr only:
|
|
// E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
|
|
|
#define ABSL_RAW_LOG(severity, ...) \
|
|
do { \
|
|
constexpr const char* absl_raw_logging_internal_basename = \
|
|
::absl::raw_logging_internal::Basename(__FILE__, \
|
|
sizeof(__FILE__) - 1); \
|
|
::absl::raw_logging_internal::RawLog(ABSL_RAW_LOGGING_INTERNAL_##severity, \
|
|
absl_raw_logging_internal_basename, \
|
|
__LINE__, __VA_ARGS__); \
|
|
} while (0)
|
|
|
|
// Similar to CHECK(condition) << message, but for low-level modules:
|
|
// we use only ABSL_RAW_LOG that does not allocate memory.
|
|
// We do not want to provide args list here to encourage this usage:
|
|
// if (!cond) ABSL_RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
|
// so that the args are not computed when not needed.
|
|
#define ABSL_RAW_CHECK(condition, message) \
|
|
do { \
|
|
if (ABSL_PREDICT_FALSE(!(condition))) { \
|
|
ABSL_RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
|
} \
|
|
} while (0)
|
|
|
|
// ABSL_INTERNAL_LOG and ABSL_INTERNAL_CHECK work like the RAW variants above,
|
|
// except that if the richer log library is linked into the binary, we dispatch
|
|
// to that instead. This is potentially useful for internal logging and
|
|
// assertions, where we are using RAW_LOG neither for its async-signal-safety
|
|
// nor for its non-allocating nature, but rather because raw logging has very
|
|
// few other dependencies.
|
|
//
|
|
// The API is a subset of the above: each macro only takes two arguments. Use
|
|
// StrCat if you need to build a richer message.
|
|
#define ABSL_INTERNAL_LOG(severity, message) \
|
|
do { \
|
|
::absl::raw_logging_internal::internal_log_function( \
|
|
ABSL_RAW_LOGGING_INTERNAL_##severity, __FILE__, __LINE__, message); \
|
|
} while (0)
|
|
|
|
#define ABSL_INTERNAL_CHECK(condition, message) \
|
|
do { \
|
|
if (ABSL_PREDICT_FALSE(!(condition))) { \
|
|
std::string death_message = "Check " #condition " failed: "; \
|
|
death_message += std::string(message); \
|
|
ABSL_INTERNAL_LOG(FATAL, death_message); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define ABSL_RAW_LOGGING_INTERNAL_INFO ::absl::LogSeverity::kInfo
|
|
#define ABSL_RAW_LOGGING_INTERNAL_WARNING ::absl::LogSeverity::kWarning
|
|
#define ABSL_RAW_LOGGING_INTERNAL_ERROR ::absl::LogSeverity::kError
|
|
#define ABSL_RAW_LOGGING_INTERNAL_FATAL ::absl::LogSeverity::kFatal
|
|
#define ABSL_RAW_LOGGING_INTERNAL_LEVEL(severity) \
|
|
::absl::NormalizeLogSeverity(severity)
|
|
|
|
namespace absl {
|
|
ABSL_NAMESPACE_BEGIN
|
|
namespace raw_logging_internal {
|
|
|
|
// Helper function to implement ABSL_RAW_LOG
|
|
// Logs format... at "severity" level, reporting it
|
|
// as called from file:line.
|
|
// This does not allocate memory or acquire locks.
|
|
void RawLog(absl::LogSeverity severity, const char* file, int line,
|
|
const char* format, ...) ABSL_PRINTF_ATTRIBUTE(4, 5);
|
|
|
|
// Writes the provided buffer directly to stderr, in a safe, low-level manner.
|
|
//
|
|
// In POSIX this means calling write(), which is async-signal safe and does
|
|
// not malloc. If the platform supports the SYS_write syscall, we invoke that
|
|
// directly to side-step any libc interception.
|
|
void SafeWriteToStderr(const char *s, size_t len);
|
|
|
|
// compile-time function to get the "base" filename, that is, the part of
|
|
// a filename after the last "/" or "\" path separator. The search starts at
|
|
// the end of the string; the second parameter is the length of the string.
|
|
constexpr const char* Basename(const char* fname, int offset) {
|
|
return offset == 0 || fname[offset - 1] == '/' || fname[offset - 1] == '\\'
|
|
? fname + offset
|
|
: Basename(fname, offset - 1);
|
|
}
|
|
|
|
// For testing only.
|
|
// Returns true if raw logging is fully supported. When it is not
|
|
// fully supported, no messages will be emitted, but a log at FATAL
|
|
// severity will cause an abort.
|
|
//
|
|
// TODO(gfalcon): Come up with a better name for this method.
|
|
bool RawLoggingFullySupported();
|
|
|
|
// Function type for a raw_logging customization hook for suppressing messages
|
|
// by severity, and for writing custom prefixes on non-suppressed messages.
|
|
//
|
|
// The installed hook is called for every raw log invocation. The message will
|
|
// be logged to stderr only if the hook returns true. FATAL errors will cause
|
|
// the process to abort, even if writing to stderr is suppressed. The hook is
|
|
// also provided with an output buffer, where it can write a custom log message
|
|
// prefix.
|
|
//
|
|
// The raw_logging system does not allocate memory or grab locks. User-provided
|
|
// hooks must avoid these operations, and must not throw exceptions.
|
|
//
|
|
// 'severity' is the severity level of the message being written.
|
|
// 'file' and 'line' are the file and line number where the ABSL_RAW_LOG macro
|
|
// was located.
|
|
// 'buffer' and 'buf_size' are pointers to the buffer and buffer size. If the
|
|
// hook writes a prefix, it must increment *buffer and decrement *buf_size
|
|
// accordingly.
|
|
using LogPrefixHook = bool (*)(absl::LogSeverity severity, const char* file,
|
|
int line, char** buffer, int* buf_size);
|
|
|
|
// Function type for a raw_logging customization hook called to abort a process
|
|
// when a FATAL message is logged. If the provided AbortHook() returns, the
|
|
// logging system will call abort().
|
|
//
|
|
// 'file' and 'line' are the file and line number where the ABSL_RAW_LOG macro
|
|
// was located.
|
|
// The NUL-terminated logged message lives in the buffer between 'buf_start'
|
|
// and 'buf_end'. 'prefix_end' points to the first non-prefix character of the
|
|
// buffer (as written by the LogPrefixHook.)
|
|
using AbortHook = void (*)(const char* file, int line, const char* buf_start,
|
|
const char* prefix_end, const char* buf_end);
|
|
|
|
// Internal logging function for ABSL_INTERNAL_LOG to dispatch to.
|
|
//
|
|
// TODO(gfalcon): When string_view no longer depends on base, change this
|
|
// interface to take its message as a string_view instead.
|
|
using InternalLogFunction = void (*)(absl::LogSeverity severity,
|
|
const char* file, int line,
|
|
const std::string& message);
|
|
|
|
ABSL_DLL extern base_internal::AtomicHook<InternalLogFunction>
|
|
internal_log_function;
|
|
|
|
void RegisterInternalLogFunction(InternalLogFunction func);
|
|
|
|
} // namespace raw_logging_internal
|
|
ABSL_NAMESPACE_END
|
|
} // namespace absl
|
|
|
|
#endif // ABSL_BASE_INTERNAL_RAW_LOGGING_H_
|