72 lines · c
1//===-- SubprocessMemory.h --------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// Defines a class that automatically handles auxiliary memory and the11/// underlying shared memory backings for memory definitions12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H16#define LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H17 18#include "BenchmarkResult.h"19#include <string>20#include <unordered_map>21#include <vector>22 23#ifdef _MSC_VER24typedef int pid_t;25#else26#include <sys/types.h>27#endif // _MSC_VER28 29 30namespace llvm {31namespace exegesis {32 33class SubprocessMemory {34public:35 static constexpr size_t AuxiliaryMemoryOffset = 1;36 static constexpr size_t AuxiliaryMemorySize = 4096;37 38 // Gets the thread ID for the calling thread.39 static long getCurrentTID();40 41 Error initializeSubprocessMemory(pid_t ProcessID);42 43 // The following function sets up memory definitions. It creates shared44 // memory objects for the definitions and fills them with the specified45 // values. Arguments: MemoryDefinitions - A map from memory value names to46 // MemoryValues, ProcessID - The ID of the current process.47 Error addMemoryDefinition(48 std::unordered_map<std::string, MemoryValue> MemoryDefinitions,49 pid_t ProcessID);50 51 // The following function sets up the auxiliary memory by opening shared52 // memory objects backing memory definitions and putting file descriptors53 // into appropriate places. Arguments: MemoryDefinitions - A map from memory54 // values names to Memoryvalues, ParentPID - The ID of the process that55 // setup the memory definitions, CounterFileDescriptor - The file descriptor56 // for the performance counter that will be placed in the auxiliary memory57 // section.58 static Expected<int> setupAuxiliaryMemoryInSubprocess(59 std::unordered_map<std::string, MemoryValue> MemoryDefinitions,60 pid_t ParentPID, long ParentTID, int CounterFileDescriptor);61 62 ~SubprocessMemory();63 64private:65 std::vector<std::string> SharedMemoryNames;66};67 68} // namespace exegesis69} // namespace llvm70 71#endif72