public unsafe void CheckShutdownFrees()
        {
            // (because of PlayerConnectionTestFixture.PerTestSetUp)
            MessageStreamManager.DestroyStreamBuilder(messageBuilder);

            // Kill any buffers already registered from the profiler system
            MessageStreamManager.Shutdown();

            long sizePreInit = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent);

            // Start fresh
            MessageStreamManager.Initialize();

            // The pointers returned by these 2 methods will get lost surely...
            MessageStreamManager.CreateStreamBuilder();
            MessageStreamManager.CreateStreamBuilder();
            long sizeCreate = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent);

            MessageStreamManager.Shutdown();

            long sizeShutdown = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent);

            // (because of PlayerConnectionTestFixture.PerTestTearDown)
            // (also do this prior to asserts in case of test failure so tear down doesn't fail and we miss the real issue)
            MessageStreamManager.Initialize();
            messageBuilder = MessageStreamManager.CreateStreamBuilder();

            Assert.IsTrue(sizePreInit < sizeCreate);
            Assert.IsTrue(sizePreInit == sizeShutdown);
        }
예제 #2
0
        public unsafe void UnsafeUtilityReallocDoesntLeak()
        {
            long  oldSize = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent);
            byte *data    = (byte *)UnsafeUtility.Malloc(128, 16, Collections.Allocator.Persistent);

            data = (byte *)UnsafeUtility.Realloc(data, 256, 16, Collections.Allocator.Persistent);
            UnsafeUtility.Free(data, Collections.Allocator.Persistent);
            Assert.AreEqual(oldSize, UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent));
        }
예제 #3
0
        public unsafe void UnsafeUtilityReallocNull()
        {
            long  oldSize = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent);
            void *data    = null;

            Assert.DoesNotThrow(() => data = (byte *)UnsafeUtility.Realloc(null, 256, 16, Collections.Allocator.Persistent));
            Assert.IsTrue(UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent) >= oldSize + 256);
            UnsafeUtility.Free(data, Collections.Allocator.Persistent);
            Assert.AreEqual(oldSize, UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent));
        }
예제 #4
0
        public void Run3SimpleJobsInSerial()
        {
#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            // Note the safety handles use Persistent, so only track TempJob
            long heapMem = UnsafeUtility.GetHeapSize(Allocator.TempJob);
#endif
            NativeArray <int> input      = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);
            NativeArray <int> jobResult1 = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);
            NativeArray <int> jobResult2 = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);
            NativeArray <int> jobResult3 = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);

            for (int i = 0; i < SimpleAddSerial.N; ++i)
            {
                input[i] = i;
            }

            SimpleAddSerial job1 = new SimpleAddSerial()
            {
                a = 1, input = input, result = jobResult1
            };
            SimpleAddSerial job2 = new SimpleAddSerial()
            {
                a = 2, input = jobResult1, result = jobResult2
            };
            SimpleAddSerial job3 = new SimpleAddSerial()
            {
                a = 3, input = jobResult2, result = jobResult3
            };

#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            Assert.IsFalse(JobsUtility.InJob);
#endif

            JobHandle handle1 = job1.Schedule();
            JobHandle handle2 = job2.Schedule(handle1);
            JobHandle handle3 = job3.Schedule(handle2);

            handle3.Complete();

#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            Assert.IsFalse(JobsUtility.InJob);
#endif

            for (int i = 0; i < SimpleAddSerial.N; ++i)
            {
                Assert.AreEqual(i + 1 + 2 + 3, jobResult3[i]);
            }

            jobResult3.Dispose();

#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            long postWork = UnsafeUtility.GetHeapSize(Allocator.TempJob);
            Assert.IsTrue(heapMem == postWork);    // make sure cleanup happened, including DeallocateOnJobCompletion
#endif
        }
