示例#1
0
    public static void CalculateFrameInterval(HanoiNode n, HanoiNode preN)
    {
        int   preFrameIndex     = 0;
        float preFrameStartTime = 0.0f;
        int   count             = n.Children.Count;

        for (int i = 0; i < count; i++)
        {
            HanoiNode node = n.Children[i];
            if (node is HanoiFrameInfo)
            {
                HanoiFrameInfo hfi = (HanoiFrameInfo)node;
                if (preFrameStartTime > 0)
                {
                    HanoiFrameInfo hfiChild = (HanoiFrameInfo)n.Children[preFrameIndex];
                    //只记录相邻帧的前帧结束时间,非相邻帧信息不显示
                    if (!hfiChild.isHandle && hfi.frameID - hfiChild.frameID == 1)
                    {
                        hfiChild.frameEndTime = hfi.frameTime;
                        hfiChild.frameFunTime = hfi.frameFunTime;
                        hfiChild.frameLuaTime = hfi.frameLuaTime;
                        hfiChild.isHandle     = true;
                    }
                }
                preFrameIndex     = i;
                preFrameStartTime = hfi.frameTime;
            }
        }
    }
示例#2
0
    private HanoiNode PickHanoiRecursively(HanoiNode n, Vector2 mousePos)
    {
        if (n.HasValidRect())
        {
            if (n.renderRect.xMin > mousePos.x || n.renderRect.xMax < mousePos.x)
            {
                return(null);
            }

            if (n.renderRect.Contains(mousePos))
            {
                return(n);
            }
        }

        for (int i = 0; i < n.Children.Count; i++)
        {
            HanoiNode child = PickHanoiRecursively(n.Children[i], mousePos);
            if (child != null)
            {
                return(child);
            }
        }
        return(null);
    }
示例#3
0
    public void handleMsgForDetailScreen(JSONObject jsonMsg, List <HanoiNode> resultNodeRoot)
    {
        if (jsonMsg == null)
        {
            return;
        }
        if (jsonMsg.IsNull || jsonMsg.type != JSONObject.Type.OBJECT)
        {
            return;
        }
        if (Root == null || Root.callStats == null)
        {
            return;
        }

        HanoiNode newNode = null;

        bool isFrameInfo = jsonMsg.GetField("fid");

        //是帧信息
        if (isFrameInfo)
        {
            newNode = new HanoiFrameInfo(Root.callStats);
        }
        else
        {
            //函数信息
            newNode = new HanoiNode(Root.callStats);
        }
        if (readObject(jsonMsg, newNode))
        {
            resultNodeRoot.Add(newNode);
        }
    }
示例#4
0
    public static void DrawRecursively(HanoiNode n)
    {
        int   hash = n.GetHashCode();
        Color c;

        if (!m_colors.TryGetValue(hash, out c))
        {
            m_colors[hash] = c = n.GetNodeColor();
        }
        if (n is HanoiFrameInfo)
        {
        }
        else
        {
            if (IsTimeRangeInScreenClipRange((float)n.beginTime, (float)n.beginTime + (float)n.timeConsuming))
            {
                n.renderRect = new Rect((float)n.beginTime, HanoiVars.StackHeight * (HanoiVars.DrawnStackCount - n.stackLevel), (float)n.timeConsuming, HanoiVars.StackHeight);
                Handles.DrawSolidRectangleWithOutline(n.renderRect, c, n.highlighted ? Color.white : c);
            }
        }

        for (int i = 0; i < n.Children.Count; i++)
        {
            DrawRecursively(n.Children[i]);
        }
    }
示例#5
0
    public static void DrawLabelsRecursively(HanoiNode n)
    {
        if (n.highlighted)
        {
            if (IsTimeRangeInScreenClipRange(n.renderRect.xMin, n.renderRect.xMin + HanoiVars.LabelBackgroundWidth))
            {
                Rect r = n.renderRect;

                r.width  = HanoiVars.LabelBackgroundWidth;
                r.height = 45;
                Color bg = Color.black;
                bg.a = 0.5f;
                Handles.DrawSolidRectangleWithOutline(r, bg, bg);

                GUI.color = Color.white;
                Handles.Label(new Vector3(n.renderRect.xMin, n.renderRect.yMin), n.funcName);
                Handles.Label(new Vector3(n.renderRect.xMin, n.renderRect.yMin + 15), n.moduleName);
                Handles.Label(new Vector3(n.renderRect.xMin, n.renderRect.yMin + 30), string.Format("Time: {0:0.000}", n.timeConsuming));
            }
        }

        for (int i = 0; i < n.Children.Count; i++)
        {
            DrawLabelsRecursively(n.Children[i]);
        }
    }
