Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfilingEvent" /> struct.
 /// </summary>
 /// <param name="profileId">The profile identifier.</param>
 /// <param name="profilingKey">The profiling key.</param>
 /// <param name="profilingType">Type of the profiling.</param>
 /// <param name="timeStamp"></param>
 /// <param name="elapsedTime">The elapsed time.</param>
 /// <param name="text">The text.</param>
 /// <param name="attributes">The attributes.</param>
 /// <param name="value0"></param>
 /// <param name="value1"></param>
 /// <param name="value2"></param>
 /// <param name="value3"></param>
 public ProfilingEvent(
     int profileId, 
     ProfilingKey profilingKey, 
     ProfilingMessageType profilingType, 
     long timeStamp, 
     long elapsedTime, 
     string text, 
     Dictionary<object, object> attributes,
     ProfilingCustomValue? value0 = null,
     ProfilingCustomValue? value1 = null,
     ProfilingCustomValue? value2 = null,
     ProfilingCustomValue? value3 = null)
 {
     Id = profileId;
     Key = profilingKey;
     Type = profilingType;
     TimeStamp = timeStamp;
     ElapsedTime = elapsedTime;
     Text = text;
     Attributes = attributes;
     Custom0 = value0;
     Custom1 = value1;
     Custom2 = value2;
     Custom3 = value3;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a profiler with the specified key. The returned object must be disposed at the end of the section
        /// being profiled. See remarks.
        /// </summary>
        /// <param name="profilingKey">The profile key.</param>
        /// <param name="textFormat">The text to format.</param>
        /// <param name="value0"></param>
        /// <param name="value1"></param>
        /// <param name="value2"></param>
        /// <param name="value3"></param>
        /// <returns>A profiler state.</returns>
        /// <remarks>It is recommended to call this method with <c>using (var profile = Profiler.Profile(...))</c> in order to make sure that the Dispose() method will be called on the
        /// <see cref="ProfilingState" /> returned object.</remarks>
        public static ProfilingState Begin(ProfilingKey profilingKey, string textFormat, ProfilingCustomValue value0, ProfilingCustomValue?value1 = null, ProfilingCustomValue?value2 = null, ProfilingCustomValue?value3 = null)
        {
            var profiler = New(profilingKey);

            if (value1.HasValue)
            {
                if (value2.HasValue)
                {
                    if (value3.HasValue)
                    {
                        profiler.Begin(textFormat, value0, value1.Value, value2.Value, value3.Value);
                    }
                    else
                    {
                        profiler.Begin(textFormat, value0, value1.Value, value2.Value);
                    }
                }
                else
                {
                    profiler.Begin(textFormat, value0, value1.Value);
                }
            }
            else
            {
                profiler.Begin(textFormat, value0);
            }
            return(profiler);
        }
Ejemplo n.º 3
0
        private void EmitEvent(ProfilingMessageType profilingType, string text, ProfilingCustomValue? value0, ProfilingCustomValue? value1, ProfilingCustomValue? value2, ProfilingCustomValue? value3)
        {
            // Perform a Mark event only if the profiling is running
            if (!isEnabled) return;

            var timeStamp = Stopwatch.GetTimestamp();

            if (profilingType == ProfilingMessageType.Begin)
            {
                startTime = timeStamp;
            }

            //this actually stores the LAST text into beginText so to be able to add it at the end
            if(profilingType != ProfilingMessageType.End && text != null)
            {
                beginText = text;
            }

            // Create profiler event
            var profilerEvent = new ProfilingEvent(profilingId, profilingKey, profilingType, timeStamp, timeStamp - startTime, beginText ?? text, attributes, value0, value1, value2, value3);

            if (profilingType == ProfilingMessageType.End)
            {
                beginText = null;
            }

            // Send profiler event to Profiler
            Profiler.ProcessEvent(ref profilerEvent);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Emits a End profiling event with the specified custom value.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="value0">Can be int, float, long or double</param>
 /// <param name="value1">Can be int, float, long or double</param>
 /// <param name="value2">Can be int, float, long or double</param>
 /// <param name="value3">Can be int, float, long or double</param>
 public void End(ProfilingCustomValue? value0, ProfilingCustomValue? value1 = null, ProfilingCustomValue? value2 = null, ProfilingCustomValue? value3 = null)
 {
     EmitEvent(ProfilingMessageType.End, null, value0, value1, value2, value3);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Emits a Mark profiling event with the specified text.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="value0">Can be int, float, long or double</param>
 /// <param name="value1">Can be int, float, long or double</param>
 /// <param name="value2">Can be int, float, long or double</param>
 /// <param name="value3">Can be int, float, long or double</param>
 public void Mark(string text, ProfilingCustomValue? value0, ProfilingCustomValue? value1 = null, ProfilingCustomValue? value2 = null, ProfilingCustomValue? value3 = null)
 {
     EmitEvent(ProfilingMessageType.Mark, text, value0, value1, value2, value3);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a profiler with the specified key. The returned object must be disposed at the end of the section
 /// being profiled. See remarks.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 /// <param name="textFormat">The text to format.</param>
 /// <param name="value0"></param>
 /// <param name="value1"></param>
 /// <param name="value2"></param>
 /// <param name="value3"></param>
 /// <returns>A profiler state.</returns>
 /// <remarks>It is recommended to call this method with <c>using (var profile = Profiler.Profile(...))</c> in order to make sure that the Dispose() method will be called on the
 /// <see cref="ProfilingState" /> returned object.</remarks>
 public static ProfilingState Begin(ProfilingKey profilingKey, string textFormat, ProfilingCustomValue value0, ProfilingCustomValue? value1 = null, ProfilingCustomValue? value2 = null, ProfilingCustomValue? value3 = null)
 {
     var profiler = New(profilingKey);
     if (value1.HasValue)
     {
         if (value2.HasValue)
         {
             if (value3.HasValue)
             {
                 profiler.Begin(textFormat, value0, value1.Value, value2.Value, value3.Value);
             }
             else
             {
                 profiler.Begin(textFormat, value0, value1.Value, value2.Value);
             }
         }
         else
         {
             profiler.Begin(textFormat, value0, value1.Value);
         }
     }
     else
     {
         profiler.Begin(textFormat, value0);
     }
     return profiler;
 }