Esempio n. 1
0
        private uint NativeCallback_EnqueueStackSnapshotBufferSegmentForExport(
            IntPtr segmentNativeObjectPtr,
            IntPtr segmentStartAddress,
            uint segmentByteCount,
            uint segmentSnapshotCount,
            ulong segmentUnixTimeUtcRangeStart,
            ulong segmentUnixTimeUtcRangeEnd)
        {
            StackSnapshotsBufferSegment segment = null;

            try
            {
                segment = new StackSnapshotsBufferSegment(
                    segmentNativeObjectPtr,
                    segmentStartAddress,
                    segmentByteCount,
                    segmentSnapshotCount,
                    segmentUnixTimeUtcRangeStart,
                    segmentUnixTimeUtcRangeEnd);

                StackSnapshotsBufferSegmentCollection completedStackSnapshots = GetCompletedStackSnapshots();
                bool isAdded = completedStackSnapshots != null && completedStackSnapshots.Add(segment);
                while (!isAdded)
                {
                    // If we get null, we are in a race on shutdown. There is nothing we can do, except just give up.
                    // We need will dispose the segment without calling native Release
                    // and return a failure code to indicate that we never kept a pointer in the first place.
                    if (completedStackSnapshots == null)
                    {
                        segment.DisposeWithoutNativeRelease();
                        segment = null;
                        return(HResult.E_CHANGED_STATE);
                    }

                    Thread.Yield();
                    completedStackSnapshots = GetCompletedStackSnapshots();
                    isAdded = completedStackSnapshots != null && completedStackSnapshots.Add(segment);
                }
            }
            catch (Exception ex)
            {
                Log.Error(LogSourceMoniker, ex);

                if (segment != null)
                {
                    segment.DisposeWithoutNativeRelease();
                }

                return(HResult.GetFailureCode(ex));
            }

            return(HResult.S_OK);
        }
Esempio n. 2
0
        public static uint SetCurrentManagedThreadName(IntPtr pThreadNameCharArr)
        {
            try
            {
                if (pThreadNameCharArr == IntPtr.Zero)
                {
                    return(HResult.E_INVALIDARG);
                }

                string threadName = Marshal.PtrToStringAnsi(pThreadNameCharArr);
                SetCurrentManagedThreadName(threadName);
                return(HResult.S_OK);
            }
            catch (Exception ex)
            {
                return(HResult.GetFailureCode(ex));
            }
        }