Esempio 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;
 }
Esempio n. 2
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(ProfilingKey parent, string name, ProfilingKeyFlags flags = ProfilingKeyFlags.None)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Children = new List <ProfilingKey>();
            Parent   = parent;

            // TODO: add a lock because the currently passed parent is static and might crash in the game studio where we have multiple concurrent games - this need to be reviewed.
            lock (parent.Children)
            {
                // Register ourself in parent's children.
                parent.Children.Add(this);
            }
            Name  = string.Format("{0}.{1}", Parent, name);
            Flags = flags;

            lock (AllKeys)
            {
                AllKeys.Add(this);
            }
        }
Esempio n. 3
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;
 }
Esempio n. 4
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(ProfilingKey profilingKey, string text)
        {
            var profiler = New(profilingKey);

            profiler.Begin(text);
            return(profiler);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityProcessor"/> class.
        /// </summary>
        /// <param name="mainComponentType">Type of the main component.</param>
        /// <param name="additionalTypes">The additional types required by this processor.</param>
        /// <exception cref="System.ArgumentNullException">If parameteters are null</exception>
        /// <exception cref="System.ArgumentException">If a type does not inherit from EntityComponent</exception>
        protected EntityProcessor(Type mainComponentType, Type[] additionalTypes)
        {
            if (mainComponentType == null) throw new ArgumentNullException(nameof(mainComponentType));
            if (additionalTypes == null) throw new ArgumentNullException(nameof(additionalTypes));

            MainComponentType = mainComponentType;
            mainTypeInfo = MainComponentType.GetTypeInfo();
            Enabled = true;

            RequiredTypes = new TypeInfo[additionalTypes.Length];

            // Check that types are valid
            for (int i = 0; i < additionalTypes.Length; i++)
            {
                var requiredType = additionalTypes[i];
                if (!typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(requiredType.GetTypeInfo()))
                {
                    throw new ArgumentException($"Invalid required type [{requiredType}]. Expecting only an EntityComponent type");
                }

                RequiredTypes[i] = requiredType.GetTypeInfo();
            }

            if (RequiredTypes.Length > 0)
            {
                componentTypesSupportedAsRequired = new Dictionary<TypeInfo, bool>();
            }

            UpdateProfilingKey = new ProfilingKey(GameProfilingKeys.GameUpdate, this.GetType().Name);
            DrawProfilingKey = new ProfilingKey(GameProfilingKeys.GameDraw, this.GetType().Name);
        }
Esempio n. 7
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>
        /// <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)
        {
            var profiler = New(profilingKey);

            profiler.Begin();
            return(profiler);
        }
Esempio n. 8
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(ProfilingKey profilingKey, string textFormat, params object[] textFormatArguments)
        {
            var profiler = New(profilingKey);

            profiler.Begin(textFormat, textFormatArguments);
            return(profiler);
        }
Esempio n. 9
0
        public static ProfilingState Begin([NotNull] ProfilingKey profilingKey, long timeStamp)
        {
            var profiler = New(profilingKey);

            profiler.Begin(timeStamp);
            return(profiler);
        }
Esempio n. 10
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, ProfilingKey profilingKey, ProfilingMessageType profilingType, string text)
            : base("Profiler", LogMessageType.Info, text)
        {
            if (profilingKey == null) throw new ArgumentNullException("profilingKey");

            Id = profileId;
            Key = profilingKey;
            ProfilingType = profilingType;
        }
Esempio n. 11
0
 internal ProfilingState(int profilingId, ProfilingKey profilingKey, bool isEnabled)
 {
     this.profilingId            = profilingId;
     this.profilingKey           = profilingKey;
     this.isEnabled              = isEnabled;
     this.disposeProfileDelegate = null;
     attributes = null;
     beginText  = null;
     startTime  = 0;
 }
Esempio n. 12
0
 internal ProfilingState(int profilingId, ProfilingKey profilingKey, bool isEnabled)
 {
     this.profilingId = profilingId;
     this.profilingKey = profilingKey;
     this.isEnabled = isEnabled;
     this.disposeProfileDelegate = null;
     attributes = null;
     beginText = null;
     startTime = 0;
 }
Esempio n. 13
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="elapsedTime">The elapsed time.</param>
 /// <param name="text">The text.</param>
 /// <param name="attributes">The attributes.</param>
 public ProfilingEvent(int profileId, ProfilingKey profilingKey, ProfilingMessageType profilingType, long timeStamp, long elapsedTime, string text, Dictionary <object, object> attributes)
 {
     Id          = profileId;
     Key         = profilingKey;
     Type        = profilingType;
     TimeStamp   = timeStamp;
     ElapsedTime = elapsedTime;
     Text        = text;
     Attributes  = attributes;
 }
