示例#1
0
        unsafe void UpdateTree(int threadIndex)
        {
            if (!m_MergedStackFrames.IsCreated)
            {
                m_MergedSamples     = new NativeArray <SampleData>(m_Trace.Samples, Allocator.Persistent);
                m_MergedStackFrames = new NativeList <StackFrameData>(Allocator.Persistent);
                new MergeCallStacksJob {
                    MergeBy        = MergeCallStacksJob.MergeMode.ByFunction,
                    NewStackFrames = m_MergedStackFrames,
                    Samples        = m_MergedSamples,
                    StackFrames    = m_Trace.StackFrames
                }.Run();
            }

            if (m_TreeDataPerThread.Count <= threadIndex || !m_TreeDataPerThread[threadIndex].Frames.IsCreated)
            {
                var threadCollection = new CollectThreadStackFrames
                {
                    Thread          = threadIndex,
                    Samples         = m_MergedSamples,
                    StackFrames     = m_MergedStackFrames,
                    FramesInThread  = new NativeList <StackFrameSamples>(Allocator.TempJob),
                    SamplesInThread = new NativeList <SampleData>(Allocator.TempJob)
                };
                threadCollection.Run();
                var frames  = threadCollection.FramesInThread.ToArray(Allocator.Persistent);
                var samples = threadCollection.SamplesInThread.ToArray(Allocator.Persistent);

                threadCollection.FramesInThread.Dispose();
                threadCollection.SamplesInThread.Dispose();

                var computeTreeJob = new ComputeTreeIndices <StackFrameSamples, StackFrameSamplesTree>
                {
                    Data = frames,
                    Tree = new StackFrameSamplesTree(),
                };
                computeTreeJob.AllocateTreeIndex(Allocator.Persistent);
                computeTreeJob.Run();

                new SortTree <SortByTotal>
                {
                    Sorter = new SortByTotal
                    {
                        Samples = (StackFrameSamples *)frames.GetUnsafeReadOnlyPtr(),
                    },
                    Tree = computeTreeJob.Indices
                }.Schedule(computeTreeJob.Indices.DataIndexToChildren.Length, 32).Complete();

                for (int i = m_TreeDataPerThread.Count; i <= threadIndex; i++)
                {
                    m_TreeDataPerThread.Add(default);
        unsafe void RefreshData(int threadIndex)
        {
            if (m_FunctionSearchField.value == m_CurrentSearchTerm && m_CurrentThread == threadIndex)
            {
                return;
            }
            if (threadIndex < 0)
            {
                return;
            }

            if (!m_MergedStackFrames.IsCreated)
            {
                m_MergedSamples     = new NativeArray <SampleData>(m_Trace.Samples, Allocator.Persistent);
                m_MergedStackFrames = new NativeList <StackFrameData>(Allocator.Persistent);
                new MergeCallStacksJob
                {
                    MergeBy        = MergeCallStacksJob.MergeMode.ByFunction,
                    NewStackFrames = m_MergedStackFrames,
                    Samples        = m_MergedSamples,
                    StackFrames    = m_Trace.StackFrames
                }.Run();
            }

            if (m_FunctionSearchField.value != m_CurrentSearchTerm)
            {
                m_CurrentSearchTerm = m_FunctionSearchField.value;
                m_FilteredSamples.TryDispose();
                m_FunctionWhiteList.TryDispose();
                m_FunctionWhiteList = FindFunctionsByName(m_FunctionSearchField.value, m_Trace.Functions);
                FilterSamplesByFunction(m_FunctionWhiteList, m_MergedSamples, m_MergedStackFrames, out m_FilteredSamples);
            }

            if (m_FunctionWhiteList.Length == 0)
            {
                m_SubtreeTreeView.ClearData();
                return;
            }

            var threadCollection = new CollectThreadStackFrames
            {
                Thread          = threadIndex,
                Samples         = m_FilteredSamples,
                StackFrames     = m_MergedStackFrames,
                FramesInThread  = new NativeList <StackFrameSamples>(Allocator.TempJob),
                SamplesInThread = new NativeList <SampleData>(Allocator.TempJob)
            };

            threadCollection.Run();
            threadCollection.SamplesInThread.Dispose();

            if (m_FunctionWhiteList.Length == 1)
            {
                new FilterFramesByFunctionJob <SingleFunctionMatcher>
                {
                    Frames  = threadCollection.FramesInThread.AsArray(),
                    Matcher = new SingleFunctionMatcher {
                        Function = m_FunctionWhiteList[0]
                    }
                }.Schedule().Complete();
            }
            else if (m_FunctionWhiteList.IsCreated)
            {
                new FilterFramesByFunctionJob <MultiFunctionMatcher>
                {
                    Frames  = threadCollection.FramesInThread.AsArray(),
                    Matcher = new MultiFunctionMatcher
                    {
                        Functions    = (int *)m_FunctionWhiteList.GetUnsafeReadOnlyPtr(),
                        NumFunctions = m_FunctionWhiteList.Length
                    }
                }.Schedule().Complete();
            }

            var stream = new UnsafeStream(threadCollection.FramesInThread.Length, Allocator.TempJob);

            new CollectSamplesJob
            {
                Frames     = (StackFrameSamples *)threadCollection.FramesInThread.GetUnsafeReadOnlyPtr(),
                OutSamples = stream.AsWriter()
            }.Schedule(threadCollection.FramesInThread.Length, 32).Complete();

            var aggregateJob = new AggregateSamplesJob
            {
                SamplesIn  = stream.ToNativeArray <FunctionSampleData>(Allocator.TempJob),
                SamplesOut = new NativeHashMap <int, FunctionSampleData>(threadCollection.FramesInThread.Length, Allocator.TempJob)
            };

            threadCollection.FramesInThread.Dispose();
            aggregateJob.Run();

            var values = aggregateJob.SamplesOut.GetValueArray(Allocator.Persistent);

            aggregateJob.SamplesIn.Dispose();
            aggregateJob.SamplesOut.Dispose();
            NativeSortExtension.Sort(values, new FunctionByTotal());
            m_FunctionSamples.TryDispose();
            m_FunctionSamples = values;

            m_SubtreeTreeView.SetData(ref m_Trace, m_FunctionSamples);
        }