зеркало из https://github.com/microsoft/BPerf.git
Naming convention changes
This commit is contained in:
Родитель
5933fb1744
Коммит
8e372f2343
|
@ -27,10 +27,15 @@
|
|||
<Compile Include="BPF\BPFProgType.cs" />
|
||||
<Compile Include="BPF\BPFRegister.cs" />
|
||||
<Compile Include="BPF\BPFUpdateMapAttr.cs" />
|
||||
<Compile Include="ELF64\ELFProgramHeader.cs" />
|
||||
<Compile Include="ELF64\ELFSectionHeader.cs" />
|
||||
<Compile Include="ELF64\ELFHeader.cs" />
|
||||
<Compile Include="ELF64\ElfSectionFlags.cs" />
|
||||
<Compile Include="EPoll\EPollEvent.cs" />
|
||||
<Compile Include="EPoll\EPollFlags.cs" />
|
||||
<Compile Include="LinuxFileDescriptor.cs" />
|
||||
<Compile Include="PerfEventDescriptors.cs" />
|
||||
<Compile Include="PerfEvents\PerfBranchSampleTypeShift.cs" />
|
||||
<Compile Include="ReadOnlyLinuxFile.cs" />
|
||||
<Compile Include="PerfEvents\ClockConstants.cs" />
|
||||
<Compile Include="PerfEvents\PerfBranchSampleType.cs" />
|
||||
|
@ -41,8 +46,8 @@
|
|||
<Compile Include="PerfEvents\PerfEventMMapPage.cs" />
|
||||
<Compile Include="PerfEvents\PerfEventReadFormat.cs" />
|
||||
<Compile Include="PerfEvents\PerfEventSampleFormat.cs" />
|
||||
<Compile Include="PerfEvents\PerfTypeId.cs" />
|
||||
<Compile Include="PerfEvents\PerfEventType.cs" />
|
||||
<Compile Include="PerfEvents\PerfRecordType.cs" />
|
||||
<Compile Include="PerfEvents\PerfTypeSpecificConfig.cs" />
|
||||
<Compile Include="RingBuffer.cs" />
|
||||
<Compile Include="RLimit\RLimit.cs" />
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
using System;
|
||||
|
||||
internal enum ELFHeaderType : ushort
|
||||
{
|
||||
Relocatable = 1,
|
||||
Executable = 2,
|
||||
Shared = 3,
|
||||
Core = 4,
|
||||
}
|
||||
|
||||
internal struct ELFHeader
|
||||
{
|
||||
public static ReadOnlySpan<byte> ElfMagic => new byte[] { 0x7F, (byte)'E', (byte)'L', (byte)'F', (byte)'\0' };
|
||||
|
||||
public unsafe fixed char Identity[16]; /* ELF identification */
|
||||
public ELFHeaderType Type; // e_type; /* Object file type */
|
||||
public ushort Machine; // e_machine; /* Machine type */
|
||||
public uint Version; // e_version; /* Object file version */
|
||||
public ulong EntryPoint; // e_entry; /* Entry point address */
|
||||
public ulong ProgramHeaderOffset; // e_phoff; /* Program header offset */
|
||||
public ulong SectionHeaderOffset; // e_shoff; /* Section header offset */
|
||||
public uint Flags; // e_flags; /* Processor-specific flags */
|
||||
public ushort EHSize; // e_ehsize; /* ELF header size */
|
||||
public ushort ProgramHeaderEntrySize; // e_phentsize; /* Size of program header entry */
|
||||
public ushort ProgramHeaderCount; // e_phnum; /* Number of program header entries */
|
||||
public ushort SectionHeaderEntrySize; // e_shentsize; /* Size of section header entry */
|
||||
public ushort SectionHeaderCount; // e_shnum; /* Number of section header entries */
|
||||
public ushort SectionHeaderStringIndex; // e_shstrndx; /* Section name string table index */
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
internal enum ELFProgramHeaderType : uint
|
||||
{
|
||||
Null = 0,
|
||||
Load = 1,
|
||||
Dynamic = 2,
|
||||
Interp = 3,
|
||||
Note = 4,
|
||||
Shlib = 5,
|
||||
Phdr = 6,
|
||||
}
|
||||
|
||||
internal struct ELFProgramHeader
|
||||
{
|
||||
public ELFProgramHeaderType Type; // p_type /* Type of segment */
|
||||
public uint Flags; // p_flags /* Segment attributes */
|
||||
public ulong FileOffset; // p_offset /* Offset in file */
|
||||
public ulong VirtualAddress; // p_vaddr /* Virtual address in memory */
|
||||
public ulong PhysicalAddress; // p_paddr /* Reserved */
|
||||
public ulong FileSize; // p_filesz /* Size of segment in file */
|
||||
public ulong VirtualSize; // p_memsz /* Size of segment in memory */
|
||||
public ulong Alignment; // p_align /* Alignment of segment */
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
internal enum ELFSectionHeaderType : uint
|
||||
{
|
||||
Null = 0,
|
||||
ProgBits = 1,
|
||||
SymTab = 2,
|
||||
StrTab = 3,
|
||||
Rela = 4,
|
||||
Hash = 5,
|
||||
Dynamic = 6,
|
||||
Note = 7,
|
||||
NoBits = 8,
|
||||
Rel = 9,
|
||||
ShLib = 10,
|
||||
DynSym = 11,
|
||||
InitArray = 14,
|
||||
FiniArray = 15,
|
||||
PreInitArray = 16,
|
||||
Group = 17,
|
||||
SymTabIndexes = 18,
|
||||
Num = 19,
|
||||
GnuAttributes = 0x6ffffff5,
|
||||
GnuHash = 0x6ffffff6,
|
||||
GnuLibList = 0x6ffffff7,
|
||||
CheckSum = 0x6ffffff8,
|
||||
GnuVerDef = 0x6ffffffd,
|
||||
GnuVerNeed = 0x6ffffffe,
|
||||
GnuVerSym = 0x6fffffff,
|
||||
}
|
||||
|
||||
internal struct ELFSectionHeader
|
||||
{
|
||||
public uint NameIndex; // sh_name
|
||||
public ELFSectionHeaderType Type; // sh_type
|
||||
public ulong Flags; // sh_flags
|
||||
public ulong VirtualAddress; // sh_addr
|
||||
public ulong FileOffset; // sh_offset
|
||||
public ulong FileSize; // sh_size
|
||||
public uint Link; // sh_link
|
||||
public uint Info; // sh_info
|
||||
public ulong Alignment; // sh_addralign
|
||||
public ulong EntrySize; // sh_entsize
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
internal enum ElfSectionFlags : uint
|
||||
{
|
||||
// Section data should be writable during execution.
|
||||
SHF_WRITE = 0x1,
|
||||
|
||||
// Section occupies memory during program execution.
|
||||
SHF_ALLOC = 0x2,
|
||||
|
||||
// Section contains executable machine instructions.
|
||||
SHF_EXECINSTR = 0x4,
|
||||
|
||||
// The data in this section may be merged.
|
||||
SHF_MERGE = 0x10,
|
||||
|
||||
// The data in this section is null-terminated strings.
|
||||
SHF_STRINGS = 0x20,
|
||||
|
||||
// A field in this section holds a section header table index.
|
||||
SHF_INFO_LINK = 0x40U,
|
||||
|
||||
// Adds special ordering requirements for link editors.
|
||||
SHF_LINK_ORDER = 0x80U,
|
||||
|
||||
// This section requires special OS-specific processing to avoid incorrect
|
||||
// behavior.
|
||||
SHF_OS_NONCONFORMING = 0x100U,
|
||||
|
||||
// This section is a member of a section group.
|
||||
SHF_GROUP = 0x200U,
|
||||
|
||||
// This section holds Thread-Local Storage.
|
||||
SHF_TLS = 0x400U,
|
||||
|
||||
// Identifies a section containing compressed data.
|
||||
SHF_COMPRESSED = 0x800U,
|
||||
|
||||
// This section is excluded from the final executable or shared library.
|
||||
SHF_EXCLUDE = 0x80000000U,
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
var syscallNumber = RuntimeInformation.OSArchitecture switch
|
||||
{
|
||||
Architecture.Arm => 364,
|
||||
Architecture.Arm64 => 241,
|
||||
Architecture.X64 => 298,
|
||||
_ => throw new NotSupportedException()
|
||||
|
|
|
@ -8,13 +8,23 @@ namespace BPerfCPUSamplesCollector
|
|||
[Flags]
|
||||
internal enum PerfBranchSampleType : ulong
|
||||
{
|
||||
PERF_SAMPLE_BRANCH_USER = 1U << 0,
|
||||
PERF_SAMPLE_BRANCH_KERNEL = 1U << 1,
|
||||
PERF_SAMPLE_BRANCH_HV = 1U << 2,
|
||||
PERF_SAMPLE_BRANCH_ANY = 1U << 3,
|
||||
PERF_SAMPLE_BRANCH_ANY_CALL = 1U << 4,
|
||||
PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << 5,
|
||||
PERF_SAMPLE_BRANCH_IND_CALL = 1U << 6,
|
||||
PERF_SAMPLE_BRANCH_MAX = 1U << 7,
|
||||
PERF_SAMPLE_BRANCH_USER = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_USER_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_KERNEL = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_KERNEL_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_HV = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_HV_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_ANY = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_ANY_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_ANY_CALL = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_IND_CALL = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_ABORT_TX = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_IN_TX = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_IN_TX_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_NO_TX = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_NO_TX_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_COND = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_COND_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_CALL = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_CALL_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_TYPE_SAVE = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT,
|
||||
PERF_SAMPLE_BRANCH_MAX = 1U << PerfBranchSampleTypeShift.PERF_SAMPLE_BRANCH_MAX_SHIFT,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
// perf_branch_sample_type_shift
|
||||
internal enum PerfBranchSampleTypeShift
|
||||
{
|
||||
PERF_SAMPLE_BRANCH_USER_SHIFT = 0, /* user branches */
|
||||
PERF_SAMPLE_BRANCH_KERNEL_SHIFT = 1, /* kernel branches */
|
||||
PERF_SAMPLE_BRANCH_HV_SHIFT = 2, /* hypervisor branches */
|
||||
PERF_SAMPLE_BRANCH_ANY_SHIFT = 3, /* any branch types */
|
||||
PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT = 4, /* any call branch */
|
||||
PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT = 5, /* any return branch */
|
||||
PERF_SAMPLE_BRANCH_IND_CALL_SHIFT = 6, /* indirect calls */
|
||||
PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT = 7, /* transaction aborts */
|
||||
PERF_SAMPLE_BRANCH_IN_TX_SHIFT = 8, /* in transaction */
|
||||
PERF_SAMPLE_BRANCH_NO_TX_SHIFT = 9, /* not in transaction */
|
||||
PERF_SAMPLE_BRANCH_COND_SHIFT = 10, /* conditional branches */
|
||||
PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* call/ret stack */
|
||||
PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT = 12, /* indirect jumps */
|
||||
PERF_SAMPLE_BRANCH_CALL_SHIFT = 13, /* direct call */
|
||||
PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT = 14, /* no flags */
|
||||
PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT = 15, /* no cycles */
|
||||
PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT = 16, /* save branch type */
|
||||
PERF_SAMPLE_BRANCH_MAX_SHIFT, /* non-ABI */
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// perf_event_attr
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct PerfEventAttr
|
||||
{
|
||||
|
@ -12,13 +13,13 @@ namespace BPerfCPUSamplesCollector
|
|||
/// Type of event
|
||||
/// </summary>
|
||||
[FieldOffset(0)]
|
||||
public PerfEventType Type;
|
||||
public PerfTypeId Type;
|
||||
|
||||
/// <summary>
|
||||
/// Size of attribute structure
|
||||
/// </summary>
|
||||
[FieldOffset(4)]
|
||||
public int Size;
|
||||
public uint Size;
|
||||
|
||||
/// <summary>
|
||||
/// Type-specific configuration.
|
||||
|
@ -87,7 +88,7 @@ namespace BPerfCPUSamplesCollector
|
|||
public ulong KProbeFunc;
|
||||
|
||||
/// <summary>
|
||||
/// for perf_uprobe
|
||||
/// for perf_uprobe (added in 4.17)
|
||||
/// </summary>
|
||||
[FieldOffset(56)]
|
||||
public ulong UProbePath;
|
||||
|
@ -105,7 +106,7 @@ namespace BPerfCPUSamplesCollector
|
|||
public ulong BPLen;
|
||||
|
||||
/// <summary>
|
||||
/// with kprobe_func == NULL
|
||||
/// with kprobe_func == NULL (added in 4.17)
|
||||
/// </summary>
|
||||
[FieldOffset(64)]
|
||||
public ulong KProbeAddr;
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
using System;
|
||||
|
||||
// perf_event_attr_flags
|
||||
[Flags]
|
||||
internal enum PerfEventAttrFlags : ulong
|
||||
{
|
||||
|
@ -47,7 +48,9 @@ namespace BPerfCPUSamplesCollector
|
|||
ContextSwitch = 1 << 26, /* context switch data */
|
||||
WriteBackward = 1 << 27, /* Write ring buffer from end to beginning */
|
||||
Namespaces = 1 << 28, /* include namespaces data */
|
||||
KSymbol = 1 << 29, /* context switch data */
|
||||
BPF_Event = 1 << 30, /* include bpf events */
|
||||
KSymbol = 1 << 29, // 5.1 /* context switch data */
|
||||
BPFEvent = 1 << 30, // 5.1 /* include bpf events */
|
||||
AUXOutput = 1UL << 31, // 5.4 /* generate AUX records instead of events */
|
||||
CGroup = 1UL << 32, // 5.7 /* include cgroup events */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace BPerfCPUSamplesCollector
|
|||
using System;
|
||||
|
||||
[Flags]
|
||||
internal enum PerfEventBreakpointType
|
||||
internal enum PerfEventBreakpointType : uint
|
||||
{
|
||||
HW_BREAKPOINT_EMPTY = 0,
|
||||
HW_BREAKPOINT_R = 1,
|
||||
|
|
|
@ -5,11 +5,12 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// perf_event_header
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct PerfEventHeader
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public PerfRecordType Type;
|
||||
public PerfEventType Type;
|
||||
|
||||
[FieldOffset(4)]
|
||||
public ushort Misc;
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// perf_event_mmap_page
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct PerfEventMMapPage
|
||||
{
|
||||
|
@ -38,9 +39,9 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
public unsafe fixed byte Reserved[(118 * 8) + 4];
|
||||
|
||||
public long DataHead;
|
||||
public ulong DataHead;
|
||||
|
||||
public long DataTail;
|
||||
public ulong DataTail;
|
||||
|
||||
public ulong DataOffset;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
using System;
|
||||
|
||||
// perf_event_read_format
|
||||
[Flags]
|
||||
internal enum PerfEventReadFormat : ulong
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
using System;
|
||||
|
||||
// perf_event_sample_format
|
||||
[Flags]
|
||||
internal enum PerfEventSampleFormat : ulong
|
||||
{
|
||||
|
@ -28,7 +29,8 @@ namespace BPerfCPUSamplesCollector
|
|||
PERF_SAMPLE_TRANSACTION = 1U << 17,
|
||||
PERF_SAMPLE_REGS_INTR = 1U << 18,
|
||||
PERF_SAMPLE_PHYS_ADDR = 1U << 19,
|
||||
PERF_SAMPLE_AUX = 1U << 20,
|
||||
PERF_SAMPLE_MAX = 1U << 21,
|
||||
PERF_SAMPLE_AUX = 1U << 20, // 5.5
|
||||
PERF_SAMPLE_CGROUP = 1U << 21, // 5.7
|
||||
PERF_SAMPLE_MAX = 1U << 22, /* non-ABI */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,29 @@
|
|||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
internal enum PerfEventType : ulong
|
||||
// perf_event_type
|
||||
internal enum PerfEventType : uint
|
||||
{
|
||||
PERF_TYPE_HARDWARE = 0,
|
||||
PERF_TYPE_SOFTWARE = 1,
|
||||
PERF_TYPE_TRACEPOINT = 2,
|
||||
PERF_TYPE_HW_CACHE = 3,
|
||||
PERF_TYPE_RAW = 4,
|
||||
PERF_TYPE_BREAKPOINT = 5,
|
||||
PERF_RECORD_MMAP = 1,
|
||||
PERF_RECORD_LOST = 2,
|
||||
PERF_RECORD_COMM = 3,
|
||||
PERF_RECORD_EXIT = 4,
|
||||
PERF_RECORD_THROTTLE = 5,
|
||||
PERF_RECORD_UNTHROTTLE = 6,
|
||||
PERF_RECORD_FORK = 7,
|
||||
PERF_RECORD_READ = 8,
|
||||
PERF_RECORD_SAMPLE = 9,
|
||||
PERF_RECORD_MMAP2 = 10,
|
||||
PERF_RECORD_AUX = 11,
|
||||
PERF_RECORD_ITRACE_START = 12,
|
||||
PERF_RECORD_LOST_SAMPLES = 13,
|
||||
PERF_RECORD_SWITCH = 14,
|
||||
PERF_RECORD_SWITCH_CPU_WIDE = 15,
|
||||
PERF_RECORD_NAMESPACES = 16,
|
||||
PERF_RECORD_KSYMBOL = 17, // 5.1
|
||||
PERF_RECORD_BPF_EVENT = 18, // 5.1
|
||||
PERF_RECORD_CGROUP = 19, // 5.7
|
||||
PERF_RECORD_TEXT_POKE = 20, // 5.9
|
||||
PERF_RECORD_MAX,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
internal enum PerfRecordType : uint
|
||||
{
|
||||
PERF_RECORD_MMAP = 1,
|
||||
PERF_RECORD_LOST = 2,
|
||||
PERF_RECORD_COMM = 3,
|
||||
PERF_RECORD_EXIT = 4,
|
||||
PERF_RECORD_THROTTLE = 5,
|
||||
PERF_RECORD_UNTHROTTLE = 6,
|
||||
PERF_RECORD_FORK = 7,
|
||||
PERF_RECORD_READ = 8,
|
||||
PERF_RECORD_SAMPLE = 9,
|
||||
PERF_RECORD_MMAP2 = 10,
|
||||
PERF_RECORD_AUX = 11,
|
||||
PERF_RECORD_ITRACE_START = 12,
|
||||
PERF_RECORD_LOST_SAMPLES = 13,
|
||||
PERF_RECORD_SWITCH = 14,
|
||||
PERF_RECORD_SWITCH_CPU_WIDE = 15,
|
||||
PERF_RECORD_NAMESPACES = 16,
|
||||
PERF_RECORD_KSYMBOL = 17,
|
||||
PERF_RECORD_BPF_EVENT = 18,
|
||||
PERF_RECORD_MAX,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
// perf_type_id
|
||||
internal enum PerfTypeId : uint
|
||||
{
|
||||
PERF_TYPE_HARDWARE = 0,
|
||||
PERF_TYPE_SOFTWARE = 1,
|
||||
PERF_TYPE_TRACEPOINT = 2,
|
||||
PERF_TYPE_HW_CACHE = 3,
|
||||
PERF_TYPE_RAW = 4,
|
||||
PERF_TYPE_BREAKPOINT = 5,
|
||||
PERF_TYPE_MAX, /* non-ABI */
|
||||
}
|
||||
}
|
|
@ -48,7 +48,15 @@ namespace BPerfCPUSamplesCollector
|
|||
return;
|
||||
}
|
||||
|
||||
using var ringBuffers = new RingBuffers(stackalloc RingBuffer[GetNumberOfConfiguredPrcoessors()]);
|
||||
using var ringBuffers = new RingBuffers(
|
||||
new PerfEventAttr
|
||||
{
|
||||
SampleType = PerfEventSampleFormat.PERF_SAMPLE_RAW,
|
||||
Type = PerfTypeId.PERF_TYPE_SOFTWARE,
|
||||
Config = PerfTypeSpecificConfig.PERF_COUNT_SW_BPF_OUTPUT,
|
||||
SamplePeriod = 1,
|
||||
WakeupEvents = 1000,
|
||||
}, stackalloc RingBuffer[GetNumberOfConfiguredPrcoessors()]);
|
||||
|
||||
for (var i = 0; i < ringBuffers.Length; ++i)
|
||||
{
|
||||
|
@ -92,7 +100,7 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
var attr = new PerfEventAttr
|
||||
{
|
||||
Type = PerfEventType.PERF_TYPE_SOFTWARE,
|
||||
Type = PerfTypeId.PERF_TYPE_SOFTWARE,
|
||||
Config = PerfTypeSpecificConfig.PERF_COUNT_SW_CPU_CLOCK,
|
||||
Flags = PerfEventAttrFlags.Freq | PerfEventAttrFlags.MMap | PerfEventAttrFlags.MMap2,
|
||||
SampleFreq = 99,
|
||||
|
@ -120,7 +128,7 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
for (var i = 0; i < numberOfReadyFileDescriptors; ++i)
|
||||
{
|
||||
IntPtr ptr = ringBuffers[events[i].Index].Address;
|
||||
var ptr = ringBuffers[events[i].Index].Address;
|
||||
ProcessRingBuffer(ptr, 4096);
|
||||
}
|
||||
}
|
||||
|
@ -130,9 +138,9 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
private static unsafe void ProcessRingBuffer(IntPtr data, int length)
|
||||
{
|
||||
byte* copyMem = stackalloc byte[64 * 1024];
|
||||
var copyMem = stackalloc byte[64 * 1024];
|
||||
|
||||
ref PerfEventMMapPage mmapPage = ref MemoryMarshal.AsRef<PerfEventMMapPage>(new Span<byte>((void*)data, length));
|
||||
ref var mmapPage = ref MemoryMarshal.AsRef<PerfEventMMapPage>(new Span<byte>((void*)data, length));
|
||||
|
||||
var dataHead = Volatile.Read(ref mmapPage.DataHead);
|
||||
|
||||
|
@ -164,7 +172,7 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
ProcessPerfRecord(eventHeader);
|
||||
|
||||
dataTail += eventHeaderSize;
|
||||
dataTail += (ulong)eventHeaderSize;
|
||||
}
|
||||
|
||||
Volatile.Write(ref mmapPage.DataTail, dataTail);
|
||||
|
@ -178,7 +186,7 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
ptr += sizeof(int);
|
||||
|
||||
ref readonly BPerfEvent bperfevent = ref MemoryMarshal.AsRef<BPerfEvent>(new ReadOnlySpan<byte>(ptr, rawSize));
|
||||
ref readonly var bperfevent = ref MemoryMarshal.AsRef<BPerfEvent>(new ReadOnlySpan<byte>(ptr, rawSize));
|
||||
|
||||
Console.WriteLine($"Type: {data->Type}, Size: {data->Size}, Misc: {data->Misc}, Raw Size: {rawSize}");
|
||||
Console.WriteLine(bperfevent);
|
||||
|
@ -187,18 +195,18 @@ namespace BPerfCPUSamplesCollector
|
|||
// uprobe, tracepoint, bpf output set wakeup=1, sample_period=1
|
||||
// makese sense because we want all uprobes tracepoint and bpf outputs to wake up
|
||||
// maybe bpf output needs to be revisited, it should be sample period 1 but watermark more
|
||||
private static int CreateUProbePerfEvent(int cpu, ulong probeOffsetInELFFile, ulong probePath)
|
||||
private static int CreateUProbePerfEvent(int cpu, ulong probeOffsetInElfFile, ulong probePath)
|
||||
{
|
||||
if (System.Buffers.Text.Utf8Parser.TryParse(new ReadOnlyLinuxFile(in Strings.UProbeType).Contents, out int dynamicPMU, out _))
|
||||
{
|
||||
var attr = new PerfEventAttr
|
||||
{
|
||||
Type = (PerfEventType)dynamicPMU,
|
||||
Type = (PerfTypeId)dynamicPMU,
|
||||
SamplePeriod = 1,
|
||||
WakeupEvents = 1,
|
||||
UProbePath = probePath,
|
||||
ProbeOffset = probeOffsetInELFFile,
|
||||
Size = Unsafe.SizeOf<PerfEventAttr>(),
|
||||
ProbeOffset = probeOffsetInElfFile,
|
||||
Size = (uint)Unsafe.SizeOf<PerfEventAttr>(),
|
||||
};
|
||||
|
||||
return PerfEventOpen(in attr, cpu);
|
||||
|
@ -260,6 +268,30 @@ namespace BPerfCPUSamplesCollector
|
|||
// talks about ksyms
|
||||
// loads perf_event_mmap_header
|
||||
// bpf_perf_event_print
|
||||
|
||||
/*
|
||||
* // DebugFS is the filesystem type for debugfs.
|
||||
DebugFS = "debugfs"
|
||||
|
||||
// TraceFS is the filesystem type for tracefs.
|
||||
TraceFS = "tracefs"
|
||||
|
||||
// ProcMounts is the mount point for file systems in procfs.
|
||||
ProcMounts = "/proc/mounts"
|
||||
|
||||
// PerfMaxStack is the mount point for the max perf event size.
|
||||
PerfMaxStack = "/proc/sys/kernel/perf_event_max_stack"
|
||||
|
||||
// PerfMaxContexts is a sysfs mount that contains the max perf contexts.
|
||||
PerfMaxContexts = "/proc/sys/kernel/perf_event_max_contexts_per_stack"
|
||||
|
||||
// SyscallsDir is a constant of the default tracing event syscalls directory.
|
||||
SyscallsDir = "/sys/kernel/debug/tracing/events/syscalls/"
|
||||
|
||||
// TracingDir is a constant of the default tracing directory.
|
||||
TracingDir = "/sys/kernel/debug/tracing"
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,17 +10,8 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
private readonly ReadOnlySpan<RingBuffer> data;
|
||||
|
||||
public RingBuffers(Span<RingBuffer> space)
|
||||
public RingBuffers(in PerfEventAttr attr, Span<RingBuffer> space)
|
||||
{
|
||||
var attr = new PerfEventAttr
|
||||
{
|
||||
SampleType = PerfEventSampleFormat.PERF_SAMPLE_RAW,
|
||||
Type = PerfEventType.PERF_TYPE_SOFTWARE,
|
||||
Config = PerfTypeSpecificConfig.PERF_COUNT_SW_BPF_OUTPUT,
|
||||
SamplePeriod = 1,
|
||||
WakeupEvents = 1000,
|
||||
};
|
||||
|
||||
for (var i = 0; i < space.Length; ++i)
|
||||
{
|
||||
var pmufd = PerfEventOpen(in attr, i);
|
||||
|
|
Загрузка…
Ссылка в новой задаче