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); }
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); }
protected override void Dispose(bool finalize) { if (!IsDisposed) { IsDisposed = true; Clear(); if (_condition) { if (ChoTraceSettings.Me.IndentProfiling) { ChoTrace.WriteLineIf(_condition, ChoStackTrace.GetStackFrame(typeof(ChoProfile)), String.Format("}} [{0}] <---", Convert.ToString(DateTime.Now - _startTime)).Indent(_indent)); } else { ChoTrace.WriteLineIf(_condition, ChoStackTrace.GetStackFrame(typeof(ChoProfile)), String.Format("}} [{0}] <---", Convert.ToString(DateTime.Now - _startTime))); } } if (!finalize) { GC.SuppressFinalize(this); } } }
private void _WriteLineIf(bool condition, string msg) { if (ChoTraceSettings.Me.IndentProfiling) { msg = msg.Indent(_indent + 1); } ChoTrace.WriteLineIf(condition, ChoStackTrace.GetStackFrame(typeof(ChoProfile)), msg); }
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; } }
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); }
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); } }
//private static void SetAsNotDisposed(IChoProfile profile, bool dispose) //{ // if (profile == null) // return; // if (profile is ChoBufferProfile) // ((ChoBufferProfile)profile).CanDispose = dispose; // else if (profile is ChoStreamProfile) // ((ChoStreamProfile)profile).CanDispose = dispose; //} private static string GetProfileName(string name, out MemberInfo memberInfo, out string typeProfileFileName, out ChoProfileAttribute memberProfileAttribute, out ChoProfileAttribute typeProfileAttribute) { typeProfileFileName = null; StackFrame stackFrame = ChoStackTrace.GetStackFrame(typeof(ChoProfile).Namespace); memberInfo = stackFrame.GetMethod(); memberProfileAttribute = null; foreach (ChoProfileAttribute profileAttribute in ChoType.GetMemberAttributesByBaseType <ChoProfileAttribute>(memberInfo)) { if (profileAttribute.Name == name) { memberProfileAttribute = profileAttribute; break; } } ChoProfileAttribute emptyTypeProfileAttribute = null; typeProfileAttribute = null; foreach (ChoProfileAttribute profileAttribute in ChoType.GetAttributes <ChoProfileAttribute>(memberInfo.ReflectedType)) { if (String.IsNullOrEmpty(profileAttribute.Name)) { emptyTypeProfileAttribute = profileAttribute; } if (profileAttribute.Name == name) { typeProfileAttribute = profileAttribute; break; } } if (typeProfileAttribute == null) { if (emptyTypeProfileAttribute == null) { typeProfileFileName = GLOBAL_PROFILE_NAME; } else { typeProfileFileName = "{0}_{1}_{2}_{3}".FormatString(name.IsNullOrEmpty() ? "Default" : name, "Type", ChoThreadLocalStorage.Target == null ? 0 : ChoThreadLocalStorage.Target.GetHashCode(), ChoPropertyManager.ExpandProperties(ChoThreadLocalStorage.Target, emptyTypeProfileAttribute.Name)); } } else { typeProfileFileName = "{0}_{1}_{2}_{3}".FormatString(name.IsNullOrEmpty() ? "Default" : name, "Type", ChoThreadLocalStorage.Target == null ? 0 : ChoThreadLocalStorage.Target.GetHashCode(), ChoPropertyManager.ExpandProperties(ChoThreadLocalStorage.Target, typeProfileAttribute.Name)); } if (memberProfileAttribute != null) { return("{0}_{1}_{2}_{3}".FormatString(name.IsNullOrEmpty() ? "Default" : name, memberInfo.Name, ChoThreadLocalStorage.Target == null ? 0 : ChoThreadLocalStorage.Target.GetHashCode(), ChoPropertyManager.ExpandProperties(ChoThreadLocalStorage.Target, memberProfileAttribute.Name))); } else { return(typeProfileFileName); } }
public static void WriteNewLineIf(bool condition) { WriteNewLineIf(condition, ChoStackTrace.GetStackFrame(typeof(ChoTrace))); }
public static bool Write(Exception ex) { // return Write(ex, ChoStackTrace.GetStackFrame(typeof(ChoTrace))); //} //internal static bool Write(Exception ex, StackFrame callerStackFrame) //{ if (ex == null) { return(false); } if (!ChoApplicationException.IsProcessed(ex)) { //if (ChoTraceSwitch.Switch.TraceError) // ChoLogger.Log(callerStackFrame, String.Format("[{0}]: {1}{2}", ChoStackTrace.GetCallerName(), ex.Message, Environment.NewLine)); try { Trace.WriteLineIf(ChoTraceSwitch.Switch.TraceError, String.Format("[{0}]: {1}", ChoStackTrace.GetCallerName(), ChoApplicationException.ToString(ex))); return(true); } catch (Exception exception) { ChoApplication.WriteToEventLog(ChoApplicationException.ToString(exception), EventLogEntryType.Error); } finally { ChoApplicationException.SetProcessed(ex); } } return(false); }
public static void WriteLineIf(bool condition, string msg) { WriteLineIf(condition, ChoStackTrace.GetStackFrame(typeof(ChoProfile)), msg); }
public static bool Write(Exception ex) { return(Write(ex, ChoStackTrace.GetStackFrame(typeof(ChoTrace)))); }