コード例 #1
0
        public static IChoProfileBackingStore GetProfileBackingStore(string name, string startActions, string stopActions)
        {
            if (_profileBackingStoreCache.ContainsKey(name))
            {
                return(_profileBackingStoreCache[name]);
            }

            lock (_padLock)
            {
                if (!_profileBackingStoreCache.ContainsKey(name))
                {
                    try
                    {
                        XmlNode configNode = ChoProfileBackingStoreConfigManager.Load(name, ref startActions, ref stopActions);
                        IChoProfileBackingStore profileBackingStore = null;                         //ChoObjectFactory.CreateInstance<IChoProfileBackingStore>(new object[] { name, startActions, stopActions, configNode });
                        if (profileBackingStore == null)
                        {
                            Trace.TraceInformation("Failed to create '{0}' profile backingstore, using default one.", name);
                            profileBackingStore = _defaultProfileBackingStore.Value;
                        }

                        _profileBackingStoreCache.Add(name, profileBackingStore);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Failed to create '{0}' profile backingstore, using default one. {2}{1}", name, ex.ToString(), Environment.NewLine);
                        _profileBackingStoreCache.Add(name, _defaultProfileBackingStore.Value);
                    }
                }
            }

            return(_profileBackingStoreCache[name]);
        }
コード例 #2
0
        internal ChoBaseProfile(bool condition, string name, string msg, IChoProfile outerProfile, bool delayedStartProfile, string startActions, string stopActions)
        {
            _condition = condition;
            _name      = name.IsNullOrWhiteSpace() || name == ChoProfile.DEFAULT_PROFILE_NAME ? String.Format("Profile_{0}".FormatString(ChoRandom.NextRandom())) : name;
            if (outerProfile != ChoProfile.NULL)
            {
                _outerProfile = outerProfile;
            }
            if (_outerProfile == null)
            {
                _profileBackingStore = ChoProfileBackingStoreManager.GetProfileBackingStore(name, startActions, stopActions);
            }
            _delayedStartProfile = delayedStartProfile;
            if (_condition)
            {
                if (!msg.IsNullOrEmpty())
                {
                    _msg = msg;
                }
                else if (!_name.IsNullOrEmpty())
                {
                    _msg = String.Format(_msg, _name);
                }
                else
                {
                    _msg = ChoProfile.GetDefaultMsg(ChoStackTrace.GetStackFrame(GetType().Namespace));
                }
            }

            if (ChoTraceSettings.Me.IndentProfiling)
            {
                if (outerProfile != null)
                {
                    if (outerProfile.ProfilerName != ChoProfile.GLOBAL_PROFILE_NAME && outerProfile.ProfilerName != ChoProfile.NULL_PROFILE_NAME)
                    {
                        _indent = outerProfile.Indent + 1;
                    }
                }
            }
            if (!_delayedStartProfile)
            {
                StartIfNotStarted();
            }

            if (_outerProfile is ChoProfileContainer)
            {
                ((ChoProfileContainer)_outerProfile).Add(this);
                _parentProfile = outerProfile;
            }

            if (name != ChoProfile.GLOBAL_PROFILE_NAME && name != ChoProfile.NULL_PROFILE_NAME && name != ChoProfile.CURRENT_CONTEXT_PROFILE /* && outerProfile != null */)
            {
                ChoProfile.Register(this);
                _registered = true;
            }
        }
