зеркало из https://github.com/microsoft/BPerf.git
Prepare uprobe support
This commit is contained in:
Родитель
5f0ae944c6
Коммит
5933fb1744
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "3.1.100",
|
||||
"version": "3.1.401",
|
||||
"rollForward": "latestPatch",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
namespace BPerfCPUSamplesCollector
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static NativeMethods;
|
||||
|
||||
internal readonly ref struct PerfEventDescriptors
|
||||
|
@ -32,5 +33,11 @@ namespace BPerfCPUSamplesCollector
|
|||
CloseFileDescriptor(this.data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public void KeepAlive()
|
||||
{
|
||||
// dummy method to silence intellisense warning
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
for (var i = 0; i < ringBuffers.Length; ++i)
|
||||
{
|
||||
AssociateBPFMapWithRingBuffer(i, perfeventmap.FileDescriptor, in ringBuffers[i]);
|
||||
AssociateBPFMapWithRingBuffer(perfeventmap.FileDescriptor, i, in ringBuffers[i]);
|
||||
}
|
||||
|
||||
Span<int> dict = stackalloc int[7]; // TODO: FIXME Hard Coded number!
|
||||
|
@ -94,7 +94,7 @@ namespace BPerfCPUSamplesCollector
|
|||
{
|
||||
Type = PerfEventType.PERF_TYPE_SOFTWARE,
|
||||
Config = PerfTypeSpecificConfig.PERF_COUNT_SW_CPU_CLOCK,
|
||||
Flags = PerfEventAttrFlags.Freq,
|
||||
Flags = PerfEventAttrFlags.Freq | PerfEventAttrFlags.MMap | PerfEventAttrFlags.MMap2,
|
||||
SampleFreq = 99,
|
||||
};
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace BPerfCPUSamplesCollector
|
|||
if (numberOfReadyFileDescriptors < 0)
|
||||
{
|
||||
ConsoleWriteLine(in Strings.EPollWaitFailed);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
for (var i = 0; i < numberOfReadyFileDescriptors; ++i)
|
||||
|
@ -125,7 +125,7 @@ namespace BPerfCPUSamplesCollector
|
|||
}
|
||||
}
|
||||
|
||||
perffds.Dispose();
|
||||
perffds.KeepAlive();
|
||||
}
|
||||
|
||||
private static unsafe void ProcessRingBuffer(IntPtr data, int length)
|
||||
|
@ -189,17 +189,22 @@ namespace BPerfCPUSamplesCollector
|
|||
// 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)
|
||||
{
|
||||
var attr = new PerfEventAttr
|
||||
if (System.Buffers.Text.Utf8Parser.TryParse(new ReadOnlyLinuxFile(in Strings.UProbeType).Contents, out int dynamicPMU, out _))
|
||||
{
|
||||
Type = (PerfEventType)10,
|
||||
SamplePeriod = 1,
|
||||
WakeupEvents = 1,
|
||||
UProbePath = probePath,
|
||||
ProbeOffset = probeOffsetInELFFile,
|
||||
Size = Unsafe.SizeOf<PerfEventAttr>(),
|
||||
};
|
||||
var attr = new PerfEventAttr
|
||||
{
|
||||
Type = (PerfEventType)dynamicPMU,
|
||||
SamplePeriod = 1,
|
||||
WakeupEvents = 1,
|
||||
UProbePath = probePath,
|
||||
ProbeOffset = probeOffsetInELFFile,
|
||||
Size = Unsafe.SizeOf<PerfEventAttr>(),
|
||||
};
|
||||
|
||||
return PerfEventOpen(in attr, cpu);
|
||||
return PerfEventOpen(in attr, cpu);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static bool AddEPollMonitor(int epfd, int index, in RingBuffer r)
|
||||
|
@ -233,7 +238,7 @@ namespace BPerfCPUSamplesCollector
|
|||
return epfd;
|
||||
}
|
||||
|
||||
private static bool AssociateBPFMapWithRingBuffer(int cpu, int mapfd, in RingBuffer r)
|
||||
private static bool AssociateBPFMapWithRingBuffer(int mapfd, int cpu, in RingBuffer r)
|
||||
{
|
||||
if (BPFUpdateElem(mapfd, in cpu, in r.FileDescriptor) == -1)
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace BPerfCPUSamplesCollector
|
|||
SetRLimitFailed = 68719477152,
|
||||
StacksEBF = 47244640689,
|
||||
StatXError = 150323855805,
|
||||
UProbeType = 176093659617,
|
||||
}
|
||||
|
||||
public static ref readonly byte BPFCreatePerCPUArrayError => ref GetCString(Key.BPFCreatePerCPUArrayError);
|
||||
|
@ -60,6 +61,8 @@ namespace BPerfCPUSamplesCollector
|
|||
|
||||
public static ref readonly byte StatXError => ref GetCString(Key.StatXError);
|
||||
|
||||
public static ref readonly byte UProbeType => ref GetCString(Key.UProbeType);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static ref readonly byte GetCString(Key arg)
|
||||
{
|
||||
|
@ -92,7 +95,8 @@ namespace BPerfCPUSamplesCollector
|
|||
0x6c,0x6c,0x5f,0x77,0x61,0x69,0x74,0x20,0x66,0x61,0x69,0x6c,0x65,0x64,0x2e,0x00,0x47,0x50,0x4c,0x00,0x0a,0x00,0x69,0x6f,0x63,0x74,0x6c,0x20,0x74,0x6f,0x20,0x65,0x6e,0x61,0x62,0x6c,0x65,0x20,0x70,0x65,
|
||||
0x72,0x66,0x20,0x65,0x76,0x65,0x6e,0x74,0x20,0x66,0x61,0x69,0x6c,0x65,0x64,0x00,0x73,0x65,0x74,0x72,0x6c,0x69,0x6d,0x69,0x74,0x20,0x66,0x61,0x69,0x6c,0x65,0x64,0x00,0x73,0x74,0x61,0x63,0x6b,0x73,0x2e,
|
||||
0x65,0x62,0x70,0x66,0x00,0x53,0x74,0x61,0x74,0x58,0x20,0x53,0x79,0x73,0x74,0x65,0x6d,0x20,0x43,0x61,0x6c,0x6c,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x65,0x64,0x20,0x61,0x6e,0x20,0x65,0x72,0x72,0x6f,0x72,
|
||||
0x00,
|
||||
0x00,0x2f,0x73,0x79,0x73,0x2f,0x62,0x75,0x73,0x2f,0x65,0x76,0x65,0x6e,0x74,0x5f,0x73,0x6f,0x75,0x72,0x63,0x65,0x2f,0x64,0x65,0x76,0x69,0x63,0x65,0x73,0x2f,0x75,0x70,0x72,0x6f,0x62,0x65,0x2f,0x74,0x79,
|
||||
0x70,0x65,0x00,
|
||||
});
|
||||
|
||||
return ref Unsafe.AsRef<byte>(data[offset]);
|
||||
|
|
|
@ -163,4 +163,7 @@
|
|||
<data name="StatXError" xml:space="preserve">
|
||||
<value>StatX System Call returned an error</value>
|
||||
</data>
|
||||
<data name="UProbeType" xml:space="preserve">
|
||||
<value>/sys/bus/event_source/devices/uprobe/type</value>
|
||||
</data>
|
||||
</root>
|
|
@ -834,11 +834,15 @@ HRESULT STDMETHODCALLTYPE BPerfProfilerCallback::DynamicMethodUnloaded(FunctionI
|
|||
|
||||
HRESULT STDMETHODCALLTYPE BPerfProfilerCallback::EventPipeEventDelivered(EVENTPIPE_PROVIDER provider, DWORD eventId, DWORD eventVersion, ULONG cbMetadataBlob, LPCBYTE metadataBlob, ULONG cbEventData, LPCBYTE eventData, LPCGUID pActivityId, LPCGUID pRelatedActivityId, ThreadID eventThread, ULONG numStackFrames, UINT_PTR stackFrames[])
|
||||
{
|
||||
this->corProfilerInfo->Even
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE BPerfProfilerCallback::EventPipeProviderCreated(EVENTPIPE_PROVIDER provider)
|
||||
{
|
||||
ULONG cchName;
|
||||
this->corProfilerInfo->
|
||||
IfFailRet(this->corProfilerInfo->EventPipeGetProviderInfo(provider, 0, &cchName, nullptr));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -296,6 +296,8 @@ private:
|
|||
std::atomic<size_t> numberOfFrozenSegments;
|
||||
|
||||
portable_wide_string reportOutOfBandMessage;
|
||||
|
||||
thread_local std::unordered_map<EVENTPIPE_PROVIDER, portable_wide_string>
|
||||
};
|
||||
|
||||
template <class TInterface>
|
||||
|
|
Загрузка…
Ссылка в новой задаче