diff --git a/PROMS/Volian.Base.Library/DebugPrint.cs b/PROMS/Volian.Base.Library/DebugPrint.cs index 99e98ee1..9ea40365 100644 --- a/PROMS/Volian.Base.Library/DebugPrint.cs +++ b/PROMS/Volian.Base.Library/DebugPrint.cs @@ -112,4 +112,36 @@ namespace Volian.Base.Library public static bool IsOpen { get { return _MyDebugPrint.IsOpen; } } } + public static class DebugProfile + { + private static DebugPrint _MyDebugPrint = new DebugPrint(); + public static void Open(string fileName) + { _MyDebugPrint.Open(fileName); } + public static void Close() + { _MyDebugPrint.Close(); _MyDebugPrint = null; } + public static void Write(string format, params object[] args) + { _MyDebugPrint.Write(format, args); } + public static void WriteLine(string format, params object[] args) + { _MyDebugPrint.WriteLine(format, args); } + public static void Show() + { _MyDebugPrint.Show(); } + public static bool IsOpen + { get { return _MyDebugPrint.IsOpen; } } + } + public static class DebugDBTrack + { + private static DebugPrint _MyDebugPrint = new DebugPrint(); + public static void Open(string fileName) + { _MyDebugPrint.Open(fileName); } + public static void Close() + { _MyDebugPrint.Close(); _MyDebugPrint = null; } + public static void Write(string format, params object[] args) + { _MyDebugPrint.Write(format, args); } + public static void WriteLine(string format, params object[] args) + { _MyDebugPrint.WriteLine(format, args); } + public static void Show() + { _MyDebugPrint.Show(); } + public static bool IsOpen + { get { return _MyDebugPrint.IsOpen; } } + } } diff --git a/PROMS/Volian.Base.Library/VlnSettings.cs b/PROMS/Volian.Base.Library/VlnSettings.cs index 0ed7c558..62ae8e4d 100644 --- a/PROMS/Volian.Base.Library/VlnSettings.cs +++ b/PROMS/Volian.Base.Library/VlnSettings.cs @@ -91,6 +91,32 @@ namespace Volian.Base.Library } return def; } + public static float GetCommandFloat(string commandName, float def) + { + string[] parameters = System.Environment.CommandLine.Split(" ".ToCharArray()); + foreach (string parameter in parameters) + { + if (parameter.ToUpper().StartsWith("/" + commandName.ToUpper() + "=")) + { + float result = def; + if (float.TryParse(parameter.Substring(commandName.Length + 2), out result)) + return result; + else + return def; + } + } + return def; + } + public static bool GetCommandFlag(string commandName) + { + string[] parameters = System.Environment.CommandLine.Split(" ".ToCharArray()); + foreach (string parameter in parameters) + { + if (parameter.ToUpper().Equals("/" + commandName.ToUpper())) + return true; + } + return false; + } private static void LoadOperatingMode() { string opMode = ConfigurationManager.AppSettings["OperatingMode"]; diff --git a/PROMS/Volian.Base.Library/VlnTimer.cs b/PROMS/Volian.Base.Library/VlnTimer.cs index e5bffd19..4a42afa8 100644 --- a/PROMS/Volian.Base.Library/VlnTimer.cs +++ b/PROMS/Volian.Base.Library/VlnTimer.cs @@ -52,4 +52,168 @@ namespace Volian.Base.Library ShowElapsedTimes(); } } + public static class ProfileTimer + { + private static Stack _MyStack = new Stack(); + + public static Stack MyStack + { + get { return _MyStack; } + set { _MyStack = value; } + } + private static DateTime _StartTime = DateTime.Now; + public static DateTime StartTime + { + get { return _StartTime; } + set { _StartTime = value; } + } + delegate int DoPushTrack(string start); + private static DoPushTrack myDoPush = new DoPushTrack(IgnorePush); + public static int Push(string start) + { + return DoPush(start); + } + private static int DoPush(string start) + { + MyStack.Push(Start); + Start = start; + return MyStack.Count; + } + private static int IgnorePush(string start) + { + Start = start; + return 1; + } + delegate int DoPopTrack(int depth); + private static DoPopTrack myDoPop = new DoPopTrack(IgnorePop); + public static int Pop(int depth) + { + return DoPop(depth); + } + private static int DoPop(int depth) + { + if (MyStack.Count != depth) + Console.WriteLine("Profile Stack Issues {0}", Start); + Start = MyStack.Pop(); + return MyStack.Count; + } + private static int IgnorePop(int depth) + { + return 0; + } + public static int Depth + { + get + { + return MyStack.Count; + } + } + private static Dictionary _TimerTable = new Dictionary(); + public static Dictionary TimerTable + { + get { return ProfileTimer._TimerTable; } + set { ProfileTimer._TimerTable = value; } + } + delegate void DoTrack(string module); + private static DoTrack myDoTrack = new DoTrack(IgnoreModule); + public static void TurnOnTracking(string filename) + { + DebugProfile.Open(VlnSettings.TemporaryFolder + "\\" + filename); + myDoTrack = new DoTrack(TrackModule); + myDoPush = new DoPushTrack(DoPush); + myDoPop = new DoPopTrack(DoPop); + } + public static void TurnOffTracking() + { + myDoTrack = new DoTrack(IgnoreModule); + myDoPush = new DoPushTrack(IgnorePush); + myDoPop = new DoPopTrack(IgnorePop); + } + private static string _Start = "Start"; + public static string Start + { + get { return _Start; } + set + { + myDoTrack(value); + } + } + private static void TrackModule(string module) + { + DateTime dtNext = DateTime.Now; + //Console.WriteLine("{0},'{1}'", TimeSpan.FromTicks(dtNext.Ticks - LastTime.Ticks).TotalSeconds, Description); + AddTimerInfo(_Start, dtNext.Ticks - LastTime.Ticks); + _Start = module; + _LastTime = dtNext; + } + private static void IgnoreModule(string module) + { + _Start = module; + } + private static void AddTimerInfo(string description, long ticks) + { + if (TimerTable.ContainsKey(description)) + TimerTable[description] += ticks; + else + TimerTable.Add(description, ticks); + } + public static void ShowTimerTable() + { + if (DebugProfile.IsOpen) + { + if (MyStack.Count > 0) + { + DebugProfile.WriteLine("{0} Items on Stack", MyStack.Count); + Dictionary stackCount = new Dictionary(); + foreach (string loc in MyStack) + { + if (!stackCount.ContainsKey(loc)) + stackCount.Add(loc, 1); + else + stackCount[loc]++; + } + foreach (string stkey in stackCount.Keys) + DebugProfile.WriteLine("\"{0}\"\t{1}", stkey, stackCount[stkey]); + DebugProfile.WriteLine("-----------------------------------"); + } + long total = 0; + foreach (long ticks in TimerTable.Values) + total += ticks; + SortedDictionary> sList = new SortedDictionary>(); + foreach (string str in TimerTable.Keys) + { + long key = -TimerTable[str]; + if (!sList.ContainsKey(key)) + sList.Add(key, new List()); + sList[key].Add(str); + } + long limit = (95 * total) / 100; + foreach (long lkey in sList.Keys) + { + foreach (string str1 in sList[lkey]) + { + TimeSpan secs = TimeSpan.FromTicks(-lkey); + if (limit > 0) + DebugProfile.WriteLine("\"{0}\"\t{1}\t{2}", str1, secs.TotalSeconds, (100 * secs.Ticks) / total); + limit += lkey; + } + } + DebugProfile.WriteLine("\"Total\"\t{0}", TimeSpan.FromTicks(total).TotalSeconds); + DebugProfile.Show(); + } + } + public static void Reset() + { + _TimerTable = new Dictionary(); + _Start = "Start"; + _LastTime = DateTime.Now; + _MyStack = new Stack(); + } + private static DateTime _LastTime = DateTime.Now; + public static DateTime LastTime + { + get { return _LastTime; } + set { _LastTime = value; } + } + } } diff --git a/PROMS/Volian.Base.Library/vlnStackTrace.cs b/PROMS/Volian.Base.Library/vlnStackTrace.cs index 40be1f5f..5250b9b4 100644 --- a/PROMS/Volian.Base.Library/vlnStackTrace.cs +++ b/PROMS/Volian.Base.Library/vlnStackTrace.cs @@ -140,6 +140,27 @@ namespace Volian.Base.Library return "No Local Method"; } } + public static string CalledFromCSLA + { + get + { + StackTrace st = new StackTrace(true); + StackFrame[] sfs = st.GetFrames(); + int count = 0; + string lastWasCSLA = null; + foreach (StackFrame sf in sfs) + { + string sType = sf.GetMethod().ReflectedType.FullName; + string sMethod = sf.GetMethod().Name; + if (sType.StartsWith("VEPROMS.CSLA.Library") && !sType.StartsWith("VEPROMS.CSLA.Library.Database") + && !sMethod.StartsWith("DataPortal") && !sMethod.StartsWith("SetParentSectionAndDocVersion"))// Only look at Local Methods + lastWasCSLA = string.Format("{0}.{1}[{2}]", sType, sMethod, sf.GetFileLineNumber()); + else + if (lastWasCSLA != null) return lastWasCSLA; + } + return "No CSLA Method"; + } + } private static StackFrame[] _LastSFS; private static int MatchingStackFrame(StackFrame[] sfs) {