예제 #1
0
        internal ChoBufferProfileEx(bool condition, string name, string filePath, ChoProfileIntializationAction mode, TextWriter streamWriter, string msg, IChoProfile outerProfile, bool register)
        {
            _condition = condition;
            _mode      = mode;
            FilePath   = String.IsNullOrEmpty(filePath) ? filePath : ChoString.ExpandProperties(filePath);
            TextWriter = streamWriter;
            //OuterProfile = outerProfile;

            if (String.IsNullOrEmpty(msg))
            {
                msg = ChoProfile.GetDefaultMsg(ChoStackTrace.GetStackFrame(GetType().Namespace));
            }

            msg = ChoString.ExpandProperties(msg);

            if (_condition)
            {
                _formattedMsg.AppendFormat("{0} {{{1}", msg, Environment.NewLine);
            }

            if (register)
            {
                ChoProfile.Register(name, this, ChoStackTrace.GetStackFrame(GetType().Namespace), false);
            }

            //if (OuterProfile is ChoProfileContainer)
            //    ((ChoProfileContainer)OuterProfile).Add(this);
        }
예제 #2
0
        //protected virtual void CloseBackingStore()
        //{
        //    if (_profileBackingStore != null)
        //        _profileBackingStore.Stop();
        //}

        protected override void Dispose(bool finalize)
        {
            try
            {
                StartIfNotStarted();

                Clear();
                if (_condition)
                {
                    if (_name != ChoProfile.GLOBAL_PROFILE_NAME && _name != ChoProfile.NULL_PROFILE_NAME)
                    {
                        Write(String.Format("}} [{0}] <---{1}", Convert.ToString(DateTime.Now - _startTime), Environment.NewLine), _indent);
                    }
                }

                Flush();

                if (_registered)
                {
                    ChoProfile.Unregister(this);
                }

                //CloseBackingStore();
            }
            catch (Exception ex)
            {
                ChoTrace.Write(ex);
            }
            finally
            {
                IsDisposed = true;
            }
        }
예제 #3
0
        public ChoProfile(bool condition, string msg, ChoProfile outerProfile)
        {
            _condition = condition;
            if (outerProfile != null)
            {
                _indent = outerProfile._indent + 1;
            }
            if (String.IsNullOrEmpty(msg))
            {
                msg = GetDefaultMsg(ChoStackTrace.GetStackFrame());
            }

            if (_condition)
            {
                if (ChoTraceSettings.Me.IndentProfiling)
                {
                    ChoTrace.WriteLineIf(_condition, ChoStackTrace.GetStackFrame(typeof(ChoProfile)), String.Format("{0} {{", msg).Indent(_indent));
                }
                else
                {
                    ChoTrace.WriteLineIf(_condition, ChoStackTrace.GetStackFrame(typeof(ChoProfile)), String.Format("{0} {{", msg));
                }
            }

            //if (outerProfile is ChoProfileContainer)
            //    ((ChoProfileContainer)outerProfile).Add(this);
        }
예제 #4
0
        protected override void Dispose(bool finalize)
        {
            if (!finalize)
            {
                return;
            }

            try
            {
                Clear();
                if (!DelayedStartProfile || (DelayedStartProfile && Started))
                {
                    if (TraceOnDispose)
                    {
                        if (Condition)
                        {
                            string msg = Environment.NewLine + ToString().Indent(Indent - 1);
                            if (!String.IsNullOrEmpty(FilePath))
                            {
                                //if (Mode == ChoProfileIntializationAction.Roll)
                                //    ChoBufferProfile.RollNWriteLine(FilePath, msg);
                                //else if (Mode == ChoProfileIntializationAction.Truncate)
                                //    ChoBufferProfile.CleanNWriteLine(FilePath, msg);
                                //else
                                //    ChoBufferProfile.WriteLine(FilePath, msg);
                            }
                            else if (TextWriter != null)
                            {
                                TextWriter.Write(msg);
                                TextWriter.Flush();
                            }
                            else
                            {
                                ChoTrace.WriteIf(Condition, ChoStackTrace.GetStackFrame(GetType()), msg);
                            }
                        }
                    }
                    //else if (OuterProfile != null)
                    //    OuterProfile.Append(ToString());
                }

                //ChoProfile.Unregister(CanDispose);

                //if (!finalize)
                //    GC.SuppressFinalize(this);
            }
            catch (Exception ex)
            {
                ChoTrace.Write(ex);
            }
            finally
            {
                IsDisposed = true;
            }
            ChoProfile.Unregister(this);
        }
예제 #5
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;
            }
        }
