llvm/llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.cpp

//===------- JITLoaderPerf.cpp - Register profiler objects ------*- 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
//
//===----------------------------------------------------------------------===//
//
// Register objects for access by profilers via the perf JIT interface.
//
//===----------------------------------------------------------------------===//

#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h"

#include "llvm/ExecutionEngine/Orc/Shared/PerfSharedStructs.h"

#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Threading.h"

#include <mutex>
#include <optional>

#ifdef __linux__

#include <sys/mman.h> // mmap()
#include <time.h>     // clock_gettime(), time(), localtime_r() */
#include <unistd.h>   // for read(), close()

#define DEBUG_TYPE

// language identifier (XXX: should we generate something better from debug
// info?)
#define JIT_LANG
#define LLVM_PERF_JIT_MAGIC
#define LLVM_PERF_JIT_VERSION

usingnamespacellvm;
usingnamespacellvm::orc;

struct PerfState {};

// prevent concurrent dumps from messing up the output file
static std::mutex Mutex;
static std::optional<PerfState> State;

struct RecHeader {};

struct DIR {};

struct DIE {};

struct CLR {};

struct UWR {};

static inline uint64_t timespec_to_ns(const struct timespec *TS) {}

static inline uint64_t perf_get_timestamp() {}

static void writeDebugRecord(const PerfJITDebugInfoRecord &DebugRecord) {}

static void writeCodeRecord(const PerfJITCodeLoadRecord &CodeRecord) {}

static void
writeUnwindRecord(const PerfJITCodeUnwindingInfoRecord &UnwindRecord) {}

static Error registerJITLoaderPerfImpl(const PerfJITRecordBatch &Batch) {}

struct Header {};

static Error OpenMarker(PerfState &State) {}

void CloseMarker(PerfState &State) {}

static Expected<Header> FillMachine(PerfState &State) {}

static Error InitDebuggingDir(PerfState &State) {}

static Error registerJITLoaderPerfStartImpl() {}

static Error registerJITLoaderPerfEndImpl() {}

extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfImpl(const char *Data, uint64_t Size) {}

extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfStart(const char *Data, uint64_t Size) {}

extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfEnd(const char *Data, uint64_t Size) {}

#else

using namespace llvm;
using namespace llvm::orc;

static Error badOS() {
  using namespace llvm;
  return llvm::make_error<StringError>(
      "unsupported OS (perf support is only available on linux!)",
      inconvertibleErrorCode());
}

static Error badOSBatch(PerfJITRecordBatch &Batch) { return badOS(); }

extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfImpl(const char *Data, uint64_t Size) {
  using namespace shared;
  return WrapperFunction<SPSError(SPSPerfJITRecordBatch)>::handle(Data, Size,
                                                                  badOSBatch)
      .release();
}

extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfStart(const char *Data, uint64_t Size) {
  using namespace shared;
  return WrapperFunction<SPSError()>::handle(Data, Size, badOS).release();
}

extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfEnd(const char *Data, uint64_t Size) {
  using namespace shared;
  return WrapperFunction<SPSError()>::handle(Data, Size, badOS).release();
}

#endif