Esempio n. 14
0
 /// <summary>
 /// Enables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static void Enable([NotNull] ProfilingKey profilingKey)
 {
     lock (Locker)
     {
         profilingKey.Enabled = true;
         foreach (var child in profilingKey.Children)
         {
             Enable(child);
         }
     }
 }
Esempio n. 15
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;
 }
Esempio n. 16
0
 /// <summary>
 /// Disables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static void Disable(ProfilingKey profilingKey)
 {
     lock (Locker)
     {
         profilingKey.Enabled = false;
         foreach (var child in profilingKey.Children)
         {
             Disable(child);
         }
     }
 }
Esempio n. 17
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(ProfilingKey profilingKey)
        {
            if (profilingKey == null)
            {
                throw new ArgumentNullException("profilingKey");
            }

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

            return(new ProfilingState(localProfileId, profilingKey, isProfileActive));
        }
Esempio n. 18
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;
        }
Esempio n. 19
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(ProfilingKey parent, string name, ProfilingKeyFlags flags = ProfilingKeyFlags.None)
        {
            if (parent == null) throw new ArgumentNullException("parent");
            if (name == null) throw new ArgumentNullException("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);
            }
        }
Esempio n. 20
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(ProfilingKey parent, string name, ProfilingKeyFlags flags = ProfilingKeyFlags.None)
        {
            if (parent == null) throw new ArgumentNullException("parent");
            if (name == null) throw new ArgumentNullException("name");
            Children = new List<ProfilingKey>();
            Parent = parent;

            // Register ourself in parent's children.
            parent.Children.Add(this);

            Name = string.Format("{0}.{1}", Parent, name);
            Flags = flags;

            lock (AllKeys)
            {
                AllKeys.Add(this);
            }
        }
Esempio n. 21
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);
            }
        }
Esempio n. 22
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(ProfilingKey parent, string name, ProfilingKeyFlags flags = ProfilingKeyFlags.None)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Children = new List <ProfilingKey>();
            Parent   = parent;

            // Register ourself in parent's children.
            parent.Children.Add(this);

            Name  = string.Format("{0}.{1}", Parent, name);
            Flags = flags;

            lock (AllKeys)
            {
                AllKeys.Add(this);
            }
        }
Esempio n. 23
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;
 }
Esempio n. 24
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, ProfilingKey profilingKey, ProfilingMessageType profilingType) : this(profileId, profilingKey, profilingType, null)
 {
 }
Esempio n. 25
0
 /// <summary>
 /// Enables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static bool IsEnabled(ProfilingKey profilingKey)
 {
     return(enableAll || profilingKey.Enabled);
 }
Esempio n. 26
0
 /// <summary>
 /// Disables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static void Disable(ProfilingKey profilingKey)
 {
     lock (Locker)
     {
         profilingKey.Enabled = false;
         foreach (var child in profilingKey.Children)
         {
             Disable(child);
         }
     }
 }
Esempio n. 27
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(ProfilingKey profilingKey)
        {
            if (profilingKey == null) throw new ArgumentNullException("profilingKey");

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

            return new ProfilingState(localProfileId, profilingKey, isProfileActive);
        }
Esempio n. 28
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>
 /// <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)
 {
     var profiler = New(profilingKey);
     profiler.Begin();
     return profiler;
 }
Esempio n. 29
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(ProfilingKey profilingKey, string text)
 {
     var profiler = New(profilingKey);
     profiler.Begin(text);
     return profiler;
 }
Esempio n. 30
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(ProfilingKey profilingKey, string textFormat, params object[] textFormatArguments)
 {
     var profiler = New(profilingKey);
     profiler.Begin(textFormat, textFormatArguments);
     return profiler;
 }
Esempio n. 31
0
 /// <summary>
 /// Enables the specified profiler.
 /// </summary>
 /// <param name="profilingKey">The profile key.</param>
 public static bool IsEnabled(ProfilingKey profilingKey)
 {
     return enableAll || profilingKey.Enabled;
 }
Esempio n. 32
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)
 {
 }
Esempio n. 33
0
 protected EntityProcessor(PropertyKey[] requiredKeys)
 {
     UpdateProfilingKey = new ProfilingKey(GameProfilingKeys.GameUpdate, this.GetType().Name);
     DrawProfilingKey = new ProfilingKey(GameProfilingKeys.GameDraw, this.GetType().Name);
     this.requiredKeys = requiredKeys;
 }