1 //===-- SubprocessMemory.h --------------------------------------*- C++ -*-===//
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-exception
7 //===----------------------------------------------------------------------===//
10 /// Defines a class that automatically handles auxiliary memory and the
11 /// underlying shared memory backings for memory definitions
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H
16 #define LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H
18 #include "BenchmarkResult.h"
20 #include <unordered_map>
26 #include <sys/types.h>
33 class SubprocessMemory
{
35 static constexpr const size_t AuxiliaryMemoryOffset
= 1;
36 static constexpr const size_t AuxiliaryMemorySize
= 4096;
38 Error
initializeSubprocessMemory(pid_t ProcessID
);
40 // The following function sets up memory definitions. It creates shared
41 // memory objects for the definitions and fills them with the specified
42 // values. Arguments: MemoryDefinitions - A map from memory value names to
43 // MemoryValues, ProcessID - The ID of the current process.
44 Error
addMemoryDefinition(
45 std::unordered_map
<std::string
, MemoryValue
> MemoryDefinitions
,
48 // The following function sets up the auxiliary memory by opening shared
49 // memory objects backing memory definitions and putting file descriptors
50 // into appropriate places. Arguments: MemoryDefinitions - A map from memory
51 // values names to Memoryvalues, ParentPID - The ID of the process that
52 // setup the memory definitions, CounterFileDescriptor - The file descriptor
53 // for the performance counter that will be placed in the auxiliary memory
55 static Expected
<int> setupAuxiliaryMemoryInSubprocess(
56 std::unordered_map
<std::string
, MemoryValue
> MemoryDefinitions
,
57 pid_t ParentPID
, int CounterFileDescriptor
);
62 std::vector
<std::string
> SharedMemoryNames
;
65 } // namespace exegesis