示例#6
0
 public bool readObject(JSONObject obj, HanoiNode node)
 {
     if (obj.type != JSONObject.Type.OBJECT)
     {
         return(false);
     }
     node.processJsonObject(obj, this);
     return(true);
 }
示例#7
0
    public static void ForeachInParentChain(HanoiNode n, HanoiNodeAction act)
    {
        HanoiNode target = n;

        while (target.Parent != null)
        {
            if (act != null)
            {
                act(target);
            }

            target = target.Parent;
        }
    }
示例#8
0
    public static float calculateTotalTimeConsuming(HanoiNode n)
    {
        int count = n.Children.Count;

        for (int i = count - 1; i > 0; i--)
        {
            HanoiNode node = n.Children[i];
            if (!(node is HanoiFrameInfo))
            {
                return((float)node.endTime);
            }
        }
        return(0);
    }
示例#9
0
    public static void DrawFrameStatementRecursively(HanoiNode n)
    {
        if (n is HanoiFrameInfo)
        {
            HanoiFrameInfo hfi      = (HanoiFrameInfo)n;
            Color          preColor = Handles.color;
            Handles.color = Color.gray;
            if (IsTimeRangeInScreenClipRange((float)hfi.frameTime, (float)hfi.frameTime))
            {
                Handles.DrawLine(new Vector3(hfi.frameTime, 0), new Vector3(hfi.frameTime, VisualizerWindow.m_winHeight));
            }
            Handles.color = preColor;
        }

        for (int i = 0; i < n.Children.Count; i++)
        {
            DrawFrameStatementRecursively(n.Children[i]);
        }
    }
示例#10
0
    public static void CalculateFrameInterval(HanoiNode n, HanoiNode preN)
    {
        int   preFrameIndex     = 0;
        float preFrameStartTime = 0.0f;
        int   count             = n.Children.Count;

        for (int i = 0; i < count; i++)
        {
            HanoiNode node = n.Children[i];
            if (node is HanoiFrameInfo)
            {
                HanoiFrameInfo hfi = (HanoiFrameInfo)node;
                if (preFrameStartTime > 0)
                {
                    HanoiFrameInfo hfiChild = (HanoiFrameInfo)n.Children[preFrameIndex];
                    hfiChild.frameEndTime = hfi.frameTime;
                }
                preFrameIndex     = i;
                preFrameStartTime = hfi.frameTime;
            }
        }
    }
示例#11
0
    public static void DrawSelectedFrameInfoRecursively(HanoiNode n, float mouseX)
    {
        if (n is HanoiFrameInfo)
        {
            HanoiFrameInfo hfi      = (HanoiFrameInfo)n;
            Color          preColor = Handles.color;

            if (mouseX >= hfi.frameTime && mouseX <= hfi.frameEndTime)
            {
                float beginPosX = hfi.frameEndTime;
                Rect  r         = new Rect();
                r.position = new Vector2(beginPosX, 0);
                r.width    = HanoiVars.LabelBackgroundWidth / 1.5f;
                r.height   = 60;
                Color bg = Color.white;
                bg.a = 0.5f;
                Handles.DrawSolidRectangleWithOutline(r, bg, bg);

                Handles.color = Color.green;
                GUI.color     = Color.black;
                Handles.Label(new Vector3(beginPosX, 0), string.Format("frameID:{0:0}", hfi.frameID));
                Handles.Label(new Vector3(beginPosX, 15), string.Format("frameTime:{0:0.00}", hfi.frameTime));
                Handles.Label(new Vector3(beginPosX, 30), string.Format("frameUnityTime:{0:0.00}", hfi.frameUnityTime));
                Handles.Label(new Vector3(beginPosX, 45), string.Format("frameInterval:{0:0.00}", hfi.frameEndTime - hfi.frameTime));
                Handles.DrawLine(new Vector3(hfi.frameTime, 0), new Vector3(hfi.frameTime, VisualizerWindow.m_winHeight));
                Handles.DrawLine(new Vector3(hfi.frameEndTime, 0), new Vector3(hfi.frameEndTime, VisualizerWindow.m_winHeight));
            }

            Handles.color = preColor;
        }

        for (int i = 0; i < n.Children.Count; i++)
        {
            DrawSelectedFrameInfoRecursively(n.Children[i], mouseX);
        }
    }
