Exemplo n.º 1
0
        // Calculates statistics from the profiling data and outputs it to the Unity log.
        private void OutputStats()
        {
            Statistics.Summary stats = new Statistics.Summary(m_FrameTimes.ToArray());
            int numBatches           = App.ActiveCanvas.BatchManager.CountBatches();
            int numTriangles         = App.ActiveCanvas.BatchManager.CountAllBatchTriangles();

            // Timing isn't always exact, which is why the 0.5ms extra is added on.
            float[] frameLimits      = m_ValidFramerates.Select(x => 1000f / x + 0.5f).ToArray();
            int[]   frameRateBuckets = new int[m_ValidFramerates.Length];
            foreach (float frameTime in m_FrameTimes)
            {
                for (int i = 0; i < frameRateBuckets.Length; ++i)
                {
                    if (frameTime < frameLimits[i])
                    {
                        frameRateBuckets[i]++;
                        break;
                    }
                }
            }

            float percentScale = 100f / m_FrameTimes.Count;

            float[] frameRatePercentages = frameRateBuckets.Select(x => x * percentScale).ToArray();

            var profileName = App.UserConfig.Profiling.ProfileName;
            var humanName   = SaveLoadScript.m_Instance.GetLastFileHumanName();
            var fileName    = System.IO.Path.GetFileNameWithoutExtension(
                SaveLoadScript.m_Instance.SceneFile.FullPath);

            StringBuilder message = new StringBuilder();
            string        file    = string.IsNullOrEmpty(App.UserConfig.Profiling.ProfileName)
                ? SaveLoadScript.m_Instance.GetLastFileHumanName()
                : App.UserConfig.Profiling.ProfileName;

            message.AppendLine("TBProfile: START");
            if (App.UserConfig.Profiling.PerfgateOutput)
            {
                PerfgateOutput(message, m_FrameTimes.ToArray(), numBatches, numTriangles, file);
            }
            else
            {
                if (App.UserConfig.Profiling.Csv)
                {
                    CsvOutput(message, stats, numBatches, numTriangles, frameRatePercentages, file);
                }
                else
                {
                    HumanReadableOutput(message, stats, numBatches, numTriangles, frameRatePercentages);
                }
            }
            message.AppendLine("TBProfile: END");

            Debug.Log(message.ToString());
        }
Exemplo n.º 2
0
        private void CsvOutput(StringBuilder output, Statistics.Summary stats, int numBatches,
                               int numTriangles, float[] frameRatePercentages, string filename)
        {
            output.AppendFormat(
                "TBProfile: {8}, {0}, {1:F2}, {2:F2}, {3:F2}, {4:F2}, {5:F1}, {6}, {7}, ",
                m_FrameTimes.Count, stats.Min, stats.Median, stats.Max, stats.StandardDeviation,
                stats.StandardDeviationPcOfMedian, numBatches, numTriangles, filename);

            IEnumerable <string> sections = frameRatePercentages.Select(x => x.ToString("F1"));

            output.AppendLine(string.Join(", ", sections.ToArray()));
        }
Exemplo n.º 3
0
        private void HumanReadableOutput(StringBuilder output, Statistics.Summary stats, int numBatches,
                                         int numTriangles, float[] frameRatePercentages)
        {
            output.AppendFormat(
                "TBProfile: Frames: {0}  Min: {1:F2}  Median: {2:F2}  Max:{3:F2}  StdDev:{4:F2} StdDev%:{5:F1} Batches:{6} Tris:{7}\n",
                m_FrameTimes.Count, stats.Min, stats.Median, stats.Max, stats.StandardDeviation,
                stats.StandardDeviationPcOfMedian, numBatches, numTriangles);

            IEnumerable <string> sections = Enumerable.Range(0, m_ValidFramerates.Length).Select(i =>
                                                                                                 string.Format("{0}fps: {1:F1}%", m_ValidFramerates[i], frameRatePercentages[i]));

            output.Append("TBProfile: ");
            output.AppendLine(string.Join("  ", sections.ToArray()));

            foreach (var sample in m_Samples)
            {
                var times = sample.frameData.Select(x => x.elapsedNanoseconds / 1000000f).Where(x => x > 0);
                stats = new Statistics.Summary(times.ToArray());
                output.AppendFormat(
                    "Profile: {0}: Frames: {1} Min: {2:F2}  Median: {3:F2}  Max:{4:F2}  StdDev:{5:F2}  StdDev%:{6:F1}\n",
                    sample.name, sample.frameData.Count, stats.Min, stats.Median, stats.Max,
                    stats.StandardDeviation, stats.StandardDeviationPcOfMedian);
            }
        }