Beispiel #1
0
        /**
         *	Draw a visual representation of the profiler.
         */
        public static void Draw(pb_Sample sample)
        {
            Rect       rect   = EditorGUILayout.GetControlRect(false, 150);
            RectOffset margin = new RectOffset(2, 2, 4, 4);

            rect.x      += margin.left;
            rect.y      += margin.top;
            rect.width  -= margin.left + margin.right;
            rect.height -= margin.top + margin.bottom;
            Color prev_color = GUI.color;

            GUI.color = Color.gray;
            GUI.Box(rect, "", ProfilerStyles.chartBackgroundStyle);
            GUI.color = prev_color;

            if (Event.current.type == EventType.Repaint)
            {
                if (sample == null)
                {
                    GUI.Label(rect, "Sample History Graph", ProfilerStyles.centeredGrayLabel);
                    return;
                }

                List <long> samples = sample.sampleHistory;
                int         count   = samples.Count;

                if (count < 3)
                {
                    GUI.Label(rect, "Too Few Samples to Graph", ProfilerStyles.centeredGrayLabel);
                    return;
                }

                long min = samples[0], max = samples[0];

                for (int i = 1; i < count; i++)
                {
                    if (samples[i] < min)
                    {
                        min = samples[i];
                    }
                    if (samples[i] > max)
                    {
                        max = samples[i];
                    }
                }

                MethodInfo mi = typeof(HandleUtility).GetMethod("ApplyWireMaterial", ALL_FLAGS);
                mi.Invoke(null, null);

                GL.Begin(GL.LINES);

                GL.Color(guideColor);

                // draw guides
                GL.Vertex3(rect.x, rect.y + (rect.height * .25f), 0f);
                GL.Vertex3(rect.x + rect.width, rect.y + (rect.height * .25f), 0f);

                GL.Vertex3(rect.x, rect.y + (rect.height * .5f), 0f);
                GL.Vertex3(rect.x + rect.width, rect.y + (rect.height * .5f), 0f);

                GL.Vertex3(rect.x, rect.y + (rect.height * .75f), 0f);
                GL.Vertex3(rect.x + rect.width, rect.y + (rect.height * .75f), 0f);

                GL.Color(lineColor);

                float x = rect.x;
                float y = (samples[0] / (float)max) * rect.height;

                for (int i = 1; i < count; i++)
                {
                    GL.Vertex3(rect.x + x, rect.y + (rect.height - y), 0f);
                    x = (i / (float)(count - 1)) * rect.width;
                    y = ((samples[i] - min) / (float)(max - min)) * rect.height;
                    GL.Vertex3(rect.x + x, rect.y + (rect.height - y), 0f);
                }

                GL.End();

                GUIContent label  = new GUIContent(ProfilerEditor.TickToString(min));
                float      height = ProfilerStyles.chartAxisLabel.CalcHeight(label, EditorGUIUtility.currentViewWidth);
                Rect       r      = new Rect(rect.x + 2, ((rect.y + rect.height) - height) - 2, 200, height);
                GUI.Label(r, label, ProfilerStyles.chartAxisLabel);
                r.y = rect.y + 2;
                GUI.Label(r, ProfilerEditor.TickToString(max), ProfilerStyles.chartAxisLabel);

                label.text = sample.name;
                r.x        = (rect.x + rect.width) - (ProfilerStyles.chartAxisLabel.CalcSize(label).x + 12);
                GUI.Label(r, label);
            }
        }
Beispiel #2
0
        void DrawSampleTree(pb_Sample sample, int indent, string key_prefix)
        {
            string key        = key_prefix + sample.name;
            int    childCount = sample.children.Count;

            if (!row_visibility.ContainsKey(key))
            {
                row_visibility.Add(key, true);
            }

            GUILayout.BeginHorizontal(ProfilerStyles.chartStyle);

            int n = 0;

            GUI.backgroundColor = column_colors[n++ % 2];

            GUILayout.BeginHorizontal(ProfilerStyles.entryStyle);

            GUILayout.Space(indent * (childCount > 0 ? 10 : 14));

            // don't use a Foldout control because it always eats the current event, which breaks clicking to follow stack trace
            if (childCount > 0)
            {
                GUI.backgroundColor = Color.white;
                GUI.color           = Color.white;
                row_visibility[key] = EditorGUILayout.Toggle(row_visibility[key], EditorStyles.foldout, GUILayout.MaxWidth(14));
            }

            GUILayout.Label(sample.name);

            GUILayout.EndHorizontal();

            Rect r = GUILayoutUtility.GetLastRect();

            color.r = sample.Percentage() / 100f;
            color.b = 1f - color.r;

            r.x      = (r.width + r.x) - COLOR_BLOCK_SIZE - COLOR_BLOCK_PAD;
            r.width  = COLOR_BLOCK_SIZE;
            r.y     += (r.height - COLOR_BLOCK_SIZE) / 2f;
            r.height = COLOR_BLOCK_SIZE;

            DrawSolidColor(r, color);

            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(sample.sampleCount.ToString(), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(sample.Percentage().ToString("F2"), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(ProfilerEditor.TickToString(sample.average), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(ProfilerEditor.TickToString(sample.sum), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(ProfilerEditor.TickToString(sample.min), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(ProfilerEditor.TickToString(sample.max), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];
            GUILayout.Label(ProfilerEditor.TickToString(sample.lastSample), ProfilerStyles.entryStyle, GUILayout.MinWidth(FIELD_WIDTH), GUILayout.MaxWidth(FIELD_WIDTH));
            GUI.backgroundColor = column_colors[n++ % 2];

            GUILayout.EndHorizontal();

            Rect lastRect = GUILayoutUtility.GetLastRect();

            if (currentEvent.type == EventType.MouseDown && lastRect.Contains(currentEvent.mousePosition))
            {
                if (currentEvent.clickCount > 1)
                {
                    StackFrame frame = sample.stackTrace.GetFrame(0);

                    string filePathRel;

                    if (RelativeFilePath(frame.GetFileName(), out filePathRel))
                    {
                        UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(filePathRel, typeof(TextAsset));
                        int lineNumber         = frame.GetFileLineNumber();
                        AssetDatabase.OpenAsset(obj, lineNumber);
                    }
                }
                else
                {
                    selectedSample = sample;
                }
            }

            if (lastRect.Contains(currentEvent.mousePosition))
            {
                if (hoveringSample != sample)
                {
                    hoveringSample = sample;
                    hoveringRect   = new Rect(
                        lastRect.x + 6,
                        lastRect.y,
                        lastRect.width - 12,
                        lastRect.height + 2);
                    wantsRepaint = true;
                }
            }

            if (row_visibility[key])
            {
                indent++;
                foreach (pb_Sample child in sample.children)
                {
                    DrawSampleTree(child, indent, key);
                }
            }
        }