示例#1
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">First value (can be int, float, long or double).</param>
        /// <param name="value1">Second value (can be int, float, long or double).</param>
        /// <param name="value2">Third value (can be int, float, long or double).</param>
        /// <param name="value3">Fourth value (can be int, float, long or double).</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([NotNull] 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);
        }
示例#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="text">The text to log with the profile.</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([NotNull] ProfilingKey profilingKey, string text = null)
        {
            var profiler = New(profilingKey);

            profiler.Begin(text);
            return(profiler);
        }
示例#3
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="textFormatArguments">The text format arguments.</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([NotNull] ProfilingKey profilingKey, string textFormat, params object[] textFormatArguments)
        {
            var profiler = New(profilingKey);

            profiler.Begin(textFormat, textFormatArguments);
            return(profiler);
        }
示例#4
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;
 }
示例#5
0
 /// <summary>
 /// Disables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static void Disable([NotNull] ProfilingKey profilingKey)
 {
     lock (Locker)
     {
         profilingKey.Enabled = false;
         foreach (var child in profilingKey.Children)
         {
             Disable(child);
         }
     }
 }
示例#6
0
 internal ProfilingState(int profilingId, ProfilingKey profilingKey, bool isEnabled)
 {
     ProfilingId     = profilingId;
     ProfilingKey    = profilingKey;
     this.isEnabled  = isEnabled;
     DisposeDelegate = null;
     attributes      = null;
     beginText       = null;
     startTime       = 0;
     eventType       = ProfilingEventType.CpuProfilingEvent;
 }
示例#7
0
        /// <summary>
        /// Creates a profiler with the specified name. The returned object must be disposed at the end of the section
        /// being profiled. See remarks.
        /// </summary>
        /// <param name="profilingKey">The profile key.</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 New([NotNull] ProfilingKey profilingKey)
        {
            if (profilingKey == null)
            {
                throw new ArgumentNullException(nameof(profilingKey));
            }

            var localProfileId  = Interlocked.Increment(ref profileId) - 1;
            var isProfileActive = IsEnabled(profilingKey);

            return(new ProfilingState(localProfileId, profilingKey, isProfileActive));
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProfilingMessage" /> class.
        /// </summary>
        /// <param name="profileId">The profile unique identifier.</param>
        /// <param name="profilingKey">The profile key.</param>
        /// <param name="profilingType">Type of the profile.</param>
        /// <param name="text">The text.</param>
        public ProfilingMessage(int profileId, [NotNull] ProfilingKey profilingKey, ProfilingMessageType profilingType, string text)
            : base("Profiler", LogMessageType.Info, text)
        {
            if (profilingKey == null)
            {
                throw new ArgumentNullException(nameof(profilingKey));
            }

            Id            = profileId;
            Key           = profilingKey;
            ProfilingType = profilingType;
        }
示例#9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProfilingKey" /> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="name">The name.</param>
        /// <exception cref="System.ArgumentNullException">parent</exception>
        public ProfilingKey([NotNull] ProfilingKey parent, [NotNull] string name, ProfilingKeyFlags flags = ProfilingKeyFlags.None)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            Children = new List <ProfilingKey>();
            Parent   = parent;
            Name     = $"{Parent}.{name}";
            Flags    = flags;

            lock (AllKeys)
            {
                // Register ourself in parent's children.
                parent.Children?.Add(this);

                AllKeys.Add(this);
            }
        }
示例#10
0
 /// <summary>
 /// Enables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static bool IsEnabled(ProfilingKey profilingKey)
 {
     return(enableAll || profilingKey.Enabled);
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfilingMessage" /> class.
 /// </summary>
 /// <param name="profileId">The profile unique identifier.</param>
 /// <param name="profilingKey">The profile key.</param>
 /// <param name="profilingType">Type of the profile.</param>
 public ProfilingMessage(int profileId, [NotNull] ProfilingKey profilingKey, ProfilingMessageType profilingType) : this(profileId, profilingKey, profilingType, null)
 {
 }