Example #1
0
        public void Serialize(BinaryReader reader, ProfileEventData data)
        {
            m_NbProfiles = reader.ReadUInt32();
            m_ThreadID   = reader.ReadUInt32();
            m_NbEvents   = reader.ReadUInt32();

            // read all the profiles
            EventFileProfileDesc profileDesc = new EventFileProfileDesc();

            for (int i = 0; i < m_NbProfiles; i++)
            {
                profileDesc.Serialize(reader);
                data.AddProfile(profileDesc.m_ProfileID, profileDesc.m_Name);
            }

            ProfileEventData.ProfileContext eventsContext = data.GetEventContext(m_ThreadID);

            // read all the events
            ProfileEvent profileEvent = new ProfileEvent();

            for (int i = 0; i < m_NbEvents; i++)
            {
                profileEvent.Serialize(reader);

                string name = data.GetProfileName(profileEvent.m_ProfileID);
                eventsContext.AddEvent(profileEvent.m_Time, profileEvent.m_ProfileID, profileEvent.m_Type);
            }

            // Send stop events with the last recorded time
            while (!eventsContext.IsTerminated)
            {
                eventsContext.AddEvent(profileEvent.m_Time, 0, ProfileEventData.ProfileContext.Event.EventStop);
            }
        }
        private void DrawEvent(ProfileEventData.ProfileContext.Event profileEvent, ref DrawEventContext drawContext)
        {
            Pen   activeRectPen = rectPen;
            float rectOffset    = 0;

            if (profileEvent == m_eventSelection)
            {
                activeRectPen = rectPenSelected;
                rectOffset    = 1.5f;
            }

            if (profileEvent.Inside(m_TimeStart, m_TimeEnd))
            {
                Int64 screenXEnd = (Int64)((profileEvent.Time + profileEvent.Length - m_TimeStart) / drawContext.m_TimeStepPerPixel);
                if (!drawContext.overDraw.ShouldDraw(screenXEnd))
                {
                    return;
                }

                // compute screen X size
                Int64 screenX      = (Int64)((profileEvent.Time - m_TimeStart) / drawContext.m_TimeStepPerPixel);
                Int64 screenLength = (Int64)((profileEvent.Length) / drawContext.m_TimeStepPerPixel);
                Int64 screenXE     = screenX + screenLength;
                bool  nulSized     = (screenLength == 0);


                // draw a rectangle
                rectBrush.Color = m_Data.GetProfileColor(profileEvent.ProfileID);
                screenX         = Math.Max(-20, screenX);
                screenXE        = Math.Min(ClientSize.Width + 20, screenXE);
                if (screenXE == screenX)
                {
                    screenXE++;
                }
                screenLength = screenXE - screenX;

                int offsetY = 0;
                if (profileEvent.EventType == ProfileEventViewer.ProfileEventData.ProfileContext.Event.EventStart)
                {
                    drawContext.Graphics.FillRectangle(rectBrush, screenX, drawContext.m_Y, screenLength, EventHeight);
                    drawContext.Graphics.DrawRectangle(activeRectPen, screenX + rectOffset, drawContext.m_Y + rectOffset, screenLength - (rectOffset * 2), EventHeight - (rectOffset * 2));
                }
                else
                {
                    //drawContext.Graphics.FillRectangle(rectBrush, screenX, drawContext.m_Y, screenLength, MarkerHeight);
                    offsetY = -2 * EventHeight;

                    rectBrush.Color = Color.Red;
                    drawContext.Graphics.FillRectangle(rectBrush, screenX, drawContext.m_Y + offsetY, screenLength, EventHeight);
                    drawContext.Graphics.DrawRectangle(activeRectPen, screenX + rectOffset, drawContext.m_Y + offsetY + rectOffset, screenLength - (rectOffset * 2), EventHeight - (rectOffset * 2));
                }


                // set the clip region and display the profile name (if there's any chance it could fit)
                if ((screenLength > 20) || (profileEvent == m_eventSelection))
                {
                    Region oldClipRegion = drawContext.Graphics.Clip;
                    drawContext.Graphics.SetClip(new Rectangle((int)screenX + 1, drawContext.m_Y + offsetY, (int)screenLength - 1, EventHeight));

                    string profileName = String.Format("{0}{1}", (screenX < 0) ? "<< " : "", m_Data.GetProfileName(profileEvent.ProfileID));
                    string profileTime = String.Format("{0}{1}", (screenX < 0) ? "<< " : "", TimeToString((UInt64)profileEvent.Length));
                    drawContext.Graphics.DrawString(profileName, barFont, fontBrush, Math.Max(screenX + 1, 0), drawContext.m_Y - 0 + offsetY);
                    drawContext.Graphics.DrawString(profileTime, barFont, fontBrush, Math.Max(screenX + 1, 0), drawContext.m_Y + 10 + offsetY);

                    drawContext.Graphics.Clip = oldClipRegion;
                }

                // must draw the childs (if we were not too small)
                if (profileEvent.Child != null && screenLength > 1)
                {
                    drawContext.Graphics.FillRectangle(selfBrush, screenX, drawContext.m_Y + EventHeight, screenLength, EventHeight);

                    drawContext.m_Y += EventHeight;
                    Int64 keepColumn = drawContext.overDraw.Reset();

                    ProfileEventData.ProfileContext.Event child = profileEvent.Child;

                    while (child != null)
                    {
                        DrawEvent(child, ref drawContext);
                        child = child.Sibling;
                    }

                    drawContext.overDraw.Reset(keepColumn);

                    drawContext.m_Y -= EventHeight;
                }
            }
        }