コード例 #3
0
        public static IChoProfileBackingStore GetProfileBackingStore(string name, string startActions, string stopActions)
        {
            IChoProfileBackingStore profileBackingStore = null;

            if (TryGetProfileBackingStore(name, startActions, stopActions, ref profileBackingStore))
            {
                return(profileBackingStore);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        private static IChoProfileBackingStore ConstructProfileBackingStore(ChoProfileBackingStoreDef profileBackingStoreDef, out string startActions, out string stopActions)
        {
            if (profileBackingStoreDef.Name.IsNullOrWhiteSpace())
            {
                throw new ApplicationException("{0}: Node does not contain profile backing store object.".FormatString(profileBackingStoreDef.Name));
            }

            startActions = null;
            stopActions  = null;
            IChoProfileBackingStore pbsObject = profileBackingStoreDef.Construct(ref startActions, ref stopActions) as IChoProfileBackingStore;

            if (pbsObject == null)
            {
                throw new ApplicationException("{0}: Node does not contain profile backing store object.".FormatString(profileBackingStoreDef.Name));
            }

            return(pbsObject);
        }
コード例 #5
0
        internal ChoBaseProfile(bool condition, string name, string msg, ChoBaseProfile outerProfile, bool delayedStartProfile, string startActions, string stopActions)
        {
            _condition    = condition;
            _name         = name;
            _outerProfile = outerProfile;
            if (_outerProfile == null)
            {
                _profileBackingStore = ChoProfileBackingStoreManager.GetProfileBackingStore(name, startActions, stopActions);
            }
            _delayedStartProfile = delayedStartProfile;
            if (_condition)
            {
                if (!msg.IsNullOrEmpty())
                {
                    _msg = msg;
                }
                else if (!_name.IsNullOrEmpty())
                {
                    _msg = String.Format(_msg, _name);
                }
                else
                {
                    _msg = ChoProfile.GetDefaultMsg(ChoStackTrace.GetStackFrame(GetType().Namespace));
                }
            }

            if (ChoTraceSettings.Me.IndentProfiling)
            {
                if (outerProfile != null)
                {
                    _indent = outerProfile.Indent + 1;
                }
            }
            if (!_delayedStartProfile)
            {
                StartIfNotStarted();
            }

            if (_outerProfile is ChoProfileContainer)
            {
                ((ChoProfileContainer)_outerProfile).Add(this);
            }
        }
コード例 #6
0
        public static IChoProfileBackingStore GetProfileBackingStore(string name, string startActions, string stopActions)
        {
            if (_profileBackingStoreCache.ContainsKey(name))
            {
                return(_profileBackingStoreCache[name]);
            }

            lock (_padLock)
            {
                if (!_profileBackingStoreCache.ContainsKey(name))
                {
                    try
                    {
                        string configStartActions = null;
                        string configStopActions  = null;

                        IChoProfileBackingStore profileBackingStore = null;

                        if (!ChoProfileBackingStoreConfigManager.TryGetProfileBackingStore(name, ref configStartActions, ref configStopActions, ref profileBackingStore))
                        {
                            Trace.TraceInformation("Failed to create '{0}' profile backingstore, using default one.", name);
                            profileBackingStore = _defaultProfileBackingStore.Value;
                        }
                        else
                        {
                            profileBackingStore.Start(configStartActions.IsNullOrWhiteSpace() ? startActions : configStartActions);
                        }

                        _profileBackingStoreCache.Add(name, profileBackingStore);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Failed to create '{0}' profile backingstore, using default one. {2}{1}", name, ex.ToString(), Environment.NewLine);
                        _profileBackingStoreCache.Add(name, _defaultProfileBackingStore.Value);
                    }
                }
            }

            return(_profileBackingStoreCache[name]);
        }
コード例 #7
0
        public static bool TryGetProfileBackingStore(string name, string startActions, string stopActions, ref IChoProfileBackingStore profileBackingStore)
        {
            ChoGuard.ArgumentNotNullOrEmpty(name, "Name");

            if (_profilerCache.ContainsKey(name))
            {
                profileBackingStore = _profilerCache[name];
                return(true);
            }

            lock (_padLock)
            {
                if (!_profilerCache.ContainsKey(name))
                {
                    try
                    {
                        profileBackingStore = ConstructProfiler(name);
                        if (profileBackingStore == null)
                        {
                            if (name == ChoProfile.GLOBAL_PROFILE_NAME || name == ChoProfile.NULL_PROFILE_NAME || name == ChoProfile.DEFAULT_PROFILE_NAME)
                            {
                            }
                            else
                            {
                                Trace.TraceInformation("Failed to find profile backingstore for '{0}' logger, using default one.", name);
                            }
                            profileBackingStore = _defaultProfileBackingStore.Value;
                        }

                        if (_profilerCache.ContainsKey(name))
                        {
                            Trace.TraceError("Duplicate '{0}' logger found. {1}", name, Environment.NewLine);
                        }
                        else
                        {
                            _profilerCache.Add(name, profileBackingStore);
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Failed to create profile backingstore for '{0}' logger, using default one. {2}{1}", name, ex.ToString(), Environment.NewLine);
                        _profilerCache.Add(name, _defaultProfileBackingStore.Value);
                    }
                }
                profileBackingStore = _profilerCache[name];
            }

            return(true);
        }