llvm/compiler-rt/lib/xray/xray_basic_logging.cpp

//===-- xray_basic_logging.cpp ----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of XRay, a dynamic runtime instrumentation system.
//
// Implementation of a simple in-memory log of XRay events. This defines a
// logging function that's compatible with the XRay handler interface, and
// routines for exporting data to files.
//
//===----------------------------------------------------------------------===//

#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/stat.h>
#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_APPLE
#include <sys/syscall.h>
#endif
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

#include "sanitizer_common/sanitizer_allocator_internal.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "xray/xray_records.h"
#include "xray_recursion_guard.h"
#include "xray_basic_flags.h"
#include "xray_basic_logging.h"
#include "xray_defs.h"
#include "xray_flags.h"
#include "xray_interface_internal.h"
#include "xray_tsc.h"
#include "xray_utils.h"

namespace __xray {

static SpinMutex LogMutex;

namespace {
// We use elements of this type to record the entry TSC of every function ID we
// see as we're tracing a particular thread's execution.
struct alignas(16) StackEntry {};

static_assert;

struct XRAY_TLS_ALIGNAS(64) ThreadLocalData {};

struct BasicLoggingOptions {};
} // namespace

static pthread_key_t PThreadKey;

static atomic_uint8_t BasicInitialized{};

struct BasicLoggingOptions GlobalOptions;

thread_local atomic_uint8_t Guard{};

static atomic_uint8_t UseRealTSC{};
static atomic_uint64_t ThresholdTicks{};
static atomic_uint64_t TicksPerSec{};
static atomic_uint64_t CycleFrequency{};

static LogWriter *getLog() XRAY_NEVER_INSTRUMENT {}

static LogWriter *getGlobalLog() XRAY_NEVER_INSTRUMENT {}

static ThreadLocalData &getThreadLocalData() XRAY_NEVER_INSTRUMENT {}

template <class RDTSC>
void InMemoryRawLog(int32_t FuncId, XRayEntryType Type,
                    RDTSC ReadTSC) XRAY_NEVER_INSTRUMENT {}

template <class RDTSC>
void InMemoryRawLogWithArg(int32_t FuncId, XRayEntryType Type, uint64_t Arg1,
                           RDTSC ReadTSC) XRAY_NEVER_INSTRUMENT {}

void basicLoggingHandleArg0RealTSC(int32_t FuncId,
                                   XRayEntryType Type) XRAY_NEVER_INSTRUMENT {}

void basicLoggingHandleArg0EmulateTSC(int32_t FuncId, XRayEntryType Type)
    XRAY_NEVER_INSTRUMENT {}

void basicLoggingHandleArg1RealTSC(int32_t FuncId, XRayEntryType Type,
                                   uint64_t Arg1) XRAY_NEVER_INSTRUMENT {}

void basicLoggingHandleArg1EmulateTSC(int32_t FuncId, XRayEntryType Type,
                                      uint64_t Arg1) XRAY_NEVER_INSTRUMENT {}

static void TLDDestructor(void *P) XRAY_NEVER_INSTRUMENT {}

XRayLogInitStatus basicLoggingInit(UNUSED size_t BufferSize,
                                   UNUSED size_t BufferMax, void *Options,
                                   size_t OptionsSize) XRAY_NEVER_INSTRUMENT {}

XRayLogInitStatus basicLoggingFinalize() XRAY_NEVER_INSTRUMENT {}

XRayLogFlushStatus basicLoggingFlush() XRAY_NEVER_INSTRUMENT {}

// This is a handler that, effectively, does nothing.
void basicLoggingHandleArg0Empty(int32_t, XRayEntryType) XRAY_NEVER_INSTRUMENT {}

bool basicLogDynamicInitializer() XRAY_NEVER_INSTRUMENT {}

} // namespace __xray

static auto UNUSED Unused =;