예제 #6
0
        public override IChoProfile ConstructProfile(object target, IChoProfile outerProfile)
        {
            IChoProfile profile = null;

            if (ChoProfile.TryGetProfile(_refProfileName, ref profile, null))
            {
                return(profile);
            }
            else
            {
                throw new ChoApplicationException("{0} profile not exists.".FormatString(_refProfileName));
            }
        }
예제 #7
0
 internal static void FlushAll()
 {
     ChoProfile.DisposeAll();
     //ChoStreamProfile.Shutdown();
     foreach (TraceListener traceListener in Trace.Listeners)
     {
         if (traceListener == null)
         {
             continue;
         }
         traceListener.Flush();
     }
 }
예제 #8
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);
            }
        }
예제 #9
0
        public override IChoProfile ConstructProfile(object target, IChoProfile outerProfile)
        {
            string message = null;

            if (!String.IsNullOrEmpty(Message))
            {
                message = ChoPropertyManager.ExpandProperties(target, Message);
            }

            IChoProfile profile = null;

            if (ChoProfile.TryGetProfile(Name, ref profile,
                                         () => new ChoBufferProfile(Condition, Name, message, (ChoBaseProfile)outerProfile, false, StartActions, StopActions)))
            {
                return(profile);
            }
            else
            {
                return(null);
            }
        }
예제 #10
0
        private static void Shutdown()
        {
            ChoProfile.DisposeAll();
            if (_pbsDataChangeWatcher != null)
            {
                _pbsDataChangeWatcher.Dispose();
            }
            _pbsDataChangeWatcher = null;

            ChoProfile.Default.Dispose();
            _pbsStore.ForEach((keyValuePair) =>
            {
                if (_profileBackingStopActionsCache.ContainsKey(keyValuePair.Key))
                {
                    keyValuePair.Value.Stop(_profileBackingStopActionsCache[keyValuePair.Key]);
                }
            });

            //_profilerCache.Clear();

            _profileBackingStopActionsCache.Clear();
        }
예제 #11
0
 public string AppendLine(string format, params object[] args)
 {
     return(ChoProfile.GetDefaultContext(_instance).AppendLine(format, args));
 }
예제 #12
0
 public string AppendLine(string msg)
 {
     return(ChoProfile.GetDefaultContext(_instance).AppendLine(msg));
 }
예제 #13
0
 public string AppendLineIf(bool condition, string format, params object[] args)
 {
     return(ChoProfile.GetDefaultContext(_instance).AppendLineIf(condition, format, args));
 }
예제 #14
0
 public string AppendLineIf(bool condition, string msg)
 {
     return(ChoProfile.GetDefaultContext(_instance).AppendLineIf(condition, msg));
 }
예제 #15
0
 public void Append(Exception ex)
 {
     ChoProfile.GetDefaultContext(_instance).Append(ex);
 }
예제 #16
0
 public void Debug(Exception exception)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).Debug(exception);
 }
예제 #17
0
 public ChoProfile(string msg, ChoProfile outerProfile)
     : this(ChoTrace.ChoSwitch.TraceVerbose, msg, outerProfile)
 {
 }
예제 #18
0
 public void WarnFormat(IFormatProvider provider, string format, params object[] args)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).WarnFormat(provider, format, args);
 }
예제 #19
0
 public void Warn(object message, Exception exception)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).Warn(message, exception);
 }
예제 #20
0
 public void Warn(object message)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).Warn(message);
 }
예제 #21
0
 public void InfoFormat(string format, params object[] args)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).InfoFormat(format, args);
 }
예제 #22
0
 public void Error(Exception exception)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).Error(exception);
 }
예제 #23
0
 public ChoBufferProfile(string name, string msg, IChoProfile outerProfile = null)
     : base(name, msg, outerProfile == null ?
            (name != ChoProfile.NULL_PROFILE_NAME && name != ChoProfile.DEFAULT_PROFILE_NAME ? ChoProfile.GetContext(new StackFrame(1)) : outerProfile) : outerProfile)
 {
 }
예제 #24
0
 protected override void Dispose(bool finalize)
 {
     ChoProfile.ResetContext();
 }
예제 #25
0
 public ChoBufferProfile(string msg)
     : base(msg, ChoProfile.GetContext(new StackFrame(1)))
 {
 }
예제 #26
0
 public void AppendIf(bool condition, Exception ex)
 {
     ChoProfile.GetDefaultContext(_instance).AppendIf(condition, ex);
 }
예제 #27
0
 public void Warn(Exception exception)
 {
     ((IChoTrace)ChoProfile.GetDefaultContext(_instance)).Warn(exception);
 }
예제 #28
0
 internal ChoBufferProfile(bool condition, string name, string msg)
     : base(condition, name, msg, ChoProfile.GetContext(new StackFrame(1)))
 {
 }