Пример #1
0
        public static unsafe void Draw()
        {
            if (!m_initialized)
            {
                m_managed     = MyMemoryLogs.GetManaged();
                m_native      = MyMemoryLogs.GetNative();
                m_timed       = MyMemoryLogs.GetTimed();
                m_events      = MyMemoryLogs.GetEvents();
                m_initialized = true;
            }
            float x    = 0f;
            float num2 = 0f;
            float num3 = 0f;

            if (m_events.Count > 0)
            {
                x = (float)(m_events[m_events.Count - 1].EndTime - m_events[0].StartTime).TotalSeconds;
            }
            for (int i = 0; i < m_events.Count; i++)
            {
                num3 += m_events[i].ProcessDelta;
                num2  = Math.Max(Math.Max(num2, m_events[i].ProcessStartSize), m_events[i].ProcessEndSize);
            }
            MyMemoryLogs.MyMemoryEvent eventFromCursor = GetEventFromCursor(((MyGuiSandbox.MouseCursorPosition - GraphOffset) * new Vector2(GraphSize.X, GraphSize.Y)) * new Vector2(x, num2));
            if (eventFromCursor != null)
            {
                new StringBuilder(100).Append(eventFromCursor.Name);
            }
            float num4 = (num2 > 0f) ? (1f / num2) : 0f;
            float num5 = (x > 0f) ? (1f / x) : 0f;
            int   num6 = 0;

            foreach (MyMemoryLogs.MyMemoryEvent local1 in m_events)
            {
                float    totalSeconds     = (float)(local1.StartTime - m_events[0].StartTime).TotalSeconds;
                TimeSpan span2            = (TimeSpan)(local1.EndTime - m_events[0].StartTime);
                float    single1          = (float)span2.TotalSeconds;
                float    managedStartSize = local1.ManagedStartSize;
                float    managedEndSize   = local1.ManagedEndSize;
                float    processStartSize = local1.ProcessStartSize;
                float    processEndSize   = local1.ProcessEndSize;
                if ((num6 % 2) != 1)
                {
                    Color lightGreen = Color.LightGreen;
                }
                else
                {
                    Color green = Color.Green;
                }
                num6++;
                if ((num6 % 2) != 1)
                {
                    Color lightBlue = Color.LightBlue;
                }
                else
                {
                    Color blue = Color.Blue;
                }
                if (local1 == eventFromCursor)
                {
                    Color yellow = Color.Yellow;
                    Color orange = Color.Orange;
                }
            }
            StringBuilder builder = new StringBuilder();
            Vector2       vector  = new Vector2(100f, 500f);

            for (int j = 0; (j < 50) && (j < m_native.Count); j++)
            {
                builder.Clear();
                builder.Append(m_native[j].Name);
                builder.Append((9.536743E-07f * m_native[j].ManagedDelta).ToString("GC: 0.0 MB "));
                builder.Clear();
                builder.Append((9.536743E-07f * m_native[j].ProcessDelta).ToString("Process: 0.0 MB "));
                float *singlePtr1 = (float *)ref vector.Y;
                singlePtr1[0] += 13f;
            }
            vector = new Vector2(1000f, 500f);
            float *singlePtr2 = (float *)ref vector.Y;

            singlePtr2[0] += 10f;
            for (int k = 0; (k < 50) && (k < m_timed.Count); k++)
            {
                builder.Clear();
                builder.Append(m_native[k].Name);
                builder.Append(m_timed[k].DeltaTime.ToString(" 0.000 s"));
                float *singlePtr3 = (float *)ref vector.Y;
                singlePtr3[0] += 13f;
            }
        }
