Example #1
0
        /// <summary>
        /// Creates a new profiler thread.
        /// </summary>
        /// <param name="Name">Name of profiler thread.</param>
        /// <param name="Type">Type of profiler thread.</param>
        /// <param name="Parent">Parent thread.</param>
        /// <returns>Profiler thread reference.</returns>
        internal ProfilerThread CreateThread(string Name, ProfilerThreadType Type, ProfilerThread Parent)
        {
            ProfilerThread Result = new ProfilerThread(Name, ++this.threadOrder, Type, Parent);

            this.threads.Add(Result);
            return(Result);
        }
Example #2
0
        /// <summary>
        /// Creates a new profiler thread.
        /// </summary>
        /// <param name="Name">Name of profiler thread.</param>
        /// <param name="Type">Type of profiler thread.</param>
        /// <returns>Profiler thread reference.</returns>
        public ProfilerThread CreateThread(string Name, ProfilerThreadType Type)
        {
            ProfilerThread Result = new ProfilerThread(Name, ++this.threadOrder, Type, this);

            this.threads.Add(Result);
            return(Result);
        }
Example #3
0
        /// <summary>
        /// Creates a new profiler thread.
        /// </summary>
        /// <param name="Name">Name of profiler thread.</param>
        /// <param name="Type">Type of profiler thread.</param>
        /// <returns>Profiler thread reference.</returns>
        public ProfilerThread CreateSubThread(string Name, ProfilerThreadType Type)
        {
            ProfilerThread Result = this.profiler.CreateThread(Name, Type, this);

            this.subThreads.Add(Result);
            return(Result);
        }
Example #4
0
 /// <summary>
 /// Class that keeps track of events and timing for one thread.
 /// </summary>
 /// <param name="Name">Name of thread.</param>
 /// <param name="Order">Order created.</param>
 /// <param name="Type">Type of profiler thread.</param>
 /// <param name="Parent">Parent thread.</param>
 public ProfilerThread(string Name, int Order, ProfilerThreadType Type, ProfilerThread Parent)
 {
     this.name     = Name;
     this.order    = Order;
     this.type     = Type;
     this.parent   = Parent;
     this.profiler = this.parent.Profiler;
 }
Example #5
0
 /// <summary>
 /// Class that keeps track of events and timing for one thread.
 /// </summary>
 /// <param name="Name">Name of thread.</param>
 /// <param name="Order">Order created.</param>
 /// <param name="Type">Type of profiler thread.</param>
 /// <param name="Profiler">Profiler reference.</param>
 public ProfilerThread(string Name, int Order, ProfilerThreadType Type, Profiler Profiler)
 {
     this.name     = Name;
     this.order    = Order;
     this.type     = Type;
     this.profiler = Profiler;
     this.parent   = null;
 }
Example #6
0
        /// <summary>
        /// String representation of time, corresponding to a measured number of high-frequency clock ticks.
        /// </summary>
        /// <param name="Ticks">Ticks</param>
        /// <param name="Thread">Thread associated with event.</param>
        /// <param name="TimeUnit">Time unit to use.</param>
        /// <returns>Corresponding time as a string.</returns>
        public string ToTimeStr(long Ticks, ProfilerThread Thread, TimeUnit TimeUnit)
        {
            KeyValuePair <double, string> Time = this.ToTime(Ticks, Thread, TimeUnit);

            return(Time.Key.ToString("F3") + " " + Time.Value);
        }
Example #7
0
        /// <summary>
        /// Time (amount, unit), corresponding to a measured number of high-frequency clock ticks.
        /// </summary>
        /// <param name="Ticks">Ticks</param>
        /// <param name="Thread">Thread associated with event.</param>
        /// <param name="TimeUnit">Time unit to use.</param>
        /// <returns>Corresponding time.</returns>
        public KeyValuePair <double, string> ToTime(long Ticks, ProfilerThread Thread, TimeUnit TimeUnit)
        {
            double Amount = this.ToSeconds(Ticks);
            double Reference;

            switch (TimeUnit)
            {
            case TimeUnit.MicroSeconds:
                return(new KeyValuePair <double, string>(Amount * 1e6, "μs"));

            case TimeUnit.MilliSeconds:
                return(new KeyValuePair <double, string>(Amount * 1e3, "ms"));

            case TimeUnit.Seconds:
                return(new KeyValuePair <double, string>(Amount, "s"));

            case TimeUnit.Minutes:
                return(new KeyValuePair <double, string>(Amount / 60, "min"));

            case TimeUnit.Hours:
                return(new KeyValuePair <double, string>(Amount / (60 * 60), "h"));

            case TimeUnit.Days:
                return(new KeyValuePair <double, string>(Amount / (24 * 60 * 60), "d"));

            case TimeUnit.DynamicPerProfiling:
                Reference = this.ToSeconds(this.MainThread.StoppedAt ?? this.ElapsedTicks);
                break;

            case TimeUnit.DynamicPerThread:
                Reference = this.ToSeconds(Thread.StoppedAt ?? this.ElapsedTicks);
                break;

            case TimeUnit.DynamicPerEvent:
            default:
                Reference = Amount;
                break;
            }

            Reference *= this.timeScale;

            if (Reference < 1)
            {
                Amount    *= 1e3;
                Reference *= 1e3;
                if (Reference < 1)
                {
                    Amount *= 1e3;
                    return(new KeyValuePair <double, string>(Amount, "μs"));
                }
                else
                {
                    return(new KeyValuePair <double, string>(Amount, "ms"));
                }
            }
            else if (Reference > 100)
            {
                Amount    /= 60;
                Reference /= 60;
                if (Reference > 100)
                {
                    Amount    /= 60;
                    Reference /= 60;
                    if (Reference > 100)
                    {
                        Amount /= 24;
                        return(new KeyValuePair <double, string>(Amount, "d"));
                    }
                    else
                    {
                        return(new KeyValuePair <double, string>(Amount, "h"));
                    }
                }
                else
                {
                    return(new KeyValuePair <double, string>(Amount, "min"));
                }
            }
            else
            {
                return(new KeyValuePair <double, string>(Amount, "s"));
            }
        }
Example #8
0
 /// <summary>
 /// Class that keeps track of events and timing.
 /// </summary>
 /// <param name="Name">Name of main thread.</param>
 /// <param name="Type">Type of profiler thread.</param>
 public Profiler(string Name, ProfilerThreadType Type)
 {
     this.mainThread = this.CreateThread(Name, Type);
     this.watch      = new Stopwatch();
 }