示例#12
0
    bool readObject(JSONObject obj, HanoiNode node)
    {
        if (obj.type != JSONObject.Type.OBJECT)
        {
            return(false);
        }
        JSONObject loadObj = null;

        if (node is HanoiFrameInfo)
        {
            HanoiFrameInfo frameNode = (HanoiFrameInfo)node;
            loadObj = obj.GetField("frameTime");
            if (loadObj && loadObj.IsNumber)
            {
                frameNode.frameTime = obj.GetField("frameTime").f;
            }
            else
            {
                Debug.LogFormat("frameTime load error");
            }

            loadObj = obj.GetField("frameUnityTime");
            if (loadObj && loadObj.IsNumber)
            {
                frameNode.frameUnityTime = obj.GetField("frameUnityTime").f;
            }
            else
            {
                Debug.LogFormat("frameUnityTime load error");
            }

            loadObj = obj.GetField("frameID");
            if (loadObj && loadObj.IsNumber)
            {
                frameNode.frameID = (int)obj.GetField("frameID").n;
            }
            else
            {
                Debug.LogFormat("frameID load error");
            }
        }
        else
        {
            loadObj = obj.GetField("currentLine");
            if (loadObj && loadObj.IsNumber)
            {
                node.currentLine = (int)obj.GetField("currentLine").n;
            }
            else
            {
                Debug.LogFormat("currentLine load error");
            }

            loadObj = obj.GetField("lineDefined");
            if (loadObj && loadObj.IsNumber)
            {
                node.lineDefined = (int)obj.GetField("lineDefined").n;
            }
            else
            {
                Debug.LogFormat("lineDefined load error");
            }

            loadObj = obj.GetField("timeConsuming");
            if (loadObj && loadObj.IsNumber)
            {
                node.timeConsuming = obj.GetField("timeConsuming").n;
            }
            else
            {
                Debug.LogFormat("timeConsuming load error");
            }

            loadObj = obj.GetField("stackLevel");
            if (loadObj && loadObj.IsNumber)
            {
                node.stackLevel = (int)obj.GetField("stackLevel").n;
                if (node.stackLevel > m_maxStackLevel)
                {
                    m_maxStackLevel = node.stackLevel;
                }
            }
            else
            {
                Debug.LogFormat("stackLevel load error");
            }

            loadObj = obj.GetField("callType");
            if (loadObj && loadObj.IsString)
            {
                switch (obj.GetField("callType").str)
                {
                case "C":
                    node.callType = eHanoiCallType.C;
                    break;

                case "Lua":
                    node.callType = eHanoiCallType.Lua;
                    break;
                }
            }
            else
            {
                Debug.LogFormat("callType load error");
            }

            loadObj = obj.GetField("begintime");
            if (loadObj && loadObj.IsNumber)
            {
                node.beginTime = obj.GetField("begintime").n;
            }
            else
            {
                Debug.LogFormat("beginTime load error");
            }

            loadObj = obj.GetField("endtime");
            if (loadObj && loadObj.IsNumber)
            {
                node.endTime = obj.GetField("endtime").n;
            }
            else
            {
                Debug.LogFormat("endTime load error");
            }

            loadObj = obj.GetField("moduleName");
            if (loadObj && loadObj.IsString)
            {
                node.moduleName = obj.GetField("moduleName").str;
            }
            else
            {
                Debug.LogFormat("moduleName load error");
            }

            loadObj = obj.GetField("funcName");
            if (loadObj && loadObj.IsString)
            {
                node.funcName = obj.GetField("funcName").str;
            }
            else
            {
                Debug.LogFormat("funcName load error");
            }

            foreach (JSONObject childJson in obj.GetField("children").list)
            {
                bool      isOnStackZero   = node.stackLevel == 0;
                double    lastStackOneEnd = 0.0;
                HanoiNode child           = new HanoiNode(node);
                if (readObject(childJson, child))
                {
                    node.Children.Add(child);
                }
                if (isOnStackZero)
                {
                    lastStackOneEnd = child.endTime;
                }
            }
        }
        return(true);
    }
示例#13
0
    public bool Load(string filename)
    {
        m_hanoiData = null;
        try
        {
            string templateJsonText = System.IO.File.ReadAllText("Assets/Resources/luaprofiler_jsonObjTemplates.json");
            string text             = System.IO.File.ReadAllText(filename);
            m_json = new JSONObject(templateJsonText.Replace("$$", text));

            if (m_json.type != JSONObject.Type.OBJECT)
            {
                return(false);
            }

            if (m_json.list.Count != 1)
            {
                return(false);
            }


            HanoiNode.s_count = 0;

            m_hanoiData = new HanoiRoot();
            if (m_json.GetField("content") && m_json.GetField("content").IsArray)
            {
                JSONObject jsonContent = m_json.GetField("content");
                HanoiNode  contentNode = new HanoiNode(null);

                for (int i = 0; i < jsonContent.list.Count; i++)
                {
                    JSONObject j       = (JSONObject)jsonContent.list[i];
                    HanoiNode  newNode = null;

                    bool isFrameInfo = j.GetField("frameID");
                    //是帧信息
                    if (isFrameInfo)
                    {
                        newNode = new HanoiFrameInfo(contentNode);
                    }
                    else
                    {
                        //函数信息
                        newNode = new HanoiNode(contentNode);
                    }
                    if (readObject(j, newNode))
                    {
                        contentNode.Children.Add(newNode);
                    }
                }
                Root.callStats = contentNode;
            }

            Debug.LogFormat("reading {0} objects.", HanoiNode.s_count);
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            return(false);
        }

        return(true);
    }