예제 #5
0
        public unsafe void UnsafeUtilityReallocSize0()
        {
            long  oldSize = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent);
            byte *data    = (byte *)UnsafeUtility.Malloc(128, 16, Collections.Allocator.Persistent);

            data = (byte *)UnsafeUtility.Realloc(data, 256, 16, Collections.Allocator.Persistent);
            // Should be equivalent to free
            data = (byte *)UnsafeUtility.Realloc(data, 0, 0, Collections.Allocator.Persistent);
            Assert.AreEqual(oldSize, UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent));
            Assert.IsTrue(data == null);
        }
예제 #6
0
        public static void CalculateStatsSnapshot()
        {
            long memReserved = UnsafeUtility.GetHeapSize(Collections.Allocator.Persistent) + UnsafeUtility.GetHeapSize(Collections.Allocator.Temp) + UnsafeUtility.GetHeapSize(Collections.Allocator.TempJob);

            memReserved += AccumStats.memReservedExternal.value;

            long memUsed = memReserved
                           - (AccumStats.memReservedExternal.value - AccumStats.memUsedExternal.value)
                           - (AccumStats.memReservedProfiler.value - AccumStats.memUsedProfiler.value)
                           //- (AccumStats.memReservedUnity.value - AccumStats.memUsedUnity.value)  // always 0 in DOTS Runtime
                           //- (AccumStats.memReservedMono.value - AccumStats.memUsedMono.value)    // always 0 in DOTS Runtime
                           - (AccumStats.memReservedGFX.value - AccumStats.memUsedGFX.value)
                           - (AccumStats.memReservedVideo.value - AccumStats.memUsedVideo.value)
                           - (AccumStats.memReservedAudio.value - AccumStats.memUsedAudio.value);

            Stats.memoryStats.kbUsedTotal        = (int)(memUsed / 1024);
            Stats.memoryStats.kbUsedUnity        = (int)(AccumStats.memUsedUnity.value / 1024);
            Stats.memoryStats.kbUsedMono         = (int)(AccumStats.memUsedMono.value / 1024);
            Stats.memoryStats.kbUsedGFX          = (int)(AccumStats.memUsedGFX.value / 1024);
            Stats.memoryStats.kbUsedAudio        = (int)(AccumStats.memUsedAudio.value / 1024);
            Stats.memoryStats.kbUsedVideo        = (int)(AccumStats.memUsedVideo.value / 1024);
            Stats.memoryStats.kbUsedProfiler     = (int)(AccumStats.memUsedProfiler.value / 1024);
            Stats.memoryStats.kbReservedTotal    = (int)(memReserved / 1024);
            Stats.memoryStats.kbReservedUnity    = (int)(AccumStats.memReservedUnity.value / 1024);
            Stats.memoryStats.kbReservedMono     = (int)(AccumStats.memReservedMono.value / 1024);
            Stats.memoryStats.kbReservedGFX      = (int)(AccumStats.memReservedGFX.value / 1024);
            Stats.memoryStats.kbReservedAudio    = (int)(AccumStats.memReservedAudio.value / 1024);
            Stats.memoryStats.kbReservedVideo    = (int)(AccumStats.memReservedVideo.value / 1024);
            Stats.memoryStats.kbReservedProfiler = (int)(AccumStats.memReservedProfiler.value / 1024);
            Stats.memoryStats.kbVirtual          = (int)(AccumStats.memVirtual.value / 1024);
            Stats.memoryStats.textureKB          = (int)(AccumStats.memTexture.value / 1024);
            Stats.memoryStats.textureCount       = (int)AccumStats.memTextureCount.value;
            Stats.memoryStats.meshKB             = (int)(AccumStats.memMesh.value / 1024);
            Stats.memoryStats.meshCount          = (int)AccumStats.memMeshCount.value;
            Stats.memoryStats.materialKB         = (int)(AccumStats.memMaterial.value / 1024);
            Stats.memoryStats.materialCount      = (int)AccumStats.memMaterialCount.value;
            Stats.memoryStats.animationClipKB    = (int)(AccumStats.memAnimationClip.value / 1024);
            Stats.memoryStats.animationClipCount = (int)AccumStats.memAnimationClipCount.value;
            Stats.memoryStats.audioKB            = (int)(AccumStats.memAudio.value / 1024);
            Stats.memoryStats.audioCount         = (int)AccumStats.memAudioCount.value;
            Stats.memoryStats.frameGCAllocKB     = (int)(AccumStats.memFrameGCAlloc.value / 1024);
            Stats.memoryStats.assetCount         = Stats.memoryStats.textureCount + Stats.memoryStats.meshCount +
                                                   Stats.memoryStats.materialCount + Stats.memoryStats.audioCount + Stats.memoryStats.animationClipCount;

            Stats.memoryStats.classCount = 0;
            Stats.memoryStats.classEnd   = -1;

            // This is the only set of stats we always gather in DOTS Runtime.
            // Other enabled bit flags should be set by the relative subsystem.
            GatheredStats |= ProfilerModes.ProfileMemory;

            Stats.debugStats.m_AllocatedProfileSamples = ProfilerProtocolSession.TotalMarkers;
            Stats.debugStats.m_GpuProfilingStatisticsAvailabilityStates = (int)GpuProfilingStatisticsAvailabilityStates.NotSupportedByGraphicsAPI;
#if UNITY_WINDOWS
            Stats.debugStats.m_RuntimePlatform = (int)RuntimePlatform.WindowsPlayer;
#elif UNITY_MACOSX
            Stats.debugStats.m_RuntimePlatform = (int)RuntimePlatform.OSXPlayer;
#elif UNITY_LINUX
            Stats.debugStats.m_RuntimePlatform = (int)RuntimePlatform.LinuxPlayer;
#elif UNITY_IOS
            Stats.debugStats.m_RuntimePlatform = (int)RuntimePlatform.IPhonePlayer;
#elif UNITY_ANDROID
            Stats.debugStats.m_RuntimePlatform = (int)RuntimePlatform.Android;
#elif UNITY_WEBGL
            Stats.debugStats.m_RuntimePlatform = (int)RuntimePlatform.WebGLPlayer;
#endif

            // If ProfilerModes.ProfileAudio is disabled, these will continue to be 0
            Stats.audioStats.playingSources           = (int)AccumStats.audioPlayingSources.value;
            Stats.audioStats.pausedSources            = (int)AccumStats.audioPausedSources.value;
            Stats.audioStats.totalAudioSourceCount    = Stats.audioStats.playingSources + Stats.audioStats.pausedSources;
            Stats.audioStats.audioClipCount           = Stats.memoryStats.audioCount;
            Stats.audioStats.numSoundChannelInstances = (int)AccumStats.audioNumSoundChannelInstances.value;
            Stats.audioStats.sampleMemory             = (int)AccumStats.audioSampleMemory.value;
            Stats.audioStats.streamDecodeMemory       = (int)AccumStats.audioStreamDecodeMemory.value;
            Stats.audioStats.streamFileMemory         = (int)AccumStats.audioStreamFileMemory.value;
            Stats.audioStats.codecMemory      = (int)AccumStats.audioCodecMemory.value;
            Stats.audioStats.otherMemory      = (int)AccumStats.audioOtherMemory.value;
            Stats.audioStats.totalMemoryUsage = Stats.audioStats.sampleMemory + Stats.audioStats.streamFileMemory + Stats.audioStats.streamDecodeMemory
                                                + Stats.audioStats.otherMemory + Stats.audioStats.codecMemory;
            Stats.audioStats.streamCPUx10 = (int)AccumStats.audioStreamCPUx10.value;
            Stats.audioStats.dspCPUx10    = (int)AccumStats.audioDspCPUx10.value;
            Stats.audioStats.otherCPUx10  = (int)AccumStats.audioOtherCPUx10.value;
            Stats.audioStats.totalCPUx10  = Stats.audioStats.dspCPUx10 + Stats.audioStats.otherCPUx10 + Stats.audioStats.streamCPUx10;
        }