コード例 #1
0
        public static LogStats GatherStats(int[] calls, double[] times, int entries)
        {
            var stats = new LogStats();

            Array.Sort(calls);
            Array.Sort(times);

            for (var i = 0; i < entries; i++)
            {
                stats.TotalCalls += calls[i];
                stats.TotalTime  += times[i];
            }

            // Mean
            stats.MeanTimePerCall         = stats.TotalTime / stats.TotalCalls;
            stats.MeanTimePerUpdateCycle  = stats.TotalTime / entries;
            stats.MeanCallsPerUpdateCycle = stats.TotalCalls / (float)entries;

            var middle = entries / 2;

            // Medians
            stats.MedianTime  = times[middle];
            stats.MedianCalls = calls[middle];

            // Max
            stats.HighestTime  = times[Profiler.RECORDS_HELD - 1];
            stats.HighestCalls = calls[Profiler.RECORDS_HELD - 1];

            // general
            stats.Entries = entries;

            return(stats);
        }
コード例 #2
0
        private static void ExecuteWorker(LogStats logic, int[] LocalCalls, double[] LocalTimes, int currentLogCount,
                                          uint currentIndex)
        {
            try
            {
                // todo
                // implement a custom sorting which also keeps track of the sum.
                // this will take this from
                // o(2*nlogn + n) to o(2*nlogn)

                Array.Sort(LocalCalls);
                Array.Sort(LocalTimes);


                for (var i = 0; i < Profiler.RECORDS_HELD; i++)
                {
                    logic.TotalCalls += LocalCalls[i];
                    logic.TotalTime  += LocalTimes[i];
                }

                // Mean
                logic.MeanTimePerCall         = logic.TotalTime / logic.TotalCalls;
                logic.MeanTimePerUpdateCycle  = logic.TotalTime / currentLogCount;
                logic.MeanCallsPerUpdateCycle = logic.TotalCalls / (float)currentLogCount;

                var medianOffset = Profiler.RECORDS_HELD - currentLogCount;
                var middle       = currentLogCount / 2;
                // Medians
                logic.MedianTime  = LocalTimes[medianOffset + middle];
                logic.MedianCalls = LocalCalls[medianOffset + middle];

                // Max
                logic.HighestTime  = LocalTimes[Profiler.RECORDS_HELD - 1];
                logic.HighestCalls = LocalCalls[Profiler.RECORDS_HELD - 1];

                // general
                logic.Entries = currentLogCount;

                lock (CurrentLogStats.sync
                      ) // Dump our current statistics into our static class which our drawing class uses
                {
                    CurrentLogStats.stats = logic;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                ThreadSafeLogger.Error(
                    $"[Analyzer] Failed while calculating stats for profiler, errored with the message {e.Message}");
#else
                if (Settings.verboseLogging)
                {
                    ThreadSafeLogger.Error($"[Analyzer] Failed while calculating stats for profiler, errored with the message {e.Message}");
                }
#endif
            }
        }
コード例 #3
0
        public void ResetState(GeneralInformation?_)
        {
            file      = null;
            prevIdx   = 0;
            curHeader = new FileHeader()
            {
                MAGIC         = FileUtility.ENTRY_FILE_MAGIC, // used to verify the file has not been corrupted on disk somehow.
                scribingVer   = FileUtility.SCRIBE_FILE_VER,
                targetEntries = Profiler.RECORDS_HELD,
                name          = " " // default to an empty name
            };

            lhsEntry = null;
            rhsEntry = null;
            lhsStats = null;
            rhsStats = null;
        }
コード例 #4
0
        public static void DrawStats(Rect inrect, GeneralInformation?currentInformation)
        {
            var stats = new LogStats();

            stats.GenerateStats();

            stats = null;

            lock (CurrentLogStats.sync)
            {
                stats = CurrentLogStats.stats;
            }

            if (stats == null)
            {
                return;
            }

            inrect = inrect.ContractedBy(4f);
            var r = inrect;

            r.height = listing.CurHeight;
            r.width  = 18;
            Widgets.BeginScrollView(inrect, ref scrolls, r);

            listing.Begin(inrect);
            Text.Font = GameFont.Tiny;

            var sb = new StringBuilder();

            if (currentInformation.HasValue)
            {
                sb.AppendLine(
                    $"Method: {currentInformation.Value.methodName}, Mod: {currentInformation.Value.modName}");
                sb.AppendLine(
                    $"Assembly: {currentInformation.Value.assname}, Patches: {currentInformation.Value.patches.Count}");

                var modLabel = sb.ToString().TrimEndNewlines();
                var rect     = listing.GetRect(Text.CalcHeight(modLabel, listing.ColumnWidth));

                Widgets.Label(rect, modLabel);
                Widgets.DrawHighlightIfMouseover(rect);

                if (Input.GetMouseButtonDown(1) && rect.Contains(Event.current.mousePosition)) // mouse button right
                {
                    var options = new List <FloatMenuOption>
                    {
                        new FloatMenuOption("Open In Github",
                                            () => Panel_BottomRow.OpenGithub(
                                                $"{currentInformation.Value.typeName}.{currentInformation.Value.methodName}")),
                        new FloatMenuOption("Open In Dnspy (requires local path)",
                                            () => Panel_BottomRow.OpenDnspy(currentInformation.Value.method))
                    };

                    Find.WindowStack.Add(new FloatMenu(options));
                }

                listing.GapLine(2f);

                sb.Clear();
            }

            sb.AppendLine($"Total Entries:".Colorize(Color.grey) + $" { stats.Entries}");
            sb.AppendLine($"Total Calls:".Colorize(Color.grey) + $" {stats.TotalCalls}");
            sb.AppendLine($"Total Time:".Colorize(Color.grey) + $" {stats.TotalTime:0.000}ms");

            sb.AppendLine($"Avg Time/Call:".Colorize(Color.grey) + $" {stats.MeanTimePerCall:0.000}ms");
            sb.AppendLine($"Avg Calls/Update:".Colorize(Color.grey) + $" {stats.MeanCallsPerUpdateCycle:0.00}");
            sb.AppendLine($"Avg Time/Update:".Colorize(Color.grey) + $" {stats.MeanTimePerUpdateCycle:0.000}ms");

            sb.AppendLine($"Median Calls:".Colorize(Color.grey) + $" {stats.MedianCalls}");
            sb.AppendLine($"Median Time:".Colorize(Color.grey) + $" {stats.MedianTime}");
            sb.AppendLine($"Max Time:".Colorize(Color.grey) + $" {stats.HighestTime:0.000}ms");
            sb.AppendLine($"Max Calls/Update:".Colorize(Color.grey) + $" {stats.HighestCalls}");

            listing.Label(sb.ToTaggedString().Trim());

            DubGUI.ResetFont();

            listing.End();

            Widgets.EndScrollView();
        }
コード例 #5
0
 public double Double(LogStats stats) => getDouble(stats);
コード例 #6
0
 public int Int(LogStats stats) => getInt(stats);