示例#14
0
    public virtual void processJsonObject(JSONObject job, HanoiData hd)
    {
        for (int i = 0; i < job.keys.Count; i++)
        {
            JSONObject val = job.list[i];
            switch (job.keys[i])
            {
            case "ln":
                if (val.IsNumber)
                {
                    currentLine = (int)val.n;
                }
                break;

            case "cs":
                if (val.IsNumber)
                {
                    timeConsuming = val.n;
                }
                break;

            case "lv":
                if (val.IsNumber)
                {
                    stackLevel = (int)val.n;
                    if (stackLevel > hd.m_maxStackLevel)
                    {
                        hd.m_maxStackLevel = stackLevel;
                    }
                }
                break;

            case "info":
                if (val.IsString)
                {
                    string type = val.str;
                    if (type.Equals("C"))
                    {
                        callType = eHanoiCallType.C;
                    }
                    if (type.Equals("Lua"))
                    {
                        callType = eHanoiCallType.Lua;
                    }
                }
                break;

            case "bt":
                if (val.IsNumber)
                {
                    beginTime = val.n;
                }
                break;

            case "et":
                if (val.IsNumber)
                {
                    endTime = val.n;
                }
                break;

            case "mod":
                if (val.IsString)
                {
                    moduleName = val.str;
                }
                break;

            case "fn":
                if (val.IsString)
                {
                    funcName = val.str;
                }
                break;

            case "sub":
                foreach (JSONObject childJson in val.list)
                {
                    HanoiNode child = new HanoiNode(this);
                    if (hd.readObject(childJson, child))
                    {
                        Children.Add(child);
                    }
                }
                break;

            default:
                // Debug.LogFormat("unknown field: {0}", obj.keys[i]);
                break;
            }
        }
    }
示例#15
0
    private void CheckForInput()
    {
        switch (Event.current.type)
        {
        case EventType.MouseMove:
        {
            if (m_picked != null)
            {
                HanoiUtil.ForeachInParentChain(m_picked, (n) => { n.highlighted = false; });
                m_picked = null;
            }

            HanoiNode picked = PickHanoiRecursively(m_data.Root.callStats, mousePositionInDrawing);
            if (picked != null)
            {
                HanoiUtil.ForeachInParentChain(picked, (n) => {
                        n.highlighted = true;
                    });
                m_picked = picked;

                Debug.LogFormat("Picked: f {0}, m {1}", m_picked.funcName, m_picked.moduleName);
            }
            else
            {
                Debug.LogFormat("Picked nothing.");
            }

            if (EditorWindow.focusedWindow == this)
            {
                if ((Event.current.mousePosition.x >= 0 && Event.current.mousePosition.x <= m_winWidth) &&
                    (Event.current.mousePosition.y >= m_detailScreenPosY && Event.current.mousePosition.y <= m_winHeight))
                {
                    Repaint();
                }
            }
        }
        break;

        case EventType.MouseDrag:
            if (Event.current.button == 1)
            {
                m_Translation.x += Event.current.delta.x;
                Repaint();
            }
            break;

        case EventType.ScrollWheel:
        {
            float delta = Event.current.delta.x + Event.current.delta.y;
            delta = -delta;

            // Scale multiplier. Don't allow scale of zero or below!
            float scale = Mathf.Max(0.1F, 1 + delta * 0.1F);

            // Offset to make zoom centered around cursor position
            m_Translation.x -= mousePositionInDrawing.x * (scale - 1) * m_Scale.x;

            // Apply zooming
            m_Scale.x *= scale;

            Repaint();
        }
        break;

        default:
            break;
        }
    }
示例#16
0
 private void drawFrameInfo(HanoiNode n, float mouseX)
 {
     HanoiUtil.DrawFrameStatementRecursively(n);
     HanoiUtil.DrawSelectedFrameInfoRecursively(n, mouseX);
 }
示例#17
0
        public override bool Equals(object obj)
        {
            HanoiNode otherNode = obj as HanoiNode;

            return(state == otherNode.state);
        }
示例#18
0
    public HanoiNode(HanoiNode parent)
    {
        s_count++;

        Parent = parent;
    }
示例#19
0
 public HanoiFrameInfo(HanoiNode parent)
     : base(parent)
 {
 }
示例#20
0
 public HanoiNode(ulong state, ref HanoiNode parent)
 {
     this.state  = state;
     this.parent = parent;
 }