Exemplo n.º 1
0
        public static void UpdatePostFrame(bool willContinue)
        {
#if ENABLE_PROFILER
            ProfilerStats.CalculateStatsSnapshot();
#endif

#if ENABLE_PROFILER
            mainMarker.End();
            rootMarker.End();
#endif

#if ENABLE_PLAYERCONNECTION
            Connection.TransmitAndReceive();
#endif

#if ENABLE_PROFILER
            if (willContinue)
            {
                ProfilerProtocolSession.SendNewFrame();
                rootMarker.Begin();
                mainMarker.Begin();
            }
#endif

            TempMemoryScope.ExitScope();
        }
        public unsafe void CheckHeapWithExternalAlloc()
        {
            ProfilerStats.CalculateStatsSnapshot();
            int oldReservedKb = ProfilerStats.Stats.memoryStats.kbReservedTotal;
            int oldUsedKb     = ProfilerStats.Stats.memoryStats.kbUsedTotal;

            void *mem = UnsafeUtility.Malloc(16384, 16, Collections.Allocator.Persistent);

            // Fake an external allocation
            ProfilerStats.AccumStats.memReservedExternal.Accumulate(4096);
            ProfilerStats.AccumStats.memUsedExternal.Accumulate(3072);
            ProfilerStats.CalculateStatsSnapshot();

            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbReservedTotal, 16 + 4 + oldReservedKb);
            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbUsedTotal, 16 + 3 + oldUsedKb);

            UnsafeUtility.Free(mem, Collections.Allocator.Persistent);
            ProfilerStats.CalculateStatsSnapshot();

            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbReservedTotal, 4 + oldReservedKb);
            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbUsedTotal, 3 + oldUsedKb);

            ProfilerStats.AccumStats.memReservedExternal.value = 0;
            ProfilerStats.AccumStats.memUsedExternal.value     = 0;
        }
        public static unsafe void CheckNativeHeapStatsInternal()
        {
            ProfilerStats.CalculateStatsSnapshot();
            int oldKb = ProfilerStats.Stats.memoryStats.kbReservedTotal;

            UnsafeUtility.EnterTempScope();

            // Taking a stats snap shot should
            // a) Fill memory stats automatically since they are part of DOTS Runtime core
            // b) Convert all AccumStats (many of which are represented as longs) into Stats (required by current profiler stats protocol)

            void *mem  = UnsafeUtility.Malloc(2048, 16, Collections.Allocator.Persistent);
            void *mem2 = UnsafeUtility.Malloc(1024, 16, Collections.Allocator.Temp);

            ProfilerStats.CalculateStatsSnapshot();
            Assert.IsTrue((ProfilerStats.GatheredStats & ProfilerModes.ProfileMemory) != 0);
            // debug build padding could make it 3 or 4 kb
            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbReservedTotal, 3 + oldKb);

            UnsafeUtility.Free(mem, Collections.Allocator.Persistent);
            ProfilerStats.CalculateStatsSnapshot();
            // debug build padding could make it 1 or 2 kb
            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbReservedTotal, 1 + oldKb);

            // Freeing a temp allocation should not adjust stats (you don't technically need to, and it
            // can cause fake leaks)
            UnsafeUtility.Free(mem2, Collections.Allocator.Temp);
            ProfilerStats.CalculateStatsSnapshot();
            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbReservedTotal, 1 + oldKb);

            // This should adjust stats - it's meant to be fast and release all temp allocations in scope
            UnsafeUtility.ExitTempScope();
            ProfilerStats.CalculateStatsSnapshot();
            Assert.IsTrue(ProfilerStats.Stats.memoryStats.kbReservedTotal == oldKb);
        }
        public unsafe void CheckAccumulationError()
        {
            ProfilerStats.CalculateStatsSnapshot();
            int oldKb = ProfilerStats.Stats.memoryStats.kbReservedTotal;

            void *mem  = UnsafeUtility.Malloc(1024 + 256, 16, Collections.Allocator.Persistent);
            void *mem2 = UnsafeUtility.Malloc(1024 + 256, 16, Collections.Allocator.Persistent);
            void *mem3 = UnsafeUtility.Malloc(1024 + 256, 16, Collections.Allocator.Persistent);
            void *mem4 = UnsafeUtility.Malloc(1024 + 256, 16, Collections.Allocator.Persistent);

            ProfilerStats.CalculateStatsSnapshot();

            // Ensure 5, not 4
            AssertHeapKbRange(ProfilerStats.Stats.memoryStats.kbReservedTotal, 5 + oldKb);

            UnsafeUtility.Free(mem, Collections.Allocator.Persistent);
            UnsafeUtility.Free(mem2, Collections.Allocator.Persistent);
            UnsafeUtility.Free(mem3, Collections.Allocator.Persistent);
            UnsafeUtility.Free(mem4, Collections.Allocator.Persistent);
            ProfilerStats.CalculateStatsSnapshot();

            Assert.IsTrue(ProfilerStats.Stats.memoryStats.kbReservedTotal == oldKb);
        }