Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new step information on the same level as before
        /// </summary>
        /// <param name="step"></param>
        public static void NextStage(string step)
        {
#if LEAK_TRACE
            EngineStageInformation parent = _current?.Parent;

            EngineStageInformation cur = _current;

            ChangeStage(step, true);  //Change out the step
            _current.Parent = parent; //Set it up to be the substep on the same level
            if (parent == null)
            {
                _informationCollection.Add(_current);

                if (cur != null)
                {
                    _console?.AddGraphValue((float)cur.TimeSpentInStage.TotalMilliseconds);
                }


                while (_informationCollection.Count >= MaxTraceCount)
                {
                    _informationCollection.RemoveAt(0);
                }
            }
            else
            {
                parent.SubStages.Add(_current); //If not null then we add it to the parent list of substeps
            }
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a "console-friendly" view of the Engine Stage by utilizing tabulators
        /// </summary>
        /// <param name="info">The info to represent</param>
        /// <param name="depth">The depth of the Engine Stage(Gets used for placing Tabulator characters)</param>
        /// <returns></returns>
        public static string ToConsoleText(EngineStageInformation info, int depth)
        {
            StringBuilder ind = new StringBuilder("\t");

            for (int i = 0; i < depth; i++)
            {
                ind.Append("\t");
            }

            StringBuilder ret = new StringBuilder(info.Name + "\n");

            ret.AppendLine($"{ind}KB Used Before: {info.Before}");
            ret.AppendLine($"{ind}KB Used After: {info.After}");
            ret.AppendLine($"{ind}KB Used After(post GC): {info.AfterGarbageCollection}");
            ret.AppendLine($"{ind}Elapsed Time(MS): {info.TimeSpentInStage.TotalMilliseconds}");
            ret.AppendLine($"{ind}Substep Count: {info.SubStages.Count}");
            ret.AppendLine($"{ind}Substeps:");


            foreach (EngineStageInformation stepMemoryInformation in info.SubStages)
            {
                ret.Append(ToConsoleText(stepMemoryInformation, depth + 1));
            }

            return(ret.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Changes the Stage to the next stage/ or a substage
        /// </summary>
        /// <param name="name">Name of the next stage</param>
        /// <param name="finalize">If true it will end the last stage(e.g. its not a substage)</param>
        /// <returns></returns>
        private static EngineStageInformation ChangeStage(string name, bool finalize)
        {
            EngineStageInformation old = _current;

            if (finalize)
            {
                old?.FinalizeStage();
            }

            _current = new EngineStageInformation(name);
            return(old);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns to the next higher parent step(does nothing when in root)
        /// </summary>
        public static void ReturnFromSubStage()
        {
#if LEAK_TRACE
            if (_current != null)
            {
                _current.FinalizeStage();
                if (_current.Parent != null)
                {
                    _current = _current.Parent;
                }
            }
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new step information on one level deeper as before
        /// </summary>
        /// <param name="step"></param>
        public static void AddSubStage(string step)
        {
#if LEAK_TRACE
            EngineStageInformation current = _current; //Store the current step or substep
            ChangeStage(step, false);
            _current.Parent = current;                 //Set it up to be the substep on one level deeper
            if (current == null)
            {
                _informationCollection.Add(_current);

                while (_informationCollection.Count >= MaxTraceCount)
                {
                    _informationCollection.RemoveAt(0);
                }
            }
            else
            {
                current.SubStages.Add(_current); //If not null then we add it to the parent list of substeps
            }
#endif
        }