public unsafe void TestProfilerSessionEmitsMarkerInfoBeforeMarker()
        {
            SpoofInitListenInternal();
            Connection.ConnectDirect(spoofIp, spoofPort);
            Baselib_Timer_WaitForAtLeast(200);
            SpoofAcceptInternal();

            ProfilerTestFixture.ReceiveConnectMessage();

#if !NET_DOTS
            HashSet <uint> markerDefined = new HashSet <uint>();
#else
            Dictionary <uint, bool> markerDefined = new Dictionary <uint, bool>();
#endif

            for (int i = 0; i < 8; i++)
            {
                for (ulong j = 0; j < 8; j++)
                {
                    ProfilerMarker marker  = new ProfilerMarker($"{Baselib_Timer_GetHighPrecisionTimerTicks() + j} test");
                    ProfilerMarker marker2 = new ProfilerMarker($"{Baselib_Timer_GetHighPrecisionTimerTicks() + j + 1} test2");

                    marker.Begin();
                    marker2.Begin();
                    marker2.End();
                    marker.End();
                }

                ProfilerProtocolSession.SendNewMarkersAndThreads();
                SendAndValidate(markerDefined);
            }

            SpoofExitInternal();
        }
        public unsafe void TestNewFrameInThreadStreamNotSessionStream()
        {
            Assert.Zero(ProfilerProtocolSession.streamSession.buffer->m_BufferList->TotalBytes);

            ProfilerTestFixture.ReceiveConnectMessage();

            int sessionBytes = ProfilerProtocolSession.streamSession.buffer->m_BufferList->TotalBytes;

            Assert.NotZero(sessionBytes);
            Assert.Zero(ProfilerProtocolThread.Stream.buffer->m_BufferList->TotalBytes);

            ProfilerProtocolSession.SendNewFrame();

            Assert.NotZero(ProfilerProtocolThread.Stream.buffer->m_BufferList->TotalBytes);
            Assert.AreEqual(ProfilerProtocolSession.streamSession.buffer->m_BufferList->TotalBytes, sessionBytes);
        }
        public unsafe void TestProfilerSessionEmitsMarkerInfoBeforeMarkerThreaded()
        {
            SpoofInitListenInternal();
            Connection.ConnectDirect(spoofIp, spoofPort);
            Baselib_Timer_WaitForAtLeast(200);
            SpoofAcceptInternal();

            ProfilerTestFixture.ReceiveConnectMessage();

            ManualResetEvent mre           = new ManualResetEvent(false);
            HashSet <uint>   markerDefined = new HashSet <uint>();

            Thread[] threads = new Thread[16];
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    for (ulong g = 0; g < 8; g++)
                    {
                        mre.WaitOne();
                        ProfilerMarker marker  = new ProfilerMarker($"{Baselib_Timer_GetHighPrecisionTimerTicks() + g * 2} test");
                        ProfilerMarker marker2 = new ProfilerMarker($"{Baselib_Timer_GetHighPrecisionTimerTicks() + g * 2 + 1} test2");

                        marker.Begin();
                        marker2.Begin();
                        marker2.End();
                        marker.End();

                        Thread.Sleep(100);
                    }
                });
                threads[i].Start();
            }

            // This test is set up to try to make new markers get created in the midst of buffers being sent over
            // the player connection. If timed just right without proper locks, we can get into a situation where
            // marker begin sample and marker end sample messages are sent without the marker info having been sent first.
            // (It ends up in the next frame's player connection datastream)
            for (int g = 0; g < 16; g++)
            {
                if ((g & 1) == 0)
                {
                    mre.Set();
                }
                ProfilerProtocolSession.SendNewMarkersAndThreads();
                SendAndValidate(markerDefined);
                if ((g & 1) == 1)
                {
                    mre.Reset();
                }
                Thread.Sleep(50);
            }

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
            }

            ProfilerProtocolSession.SendNewMarkersAndThreads();
            SendAndValidate(markerDefined);

            SpoofExitInternal();
        }