Пример #2
0
//         static public void DumpLoadedMemory(float minimumMegabytesToDump)
//         {
//             float minimumInBytes = 0;// minimumMegabytesToDump * 1024 * 1024;
//
//             m_events = MyMemoryLogs.GetEvents();
//             StringBuilder sb = new StringBuilder(100000);
//             StringBuilder sb2 = new StringBuilder(100);
//
//             sb.AppendLine("\n\nMemory dump for events larger than " + minimumMegabytesToDump + "MB:\n");
//
//             sb.AppendLine("Managed /  Process \n");
//
//             float sumManaged = 0;
//             float sumProcess = 0;
//
//             for (int i = 0; i < m_events.Count; i++)
//             {
//                 MyMemoryLogs.MyMemoryEvent ev = m_events[i];
//
//                 if (ev.Indent == 1)
//                 {
//                     sumManaged += ev.ManagedDelta;
//                     sumProcess += ev.ProcessDelta;
//                 }
//
//                 if (ev.ManagedDelta >= minimumInBytes || ev.ProcessDelta >= minimumInBytes)
//                 {
//                     sb2.Clear();
//                     sb2.Append(String.Format("{0,7:0.0}", ev.ManagedDelta / (1024 * 1024)));
//                     sb2.Append(" / ");
//                     sb2.Append(String.Format("{0,7:0.0}", ev.ProcessDelta / (1024 * 1024)));
//                     sb2.Append("\t");
//
//                     for (int k = 0; k < ev.Indent; k++ )
//                         sb2.Append("\t");
//
//                     sb2.Append(ev.Name);
//                     sb2.Append(" ");
//                     sb.AppendLine(sb2.ToString());
//                 }
//             }
//
//             sb.AppendLine("\nTotal managed: " + (sumManaged / (1024 * 1024)) + "   Total process: " + (sumProcess / (1024 * 1024)) + "\n\n");
//
//             MyMwcLog.Write(sb.ToString());
//         }

        static public void Draw()
        {
            //return;
            //  if (!Enabled)
            //    return;

            if (!m_initialized)
            {
                m_managed     = MyMemoryLogs.GetManaged();
                m_native      = MyMemoryLogs.GetNative();
                m_timed       = MyMemoryLogs.GetTimed();
                m_events      = MyMemoryLogs.GetEvents();
                m_initialized = true;
            }

            float totalTime = 0;
            float maxMB     = 0;
            float totalMB   = 0;

            if (m_events.Count > 0)
            {
                TimeSpan span = m_events[m_events.Count - 1].EndTime - m_events[0].StartTime;
                totalTime = (float)span.TotalSeconds;
            }

            for (int i = 0; i < m_events.Count; i++)
            {
                //totalTime += m_events[i].DeltaTime;
                totalMB += m_events[i].ProcessDelta;
                maxMB    = Math.Max(maxMB, m_events[i].ProcessStartSize);
                maxMB    = Math.Max(maxMB, m_events[i].ProcessEndSize);
            }


            Vector2 cursorPos = MinerWars.AppCode.Game.GUI.Core.MyGuiManager.MouseCursorPosition;
            //cursorPos
            Vector2 timeAndMemory = (cursorPos - GraphOffset) * new Vector2(GraphSize.X, GraphSize.Y);

            timeAndMemory *= new Vector2(totalTime, maxMB);

            MyMemoryLogs.MyMemoryEvent selectedEvent = GetEventFromCursor(timeAndMemory);

            if (selectedEvent != null)
            {
                StringBuilder sb = new StringBuilder(100);
                sb.Append(selectedEvent.Name);
                MyDebugDraw.DrawText(new Vector2(100, 100), sb, Color.YellowGreen, 1);
            }

            //float time = 0;
            float invMaxMB     = maxMB > 0 ? 1 / maxMB : 0;
            float invTotalTime = totalTime > 0 ? 1 / totalTime : 0;

            int colorCnt = 0;

            //int eventCnt = 0;
            foreach (MyMemoryLogs.MyMemoryEvent ev in m_events)
            {
                float startTime = (float)(ev.StartTime - m_events[0].StartTime).TotalSeconds;
                float endTime   = (float)(ev.EndTime - m_events[0].StartTime).TotalSeconds;

                float x0 = startTime * invTotalTime;
                //time += ev.DeltaTime;
                float x1 = endTime * invTotalTime + 0.1f;

                float deltaTime = (endTime - startTime) * invTotalTime;

//                 if (1000 * Math.Abs(x0 - x1) < 1)
//                 {
//                     x1 += 0.1f;
//                 }

                //x1 = ++eventCnt / 600.0f;

                float y0 = ev.ManagedStartSize * invMaxMB;
                float y1 = ev.ManagedEndSize * invMaxMB;

                float z0 = ev.ProcessStartSize * invMaxMB;
                float z1 = ev.ProcessEndSize * invMaxMB;

                Color color  = (colorCnt % 2) == 1 ? Color.Green : Color.LightGreen;
                Color color2 = (colorCnt++ % 2) == 1 ? Color.Blue : Color.LightBlue;

                if (ev == selectedEvent)
                {
                    color  = Color.Yellow;
                    color2 = Color.Orange;
                }

                // managed memory

/*
 *              MyDebugDraw.DrawLine2D(new Vector2(x0, y0) * GraphSize + GraphOffset, new Vector2(x1, y1) * GraphSize + GraphOffset, Color.Red, Color.Red);
 *
 *              MyDebugDraw.DrawTriangle2D(new Vector2(x0, 0) * GraphSize + GraphOffset,
 *                                          new Vector2(x1, 0) * GraphSize + GraphOffset,
 *                                          new Vector2(x1, y1) * GraphSize + GraphOffset, color);
 *              MyDebugDraw.DrawTriangle2D(new Vector2(x1, y1) * GraphSize + GraphOffset,
 *                                          new Vector2(x0, y0) * GraphSize + GraphOffset,
 *                                          new Vector2(x0, 0) * GraphSize + GraphOffset, color);
 *
 *              // process memory
 *              MyDebugDraw.DrawTriangle2D(new Vector2(x0, y0) * GraphSize + GraphOffset,
 *                                          new Vector2(x1, y1) * GraphSize + GraphOffset,
 *                                          new Vector2(x1, z1) * GraphSize + GraphOffset, color2);
 *              MyDebugDraw.DrawTriangle2D(new Vector2(x1, z1) * GraphSize + GraphOffset,
 *                                          new Vector2(x0, z0) * GraphSize + GraphOffset,
 *                                          new Vector2(x0, y0) * GraphSize + GraphOffset, color2);
 */
            }


            // Top 20 native
            StringBuilder sb2        = new StringBuilder();
            Vector2       textOffset = new Vector2(100, 500);

            for (int i = 0; i < 50 && i < m_native.Count; i++)
            {
                //if ( m_native[i].Name.Contains("MyModels"))
                {
                    // native
                    sb2.Clear();
                    sb2.Append(m_native[i].Name);
                    sb2.Append((0.00000095367431f * m_native[i].ManagedDelta).ToString("GC: 0.0 MB "));
                    //sb2.Append((0.00000095367431f * m_native[i].ProcessDelta).ToString("Process: 0.0 MB "));

                    float x_offset = MyDebugDraw.DrawText(textOffset, sb2, Color.Red, 0.7f);
                    //textOffset.Y += 13;

                    // managed
                    sb2.Clear();
                    sb2.Append((0.00000095367431f * m_native[i].ProcessDelta).ToString("Process: 0.0 MB "));

                    MyDebugDraw.DrawText(textOffset + new Vector2(x_offset, 0), sb2, Color.Yellow, 0.7f);
                    textOffset.Y += 13;
                }
            }

            textOffset    = new Vector2(1000, 500);
            textOffset.Y += 10;

            // Top 20 timed
            for (int i = 0; i < 50 && i < m_timed.Count; i++)
            {
                sb2.Clear();
                sb2.Append(m_native[i].Name);
                sb2.Append((m_timed[i].DeltaTime).ToString(" 0.000 s"));

                MyDebugDraw.DrawText(textOffset, sb2, Color.Yellow, 0.7f);
                textOffset.Y += 13;
            }


//             for (int i = 0; i < m_native.Count && i < 30; i++)
//             {
//                 totalTime += m_native[i].DeltaTime;
//                 maxMB = Math.Max(maxMB, m_native[i].ProcessStartSize);
//                 maxMB = Math.Max(maxMB, m_native[i].ProcessEndSize);
//
// //                 float sizeInMB = m_native[i].ManagedDelta * 1.0f / (1024 * 1024);
// //                 MyMwcLog.WriteLine(m_native[i].Name + sizeInMB.ToString());
//             }
//
//             for (int i = 0; i < m_native.Count && i < 30; i++)
//             {
//
//             }


            //    MyDebugDraw.DrawTriangle2D(new Vector2(0.5f, 0), new Vector2(1, 0), new Vector2(1, 1), Color.Yellow);

            //  MyDebugDraw.DrawLine2D(new Vector2(0, 0), new Vector2(1000, 1000), Color.Red, Color.GreenYellow);


//             m_managed = MyMemoryLogs.
//
//             m_managed.Sort(m_managedComparer);
//
//             MyMwcLog.WriteLine("\n\n");
//             MyMwcLog.WriteLine("Managed MemoryUsage: \n");
//
//             float totalMB = 0;
//
//             for (int i = 0; i < m_events.Count && i < 30; i++)
//             {
//                 float sizeInMB = m_events[i].ManagedDelta * 1.0f / (1024 * 1024);
//                 totalMB += sizeInMB;
//                 MyMwcLog.WriteLine(m_events[i].Name + sizeInMB.ToString());
//             }
//
//             MyMwcLog.WriteLine("Total Managed MemoryUsage: " + totalMB + " [MB]");
        }