//===-- malloc_benchmark.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
//
//===----------------------------------------------------------------------===//

#include "allocator_config.h"
#include "combined.h"
#include "common.h"

#include "benchmark/benchmark.h"

#include <memory>
#include <vector>

void *CurrentAllocator;
template <typename Config> void PostInitCallback() {
  reinterpret_cast<scudo::Allocator<Config> *>(CurrentAllocator)->initGwpAsan();
}

template <typename Config> static void BM_malloc_free(benchmark::State &State) {
  using AllocatorT = scudo::Allocator<Config, PostInitCallback<Config>>;
  auto Deleter = [](AllocatorT *A) {
    A->unmapTestOnly();
    delete A;
  };
  std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
                                                           Deleter);
  CurrentAllocator = Allocator.get();
  Allocator->reset();

  const size_t NBytes = State.range(0);
  size_t PageSize = scudo::getPageSizeCached();

  for (auto _ : State) {
    void *Ptr = Allocator->allocate(NBytes, scudo::Chunk::Origin::Malloc);
    auto *Data = reinterpret_cast<uint8_t *>(Ptr);
    for (size_t I = 0; I < NBytes; I += PageSize)
      Data[I] = 1;
    benchmark::DoNotOptimize(Ptr);
    Allocator->deallocate(Ptr, scudo::Chunk::Origin::Malloc);
  }

  State.SetBytesProcessed(uint64_t(State.iterations()) * uint64_t(NBytes));
}

static const size_t MinSize = 8;
static const size_t MaxSize = 128 * 1024;

// FIXME: Add DefaultConfig here once we can tear down the exclusive TSD
// cleanly.
BENCHMARK_TEMPLATE(BM_malloc_free, scudo::AndroidConfig)
    ->Range(MinSize, MaxSize);
BENCHMARK_TEMPLATE(BM_malloc_free, scudo::AndroidSvelteConfig)
    ->Range(MinSize, MaxSize);
#if SCUDO_CAN_USE_PRIMARY64
BENCHMARK_TEMPLATE(BM_malloc_free, scudo::FuchsiaConfig)
    ->Range(MinSize, MaxSize);
#endif

template <typename Config>
static void BM_malloc_free_loop(benchmark::State &State) {
  using AllocatorT = scudo::Allocator<Config, PostInitCallback<Config>>;
  auto Deleter = [](AllocatorT *A) {
    A->unmapTestOnly();
    delete A;
  };
  std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
                                                           Deleter);
  CurrentAllocator = Allocator.get();
  Allocator->reset();

  const size_t NumIters = State.range(0);
  size_t PageSize = scudo::getPageSizeCached();
  std::vector<void *> Ptrs(NumIters);

  for (auto _ : State) {
    size_t SizeLog2 = 0;
    for (void *&Ptr : Ptrs) {
      Ptr = Allocator->allocate(1 << SizeLog2, scudo::Chunk::Origin::Malloc);
      auto *Data = reinterpret_cast<uint8_t *>(Ptr);
      for (size_t I = 0; I < 1 << SizeLog2; I += PageSize)
        Data[I] = 1;
      benchmark::DoNotOptimize(Ptr);
      SizeLog2 = (SizeLog2 + 1) % 16;
    }
    for (void *&Ptr : Ptrs)
      Allocator->deallocate(Ptr, scudo::Chunk::Origin::Malloc);
  }

  State.SetBytesProcessed(uint64_t(State.iterations()) * uint64_t(NumIters) *
                          8192);
}

static const size_t MinIters = 8;
static const size_t MaxIters = 32 * 1024;

// FIXME: Add DefaultConfig here once we can tear down the exclusive TSD
// cleanly.
BENCHMARK_TEMPLATE(BM_malloc_free_loop, scudo::AndroidConfig)
    ->Range(MinIters, MaxIters);
BENCHMARK_TEMPLATE(BM_malloc_free_loop, scudo::AndroidSvelteConfig)
    ->Range(MinIters, MaxIters);
#if SCUDO_CAN_USE_PRIMARY64
BENCHMARK_TEMPLATE(BM_malloc_free_loop, scudo::FuchsiaConfig)
    ->Range(MinIters, MaxIters);
#endif

BENCHMARK_MAIN();
